You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2021/03/02 18:35:39 UTC

[camel-quarkus] branch master updated: bindy: added native support for methods registered with @DataField

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

aldettinger pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/master by this push:
     new 8aca58c  bindy: added native support for methods registered with @DataField
8aca58c is described below

commit 8aca58c15a2ea7a47ca4ebf89587a1c38ab4bc83
Author: aldettinger <al...@gmail.com>
AuthorDate: Mon Mar 1 18:40:22 2021 +0100

    bindy: added native support for methods registered with @DataField
---
 .../component/bindy/deployment/BindyProcessor.java | 19 ++++++++++++++++
 .../quarkus/component/bindy/it/BindyResource.java  |  6 +++++-
 .../component/bindy/it/model/CharReplacer.java     | 25 ++++++++++++++++++++++
 .../quarkus/component/bindy/it/model/CsvOrder.java | 23 ++++++++++++++++++++
 4 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/extensions/bindy/deployment/src/main/java/org/apache/camel/quarkus/component/bindy/deployment/BindyProcessor.java b/extensions/bindy/deployment/src/main/java/org/apache/camel/quarkus/component/bindy/deployment/BindyProcessor.java
index c79f50a..ccb5f0a 100644
--- a/extensions/bindy/deployment/src/main/java/org/apache/camel/quarkus/component/bindy/deployment/BindyProcessor.java
+++ b/extensions/bindy/deployment/src/main/java/org/apache/camel/quarkus/component/bindy/deployment/BindyProcessor.java
@@ -26,6 +26,7 @@ import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceDirectoryB
 import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
 import org.apache.camel.dataformat.bindy.annotation.BindyConverter;
 import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
 import org.apache.camel.dataformat.bindy.annotation.FixedLengthRecord;
 import org.apache.camel.dataformat.bindy.annotation.FormatFactories;
 import org.apache.camel.dataformat.bindy.annotation.Link;
@@ -118,5 +119,23 @@ class BindyProcessor {
                         producer.produce(new ReflectiveClassBuildItem(false, false, t.name().toString()));
                     }
                 });
+
+        // Registering @DataField.method() classes for fields annotated with @DataField and using the method parameter
+        Stream.of(DataField.class)
+                .map(clazz -> DotName.createSimple(clazz.getName()))
+                .flatMap(dotName -> idx.getAnnotations(dotName).stream())
+                .filter(anno -> anno.value("method") != null && !anno.value("method").asString().isEmpty())
+                .filter(anno -> anno.target() != null && anno.target().kind() == Kind.FIELD)
+                .forEach(anno -> {
+                    String method = anno.value("method").asString();
+                    String methodClazz;
+                    if (method.contains(".")) {
+                        methodClazz = method.substring(0, method.lastIndexOf('.'));
+                    } else {
+                        methodClazz = anno.target().asField().type().toString();
+                    }
+                    LOG.debugf("Registering @DataField.method() class as reflective: %s", methodClazz);
+                    producer.produce(new ReflectiveClassBuildItem(true, false, methodClazz));
+                });
     }
 }
diff --git a/integration-tests/bindy/src/main/java/org/apache/camel/quarkus/component/bindy/it/BindyResource.java b/integration-tests/bindy/src/main/java/org/apache/camel/quarkus/component/bindy/it/BindyResource.java
index 3046a1f..994bf8f 100644
--- a/integration-tests/bindy/src/main/java/org/apache/camel/quarkus/component/bindy/it/BindyResource.java
+++ b/integration-tests/bindy/src/main/java/org/apache/camel/quarkus/component/bindy/it/BindyResource.java
@@ -45,7 +45,7 @@ public class BindyResource {
 
     private static final Logger LOG = Logger.getLogger(BindyResource.class);
 
-    private static final String CSV = "bindy-order-name-16,BINDY-COUNTRY";
+    private static final String CSV = "bindy-order-name-16,BINDY-COUNTRY,fr,A1B2C3";
     private static final String FIXED_LENGTH_ORDER = "BobSpa\r\n";
     private static final String MESSAGE_ORDER = "1=BE.CHM.0018=BEGIN9=2010=22022=458=camel - quarkus - bindy test\r\n";
 
@@ -60,6 +60,8 @@ public class BindyResource {
         CsvOrder order = new CsvOrder();
         order.setNameWithLengthSuffix(NameWithLengthSuffix.ofString("bindy-order-name"));
         order.setCountry("bindy-country");
+        order.setLanguage("fr");
+        order.setClientReference("A1B2C3");
 
         String marshalled = template.requestBody("direct:marshal-csv-record", order, String.class);
 
@@ -77,6 +79,8 @@ public class BindyResource {
         assertNotNull(order.getNameWithLengthSuffix());
         assertEquals("bindy-order-name-16-19", order.getNameWithLengthSuffix().toString());
         assertEquals("B_ND_-C__NTR_", order.getCountry());
+        assertEquals("FR", order.getLanguage());
+        assertEquals("A_B_C_", order.getClientReference());
     }
 
     @Path("/marshalFixedLengthRecordShouldSucceed")
diff --git a/integration-tests/bindy/src/main/java/org/apache/camel/quarkus/component/bindy/it/model/CharReplacer.java b/integration-tests/bindy/src/main/java/org/apache/camel/quarkus/component/bindy/it/model/CharReplacer.java
new file mode 100644
index 0000000..56053d2
--- /dev/null
+++ b/integration-tests/bindy/src/main/java/org/apache/camel/quarkus/component/bindy/it/model/CharReplacer.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.bindy.it.model;
+
+public class CharReplacer {
+
+    public static String replaceDigitsWithUnderScore(String input) {
+        return input.replaceAll("([0-9])", "_");
+    }
+
+}
diff --git a/integration-tests/bindy/src/main/java/org/apache/camel/quarkus/component/bindy/it/model/CsvOrder.java b/integration-tests/bindy/src/main/java/org/apache/camel/quarkus/component/bindy/it/model/CsvOrder.java
index 5cce291..22ce226 100644
--- a/integration-tests/bindy/src/main/java/org/apache/camel/quarkus/component/bindy/it/model/CsvOrder.java
+++ b/integration-tests/bindy/src/main/java/org/apache/camel/quarkus/component/bindy/it/model/CsvOrder.java
@@ -32,6 +32,12 @@ public class CsvOrder {
     @BindyConverter(TestConverter.class)
     private String country;
 
+    @DataField(pos = 3, method = "toUpperCase")
+    private String language;
+
+    @DataField(pos = 4, method = "org.apache.camel.quarkus.component.bindy.it.model.CharReplacer.replaceDigitsWithUnderScore")
+    private String clientReference;
+
     public NameWithLengthSuffix getNameWithLengthSuffix() {
         return nameWithLengthSuffix;
     }
@@ -47,4 +53,21 @@ public class CsvOrder {
     public void setCountry(String country) {
         this.country = country;
     }
+
+    public String getLanguage() {
+        return language;
+    }
+
+    public void setLanguage(String language) {
+        this.language = language;
+    }
+
+    public String getClientReference() {
+        return clientReference;
+    }
+
+    public void setClientReference(String clientReference) {
+        this.clientReference = clientReference;
+    }
+
 }