You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2023/03/22 10:44:05 UTC

[camel-kamelets] branch 3.x-trimming-field created (now 1410e2b5)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch 3.x-trimming-field
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git


      at 1410e2b5 Extract Field: Add a property to trim the field

This branch includes the following new commits:

     new 1410e2b5 Extract Field: Add a property to trim the field

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[camel-kamelets] 01/01: Extract Field: Add a property to trim the field

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch 3.x-trimming-field
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git

commit 1410e2b5851b50be8b15a8304568ec2534072686
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Mar 22 11:39:34 2023 +0100

    Extract Field: Add a property to trim the field
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 kamelets/extract-field-action.kamelet.yaml         | 29 ++++++++++++++++------
 .../kamelets/utils/transform/ExtractField.java     | 10 ++++++++
 .../kamelets/extract-field-action.kamelet.yaml     | 29 ++++++++++++++++------
 3 files changed, 52 insertions(+), 16 deletions(-)

diff --git a/kamelets/extract-field-action.kamelet.yaml b/kamelets/extract-field-action.kamelet.yaml
index 163b1175..56f2c379 100644
--- a/kamelets/extract-field-action.kamelet.yaml
+++ b/kamelets/extract-field-action.kamelet.yaml
@@ -71,6 +71,13 @@ spec:
         default: false
         x-descriptors:
         - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+      trimField:
+        title: Trim Field
+        description: If enabled we return the Raw extracted field
+        type: boolean
+        default: false
+        x-descriptors:
+        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
     type: object
   dependencies:
   - "github:apache.camel-kamelets:camel-kamelets-utils:3.21.0-SNAPSHOT"
@@ -92,6 +99,8 @@ spec:
             value: '{{headerOutputName}}'
           - key: strictHeaderCheck
             value: '{{strictHeaderCheck}}'
+          - key: trimField
+            value: '{{trimField}}'
     from:
       uri: kamelet:source
       steps:
@@ -110,12 +119,16 @@ spec:
           ref: "{{extractField}}"
       - choice:
           when:
-          - simple: "${exchangeProperty[deserialized]} == 'true'"
+          - simple: "${exchangeProperty[trimField]} == 'false'"
             steps:
-            - marshal:
-                json:
-                  library: Jackson
-                  unmarshalType: com.fasterxml.jackson.databind.JsonNode
-            - set-header:
-                name: "Content-Type"
-                constant: "application/json"
+            - choice:
+                when:
+                - simple: "${exchangeProperty[deserialized]} == 'true'"
+                  steps:
+                  - marshal:
+                      json:
+                        library: Jackson
+                        unmarshalType: com.fasterxml.jackson.databind.JsonNode
+                  - set-header:
+                      name: "Content-Type"
+                      constant: "application/json"
diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/ExtractField.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/ExtractField.java
index 80ca041c..bdb636b5 100644
--- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/ExtractField.java
+++ b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/ExtractField.java
@@ -31,6 +31,7 @@ public class ExtractField implements Processor {
     String headerOutputName;
     boolean headerOutput;
     boolean strictHeaderCheck;
+    boolean trimField;
 
     static final String EXTRACTED_FIELD_HEADER = "CamelKameletsExtractFieldName";
 
@@ -64,6 +65,11 @@ public class ExtractField implements Processor {
         } else {
             extractToHeader(ex, body);
         }
+        if (trimField) {
+            ex.setProperty("trimField", "true");
+        } else {
+            ex.setProperty("trimField", "false");
+        }
     }
 
     private void extractToHeader(Exchange ex, Map<Object, Object> body) {
@@ -97,4 +103,8 @@ public class ExtractField implements Processor {
     public void setStrictHeaderCheck(boolean strictHeaderCheck) {
         this.strictHeaderCheck = strictHeaderCheck;
     }
+
+    public void setTrimField(boolean trimField) {
+        this.trimField = trimField;
+    }
 }
diff --git a/library/camel-kamelets/src/main/resources/kamelets/extract-field-action.kamelet.yaml b/library/camel-kamelets/src/main/resources/kamelets/extract-field-action.kamelet.yaml
index 163b1175..56f2c379 100644
--- a/library/camel-kamelets/src/main/resources/kamelets/extract-field-action.kamelet.yaml
+++ b/library/camel-kamelets/src/main/resources/kamelets/extract-field-action.kamelet.yaml
@@ -71,6 +71,13 @@ spec:
         default: false
         x-descriptors:
         - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+      trimField:
+        title: Trim Field
+        description: If enabled we return the Raw extracted field
+        type: boolean
+        default: false
+        x-descriptors:
+        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
     type: object
   dependencies:
   - "github:apache.camel-kamelets:camel-kamelets-utils:3.21.0-SNAPSHOT"
@@ -92,6 +99,8 @@ spec:
             value: '{{headerOutputName}}'
           - key: strictHeaderCheck
             value: '{{strictHeaderCheck}}'
+          - key: trimField
+            value: '{{trimField}}'
     from:
       uri: kamelet:source
       steps:
@@ -110,12 +119,16 @@ spec:
           ref: "{{extractField}}"
       - choice:
           when:
-          - simple: "${exchangeProperty[deserialized]} == 'true'"
+          - simple: "${exchangeProperty[trimField]} == 'false'"
             steps:
-            - marshal:
-                json:
-                  library: Jackson
-                  unmarshalType: com.fasterxml.jackson.databind.JsonNode
-            - set-header:
-                name: "Content-Type"
-                constant: "application/json"
+            - choice:
+                when:
+                - simple: "${exchangeProperty[deserialized]} == 'true'"
+                  steps:
+                  - marshal:
+                      json:
+                        library: Jackson
+                        unmarshalType: com.fasterxml.jackson.databind.JsonNode
+                  - set-header:
+                      name: "Content-Type"
+                      constant: "application/json"