[GitHub] [camel-kafka-connector] luigidemasi opened a new pull request #855: Support camel dataformat configuration for marshaller/unmarshaller #816

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-kafka-connector] luigidemasi opened a new pull request #855: Support camel dataformat configuration for marshaller/unmarshaller #816

GitBox

luigidemasi opened a new pull request #855:
URL: https://github.com/apache/camel-kafka-connector/pull/855


   this pr allow the configuration of a dataformat directly in properties file, something like:
   
   
   ```
   camel.source.unmarshal=fhirJson
   camel.source.unmarshal.fhirJson.fhirVersion=R4
   camel.source.unmarshal.fhirJson.prettyPrint=true
   ```


----------------------------------------------------------------
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:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

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

GitBox

oscerd commented on pull request #855:
URL: https://github.com/apache/camel-kafka-connector/pull/855#issuecomment-759234657


   Can you fix the codestyle?


----------------------------------------------------------------
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:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

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

GitBox
In reply to this post by GitBox

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:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

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

GitBox
In reply to this post by GitBox

luigidemasi commented on pull request #855:
URL: https://github.com/apache/camel-kafka-connector/pull/855#issuecomment-759652739


   > I was under the general impression that this usecase should have worked already using something like:
   >
   > ```
   > camel.dataformat.fhirJson.fhirVersion=R4
   > camel.dataformat.fhirJson.prettyPrint=true
   > ```
   >
   > see https://github.com/apache/camel-kafka-connector/blob/master/core/src/test/java/org/apache/camel/kafkaconnector/DataFormatTest.java#L128
   > Give me some more time to investigate further.
   
   It should work but it doesn't, if you look at the test, you disable validation and then assert that the validation is enabled.
   I think it's a bug on camel-main atuoconfiguration that doesn't bind the dataformat in the registry and a new one is created when the route starts. Opened an issue for this: [CAMEL-16032](https://issues.apache.org/jira/browse/CAMEL-16032)


----------------------------------------------------------------
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:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-kafka-connector] luigidemasi edited a comment on pull request #855: Support camel dataformat configuration for marshaller/unmarshaller #816

GitBox
In reply to this post by GitBox

luigidemasi edited a comment on pull request #855:
URL: https://github.com/apache/camel-kafka-connector/pull/855#issuecomment-759652739


   > I was under the general impression that this usecase should have worked already using something like:
   >
   > ```
   > camel.dataformat.fhirJson.fhirVersion=R4
   > camel.dataformat.fhirJson.prettyPrint=true
   > ```
   >
   > see https://github.com/apache/camel-kafka-connector/blob/master/core/src/test/java/org/apache/camel/kafkaconnector/DataFormatTest.java#L128
   > Give me some more time to investigate further.
   
   It should work but it doesn't, if you look at the test, you disable validation and then assert that the validation is enabled.
   I think it's a bug on camel-main atuoconfiguration that doesn't bind the dataformat in the registry after configuring it and an empty new one is created when the route starts. Opened an issue for this: [CAMEL-16032](https://issues.apache.org/jira/browse/CAMEL-16032)


----------------------------------------------------------------
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:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-kafka-connector] valdar closed pull request #855: Support camel dataformat configuration for marshaller/unmarshaller #816

GitBox
In reply to this post by GitBox

valdar closed pull request #855:
URL: https://github.com/apache/camel-kafka-connector/pull/855


   


----------------------------------------------------------------
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:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

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

GitBox
In reply to this post by GitBox

valdar commented on pull request #855:
URL: https://github.com/apache/camel-kafka-connector/pull/855#issuecomment-760340258


   Thanks a lot for the effort in seeking the root cause of this and fixing it @luigidemasi !
   I close this and the effort is tracked here: https://github.com/apache/camel-kafka-connector/issues/816


----------------------------------------------------------------
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:
[hidden email]