camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/7] camel git commit: CAMEL-9470: Component docs - Some options support using an optional prefix such as consumer.
Date Sun, 03 Jan 2016 16:56:24 GMT
CAMEL-9470: Component docs - Some options support using an optional prefix such as consumer.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0d48cab8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0d48cab8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0d48cab8

Branch: refs/heads/camel-2.16.x
Commit: 0d48cab84216448c95f476ba5585716129038ed4
Parents: 4543960
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Jan 3 14:54:35 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Jan 3 17:53:56 2016 +0100

----------------------------------------------------------------------
 .../camel/catalog/DefaultCamelCatalog.java      | 11 +++++++++
 .../apache/camel/catalog/JSonSchemaHelper.java  | 24 ++++++++++++++++++++
 .../apache/camel/catalog/CamelCatalogTest.java  | 12 ++++++++++
 3 files changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0d48cab8/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index b8dcc92..1c70f40 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -47,6 +47,7 @@ import static org.apache.camel.catalog.JSonSchemaHelper.getNames;
 import static org.apache.camel.catalog.JSonSchemaHelper.getPropertyDefaultValue;
 import static org.apache.camel.catalog.JSonSchemaHelper.getPropertyEnum;
 import static org.apache.camel.catalog.JSonSchemaHelper.getPropertyKind;
+import static org.apache.camel.catalog.JSonSchemaHelper.getPropertyOptionalPrefix;
 import static org.apache.camel.catalog.JSonSchemaHelper.getRow;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyBoolean;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyInteger;
@@ -752,11 +753,21 @@ public class DefaultCamelCatalog implements CamelCatalog {
         // validate all the options
         for (Map.Entry<String, String> property : properties.entrySet()) {
             String name = property.getKey();
+            String optionalPrefix = getPropertyOptionalPrefix(rows, name);
             String value = property.getValue();
             boolean placeholder = value.startsWith("{{") || value.startsWith("${") || value.startsWith("$simple{");
             boolean lookup = value.startsWith("#") && value.length() > 1;
 
             Map<String, String> row = getRow(rows, name);
+
+            // maybe the name was using an optional prefix, and if so then lookup without
the prefix
+            if (row == null && !isEmpty(optionalPrefix)) {
+                if (name.startsWith(optionalPrefix)) {
+                    name = name.substring(optionalPrefix.length());
+                }
+                row = getRow(rows, name);
+            }
+
             if (row == null) {
                 // unknown option
                 result.addUnknown(name);

http://git-wip-us.apache.org/repos/asf/camel/blob/0d48cab8/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
index a4b27df..bbfe7c1 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
@@ -233,6 +233,30 @@ public final class JSonSchemaHelper {
         return null;
     }
 
+    public static String getPropertyOptionalPrefix(List<Map<String, String>>
rows, String name) {
+        for (Map<String, String> row : rows) {
+            String optionalPrefix = null;
+            boolean found = false;
+            if (row.containsKey("optionalPrefix")) {
+                optionalPrefix = row.get("optionalPrefix");
+            }
+            if (row.containsKey("name")) {
+                String key = name;
+                if (optionalPrefix != null && key.startsWith(optionalPrefix)) {
+                    key = key.substring(optionalPrefix.length());
+                    // found the optional prefix so remove it from the key, and lookup again
+                    return getPropertyOptionalPrefix(rows, key);
+                } else {
+                    found = key.equals(row.get("name"));
+                }
+            }
+            if (found) {
+                return optionalPrefix;
+            }
+        }
+        return null;
+    }
+
     public static String getPropertyEnum(List<Map<String, String>> rows, String
name) {
         for (Map<String, String> row : rows) {
             String enums = null;

http://git-wip-us.apache.org/repos/asf/camel/blob/0d48cab8/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index cefa765..0b8923f 100644
--- a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -468,6 +468,18 @@ public class CamelCatalogTest {
         // reference lookup
         result = catalog.validateEndpointProperties("timer://foo?fixedRate=#fixed&delay=#myDelay");
         assertTrue(result.isSuccess());
+
+        // optional consumer. prefix
+        result = catalog.validateEndpointProperties("file:inbox?consumer.delay=5000&consumer.greedy=true");
+        assertTrue(result.isSuccess());
+
+        // optional without consumer. prefix
+        result = catalog.validateEndpointProperties("file:inbox?delay=5000&greedy=true");
+        assertTrue(result.isSuccess());
+
+        // mixed optional without consumer. prefix
+        result = catalog.validateEndpointProperties("file:inbox?delay=5000&consumer.greedy=true");
+        assertTrue(result.isSuccess());
     }
 
     @Test


Mime
View raw message