This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit bbfdd200dba64e092d1ae9ee3dc4591d82be2751 Author: Otavio Rodolfo Piske <[email protected]> AuthorDate: Tue May 16 11:59:56 2023 +0200 (chores) camel-core-catalog: cleanup code duplications --- .../camel/catalog/impl/AbstractCamelCatalog.java | 46 +++++++++++++--------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java index 0f524775208..f634ed47be5 100644 --- a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java +++ b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java @@ -283,16 +283,7 @@ public abstract class AbstractCamelCatalog { } } if (!found) { - result.addInvalidEnum(name, value); - result.addInvalidEnumChoices(name, enums.toArray(new String[0])); - if (suggestionStrategy != null) { - Set<String> names = new LinkedHashSet<>(enums); - String[] suggestions = suggestionStrategy.suggestEndpointOptions(names, value); - if (suggestions != null) { - result.addInvalidEnumSuggestions(name, suggestions); - } - } - + handleNotFound(result, value, name, enums); } } @@ -402,6 +393,30 @@ public abstract class AbstractCamelCatalog { return result; } + private void handleNotFound(EndpointValidationResult result, String value, String name, List<String> enums) { + result.addInvalidEnum(name, value); + result.addInvalidEnumChoices(name, enums.toArray(new String[0])); + if (suggestionStrategy != null) { + Set<String> names = new LinkedHashSet<>(enums); + String[] suggestions = suggestionStrategy.suggestEndpointOptions(names, value); + if (suggestions != null) { + result.addInvalidEnumSuggestions(name, suggestions); + } + } + } + + private void handleNotFound(ConfigurationPropertiesValidationResult result, String value, String longKey, List<String> enums) { + result.addInvalidEnum(longKey, value); + result.addInvalidEnumChoices(longKey, enums.toArray(new String[0])); + if (suggestionStrategy != null) { + Set<String> names = new LinkedHashSet<>(enums); + String[] suggestions = suggestionStrategy.suggestEndpointOptions(names, value); + if (suggestions != null) { + result.addInvalidEnumSuggestions(longKey, suggestions); + } + } + } + public EndpointValidationResult validateEndpointProperties(String uri, boolean ignoreLenientProperties, boolean consumerOnly, boolean producerOnly) { try { URI u = URISupport.normalizeUri(uri); @@ -1228,15 +1243,7 @@ public abstract class AbstractCamelCatalog { } } if (!found) { - result.addInvalidEnum(longKey, value); - result.addInvalidEnumChoices(longKey, enums.toArray(new String[0])); - if (suggestionStrategy != null) { - Set<String> names = new LinkedHashSet<>(enums); - String[] suggestions = suggestionStrategy.suggestEndpointOptions(names, value); - if (suggestions != null) { - result.addInvalidEnumSuggestions(longKey, suggestions); - } - } + handleNotFound(result, value, longKey, enums); } } @@ -1268,6 +1275,7 @@ public abstract class AbstractCamelCatalog { } } + private static boolean acceptConfigurationPropertyKey(String key) { if (key == null) { return false;
