camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/6] camel git commit: Camel catalog - Add did you mean to enum also.
Date Sun, 10 Jan 2016 13:32:46 GMT
Camel catalog - Add did you mean to enum also.


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

Branch: refs/heads/master
Commit: 92a4051224c16e8ee6b238e89d82278f6c77b128
Parents: 0e42ad2
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Jan 10 14:31:08 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Jan 10 14:31:08 2016 +0100

----------------------------------------------------------------------
 .../camel/catalog/DefaultCamelCatalog.java       | 11 +++++++++++
 .../camel/catalog/EndpointValidationResult.java  | 19 ++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/92a40512/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 ae955d6..c178184 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
@@ -23,10 +23,12 @@ import java.lang.reflect.InvocationTargetException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -857,6 +859,15 @@ public class DefaultCamelCatalog implements CamelCatalog {
                     if (!found) {
                         result.addInvalidEnum(name, value);
                         result.addInvalidEnumChoices(name, choices);
+                        if (suggestionStrategy != null) {
+                            Set<String> names = new LinkedHashSet<>();
+                            names.addAll(Arrays.asList(choices));
+                            String[] suggestions = suggestionStrategy.suggestEndpointOptions(names,
value);
+                            if (suggestions != null) {
+                                result.addInvalidEnumSuggestions(name, suggestions);
+                            }
+                        }
+
                     }
                 }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/92a40512/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
index f913c54..d1f31e6 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
@@ -44,6 +44,7 @@ public class EndpointValidationResult implements Serializable {
     private Set<String> required;
     private Map<String, String> invalidEnum;
     private Map<String, String[]> invalidEnumChoices;
+    private Map<String, String[]> invalidEnumSuggestions;
     private Map<String, String> invalidReference;
     private Map<String, String> invalidBoolean;
     private Map<String, String> invalidInteger;
@@ -131,6 +132,13 @@ public class EndpointValidationResult implements Serializable {
         invalidEnumChoices.put(name, choices);
     }
 
+    public void addInvalidEnumSuggestions(String name, String[] suggestions) {
+        if (invalidEnumSuggestions == null) {
+            invalidEnumSuggestions = new LinkedHashMap<String, String[]>();
+        }
+        invalidEnumSuggestions.put(name, suggestions);
+    }
+
     public void addInvalidReference(String name, String value) {
         if (invalidReference == null) {
             invalidReference = new LinkedHashMap<String, String>();
@@ -273,13 +281,22 @@ public class EndpointValidationResult implements Serializable {
         }
         if (invalidEnum != null) {
             for (Map.Entry<String, String> entry : invalidEnum.entrySet()) {
-                String[] choices = invalidEnumChoices.get(entry.getKey());
+                String name = entry.getKey();
+                String[] choices = invalidEnumChoices.get(name);
                 String defaultValue = defaultValues != null ? defaultValues.get(entry.getKey())
: null;
                 String str = Arrays.asList(choices).toString();
                 String msg = "Invalid enum value: " + entry.getValue() + ". Possible values:
" + str;
+                if (invalidEnumSuggestions != null) {
+                    String[] suggestions = invalidEnumSuggestions.get(name);
+                    if (suggestions != null && suggestions.length > 0) {
+                        str = Arrays.asList(suggestions).toString();
+                        msg += ". Did you mean: " + str;
+                    }
+                }
                 if (defaultValue != null) {
                     msg += ". Default value: " + defaultValue;
                 }
+
                 options.put(entry.getKey(), msg);
             }
         }


Mime
View raw message