diff --git a/eventmesh-connectors/eventmesh-connector-dingtalk/src/main/java/org/apache/eventmesh/connector/dingtalk/common/constants/ConnectRecordExtensionKeys.java b/eventmesh-connectors/eventmesh-connector-dingtalk/src/main/java/org/apache/eventmesh/connector/dingtalk/common/constants/ConnectRecordExtensionKeys.java index 733de2c43e..bb6292134b 100644 --- a/eventmesh-connectors/eventmesh-connector-dingtalk/src/main/java/org/apache/eventmesh/connector/dingtalk/common/constants/ConnectRecordExtensionKeys.java +++ b/eventmesh-connectors/eventmesh-connector-dingtalk/src/main/java/org/apache/eventmesh/connector/dingtalk/common/constants/ConnectRecordExtensionKeys.java @@ -22,7 +22,7 @@ */ public interface ConnectRecordExtensionKeys { - String DINGTALK_TEMPLATE_TYPE_KEY = "dingtalktemplatetype"; + String DINGTALK_TEMPLATE_TYPE = "dingtalktemplatetype"; String DINGTALK_MARKDOWN_MESSAGE_TITLE = "dingtalkmarkdownmessagetitle"; } diff --git a/eventmesh-connectors/eventmesh-connector-dingtalk/src/main/java/org/apache/eventmesh/connector/dingtalk/config/DingDingMessageTemplateType.java b/eventmesh-connectors/eventmesh-connector-dingtalk/src/main/java/org/apache/eventmesh/connector/dingtalk/config/DingDingMessageTemplateType.java index 3477c94359..5c26066869 100644 --- a/eventmesh-connectors/eventmesh-connector-dingtalk/src/main/java/org/apache/eventmesh/connector/dingtalk/config/DingDingMessageTemplateType.java +++ b/eventmesh-connectors/eventmesh-connector-dingtalk/src/main/java/org/apache/eventmesh/connector/dingtalk/config/DingDingMessageTemplateType.java @@ -21,23 +21,30 @@ public enum DingDingMessageTemplateType { - PLAIN_TEXT("sampleText"), - MARKDOWN("sampleMarkdown"); + PLAIN_TEXT("text", "sampleText"), + MARKDOWN("markdown", "sampleMarkdown"); + + private final String templateType; private final String templateKey; - DingDingMessageTemplateType(String templateKey) { + DingDingMessageTemplateType(String templateType, String templateKey) { + this.templateType = templateType; this.templateKey = templateKey; } + public String getTemplateType() { + return templateType; + } + public String getTemplateKey() { return templateKey; } - public static DingDingMessageTemplateType of(String templateKey) { + public static DingDingMessageTemplateType of(String templateType) { return Arrays.stream(values()) - .filter(v -> v.getTemplateKey().equals(templateKey)) + .filter(v -> v.getTemplateType().equals(templateType)) .findFirst() - .orElseThrow(() -> new IllegalArgumentException("TemplateKey: " + templateKey + " not found.")); + .orElseThrow(() -> new IllegalArgumentException("TemplateType: " + templateType + " not found.")); } } diff --git a/eventmesh-connectors/eventmesh-connector-dingtalk/src/main/java/org/apache/eventmesh/connector/dingtalk/sink/connector/DingDingSinkConnector.java b/eventmesh-connectors/eventmesh-connector-dingtalk/src/main/java/org/apache/eventmesh/connector/dingtalk/sink/connector/DingDingSinkConnector.java index 864ac3ae6a..ff41855e36 100644 --- a/eventmesh-connectors/eventmesh-connector-dingtalk/src/main/java/org/apache/eventmesh/connector/dingtalk/sink/connector/DingDingSinkConnector.java +++ b/eventmesh-connectors/eventmesh-connector-dingtalk/src/main/java/org/apache/eventmesh/connector/dingtalk/sink/connector/DingDingSinkConnector.java @@ -126,9 +126,9 @@ public void put(List sinkRecords) { new OrgGroupSendHeaders(); orgGroupSendHeaders.xAcsDingtalkAccessToken = accessToken; - String templateTypeKey = record.getExtension(ConnectRecordExtensionKeys.DINGTALK_TEMPLATE_TYPE_KEY); + String templateTypeKey = record.getExtension(ConnectRecordExtensionKeys.DINGTALK_TEMPLATE_TYPE); if (null == templateTypeKey || "null".equals(templateTypeKey)) { - templateTypeKey = DingDingMessageTemplateType.PLAIN_TEXT.getTemplateKey(); + templateTypeKey = DingDingMessageTemplateType.PLAIN_TEXT.getTemplateType(); } DingDingMessageTemplateType templateType = DingDingMessageTemplateType.of(templateTypeKey); diff --git a/eventmesh-connectors/eventmesh-connector-dingtalk/src/test/java/org/apache/eventmesh/connector/dingtalk/sink/connector/DingDingSinkConnectorTest.java b/eventmesh-connectors/eventmesh-connector-dingtalk/src/test/java/org/apache/eventmesh/connector/dingtalk/sink/connector/DingDingSinkConnectorTest.java index d24c51ffa8..38a136748c 100644 --- a/eventmesh-connectors/eventmesh-connector-dingtalk/src/test/java/org/apache/eventmesh/connector/dingtalk/sink/connector/DingDingSinkConnectorTest.java +++ b/eventmesh-connectors/eventmesh-connector-dingtalk/src/test/java/org/apache/eventmesh/connector/dingtalk/sink/connector/DingDingSinkConnectorTest.java @@ -94,8 +94,8 @@ public void testSendMessageToDingDing() throws Exception { RecordOffset offset = new RecordOffset(); ConnectRecord connectRecord = new ConnectRecord(partition, offset, System.currentTimeMillis(), "Hello, EventMesh!".getBytes(StandardCharsets.UTF_8)); - connectRecord.addExtension(ConnectRecordExtensionKeys.DINGTALK_TEMPLATE_TYPE_KEY, - DingDingMessageTemplateType.PLAIN_TEXT.getTemplateKey()); + connectRecord.addExtension(ConnectRecordExtensionKeys.DINGTALK_TEMPLATE_TYPE, + DingDingMessageTemplateType.PLAIN_TEXT.getTemplateType()); records.add(connectRecord); } connector.put(records); diff --git a/eventmesh-connectors/eventmesh-connector-wecom/src/main/java/org/apache/eventmesh/connector/wecom/config/WeComMessageTemplateType.java b/eventmesh-connectors/eventmesh-connector-wecom/src/main/java/org/apache/eventmesh/connector/wecom/config/WeComMessageTemplateType.java index 459d078946..a166022731 100644 --- a/eventmesh-connectors/eventmesh-connector-wecom/src/main/java/org/apache/eventmesh/connector/wecom/config/WeComMessageTemplateType.java +++ b/eventmesh-connectors/eventmesh-connector-wecom/src/main/java/org/apache/eventmesh/connector/wecom/config/WeComMessageTemplateType.java @@ -21,23 +21,30 @@ public enum WeComMessageTemplateType { - PLAIN_TEXT("text"), - MARKDOWN("markdown"); + PLAIN_TEXT("text", "text"), + MARKDOWN("markdown", "markdown"); + + private final String templateType; private final String templateKey; - WeComMessageTemplateType(String templateKey) { + WeComMessageTemplateType(String templateType, String templateKey) { + this.templateType = templateType; this.templateKey = templateKey; } + public String getTemplateType() { + return templateType; + } + public String getTemplateKey() { return templateKey; } - public static WeComMessageTemplateType of(String templateKey) { + public static WeComMessageTemplateType of(String templateType) { return Arrays.stream(values()) - .filter(v -> v.getTemplateKey().equals(templateKey)) + .filter(v -> v.getTemplateType().equals(templateType)) .findFirst() - .orElseThrow(() -> new IllegalArgumentException("TemplateKey: " + templateKey + " not found.")); + .orElseThrow(() -> new IllegalArgumentException("TemplateType: " + templateType + " not found.")); } } diff --git a/eventmesh-connectors/eventmesh-connector-wecom/src/main/java/org/apache/eventmesh/connector/wecom/constants/ConnectRecordExtensionKeys.java b/eventmesh-connectors/eventmesh-connector-wecom/src/main/java/org/apache/eventmesh/connector/wecom/constants/ConnectRecordExtensionKeys.java index 7958a7375d..3c1a9dfa8b 100644 --- a/eventmesh-connectors/eventmesh-connector-wecom/src/main/java/org/apache/eventmesh/connector/wecom/constants/ConnectRecordExtensionKeys.java +++ b/eventmesh-connectors/eventmesh-connector-wecom/src/main/java/org/apache/eventmesh/connector/wecom/constants/ConnectRecordExtensionKeys.java @@ -22,6 +22,6 @@ */ public interface ConnectRecordExtensionKeys { - String WECOM_MESSAGE_TEMPLATE_TYPE_KEY = "weCom:MessageTemplateTypeKey"; + String WECOM_MESSAGE_TEMPLATE_TYPE = "wecomtemplatetype"; } diff --git a/eventmesh-connectors/eventmesh-connector-wecom/src/main/java/org/apache/eventmesh/connector/wecom/sink/connector/WeComSinkConnector.java b/eventmesh-connectors/eventmesh-connector-wecom/src/main/java/org/apache/eventmesh/connector/wecom/sink/connector/WeComSinkConnector.java index bf884916d3..499104e11a 100644 --- a/eventmesh-connectors/eventmesh-connector-wecom/src/main/java/org/apache/eventmesh/connector/wecom/sink/connector/WeComSinkConnector.java +++ b/eventmesh-connectors/eventmesh-connector-wecom/src/main/java/org/apache/eventmesh/connector/wecom/sink/connector/WeComSinkConnector.java @@ -127,8 +127,8 @@ private void sendMessage(ConnectRecord record) { HttpPost httpPost = new HttpPost(target); httpPost.addHeader("Content-Type", EventMeshDataContentType.JSON.getCode()); WeComMessageTemplateType templateType = WeComMessageTemplateType.of( - Optional.ofNullable(record.getExtension(ConnectRecordExtensionKeys.WECOM_MESSAGE_TEMPLATE_TYPE_KEY)) - .orElse(WeComMessageTemplateType.PLAIN_TEXT.getTemplateKey())); + Optional.ofNullable(record.getExtension(ConnectRecordExtensionKeys.WECOM_MESSAGE_TEMPLATE_TYPE)) + .orElse(WeComMessageTemplateType.PLAIN_TEXT.getTemplateType())); Map contentMap = new HashMap<>(); if (WeComMessageTemplateType.PLAIN_TEXT == templateType) { contentMap.put("content", new String((byte[]) record.getData())); diff --git a/eventmesh-connectors/eventmesh-connector-wecom/src/test/java/org/apache/eventmesh/connector/wecom/connector/WeComSinkConnectorTest.java b/eventmesh-connectors/eventmesh-connector-wecom/src/test/java/org/apache/eventmesh/connector/wecom/connector/WeComSinkConnectorTest.java index de363346b3..4cf9f3523b 100644 --- a/eventmesh-connectors/eventmesh-connector-wecom/src/test/java/org/apache/eventmesh/connector/wecom/connector/WeComSinkConnectorTest.java +++ b/eventmesh-connectors/eventmesh-connector-wecom/src/test/java/org/apache/eventmesh/connector/wecom/connector/WeComSinkConnectorTest.java @@ -93,8 +93,8 @@ public void testSendMessageToWeCom() throws IOException { RecordOffset offset = new RecordOffset(); ConnectRecord connectRecord = new ConnectRecord(partition, offset, System.currentTimeMillis(), "Hello, EventMesh!".getBytes(StandardCharsets.UTF_8)); - connectRecord.addExtension(ConnectRecordExtensionKeys.WECOM_MESSAGE_TEMPLATE_TYPE_KEY, - WeComMessageTemplateType.PLAIN_TEXT.getTemplateKey()); + connectRecord.addExtension(ConnectRecordExtensionKeys.WECOM_MESSAGE_TEMPLATE_TYPE, + WeComMessageTemplateType.PLAIN_TEXT.getTemplateType()); records.add(connectRecord); } connector.put(records); diff --git a/eventmesh-examples/src/main/resources/application.properties b/eventmesh-examples/src/main/resources/application.properties index 6c7b727d2e..726d05d192 100644 --- a/eventmesh-examples/src/main/resources/application.properties +++ b/eventmesh-examples/src/main/resources/application.properties @@ -24,4 +24,5 @@ eventmesh.selector.type=nacos eventmesh.selector.nacos.address=127.0.0.1:8848 eventmesh.catalog.name=EVENTMESH-catalog eventmesh.workflow.name=EVENTMESH-workflow -eventmesh.connector.dingtalkTemplateType=sampleText \ No newline at end of file +eventmesh.connector.dingtalkTemplateType=text +eventmesh.connector.wecomTemplateType=text \ No newline at end of file