This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 626232402085bf61be5f83bfa2363d957d8ed5b8 Author: Andrea Cosentino <[email protected]> AuthorDate: Wed Dec 15 13:16:45 2021 +0100 CAMEL-17339 - Avoid List<String> as configuration parameter types in Endpoint configurations - Azure-CosmosDB --- .../cosmosdb/CosmosDbComponentConfigurer.java | 13 +--- .../azure/cosmosdb/CosmosDbEndpointConfigurer.java | 13 +--- .../component/azure/cosmosdb/azure-cosmosdb.json | 4 +- .../azure/cosmosdb/CosmosDbConfiguration.java | 2 - .../cosmosdb/client/CosmosDbClientFactory.java | 19 +++--- .../dsl/AzureCosmosdbComponentBuilderFactory.java | 7 +-- .../dsl/CosmosDbEndpointBuilderFactory.java | 70 +--------------------- 7 files changed, 24 insertions(+), 104 deletions(-) diff --git a/components/camel-azure/camel-azure-cosmosdb/src/generated/java/org/apache/camel/component/azure/cosmosdb/CosmosDbComponentConfigurer.java b/components/camel-azure/camel-azure-cosmosdb/src/generated/java/org/apache/camel/component/azure/cosmosdb/CosmosDbComponentConfigurer.java index eeb0309..039a76b 100644 --- a/components/camel-azure/camel-azure-cosmosdb/src/generated/java/org/apache/camel/component/azure/cosmosdb/CosmosDbComponentConfigurer.java +++ b/components/camel-azure/camel-azure-cosmosdb/src/generated/java/org/apache/camel/component/azure/cosmosdb/CosmosDbComponentConfigurer.java @@ -75,7 +75,7 @@ public class CosmosDbComponentConfigurer extends PropertyConfigurerSupport imple case "multipleWriteRegionsEnabled": getOrCreateConfiguration(target).setMultipleWriteRegionsEnabled(property(camelContext, boolean.class, value)); return true; case "operation": getOrCreateConfiguration(target).setOperation(property(camelContext, org.apache.camel.component.azure.cosmosdb.CosmosDbOperationsDefinition.class, value)); return true; case "preferredregions": - case "preferredRegions": getOrCreateConfiguration(target).setPreferredRegions(property(camelContext, java.util.List.class, value)); return true; + case "preferredRegions": getOrCreateConfiguration(target).setPreferredRegions(property(camelContext, java.lang.String.class, value)); return true; case "query": getOrCreateConfiguration(target).setQuery(property(camelContext, java.lang.String.class, value)); return true; case "queryrequestoptions": case "queryRequestOptions": getOrCreateConfiguration(target).setQueryRequestOptions(property(camelContext, com.azure.cosmos.models.CosmosQueryRequestOptions.class, value)); return true; @@ -142,7 +142,7 @@ public class CosmosDbComponentConfigurer extends PropertyConfigurerSupport imple case "multipleWriteRegionsEnabled": return boolean.class; case "operation": return org.apache.camel.component.azure.cosmosdb.CosmosDbOperationsDefinition.class; case "preferredregions": - case "preferredRegions": return java.util.List.class; + case "preferredRegions": return java.lang.String.class; case "query": return java.lang.String.class; case "queryrequestoptions": case "queryRequestOptions": return com.azure.cosmos.models.CosmosQueryRequestOptions.class; @@ -216,14 +216,5 @@ public class CosmosDbComponentConfigurer extends PropertyConfigurerSupport imple default: return null; } } - - @Override - public Object getCollectionValueType(Object target, String name, boolean ignoreCase) { - switch (ignoreCase ? name.toLowerCase() : name) { - case "preferredregions": - case "preferredRegions": return java.lang.String.class; - default: return null; - } - } } diff --git a/components/camel-azure/camel-azure-cosmosdb/src/generated/java/org/apache/camel/component/azure/cosmosdb/CosmosDbEndpointConfigurer.java b/components/camel-azure/camel-azure-cosmosdb/src/generated/java/org/apache/camel/component/azure/cosmosdb/CosmosDbEndpointConfigurer.java index b3d92ad..ea0af3b 100644 --- a/components/camel-azure/camel-azure-cosmosdb/src/generated/java/org/apache/camel/component/azure/cosmosdb/CosmosDbEndpointConfigurer.java +++ b/components/camel-azure/camel-azure-cosmosdb/src/generated/java/org/apache/camel/component/azure/cosmosdb/CosmosDbEndpointConfigurer.java @@ -69,7 +69,7 @@ public class CosmosDbEndpointConfigurer extends PropertyConfigurerSupport implem case "multipleWriteRegionsEnabled": target.getConfiguration().setMultipleWriteRegionsEnabled(property(camelContext, boolean.class, value)); return true; case "operation": target.getConfiguration().setOperation(property(camelContext, org.apache.camel.component.azure.cosmosdb.CosmosDbOperationsDefinition.class, value)); return true; case "preferredregions": - case "preferredRegions": target.getConfiguration().setPreferredRegions(property(camelContext, java.util.List.class, value)); return true; + case "preferredRegions": target.getConfiguration().setPreferredRegions(property(camelContext, java.lang.String.class, value)); return true; case "query": target.getConfiguration().setQuery(property(camelContext, java.lang.String.class, value)); return true; case "queryrequestoptions": case "queryRequestOptions": target.getConfiguration().setQueryRequestOptions(property(camelContext, com.azure.cosmos.models.CosmosQueryRequestOptions.class, value)); return true; @@ -137,7 +137,7 @@ public class CosmosDbEndpointConfigurer extends PropertyConfigurerSupport implem case "multipleWriteRegionsEnabled": return boolean.class; case "operation": return org.apache.camel.component.azure.cosmosdb.CosmosDbOperationsDefinition.class; case "preferredregions": - case "preferredRegions": return java.util.List.class; + case "preferredRegions": return java.lang.String.class; case "query": return java.lang.String.class; case "queryrequestoptions": case "queryRequestOptions": return com.azure.cosmos.models.CosmosQueryRequestOptions.class; @@ -212,14 +212,5 @@ public class CosmosDbEndpointConfigurer extends PropertyConfigurerSupport implem default: return null; } } - - @Override - public Object getCollectionValueType(Object target, String name, boolean ignoreCase) { - switch (ignoreCase ? name.toLowerCase() : name) { - case "preferredregions": - case "preferredRegions": return java.lang.String.class; - default: return null; - } - } } diff --git a/components/camel-azure/camel-azure-cosmosdb/src/generated/resources/org/apache/camel/component/azure/cosmosdb/azure-cosmosdb.json b/components/camel-azure/camel-azure-cosmosdb/src/generated/resources/org/apache/camel/component/azure/cosmosdb/azure-cosmosdb.json index d4dccf1..79a9812 100644 --- a/components/camel-azure/camel-azure-cosmosdb/src/generated/resources/org/apache/camel/component/azure/cosmosdb/azure-cosmosdb.json +++ b/components/camel-azure/camel-azure-cosmosdb/src/generated/resources/org/apache/camel/component/azure/cosmosdb/azure-cosmosdb.json @@ -33,7 +33,7 @@ "createDatabaseIfNotExists": { "kind": "property", "displayName": "Create Database If Not Exists", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets if the component should create Cosmos database automatically [...] "databaseEndpoint": { "kind": "property", "displayName": "Database Endpoint", "group": "common", "label": "common", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets the Azure Cosmos database endpoint the component will connect to." }, "multipleWriteRegionsEnabled": { "kind": "property", "displayName": "Multiple Write Regions Enabled", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets the flag to enable writes on any regions for geo-replicate [...] - "preferredRegions": { "kind": "property", "displayName": "Preferred Regions", "group": "common", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<java.lang.String>", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets the preferred regions for geo-replicated database accounts. For example, East US [...] + "preferredRegions": { "kind": "property", "displayName": "Preferred Regions", "group": "common", "label": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets the preferred regions for geo-replicated database accounts. For example, East US as the preferre [...] "readRequestsFallbackEnabled": { "kind": "property", "displayName": "Read Requests Fallback Enabled", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets whether to allow for reads to go to multiple regions confi [...] "throughputProperties": { "kind": "property", "displayName": "Throughput Properties", "group": "common", "label": "common", "required": false, "type": "object", "javaType": "com.azure.cosmos.models.ThroughputProperties", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets throughput of the resources in the Azure Cosmos DB service." }, "bridgeErrorHandler": { "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a me [...] @@ -65,7 +65,7 @@ "createDatabaseIfNotExists": { "kind": "parameter", "displayName": "Create Database If Not Exists", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets if the component should create Cosmos database automaticall [...] "databaseEndpoint": { "kind": "parameter", "displayName": "Database Endpoint", "group": "common", "label": "common", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets the Azure Cosmos database endpoint the component will connect to." }, "multipleWriteRegionsEnabled": { "kind": "parameter", "displayName": "Multiple Write Regions Enabled", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets the flag to enable writes on any regions for geo-replicat [...] - "preferredRegions": { "kind": "parameter", "displayName": "Preferred Regions", "group": "common", "label": "common", "required": false, "type": "array", "javaType": "java.util.List<java.lang.String>", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets the preferred regions for geo-replicated database accounts. For example, East US [...] + "preferredRegions": { "kind": "parameter", "displayName": "Preferred Regions", "group": "common", "label": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets the preferred regions for geo-replicated database accounts. For example, East US as the preferr [...] "readRequestsFallbackEnabled": { "kind": "parameter", "displayName": "Read Requests Fallback Enabled", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets whether to allow for reads to go to multiple regions conf [...] "throughputProperties": { "kind": "parameter", "displayName": "Throughput Properties", "group": "common", "label": "common", "required": false, "type": "object", "javaType": "com.azure.cosmos.models.ThroughputProperties", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration", "configurationField": "configuration", "description": "Sets throughput of the resources in the Azure Cosmos DB service." }, "bridgeErrorHandler": { "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a m [...] diff --git a/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConfiguration.java b/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConfiguration.java index c8d099b..2de0ae7 100644 --- a/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConfiguration.java +++ b/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConfiguration.java @@ -16,8 +16,6 @@ */ package org.apache.camel.component.azure.cosmosdb; -import java.util.List; - import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.CosmosAsyncClient; import com.azure.cosmos.models.ChangeFeedProcessorOptions; diff --git a/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/client/CosmosDbClientFactory.java b/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/client/CosmosDbClientFactory.java index 9d43858..192aea0 100644 --- a/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/client/CosmosDbClientFactory.java +++ b/components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/client/CosmosDbClientFactory.java @@ -16,13 +16,14 @@ */ package org.apache.camel.component.azure.cosmosdb.client; +import java.util.stream.Collectors; +import java.util.stream.Stream; + import com.azure.cosmos.CosmosAsyncClient; import com.azure.cosmos.CosmosClient; import com.azure.cosmos.CosmosClientBuilder; import org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration; - -import java.util.stream.Collectors; -import java.util.stream.Stream; +import org.apache.camel.util.ObjectHelper; public final class CosmosDbClientFactory { @@ -40,17 +41,21 @@ public final class CosmosDbClientFactory { } private static CosmosClientBuilder createBasicClient(final CosmosDbConfiguration configuration) { - return new CosmosClientBuilder() + CosmosClientBuilder builder = new CosmosClientBuilder() .key(configuration.getAccountKey()) .endpoint(configuration.getDatabaseEndpoint()) .contentResponseOnWriteEnabled(configuration.isContentResponseOnWriteEnabled()) .consistencyLevel(configuration.getConsistencyLevel()) - .preferredRegions(Stream.of(configuration.getPreferredRegions().split(",")) - .map(String::trim) - .collect(Collectors.toList())) .connectionSharingAcrossClientsEnabled(configuration.isConnectionSharingAcrossClientsEnabled()) .clientTelemetryEnabled(configuration.isClientTelemetryEnabled()) .multipleWriteRegionsEnabled(configuration.isMultipleWriteRegionsEnabled()) .readRequestsFallbackEnabled(configuration.isReadRequestsFallbackEnabled()); + if (ObjectHelper.isNotEmpty(configuration.getPreferredRegions())) { + builder.preferredRegions(Stream.of(configuration.getPreferredRegions().split(",")) + .map(String::trim) + .collect(Collectors.toList())); + } + + return builder; } } diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AzureCosmosdbComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AzureCosmosdbComponentBuilderFactory.java index b3e7c9c..186f2a2 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AzureCosmosdbComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AzureCosmosdbComponentBuilderFactory.java @@ -270,8 +270,7 @@ public interface AzureCosmosdbComponentBuilderFactory { * the SDK will prefer to use the regions in the container in the order * they are specified to perform operations. * - * The option is a: - * <code>java.util.List&lt;java.lang.String&gt;</code> type. + * The option is a: <code>java.lang.String</code> type. * * Group: common * @@ -279,7 +278,7 @@ public interface AzureCosmosdbComponentBuilderFactory { * @return the dsl builder */ default AzureCosmosdbComponentBuilder preferredRegions( - java.util.List<java.lang.String> preferredRegions) { + java.lang.String preferredRegions) { doSetProperty("preferredRegions", preferredRegions); return this; } @@ -634,7 +633,7 @@ public interface AzureCosmosdbComponentBuilderFactory { case "createDatabaseIfNotExists": getOrCreateConfiguration((CosmosDbComponent) component).setCreateDatabaseIfNotExists((boolean) value); return true; case "databaseEndpoint": getOrCreateConfiguration((CosmosDbComponent) component).setDatabaseEndpoint((java.lang.String) value); return true; case "multipleWriteRegionsEnabled": getOrCreateConfiguration((CosmosDbComponent) component).setMultipleWriteRegionsEnabled((boolean) value); return true; - case "preferredRegions": getOrCreateConfiguration((CosmosDbComponent) component).setPreferredRegions((java.util.List) value); return true; + case "preferredRegions": getOrCreateConfiguration((CosmosDbComponent) component).setPreferredRegions((java.lang.String) value); return true; case "readRequestsFallbackEnabled": getOrCreateConfiguration((CosmosDbComponent) component).setReadRequestsFallbackEnabled((boolean) value); return true; case "throughputProperties": getOrCreateConfiguration((CosmosDbComponent) component).setThroughputProperties((com.azure.cosmos.models.ThroughputProperties) value); return true; case "bridgeErrorHandler": ((CosmosDbComponent) component).setBridgeErrorHandler((boolean) value); return true; diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CosmosDbEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CosmosDbEndpointBuilderFactory.java index f9471df..6836400 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CosmosDbEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CosmosDbEndpointBuilderFactory.java @@ -16,7 +16,6 @@ */ package org.apache.camel.builder.endpoint.dsl; -import java.util.List; import javax.annotation.Generated; import org.apache.camel.ExchangePattern; import org.apache.camel.builder.EndpointConsumerBuilder; @@ -417,28 +416,7 @@ public interface CosmosDbEndpointBuilderFactory { * the SDK will prefer to use the regions in the container in the order * they are specified to perform operations. * - * The option is a: - * <code>java.util.List&lt;java.lang.String&gt;</code> type. - * - * Group: common - * - * @param preferredRegions the value to set - * @return the dsl builder - */ - default CosmosDbEndpointConsumerBuilder preferredRegions( - List<String> preferredRegions) { - doSetProperty("preferredRegions", preferredRegions); - return this; - } - /** - * Sets the preferred regions for geo-replicated database accounts. For - * example, East US as the preferred region. When - * EnableEndpointDiscovery is true and PreferredRegions is non-empty, - * the SDK will prefer to use the regions in the container in the order - * they are specified to perform operations. - * - * The option will be converted to a - * <code>java.util.List&lt;java.lang.String&gt;</code> type. + * The option is a: <code>java.lang.String</code> type. * * Group: common * @@ -1221,28 +1199,7 @@ public interface CosmosDbEndpointBuilderFactory { * the SDK will prefer to use the regions in the container in the order * they are specified to perform operations. * - * The option is a: - * <code>java.util.List&lt;java.lang.String&gt;</code> type. - * - * Group: common - * - * @param preferredRegions the value to set - * @return the dsl builder - */ - default CosmosDbEndpointProducerBuilder preferredRegions( - List<String> preferredRegions) { - doSetProperty("preferredRegions", preferredRegions); - return this; - } - /** - * Sets the preferred regions for geo-replicated database accounts. For - * example, East US as the preferred region. When - * EnableEndpointDiscovery is true and PreferredRegions is non-empty, - * the SDK will prefer to use the regions in the container in the order - * they are specified to perform operations. - * - * The option will be converted to a - * <code>java.util.List&lt;java.lang.String&gt;</code> type. + * The option is a: <code>java.lang.String</code> type. * * Group: common * @@ -1930,28 +1887,7 @@ public interface CosmosDbEndpointBuilderFactory { * the SDK will prefer to use the regions in the container in the order * they are specified to perform operations. * - * The option is a: - * <code>java.util.List&lt;java.lang.String&gt;</code> type. - * - * Group: common - * - * @param preferredRegions the value to set - * @return the dsl builder - */ - default CosmosDbEndpointBuilder preferredRegions( - List<String> preferredRegions) { - doSetProperty("preferredRegions", preferredRegions); - return this; - } - /** - * Sets the preferred regions for geo-replicated database accounts. For - * example, East US as the preferred region. When - * EnableEndpointDiscovery is true and PreferredRegions is non-empty, - * the SDK will prefer to use the regions in the container in the order - * they are specified to perform operations. - * - * The option will be converted to a - * <code>java.util.List&lt;java.lang.String&gt;</code> type. + * The option is a: <code>java.lang.String</code> type. * * Group: common *
