You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/01/13 11:16:43 UTC

[GitHub] [camel-kafka-connector] valdar commented on a change in pull request #855: Support camel dataformat configuration for marshaller/unmarshaller #816

valdar commented on a change in pull request #855:
URL: https://github.com/apache/camel-kafka-connector/pull/855#discussion_r556445188



##########
File path: core/src/main/java/org/apache/camel/kafkaconnector/utils/CamelKafkaConnectDataformat.java
##########
@@ -35,6 +80,147 @@ public CamelKafkaConnectDataformatKind getDataformatKind() {
 
     public enum CamelKafkaConnectDataformatKind {
         MARSHALL,
-        UNMARSHALL
+        UNMARSHALL;
+    }
+
+    public static void configureMarshalDataformat(RouteDefinition rd, CamelContext context, String dataFormatName, Properties camelProperties) {
+        Predicate<String> keyFilter = key -> key.contains(".marshal." + dataFormatName + ".");
+        DataFormatDefinition dfd = configureDataformat(context, dataFormatName, keyFilter, camelProperties);
+        if (dfd != null) {
+            rd.marshal(dfd);
+        } else {
+            rd.marshal(dataFormatName);
+        }
+    }
+
+
+    public static void configureUnmarshalDataformat(RouteDefinition rd, CamelContext context, String dataFormatName, Properties camelProperties) {
+        Predicate<String> keyFilter = key -> key.contains(".unmarshal." + dataFormatName + ".");
+        DataFormatDefinition dfd = configureDataformat(context, dataFormatName, keyFilter, camelProperties);
+        if (dfd != null) {
+            rd.unmarshal(dfd);
+        } else {
+            rd.unmarshal(dataFormatName);
+        }
+    }
+
+    public static DataFormatDefinition configureDataformat(CamelContext context, String dataFormatName, Predicate<String> keyFilter, Properties camelProperties) {
+        Map<String, Object> dataFormatProps = camelProperties.stringPropertyNames()
+                .stream()
+                .filter(keyFilter)
+                .collect(Collectors.toMap(key -> key.substring(key.lastIndexOf(".") + 1), key -> camelProperties.get(key)));
+
+        DataFormatDefinition dataformat;
+
+        switch (dataFormatName) {

Review comment:
       I hope this switch case could be avoided by something on the line of `context.createDataFormat(dataFormatName)`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org