camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [7/8] camel git commit: Camel catalog - Add api to validate endpoint uri
Date Mon, 21 Dec 2015 12:43:01 GMT
Camel catalog - Add api to validate endpoint uri


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

Branch: refs/heads/camel-2.16.x
Commit: 521424b7cadde6e76ebd77470624e9c4a561f473
Parents: 7caf775
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Dec 20 15:59:02 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Dec 21 13:42:38 2015 +0100

----------------------------------------------------------------------
 .../apache/camel/catalog/DefaultCamelCatalog.java |  4 +++-
 .../apache/camel/catalog/ValidationResult.java    | 18 ++++++++++++++++--
 2 files changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/521424b7/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 2580536..efb5db4 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
@@ -691,8 +691,9 @@ public class DefaultCamelCatalog implements CamelCatalog {
                 // but we can only check if the value is not a placeholder
                 String enums = getPropertyEnum(rows, name);
                 if (!placeholder && enums != null) {
+                    String[] choices = enums.split(",");
                     boolean found = false;
-                    for (String s : enums.split(",")) {
+                    for (String s : choices) {
                         if (value.equalsIgnoreCase(s)) {
                             found = true;
                             break;
@@ -700,6 +701,7 @@ public class DefaultCamelCatalog implements CamelCatalog {
                     }
                     if (!found) {
                         result.addInvalidEnum(name, value);
+                        result.addInvalidEnumChoices(name, choices);
                     }
                 }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/521424b7/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java
index 4450133..40aacb3 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java
@@ -17,11 +17,15 @@
 package org.apache.camel.catalog;
 
 import java.io.Serializable;
+import java.util.Arrays;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 
+/**
+ * Details result of validating endpoint uri.
+ */
 public class ValidationResult implements Serializable {
 
     private final String uri;
@@ -34,6 +38,7 @@ public class ValidationResult implements Serializable {
     private Set<String> unknown;
     private Set<String> required;
     private Map<String, String> invalidEnum;
+    private Map<String, String[]> invalidEnumChoices;
     private Map<String, String> invalidBoolean;
     private Map<String, String> invalidInteger;
     private Map<String, String> invalidNumber;
@@ -44,7 +49,7 @@ public class ValidationResult implements Serializable {
 
     public boolean isSuccess() {
         return syntaxError == null && unknownComponent == null
-                && unknown == null && required == null && invalidEnum
== null
+                && unknown == null && required == null && invalidEnum
== null && invalidEnumChoices == null
                 && invalidBoolean == null && invalidInteger == null &&
invalidNumber == null;
     }
 
@@ -77,6 +82,13 @@ public class ValidationResult implements Serializable {
         invalidEnum.put(name, value);
     }
 
+    public void addInvalidEnumChoices(String name, String[] choices) {
+        if (invalidEnumChoices == null) {
+            invalidEnumChoices = new LinkedHashMap<String, String[]>();
+        }
+        invalidEnumChoices.put(name, choices);
+    }
+
     public void addInvalidBoolean(String name, String value) {
         if (invalidBoolean == null) {
             invalidBoolean = new LinkedHashMap<String, String>();;
@@ -160,7 +172,9 @@ public class ValidationResult implements Serializable {
         }
         if (invalidEnum != null) {
             for (Map.Entry<String, String> entry : invalidEnum.entrySet()) {
-                options.put(entry.getKey(), "Invalid enum value: " + entry.getValue());
+                String[] choices = invalidEnumChoices.get(entry.getKey());
+                String str = Arrays.asList(choices).toString();
+                options.put(entry.getKey(), "Invalid enum value: " + entry.getValue() + ".
Possible values: " + str);
             }
         }
         if (invalidBoolean != null) {


Mime
View raw message