From d543798e99290336f194cb44c6e13b1d8e6766ec Mon Sep 17 00:00:00 2001 From: Christoph Deppisch Date: Tue, 14 Nov 2023 15:51:21 +0100 Subject: [PATCH] fix(#1716): Remove obsolete data type transformer implementations - Data type transformer implementations have been moved to the Camel core project - Using those transformers in Camel works with version 4.2.0 onwards --- kamelets/avro-deserialize-action.kamelet.yaml | 3 +- kamelets/avro-serialize-action.kamelet.yaml | 3 +- kamelets/data-type-action.kamelet.yaml | 1 - .../protobuf-deserialize-action.kamelet.yaml | 2 +- .../protobuf-serialize-action.kamelet.yaml | 2 +- .../kamelets/catalog/KameletsCatalogTest.java | 4 +- library/camel-kamelets-utils/pom.xml | 27 +- .../utils/format/converter/avro/Avro.java | 29 -- .../converter/avro/AvroBinaryDataType.java | 83 ---- .../converter/avro/AvroSchemaResolver.java | 160 ------- .../converter/avro/AvroStructDataType.java | 72 --- .../converter/aws2/ddb/Ddb2JsonInputType.java | 241 ---------- .../aws2/s3/AWS2S3CloudEventOutputType.java | 46 -- .../aws2/sqs/AWS2SQSCloudEventOutputType.java | 47 -- .../AzureStorageBlobCloudEventOutputType.java | 47 -- .../google/sheets/CellCoordinate.java | 195 -------- .../GoogleSheetsJsonStructDataType.java | 337 -------------- .../google/sheets/RangeCoordinate.java | 149 ------ .../GoogleStorageCloudEventOutputType.java | 47 -- .../http/HttpCloudEventOutputType.java | 54 --- .../utils/format/converter/json/Json.java | 107 ----- .../format/converter/json/JsonDataType.java | 51 --- .../converter/json/JsonFormatSchema.java | 22 - .../converter/json/JsonSchemaResolver.java | 155 ------- .../converter/json/JsonStructDataType.java | 66 --- .../converter/pojo/JavaObjectDataType.java | 108 ----- .../format/converter/utils/CloudEvents.java | 45 -- .../format/converter/utils/PojoHelper.java | 89 ---- .../format/converter/utils/SchemaHelper.java | 34 -- .../schema/DelegatingSchemaResolver.java | 6 +- .../protobuf/Protobuf.java | 2 +- .../protobuf/ProtobufSchemaResolver.java | 4 +- .../org/apache/camel/DataTypeConverter | 25 - .../datatype/transformer/application-json | 18 - .../transformer/application-x-java-object | 18 - .../datatype/transformer/application-x-struct | 18 - .../camel/datatype/transformer/avro-binary | 18 - .../camel/datatype/transformer/avro-x-struct | 18 - .../transformer/aws2-ddb-application-json | 18 - .../aws2-s3-application-cloudevents | 18 - .../aws2-sqs-application-cloudevents | 18 - ...azure-storage-blob-application-cloudevents | 18 - .../google-sheets-application-x-struct | 18 - .../google-storage-application-cloudevents | 18 - .../transformer/http-application-cloudevents | 18 - .../aws2/ddb/Ddb2JsonInputTypeTest.java | 217 --------- .../GoogleSheetsJsonStructDataTypeTest.java | 429 ------------------ .../http/HttpCloudEventOutputTypeTest.java | 70 --- .../avro-deserialize-action.kamelet.yaml | 3 +- .../avro-serialize-action.kamelet.yaml | 3 +- .../kamelets/data-type-action.kamelet.yaml | 1 - .../protobuf-deserialize-action.kamelet.yaml | 2 +- .../protobuf-serialize-action.kamelet.yaml | 2 +- pom.xml | 4 +- test/Makefile | 2 +- test/avro-data-type/avro-to-log-pipe.yaml | 9 + test/avro-data-type/json-to-avro-pipe.yaml | 3 + test/aws-s3/aws-s3-knative-broker.feature | 2 +- .../data-type-action-pipe.yaml | 3 + 59 files changed, 36 insertions(+), 3193 deletions(-) delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/Avro.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroBinaryDataType.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroSchemaResolver.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroStructDataType.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/ddb/Ddb2JsonInputType.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/s3/AWS2S3CloudEventOutputType.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/sqs/AWS2SQSCloudEventOutputType.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/azure/storage/blob/AzureStorageBlobCloudEventOutputType.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/CellCoordinate.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/GoogleSheetsJsonStructDataType.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/RangeCoordinate.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/storage/GoogleStorageCloudEventOutputType.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/http/HttpCloudEventOutputType.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/Json.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonDataType.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonFormatSchema.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonSchemaResolver.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonStructDataType.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/pojo/JavaObjectDataType.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/utils/CloudEvents.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/utils/PojoHelper.java delete mode 100644 library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/utils/SchemaHelper.java rename library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/{converter => schema}/protobuf/Protobuf.java (94%) rename library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/{converter => schema}/protobuf/ProtobufSchemaResolver.java (97%) delete mode 100644 library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/DataTypeConverter delete mode 100644 library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/application-json delete mode 100644 library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/application-x-java-object delete mode 100644 library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/application-x-struct delete mode 100644 library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/avro-binary delete mode 100644 library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/avro-x-struct delete mode 100644 library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-ddb-application-json delete mode 100644 library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-s3-application-cloudevents delete mode 100644 library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-sqs-application-cloudevents delete mode 100644 library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/azure-storage-blob-application-cloudevents delete mode 100644 library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/google-sheets-application-x-struct delete mode 100644 library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/google-storage-application-cloudevents delete mode 100644 library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/http-application-cloudevents delete mode 100644 library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/aws2/ddb/Ddb2JsonInputTypeTest.java delete mode 100644 library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/GoogleSheetsJsonStructDataTypeTest.java delete mode 100644 library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/http/HttpCloudEventOutputTypeTest.java diff --git a/kamelets/avro-deserialize-action.kamelet.yaml b/kamelets/avro-deserialize-action.kamelet.yaml index 31620ff9b..2115ab061 100644 --- a/kamelets/avro-deserialize-action.kamelet.yaml +++ b/kamelets/avro-deserialize-action.kamelet.yaml @@ -47,14 +47,13 @@ spec: x-descriptors: - 'urn:alm:descriptor:com.tectonic.ui:checkbox' dependencies: - - "mvn:org.apache.camel.kamelets:camel-kamelets-utils:4.2.0-SNAPSHOT" - "camel:kamelet" - "camel:core" - "camel:jackson-avro" template: beans: - name: schemaResolver - type: "#class:org.apache.camel.kamelets.utils.format.converter.avro.AvroSchemaResolver" + type: "#class:org.apache.camel.component.jackson.avro.transform.AvroSchemaResolver" property: - key: validate value: '{{validate}}' diff --git a/kamelets/avro-serialize-action.kamelet.yaml b/kamelets/avro-serialize-action.kamelet.yaml index 4a70cc531..6cfbe17f3 100644 --- a/kamelets/avro-serialize-action.kamelet.yaml +++ b/kamelets/avro-serialize-action.kamelet.yaml @@ -47,14 +47,13 @@ spec: x-descriptors: - 'urn:alm:descriptor:com.tectonic.ui:checkbox' dependencies: - - "mvn:org.apache.camel.kamelets:camel-kamelets-utils:4.2.0-SNAPSHOT" - "camel:kamelet" - "camel:core" - "camel:jackson-avro" template: beans: - name: schemaResolver - type: "#class:org.apache.camel.kamelets.utils.format.converter.avro.AvroSchemaResolver" + type: "#class:org.apache.camel.component.jackson.avro.transform.AvroSchemaResolver" property: - key: validate value: '{{validate}}' diff --git a/kamelets/data-type-action.kamelet.yaml b/kamelets/data-type-action.kamelet.yaml index 35e9124e6..1cc13943c 100644 --- a/kamelets/data-type-action.kamelet.yaml +++ b/kamelets/data-type-action.kamelet.yaml @@ -45,7 +45,6 @@ spec: description: Defines the data type that will be applied by this action. Apache Camel and the Kamelet catalog support different data types and performs automatic message conversion according to the given type. type: string dependencies: - - "mvn:org.apache.camel.kamelets:camel-kamelets-utils:4.2.0-SNAPSHOT" - "camel:kamelet" - "camel:core" template: diff --git a/kamelets/protobuf-deserialize-action.kamelet.yaml b/kamelets/protobuf-deserialize-action.kamelet.yaml index 41c87d2e6..084505d9d 100644 --- a/kamelets/protobuf-deserialize-action.kamelet.yaml +++ b/kamelets/protobuf-deserialize-action.kamelet.yaml @@ -46,7 +46,7 @@ spec: template: beans: - name: schemaResolver - type: "#class:org.apache.camel.kamelets.utils.format.converter.protobuf.ProtobufSchemaResolver" + type: "#class:org.apache.camel.kamelets.utils.format.schema.protobuf.ProtobufSchemaResolver" property: - key: schema value: '{{schema:}}' diff --git a/kamelets/protobuf-serialize-action.kamelet.yaml b/kamelets/protobuf-serialize-action.kamelet.yaml index d201ddd8b..598bff37b 100644 --- a/kamelets/protobuf-serialize-action.kamelet.yaml +++ b/kamelets/protobuf-serialize-action.kamelet.yaml @@ -46,7 +46,7 @@ spec: template: beans: - name: schemaResolver - type: "#class:org.apache.camel.kamelets.utils.format.converter.protobuf.ProtobufSchemaResolver" + type: "#class:org.apache.camel.kamelets.utils.format.schema.protobuf.ProtobufSchemaResolver" property: - key: schema value: '{{schema:}}' diff --git a/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/KameletsCatalogTest.java b/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/KameletsCatalogTest.java index 6b7448932..35de6f43c 100644 --- a/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/KameletsCatalogTest.java +++ b/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/KameletsCatalogTest.java @@ -147,8 +147,8 @@ void testSupportedHeaders() throws Exception { verifyHeaders("azure-storage-blob-source", 34); verifyHeaders("azure-storage-blob-sink", 33); verifyHeaders("azure-storage-blob-changefeed-source", 34); - verifyHeaders("azure-storage-datalake-source", 0); - verifyHeaders("azure-storage-datalake-sink", 0); + verifyHeaders("azure-storage-datalake-source", 25); + verifyHeaders("azure-storage-datalake-sink", 37); verifyHeaders("azure-storage-queue-source", 6); verifyHeaders("azure-storage-queue-sink", 16); verifyHeaders("cassandra-sink", 1); diff --git a/library/camel-kamelets-utils/pom.xml b/library/camel-kamelets-utils/pom.xml index f287f3e6c..7b75ab912 100644 --- a/library/camel-kamelets-utils/pom.xml +++ b/library/camel-kamelets-utils/pom.xml @@ -71,37 +71,12 @@ camel-kafka - - - org.apache.camel - camel-aws2-ddb - provided - - - org.apache.camel - camel-aws2-s3 - provided - - - org.apache.camel - camel-aws2-sqs - provided - + org.apache.camel camel-azure-storage-blob provided - - org.apache.camel - camel-google-storage - provided - - - org.apache.camel - camel-google-sheets - provided - diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/Avro.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/Avro.java deleted file mode 100644 index cfadf972b..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/Avro.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.avro; - -import com.fasterxml.jackson.dataformat.avro.AvroMapper; - -public final class Avro { - - public static final AvroMapper MAPPER = new AvroMapper(); - - private Avro() { - // prevent instantiation of utility class - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroBinaryDataType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroBinaryDataType.java deleted file mode 100644 index de468e1b4..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroBinaryDataType.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.avro; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.dataformat.avro.AvroSchema; -import org.apache.camel.CamelExecutionException; -import org.apache.camel.Exchange; -import org.apache.camel.InvalidPayloadException; -import org.apache.camel.Message; -import org.apache.camel.kamelets.utils.format.MimeType; -import org.apache.camel.kamelets.utils.format.converter.utils.SchemaHelper; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.DataTypeTransformer; -import org.apache.camel.spi.Transformer; - -/** - * Data type uses Jackson Avro data format to marshal given JsonNode in Exchange body to a binary (byte array) representation. - * Uses given Avro schema from the Exchange properties when marshalling the payload (usually already resolved via schema - * resolver Kamelet action). - */ -@DataTypeTransformer(name = "avro-binary") -public class AvroBinaryDataType extends Transformer { - - @Override - public void transform(Message message, DataType fromType, DataType toType) { - AvroSchema schema = message.getExchange().getProperty(SchemaHelper.CONTENT_SCHEMA, AvroSchema.class); - - if (schema == null) { - throw new CamelExecutionException("Missing proper avro schema for data type processing", message.getExchange()); - } - - try { - byte[] marshalled = Avro.MAPPER.writer().forType(JsonNode.class).with(schema) - .writeValueAsBytes(getBodyAsJsonNode(message, schema)); - message.setBody(marshalled); - - message.setHeader(Exchange.CONTENT_TYPE, MimeType.AVRO_BINARY.type()); - message.setHeader(SchemaHelper.CONTENT_SCHEMA, - message.getExchange().getProperty(SchemaHelper.CONTENT_SCHEMA, "", String.class)); - } catch (InvalidPayloadException | IOException e) { - throw new CamelExecutionException("Failed to apply Avro binary data type on exchange", message.getExchange(), e); - } - } - - private JsonNode getBodyAsJsonNode(Message message, AvroSchema schema) throws InvalidPayloadException, IOException { - if (message.getBody() instanceof JsonNode) { - return (JsonNode) message.getBody(); - } - - return Avro.MAPPER.reader().forType(JsonNode.class).with(schema) - .readValue(getBodyAsStream(message)); - } - - private InputStream getBodyAsStream(Message message) throws InvalidPayloadException { - InputStream bodyStream = message.getBody(InputStream.class); - - if (bodyStream == null) { - bodyStream = new ByteArrayInputStream(message.getMandatoryBody(byte[].class)); - } - - return bodyStream; - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroSchemaResolver.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroSchemaResolver.java deleted file mode 100644 index e6a71ad0c..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroSchemaResolver.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.avro; - -import java.io.InputStream; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import com.fasterxml.jackson.core.FormatSchema; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.dataformat.avro.AvroSchema; -import org.apache.avro.Schema; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.component.jackson.SchemaResolver; -import org.apache.camel.kamelets.utils.format.SchemaType; -import org.apache.camel.kamelets.utils.format.converter.utils.SchemaHelper; -import org.apache.camel.spi.Resource; -import org.apache.camel.support.PluginHelper; -import org.apache.camel.util.ObjectHelper; - -public class AvroSchemaResolver implements SchemaResolver, Processor { - private final ConcurrentMap schemes; - - private AvroSchema schema; - private String contentClass; - - private boolean validate = true; - - public AvroSchemaResolver() { - this.schemes = new ConcurrentHashMap<>(); - } - - public String getSchema() { - if (this.schema != null) { - return this.schema.getAvroSchema().toString(); - } - - return null; - } - - public void setSchema(String schema) { - if (ObjectHelper.isNotEmpty(schema)) { - this.schema = new AvroSchema(new Schema.Parser().setValidate(validate).parse(schema)); - } else { - this.schema = null; - } - } - - public boolean isValidate() { - return validate; - } - - public void setValidate(boolean validate) { - this.validate = validate; - } - - public String getContentClass() { - return contentClass; - } - - public void setContentClass(String contentClass) { - if (ObjectHelper.isNotEmpty(contentClass)) { - this.contentClass = contentClass; - } else { - this.contentClass = null; - } - } - - @Override - public void process(Exchange exchange) throws Exception { - Object payload = exchange.getMessage().getBody(); - if (payload == null) { - return; - } - - AvroSchema answer = computeIfAbsent(exchange); - - if (answer != null) { - exchange.setProperty(SchemaHelper.CONTENT_SCHEMA, answer); - exchange.setProperty(SchemaHelper.CONTENT_SCHEMA_TYPE, SchemaType.AVRO.type()); - exchange.setProperty(SchemaHelper.CONTENT_CLASS, SchemaHelper.resolveContentClass(exchange, this.contentClass)); - } - } - - @Override - public FormatSchema resolve(Exchange exchange) { - AvroSchema answer = exchange.getProperty(SchemaHelper.CONTENT_SCHEMA, AvroSchema.class); - if (answer == null) { - answer = computeIfAbsent(exchange); - } - - return answer; - } - - private AvroSchema computeIfAbsent(Exchange exchange) { - if (this.schema != null) { - return this.schema; - } - - AvroSchema answer = exchange.getProperty(SchemaHelper.CONTENT_SCHEMA, AvroSchema.class); - - if (answer == null && exchange.getProperties().containsKey(SchemaHelper.SCHEMA)) { - String schemaJson = exchange.getProperty(SchemaHelper.SCHEMA, String.class); - Schema raw = new Schema.Parser().setValidate(validate).parse(schemaJson); - answer = new AvroSchema(raw); - } - - if (answer == null) { - String contentClass = SchemaHelper.resolveContentClass(exchange, this.contentClass); - if (contentClass != null) { - answer = this.schemes.computeIfAbsent(contentClass, t -> { - Resource res = PluginHelper.getResourceLoader(exchange.getContext()) - .resolveResource("classpath:schemas/" + SchemaType.AVRO.type() + "/" + t + "." + SchemaType.AVRO.type()); - - try { - if (res.exists()) { - try (InputStream is = res.getInputStream()) { - if (is != null) { - return Avro.MAPPER.schemaFrom(is); - } - } - } - } catch (Exception e) { - throw new RuntimeException( - "Unable to load Avro schema for type: " + t + ", resource: " + res.getLocation(), e); - } - - try { - return Avro.MAPPER.schemaFor(Class.forName(contentClass)); - } catch (JsonMappingException | ClassNotFoundException e) { - throw new RuntimeException( - "Unable to compute Avro schema for type: " + t, e); - } - }); - } - } - - if (answer != null) { - this.schema = answer; - } - - return answer; - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroStructDataType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroStructDataType.java deleted file mode 100644 index 4186d8c16..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroStructDataType.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.avro; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.dataformat.avro.AvroSchema; -import org.apache.camel.CamelExecutionException; -import org.apache.camel.Exchange; -import org.apache.camel.InvalidPayloadException; -import org.apache.camel.Message; -import org.apache.camel.kamelets.utils.format.MimeType; -import org.apache.camel.kamelets.utils.format.converter.utils.SchemaHelper; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.DataTypeTransformer; -import org.apache.camel.spi.Transformer; - -/** - * Data type uses Avro Jackson data format to unmarshal Exchange body to generic JsonNode. - * Uses given Avro schema from the Exchange properties when unmarshalling the payload (usually already resolved via schema - * resolver Kamelet action). - */ -@DataTypeTransformer(name = "avro-x-struct") -public class AvroStructDataType extends Transformer { - - @Override - public void transform(Message message, DataType fromType, DataType toType) { - AvroSchema schema = message.getExchange().getProperty(SchemaHelper.CONTENT_SCHEMA, AvroSchema.class); - - if (schema == null) { - throw new CamelExecutionException("Missing proper avro schema for data type processing", message.getExchange()); - } - - try { - Object unmarshalled = Avro.MAPPER.reader().forType(JsonNode.class).with(schema) - .readValue(getBodyAsStream(message)); - message.setBody(unmarshalled); - - message.setHeader(Exchange.CONTENT_TYPE, MimeType.STRUCT.type()); - } catch (InvalidPayloadException | IOException e) { - throw new CamelExecutionException("Failed to apply Avro x-struct data type on exchange", message.getExchange(), e); - } - } - - private InputStream getBodyAsStream(Message message) throws InvalidPayloadException { - InputStream bodyStream = message.getBody(InputStream.class); - - if (bodyStream == null) { - bodyStream = new ByteArrayInputStream(message.getMandatoryBody(byte[].class)); - } - - return bodyStream; - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/ddb/Ddb2JsonInputType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/ddb/Ddb2JsonInputType.java deleted file mode 100644 index d56b6f0e4..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/ddb/Ddb2JsonInputType.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.aws2.ddb; - -import java.io.InputStream; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.JsonNode; -import org.apache.camel.CamelExecutionException; -import org.apache.camel.Message; -import org.apache.camel.component.aws2.ddb.Ddb2Constants; -import org.apache.camel.component.aws2.ddb.Ddb2Operations; -import org.apache.camel.component.jackson.JacksonDataFormat; -import org.apache.camel.kamelets.utils.format.converter.json.Json; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.DataTypeTransformer; -import org.apache.camel.spi.Transformer; -import software.amazon.awssdk.services.dynamodb.model.AttributeAction; -import software.amazon.awssdk.services.dynamodb.model.AttributeValue; -import software.amazon.awssdk.services.dynamodb.model.AttributeValueUpdate; -import software.amazon.awssdk.services.dynamodb.model.ReturnValue; - -/** - * Maps Json body to DynamoDB attribute value map and sets the attribute map as Camel DynamoDB header entries. - * - * Json property names map to attribute keys and Json property values map to attribute values. - * - * During mapping the Json property types resolve to the respective attribute types - * ({@code String, StringSet, Boolean, Number, NumberSet, Map, Null}). Primitive typed arrays in Json get mapped to - * {@code StringSet} or {@code NumberSet} attribute values. - * - * The input type supports the operations: PutItem, UpdateItem, DeleteItem - * - * For PutItem operation the Json body defines all item attributes. - * - * For DeleteItem operation the Json body defines only the primary key attributes that identify the item to delete. - * - * For UpdateItem operation the Json body defines both key attributes to identify the item to be updated and all item - * attributes tht get updated on the item. - * - * The given Json body can use "operation", "key" and "item" as top level properties that will be mapped to respective - * attribute value maps: - * - *
- * {@code
- * {
- *   "operation": "PutItem"
- *   "key": {},
- *   "item": {}
- * }
- * }
- * 
- * - * The transformer will extract the objects and set respective attribute value maps as header entries. This is a - * comfortable way to define different key and item attribute value maps e.g. on UpdateItem operation. - * - * In case key and item attribute value maps are identical you can omit the special top level properties completely. The - * transformer will map the whole Json body as is then and use it as source for the attribute value map. - */ -@DataTypeTransformer(name = "aws2-ddb:application-json") -public class Ddb2JsonInputType extends Transformer { - - private final JacksonDataFormat dataFormat = new JacksonDataFormat(Json.MAPPER, JsonNode.class); - - @Override - public void transform(Message message, DataType fromType, DataType toType) { - if (message.getHeaders().containsKey(Ddb2Constants.ITEM) || - message.getHeaders().containsKey(Ddb2Constants.KEY)) { - return; - } - - JsonNode jsonBody = getBodyAsJsonNode(message); - - String operation - = Optional.ofNullable(jsonBody.get("operation")).map(JsonNode::asText).orElse(Ddb2Operations.PutItem.name()); - if (message.getExchange().hasProperties() && message.getExchange().getProperty("operation", String.class) != null) { - operation = message.getExchange().getProperty("operation", String.class); - } - - if (message.getHeaders().containsKey(Ddb2Constants.OPERATION)) { - operation = message.getHeader(Ddb2Constants.OPERATION, Ddb2Operations.class).name(); - } - - JsonNode key = jsonBody.get("key"); - JsonNode item = jsonBody.get("item"); - - Map keyProps; - if (key != null) { - keyProps = dataFormat.getObjectMapper().convertValue(key, new TypeReference<>() { - }); - } else { - keyProps = dataFormat.getObjectMapper().convertValue(jsonBody, new TypeReference<>() { - }); - } - - Map itemProps; - if (item != null) { - itemProps = dataFormat.getObjectMapper().convertValue(item, new TypeReference<>() { - }); - } else { - itemProps = keyProps; - } - - final Map keyMap = getAttributeValueMap(keyProps); - - switch (Ddb2Operations.valueOf(operation)) { - case PutItem: - message.setHeader(Ddb2Constants.OPERATION, Ddb2Operations.PutItem); - message.setHeader(Ddb2Constants.ITEM, getAttributeValueMap(itemProps)); - setHeaderIfNotPresent(Ddb2Constants.RETURN_VALUES, ReturnValue.ALL_OLD.toString(), message); - break; - case UpdateItem: - message.setHeader(Ddb2Constants.OPERATION, Ddb2Operations.UpdateItem); - message.setHeader(Ddb2Constants.KEY, keyMap); - message.setHeader(Ddb2Constants.UPDATE_VALUES, getAttributeValueUpdateMap(itemProps)); - setHeaderIfNotPresent(Ddb2Constants.RETURN_VALUES, ReturnValue.ALL_NEW.toString(), message); - break; - case DeleteItem: - message.setHeader(Ddb2Constants.OPERATION, Ddb2Operations.DeleteItem); - message.setHeader(Ddb2Constants.KEY, keyMap); - setHeaderIfNotPresent(Ddb2Constants.RETURN_VALUES, ReturnValue.ALL_OLD.toString(), message); - break; - default: - throw new UnsupportedOperationException(String.format("Unsupported operation '%s'", operation)); - } - } - - private JsonNode getBodyAsJsonNode(Message message) { - try { - if (message.getBody() instanceof JsonNode) { - return message.getMandatoryBody(JsonNode.class); - } - - return (JsonNode) dataFormat.unmarshal(message.getExchange(), message.getMandatoryBody(InputStream.class)); - } catch (Exception e) { - throw new CamelExecutionException("Failed to get mandatory Json node from message body", message.getExchange(), e); - } - } - - private void setHeaderIfNotPresent(String headerName, Object value, Message message) { - message.setHeader(headerName, value); - } - - private Map getAttributeValueMap(Map body) { - final Map attributeValueMap = new LinkedHashMap<>(); - - for (Map.Entry attribute : body.entrySet()) { - attributeValueMap.put(attribute.getKey(), getAttributeValue(attribute.getValue())); - } - - return attributeValueMap; - } - - private Map getAttributeValueUpdateMap(Map body) { - final Map attributeValueMap = new LinkedHashMap<>(); - - for (Map.Entry attribute : body.entrySet()) { - attributeValueMap.put(attribute.getKey(), getAttributeValueUpdate(attribute.getValue())); - } - - return attributeValueMap; - } - - private static AttributeValue getAttributeValue(Object value) { - if (value == null) { - return AttributeValue.builder().nul(true).build(); - } - - if (value instanceof String) { - return AttributeValue.builder().s(value.toString()).build(); - } - - if (value instanceof Integer) { - return AttributeValue.builder().n(value.toString()).build(); - } - - if (value instanceof Boolean) { - return AttributeValue.builder().bool((Boolean) value).build(); - } - - if (value instanceof String[]) { - return AttributeValue.builder().ss((String[]) value).build(); - } - - if (value instanceof int[]) { - return AttributeValue.builder().ns(Stream.of((int[]) value).map(Object::toString).collect(Collectors.toList())) - .build(); - } - - if (value instanceof List) { - List values = (List) value; - - if (values.isEmpty()) { - return AttributeValue.builder().ss().build(); - } else if (values.get(0) instanceof Integer) { - return AttributeValue.builder().ns(values.stream().map(Object::toString).collect(Collectors.toList())).build(); - } else { - return AttributeValue.builder().ss(values.stream().map(Object::toString).collect(Collectors.toList())).build(); - } - } - - if (value instanceof Map) { - Map nestedAttributes = new LinkedHashMap<>(); - - for (Map.Entry nested : ((Map) value).entrySet()) { - nestedAttributes.put(nested.getKey().toString(), getAttributeValue(nested.getValue())); - } - - return AttributeValue.builder().m(nestedAttributes).build(); - } - - return AttributeValue.builder().s(value.toString()).build(); - } - - private static AttributeValueUpdate getAttributeValueUpdate(Object value) { - return AttributeValueUpdate.builder() - .action(AttributeAction.PUT) - .value(getAttributeValue(value)).build(); - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/s3/AWS2S3CloudEventOutputType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/s3/AWS2S3CloudEventOutputType.java deleted file mode 100644 index 0dee160f9..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/s3/AWS2S3CloudEventOutputType.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.aws2.s3; - -import java.util.Map; - -import org.apache.camel.Message; -import org.apache.camel.component.aws2.s3.AWS2S3Constants; -import org.apache.camel.kamelets.utils.format.converter.utils.CloudEvents; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.DataTypeTransformer; -import org.apache.camel.spi.Transformer; - -/** - * Output data type represents AWS S3 get object response as CloudEvent V1. The data type sets Camel specific - * CloudEvent headers on the exchange. - */ -@DataTypeTransformer(name = "aws2-s3:application-cloudevents") -public class AWS2S3CloudEventOutputType extends Transformer { - - @Override - public void transform(Message message, DataType fromType, DataType toType) { - final Map headers = message.getHeaders(); - - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_ID, message.getExchange().getExchangeId()); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TYPE, "org.apache.camel.event.aws.s3.getObject"); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SOURCE, "aws.s3.bucket." + message.getHeader(AWS2S3Constants.BUCKET_NAME, String.class)); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SUBJECT, message.getHeader(AWS2S3Constants.KEY, String.class)); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TIME, CloudEvents.getEventTime(message.getExchange())); - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/sqs/AWS2SQSCloudEventOutputType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/sqs/AWS2SQSCloudEventOutputType.java deleted file mode 100644 index e4d71e8e9..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/sqs/AWS2SQSCloudEventOutputType.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.aws2.sqs; - -import org.apache.camel.Message; -import org.apache.camel.component.aws2.s3.AWS2S3Constants; -import org.apache.camel.component.aws2.sqs.Sqs2Constants; -import org.apache.camel.kamelets.utils.format.converter.utils.CloudEvents; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.DataTypeTransformer; -import org.apache.camel.spi.Transformer; - -import java.util.Map; - -/** - * Output data type represents AWS SQS receive Message response as CloudEvent V1. The data type sets Camel specific - * CloudEvent headers on the exchange. - */ -@DataTypeTransformer(name = "aws2-sqs:application-cloudevents") -public class AWS2SQSCloudEventOutputType extends Transformer { - - @Override - public void transform(Message message, DataType fromType, DataType toType) { - final Map headers = message.getHeaders(); - - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_ID, message.getExchange().getExchangeId()); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TYPE, "org.apache.camel.event.aws.sqs.receiveMessage"); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SOURCE, "aws.sqs.queue." + message.getHeader(Sqs2Constants.RECEIPT_HANDLE, String.class)); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SUBJECT, message.getHeader(Sqs2Constants.MESSAGE_ID, String.class)); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TIME, CloudEvents.getEventTime(message.getExchange())); - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/azure/storage/blob/AzureStorageBlobCloudEventOutputType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/azure/storage/blob/AzureStorageBlobCloudEventOutputType.java deleted file mode 100644 index cbf1dd96a..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/azure/storage/blob/AzureStorageBlobCloudEventOutputType.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.azure.storage.blob; - -import org.apache.camel.Message; -import org.apache.camel.component.aws2.s3.AWS2S3Constants; -import org.apache.camel.component.azure.storage.blob.BlobConstants; -import org.apache.camel.kamelets.utils.format.converter.utils.CloudEvents; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.DataTypeTransformer; -import org.apache.camel.spi.Transformer; - -import java.util.Map; - -/** - * Output data type represents Azure Storage Blob get blob response as CloudEvent V1. The data type sets Camel specific - * CloudEvent headers on the exchange. - */ -@DataTypeTransformer(name = "azure-storage-blob:application-cloudevents") -public class AzureStorageBlobCloudEventOutputType extends Transformer { - - @Override - public void transform(Message message, DataType fromType, DataType toType) { - final Map headers = message.getHeaders(); - - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_ID, message.getExchange().getExchangeId()); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TYPE, "org.apache.camel.event.azure.storage.blob.getBlob"); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SOURCE, "azure.storage.blob." + message.getHeader(BlobConstants.E_TAG, String.class)); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SUBJECT, message.getHeader(BlobConstants.BLOB_NAME, String.class)); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TIME, CloudEvents.getEventTime(message.getExchange())); - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/CellCoordinate.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/CellCoordinate.java deleted file mode 100644 index 60553b299..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/CellCoordinate.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.google.sheets; - -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import org.apache.camel.util.ObjectHelper; - -public class CellCoordinate { - - private int rowIndex; - private int columnIndex; - - /** - * Prevent direct instantiation - */ - CellCoordinate() { - super(); - } - - /** - * Construct grid coordinate from given cell identifier representation in A1 form. For instance convert - * cell id string "A1" to a coordinate with rowIndex=0, and columnIndex=0. - * - * @param cellId - * @return - */ - public static CellCoordinate fromCellId(String cellId) { - CellCoordinate coordinate = new CellCoordinate(); - - if (cellId != null) { - coordinate.setRowIndex(getRowIndex(cellId)); - coordinate.setColumnIndex(getColumnIndex(cellId)); - } - - return coordinate; - } - - /** - * Evaluate the column index from cellId in A1 notation. Column name letters are translated to numeric column index values. - * Column "A" will result in column index 0. Method does support columns with combined name letters such as "AA" where this is - * the first column after "Z" resulting in a column index of 26. - * - * @param cellId - * @return - */ - protected static int getColumnIndex(String cellId) { - char[] characters = cellId.toCharArray(); - List chars = IntStream.range(0, characters.length) - .mapToObj(i -> characters[i]) - .filter(c -> !Character.isDigit(c)) - .map(Character::toUpperCase) - .map(Character::getNumericValue) - .collect(Collectors.toList()); - - if (chars.size() > 1) { - int index = 0; - for (int i = 0; i < chars.size(); i++) { - if (i == chars.size() -1) { - index += chars.get(i) - Character.getNumericValue('A'); - } else { - index += ((chars.get(i) - Character.getNumericValue('A')) + 1) * 26; - } - } - return index; - } else if (chars.size() == 1) { - return chars.get(0) - Character.getNumericValue('A'); - } else { - return 0; - } - } - - /** - * Evaluates the row index from a given cellId in A1 notation. Extracts the row number and translates that to an numeric - * index value beginning with 0. - * - * @param cellId - * @return - */ - protected static int getRowIndex(String cellId) { - char[] characters = cellId.toCharArray(); - String index = IntStream.range(0, characters.length) - .mapToObj(i -> characters[i]) - .filter(Character::isDigit) - .map(String::valueOf) - .collect(Collectors.joining()); - - if (ObjectHelper.isNotEmpty(index)) { - return Integer.parseInt(index) - 1; - } - - return 0; - } - - /** - * Evaluates column name in A1 notation based on the column index. Index 0 will be "A" and index 25 will be "Z". Method also supports - * name overflow where index 26 will be "AA" and index 51 will be "AZ" and so on. - * - * @param columnIndex - * @return - */ - public static String getColumnName(int columnIndex) { - String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - StringBuilder columnName = new StringBuilder(); - - int index = columnIndex; - int overflowIndex = -1; - while (index > 25) { - overflowIndex++; - index -= 26; - } - - if (overflowIndex >= 0) { - columnName.append(alphabet.toCharArray()[overflowIndex]); - } - - columnName.append(alphabet.toCharArray()[index]); - - return columnName.toString(); - } - - /** - * Special getter for column name where user is able to give set of user defined column names. When given column index is resolvable via custom names - * the custom column name is returned otherwise the evaluated default column name is returned. - * - * @param columnIndex - * @param columnStartIndex - * @param columnNames - * @return - */ - public static String getColumnName(int columnIndex, int columnStartIndex, String ... columnNames) { - String columnName = getColumnName(columnIndex); - - int index; - if (columnStartIndex > 0) { - index = columnIndex % columnStartIndex; - } else { - index = columnIndex; - } - - if (index < columnNames.length) { - String name = columnNames[index]; - if (columnName.equals(name)) { - return columnName; - } else { - return name; - } - } - - return columnName; - } - - public int getRowIndex() { - return rowIndex; - } - - /** - * Specifies the rowIndex. - * - * @param rowIndex - */ - public void setRowIndex(int rowIndex) { - this.rowIndex = rowIndex; - } - - public int getColumnIndex() { - return columnIndex; - } - - /** - * Specifies the columnIndex. - * - * @param columnIndex - */ - public void setColumnIndex(int columnIndex) { - this.columnIndex = columnIndex; - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/GoogleSheetsJsonStructDataType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/GoogleSheetsJsonStructDataType.java deleted file mode 100644 index 4336a10c4..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/GoogleSheetsJsonStructDataType.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.google.sheets; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.api.services.sheets.v4.model.ValueRange; -import org.apache.camel.CamelExecutionException; -import org.apache.camel.InvalidPayloadException; -import org.apache.camel.Message; -import org.apache.camel.component.google.sheets.internal.GoogleSheetsConstants; -import org.apache.camel.component.google.sheets.stream.GoogleSheetsStreamConstants; -import org.apache.camel.kamelets.utils.format.converter.json.Json; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.DataTypeTransformer; -import org.apache.camel.spi.Transformer; -import org.apache.camel.util.ObjectHelper; - -/** - * Data type supports generic JsonNode representation of Google Sheets row and column values. - * Transforms generic JsonNode struct to/from a Google Sheets ValueRange object. - * Supports both inbound and outbound transformation depending on the given message body content. - * When Google Sheets ValueRange object is given as message body (e.g. as a result of a get values operation) the transformer will transform into generic Json struct. - * When generic Json struct is given as a message body transformer will transform into a proper ValueRange object that is ready to be used in an update/append values operation. - * Implementation also supports splitResults setting where a set of values is split into its individual items. - */ -@DataTypeTransformer(name = "google-sheets:application-x-struct") -public class GoogleSheetsJsonStructDataType extends Transformer { - - private static final String ROW_PREFIX = "#"; - - @Override - public void transform(Message message, DataType fromType, DataType toType) { - final Optional valueRange = getValueRangeBody(message); - - String range = message.getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", "A:A").toString(); - String majorDimension = message.getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "majorDimension", RangeCoordinate.DIMENSION_ROWS).toString(); - String spreadsheetId = message.getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "spreadsheetId", "").toString(); - String[] columnNames = message.getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "columnNames", "A").toString().split(","); - - boolean splitResults = Boolean.parseBoolean(message.getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "splitResults", "false").toString()); - - if (valueRange.isPresent()) { - message.setBody(transformFromValueRangeModel(message, valueRange.get(), spreadsheetId, range, majorDimension, columnNames)); - } else if (splitResults) { - message.setBody(transformFromSplitValuesModel(message, spreadsheetId, range, majorDimension, columnNames)); - } else { - String valueInputOption = message.getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption", "USER_ENTERED").toString(); - message.setBody(transformToValueRangeModel(message, spreadsheetId, range, majorDimension, valueInputOption, columnNames)); - } - } - - /** - * Constructs proper ValueRange object from given generic Json struct. - * @param message - * @param spreadsheetId - * @param range - * @param majorDimension - * @param valueInputOption - * @param columnNames - * @return - */ - private ValueRange transformToValueRangeModel(Message message, String spreadsheetId, String range, String majorDimension, String valueInputOption, String[] columnNames) { - try { - List jsonBeans = bodyAsJsonBeans(message); - - ValueRange valueRange = new ValueRange(); - List> values = new ArrayList<>(); - - if (ObjectHelper.isNotEmpty(jsonBeans)) { - final ArrayList properties = createCoordinateNameSpec(range, majorDimension, columnNames); - - for (String json : jsonBeans) { - Map dataShape = Json.MAPPER.reader().forType(Map.class).readValue(json); - - if (dataShape.containsKey("spreadsheetId")) { - spreadsheetId = Optional.ofNullable(dataShape.remove("spreadsheetId")) - .map(Object::toString) - .orElse(spreadsheetId); - } - - List rangeValues = new ArrayList<>(); - properties - .stream() - .filter(specEntry -> !Objects.equals("spreadsheetId", specEntry)) - .forEach(specEntry -> rangeValues.add(dataShape.getOrDefault(specEntry, null))); - - values.add(rangeValues); - } - } - - valueRange.setMajorDimension(majorDimension); - valueRange.setValues(values); - - message.setHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID, spreadsheetId); - message.setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "spreadsheetId", spreadsheetId); - message.setHeader(GoogleSheetsStreamConstants.RANGE, range); - message.setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", range); - message.setHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION, majorDimension); - message.setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "majorDimension", majorDimension); - message.setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption", valueInputOption); - message.setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values", valueRange); - - return valueRange; - } catch (InvalidPayloadException | JsonProcessingException e) { - throw new CamelExecutionException("Failed to apply Google Sheets Json struct " + - "data type on exchange", message.getExchange(), e); - } - } - - /** - * Construct generic Json struct from given ValueRange object. - * Json struct represents the row and column values only. - * @param message - * @param valueRange - * @param spreadsheetId - * @param range - * @param majorDimension - * @param columnNames - * @return - */ - private List transformFromValueRangeModel(Message message, ValueRange valueRange, String spreadsheetId, String range, String majorDimension, String[] columnNames) { - final List jsonBeans = new ArrayList<>(); - - try { - if (valueRange != null) { - if (ObjectHelper.isNotEmpty(valueRange.getRange())) { - range = valueRange.getRange(); - } - RangeCoordinate rangeCoordinate = RangeCoordinate.fromRange(range); - - if (ObjectHelper.isNotEmpty(valueRange.getMajorDimension())) { - majorDimension = valueRange.getMajorDimension(); - } - - if (ObjectHelper.equal(RangeCoordinate.DIMENSION_ROWS, majorDimension)) { - for (List values : valueRange.getValues()) { - final Map model = new HashMap<>(); - model.put("spreadsheetId", spreadsheetId); - int columnIndex = rangeCoordinate.getColumnStartIndex(); - for (Object value : values) { - model.put(CellCoordinate.getColumnName(columnIndex, rangeCoordinate.getColumnStartIndex(), columnNames), value); - columnIndex++; - } - jsonBeans.add(Json.MAPPER.writer().writeValueAsString(model)); - } - } else if (ObjectHelper.equal(RangeCoordinate.DIMENSION_COLUMNS, majorDimension)) { - for (List values : valueRange.getValues()) { - final Map model = new HashMap<>(); - model.put("spreadsheetId", spreadsheetId); - int rowIndex = rangeCoordinate.getRowStartIndex() + 1; - for (Object value : values) { - model.put(ROW_PREFIX + rowIndex, value); - rowIndex++; - } - jsonBeans.add(Json.MAPPER.writer().writeValueAsString(model)); - } - } - } - - } catch (IOException e) { - throw new CamelExecutionException("Failed to apply Google Sheets Json struct " + - "data type on exchange", message.getExchange(), e); - } - - return jsonBeans; - } - - /** - * Construct generic Json struct from given split values model. - * Json struct represents the row and column values only. - * In split mode one single row/column is handled as an individual result. - * @param message - * @param spreadsheetId - * @param range - * @param majorDimension - * @param columnNames - * @return - */ - private String transformFromSplitValuesModel(Message message, String spreadsheetId, String range, String majorDimension, String[] columnNames) { - try { - final List values = bodyAsJsonBeans(message); - - final Map model = new HashMap<>(); - model.put("spreadsheetId", spreadsheetId); - - if (values != null) { - if (ObjectHelper.isNotEmpty(message.getHeader(GoogleSheetsStreamConstants.RANGE))) { - range = message.getHeader(GoogleSheetsStreamConstants.RANGE).toString(); - } - RangeCoordinate rangeCoordinate = RangeCoordinate.fromRange(range); - - if (ObjectHelper.isNotEmpty(message.getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION))) { - majorDimension = message.getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION).toString(); - } - - if (ObjectHelper.equal(RangeCoordinate.DIMENSION_ROWS, majorDimension)) { - int columnIndex = rangeCoordinate.getColumnStartIndex(); - for (Object value : values) { - model.put(CellCoordinate.getColumnName(columnIndex, rangeCoordinate.getColumnStartIndex(), columnNames), value); - columnIndex++; - } - } else if (ObjectHelper.equal(RangeCoordinate.DIMENSION_COLUMNS, majorDimension)) { - int rowIndex = rangeCoordinate.getRowStartIndex() + 1; - for (Object value : values) { - model.put(ROW_PREFIX + rowIndex, value); - rowIndex++; - } - } - } - - return Json.MAPPER.writer().writeValueAsString(model); - } catch (InvalidPayloadException | JsonProcessingException e) { - throw new CamelExecutionException("Failed to apply Google Sheets Json struct " + - "data type on exchange", message.getExchange(), e); - } - } - - /** - * Try to convert message body to a ValueRange object if possible. - * Returns empty optional when message body conversion is not applicable. - * @param message - * @return - */ - private static Optional getValueRangeBody(Message message) { - if (message.getBody() instanceof ValueRange) { - return Optional.of(message.getBody(ValueRange.class)); - } - - String jsonBody = message.getBody(String.class); - if (jsonBody != null) { - try { - ValueRange valueRange = Json.MAPPER.reader().readValue(jsonBody, ValueRange.class); - return valueRange.getValues() != null ? Optional.of(valueRange) : Optional.empty(); - } catch (IOException e) { - return Optional.empty(); - } - } - - return Optional.empty(); - } - - /** - * Converts message body to list of Json objects. Supports different message body types such as - * List, String, InputStream. - * @param message - * @return - * @throws JsonProcessingException - */ - private static List bodyAsJsonBeans(Message message) throws JsonProcessingException, InvalidPayloadException { - if (message.getBody() == null) { - return Collections.emptyList(); - } - - if (message.getBody() instanceof List) { - return message.getBody(List.class); - } - - String body = message.getMandatoryBody(String.class); - if (Json.isJsonArray(body)) { - return Json.arrayToJsonBeans(Json.MAPPER.reader().readTree(body)); - } else if (Json.isJson(body)) { - return Collections.singletonList(body); - } - - return Collections.emptyList(); - } - - /** - * Construct row and column coordinate names for given range. - * Supports mapping of custom column names to proper row/column coordinates. - * @param range - * @param majorDimension - * @param columnNames - * @return - */ - public static ArrayList createCoordinateNameSpec(String range, String majorDimension, String ... columnNames) { - ArrayList names = new ArrayList<>(); - - RangeCoordinate coordinate = RangeCoordinate.fromRange(range); - if (ObjectHelper.equal(RangeCoordinate.DIMENSION_ROWS, majorDimension)) { - createSchemaFromRowDimension(names, coordinate, columnNames); - } else if (ObjectHelper.equal(RangeCoordinate.DIMENSION_COLUMNS, majorDimension)) { - createSchemaFromColumnDimension(names, coordinate); - } - - return names; - } - - /** - * Create dynamic json schema from row dimension. If split only a single object "ROW" holding 1-n column values is - * created. Otherwise, each row results in a separate object with 1-n column values as property. - * @param properties - * @param coordinate - * @param columnNames - */ - private static void createSchemaFromRowDimension(ArrayList properties, RangeCoordinate coordinate, String ... columnNames) { - for (int i = coordinate.getColumnStartIndex(); i < coordinate.getColumnEndIndex(); i++) { - properties.add(CellCoordinate.getColumnName(i, coordinate.getColumnStartIndex(), columnNames)); - } - } - - /** - * Create dynamic json schema from column dimension. If split only a single object "COLUMN" holding 1-n row values is - * created. Otherwise, each column results in a separate object with 1-n row values as property. - * @param properties - * @param coordinate - */ - private static void createSchemaFromColumnDimension(ArrayList properties, RangeCoordinate coordinate) { - for (int i = coordinate.getRowStartIndex() + 1; i <= coordinate.getRowEndIndex(); i++) { - properties.add("#" + i); - } - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/RangeCoordinate.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/RangeCoordinate.java deleted file mode 100644 index 403e84e1e..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/RangeCoordinate.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.google.sheets; - -import java.util.StringJoiner; - -public final class RangeCoordinate extends CellCoordinate { - - public static final String DIMENSION_ROWS = "ROWS"; - public static final String DIMENSION_COLUMNS = "COLUMNS"; - - private int rowStartIndex; - private int rowEndIndex; - - private int columnStartIndex; - private int columnEndIndex; - - /** - * Prevent direct instantiation - */ - private RangeCoordinate() { - super(); - } - - /** - * Construct range coordinates from range string representation in A1 form. For instance convert - * range string "A1:C2" to a coordinate with rowStartIndex=1, rowEndIndex=2, columnStartIndex=1, columnEndIndex=3. - * - * Supports missing range ends with "A5" resulting in rowStartIndex=5, rowEndIndex=6, columnStartIndex=1, columnEndIndex=2. - * @param range - * @return - */ - public static RangeCoordinate fromRange(String range) { - RangeCoordinate coordinate = new RangeCoordinate(); - - String rangeExpression = normalizeRange(range); - - if (rangeExpression.contains(":")) { - String[] coordinates = rangeExpression.split(":", -1); - - coordinate.setRowStartIndex(getRowIndex(coordinates[0])); - coordinate.setColumnStartIndex(getColumnIndex(coordinates[0])); - coordinate.setRowEndIndex(getRowIndex(coordinates[1]) + 1); - coordinate.setColumnEndIndex(getColumnIndex(coordinates[1]) + 1); - } else { - CellCoordinate cellCoordinate = CellCoordinate.fromCellId(rangeExpression); - coordinate.setRowIndex(cellCoordinate.getRowIndex()); - coordinate.setColumnIndex(cellCoordinate.getColumnIndex()); - coordinate.setRowStartIndex(cellCoordinate.getRowIndex()); - coordinate.setColumnStartIndex(cellCoordinate.getColumnIndex()); - coordinate.setRowEndIndex(cellCoordinate.getRowIndex() + 1); - coordinate.setColumnEndIndex(cellCoordinate.getColumnIndex() + 1); - } - - return coordinate; - } - - /** - * Removes optional sheet name from range expression if any. - * @param range - * @return - */ - private static String normalizeRange(String range) { - if (range.contains("!")) { - return range.substring(range.indexOf('!') + 1); - } else { - return range; - } - } - - /** - * Get all names of columns included in this range. - * @return - */ - public String getColumnNames() { - StringJoiner delimitedList = new StringJoiner(","); - for (int i = columnStartIndex; i < columnEndIndex; i++) { - delimitedList.add(CellCoordinate.getColumnName(i)); - } - return delimitedList.toString(); - } - - public int getRowStartIndex() { - return rowStartIndex; - } - - /** - * Specifies the rowStartIndex. - * - * @param rowStartIndex - */ - public void setRowStartIndex(int rowStartIndex) { - this.rowStartIndex = rowStartIndex; - } - - public int getRowEndIndex() { - return rowEndIndex; - } - - /** - * Specifies the rowEndIndex. - * - * @param rowEndIndex - */ - public void setRowEndIndex(int rowEndIndex) { - this.rowEndIndex = rowEndIndex; - } - - public int getColumnStartIndex() { - return columnStartIndex; - } - - /** - * Specifies the columnStartIndex. - * - * @param columnStartIndex - */ - public void setColumnStartIndex(int columnStartIndex) { - this.columnStartIndex = columnStartIndex; - } - - public int getColumnEndIndex() { - return columnEndIndex; - } - - /** - * Specifies the columnEndIndex. - * - * @param columnEndIndex - */ - public void setColumnEndIndex(int columnEndIndex) { - this.columnEndIndex = columnEndIndex; - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/storage/GoogleStorageCloudEventOutputType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/storage/GoogleStorageCloudEventOutputType.java deleted file mode 100644 index 51604958c..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/storage/GoogleStorageCloudEventOutputType.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.google.storage; - -import org.apache.camel.Message; -import org.apache.camel.component.aws2.s3.AWS2S3Constants; -import org.apache.camel.component.google.storage.GoogleCloudStorageConstants; -import org.apache.camel.kamelets.utils.format.converter.utils.CloudEvents; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.DataTypeTransformer; -import org.apache.camel.spi.Transformer; - -import java.util.Map; - -/** - * Output data type represents Google Storage downloadTo response as CloudEvent V1. The data type sets Camel specific - * CloudEvent headers on the exchange. - */ -@DataTypeTransformer(name = "google-storage:application-cloudevents") -public class GoogleStorageCloudEventOutputType extends Transformer { - - @Override - public void transform(Message message, DataType fromType, DataType toType) { - final Map headers = message.getHeaders(); - - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_ID, message.getExchange().getExchangeId()); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TYPE, "org.apache.camel.event.google.storage.downloadTo"); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SOURCE, "google.storage.bucket." + message.getHeader(GoogleCloudStorageConstants.BUCKET_NAME, String.class)); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SUBJECT, message.getHeader(GoogleCloudStorageConstants.OBJECT_NAME, String.class)); - headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TIME, CloudEvents.getEventTime(message.getExchange())); - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/http/HttpCloudEventOutputType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/http/HttpCloudEventOutputType.java deleted file mode 100644 index 7c1ee17c7..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/http/HttpCloudEventOutputType.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.http; - -import java.util.Map; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.kamelets.utils.format.converter.utils.CloudEvents; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.DataTypeTransformer; -import org.apache.camel.spi.Transformer; - -/** - * Output data type represents the CloudEvent V1 Http binding. The data type reads Camel specific - * CloudEvent headers and transforms these to Http headers according to the CloudEvents Http binding specification. - * - * By default, sets the Http content type header to application/json when not set explicitly. - */ -@DataTypeTransformer(name = "http:application-cloudevents") -public class HttpCloudEventOutputType extends Transformer { - - @Override - public void transform(Message message, DataType fromType, DataType toType) { - final Map headers = message.getHeaders(); - - headers.put("ce-id", message.getExchange().getExchangeId()); - headers.put("ce-specversion", headers.getOrDefault(CloudEvents.CAMEL_CLOUD_EVENT_VERSION, "1.0")); - headers.put("ce-type", headers.getOrDefault(CloudEvents.CAMEL_CLOUD_EVENT_TYPE, "org.apache.camel.event")); - headers.put("ce-source", headers.getOrDefault(CloudEvents.CAMEL_CLOUD_EVENT_SOURCE, "org.apache.camel")); - - if (headers.containsKey(CloudEvents.CAMEL_CLOUD_EVENT_SUBJECT)) { - headers.put("ce-subject", headers.get(CloudEvents.CAMEL_CLOUD_EVENT_SUBJECT)); - } - - headers.put("ce-time", headers.getOrDefault(CloudEvents.CAMEL_CLOUD_EVENT_TIME, CloudEvents.getEventTime(message.getExchange()))); - headers.put(Exchange.CONTENT_TYPE, headers.getOrDefault(CloudEvents.CAMEL_CLOUD_EVENT_CONTENT_TYPE, "application/json")); - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/Json.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/Json.java deleted file mode 100644 index b1ce762d4..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/Json.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.json; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.TextNode; -import org.apache.camel.util.StringHelper; - -public final class Json { - - public static final ObjectMapper MAPPER = new ObjectMapper(); - - private Json() { - // prevent instantiation of utility class - } - - /** - * Checks given value to be a Json array of object representation. - * @param value - * @return - */ - public static boolean isJson(String value) { - if (value == null) { - return false; - } - - return isJsonObject(value) || isJsonArray(value); - } - - /** - * Checks given value could be JSON object string. - * @param value - * @return - */ - public static boolean isJsonObject(String value) { - if (value == null || value.isEmpty() || value.isBlank()) { - return false; - } - - final String trimmed = value.trim(); - - return trimmed.charAt(0) == '{' && trimmed.charAt(trimmed.length() - 1) == '}'; - } - - /** - * Checks given value could be JSON array string. - * @param value - * @return - */ - public static boolean isJsonArray(String value) { - if (value == null || value.isEmpty() || value.isBlank()) { - return false; - } - - final String trimmed = value.trim(); - - return trimmed.charAt(0) == '[' && trimmed.charAt(trimmed.length() - 1) == ']'; - } - - /** - * Converts array json node to a list of json object strings. Used when splitting a - * json array with split EIP. - * @param json - * @return - * @throws JsonProcessingException - */ - public static List arrayToJsonBeans(JsonNode json) throws JsonProcessingException { - List jsonBeans = new ArrayList<>(); - - if (json.isArray()) { - Iterator it = json.elements(); - while (it.hasNext()) { - Object item = it.next(); - if (item instanceof TextNode) { - jsonBeans.add(StringHelper.removeLeadingAndEndingQuotes(((TextNode) item).asText())); - } else { - jsonBeans.add(MAPPER.writeValueAsString(item)); - } - } - - return jsonBeans; - } - - return jsonBeans; - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonDataType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonDataType.java deleted file mode 100644 index 188af51e7..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonDataType.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.json; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import org.apache.camel.CamelExecutionException; -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.kamelets.utils.format.MimeType; -import org.apache.camel.kamelets.utils.format.converter.utils.SchemaHelper; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.DataTypeTransformer; -import org.apache.camel.spi.Transformer; - -/** - * Data type uses Jackson data format to marshal given Exchange payload to a Json (binary byte array representation). - * Requires Exchange payload as JsonNode representation. - */ -@DataTypeTransformer(name = "application-json") -public class JsonDataType extends Transformer { - - @Override - public void transform(Message message, DataType fromType, DataType toType) { - try { - byte[] marshalled = Json.MAPPER.writer().forType(JsonNode.class).writeValueAsBytes(message.getBody()); - message.setBody(marshalled); - - message.setHeader(Exchange.CONTENT_TYPE, MimeType.JSON.type()); - message.setHeader(SchemaHelper.CONTENT_SCHEMA, - message.getExchange().getProperty(SchemaHelper.CONTENT_SCHEMA, "", String.class)); - } catch (JsonProcessingException e) { - throw new CamelExecutionException("Failed to apply Json output data type on exchange", message.getExchange(), e); - } - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonFormatSchema.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonFormatSchema.java deleted file mode 100644 index cea76aa6b..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonFormatSchema.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.apache.camel.kamelets.utils.format.converter.json; - -import com.fasterxml.jackson.core.FormatSchema; -import com.fasterxml.jackson.databind.JsonNode; -import org.apache.camel.kamelets.utils.format.SchemaType; - -public class JsonFormatSchema implements FormatSchema { - private final JsonNode schema; - - public JsonFormatSchema(JsonNode schema) { - this.schema = schema; - } - - @Override - public String getSchemaType() { - return SchemaType.JSON.type(); - } - - public JsonNode getSchema() { - return schema; - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonSchemaResolver.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonSchemaResolver.java deleted file mode 100644 index 74a42a33e..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonSchemaResolver.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.json; - -import java.io.InputStream; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import com.fasterxml.jackson.core.FormatSchema; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.component.jackson.SchemaResolver; -import org.apache.camel.kamelets.utils.format.SchemaType; -import org.apache.camel.kamelets.utils.format.converter.utils.SchemaHelper; -import org.apache.camel.spi.Resource; -import org.apache.camel.support.PluginHelper; -import org.apache.camel.util.ObjectHelper; - -public class JsonSchemaResolver implements SchemaResolver, Processor { - private final ConcurrentMap schemes; - - private JsonNode schema; - private String contentClass; - - public JsonSchemaResolver() { - this.schemes = new ConcurrentHashMap<>(); - } - - public String getSchema() { - if (this.schema != null) { - try { - return Json.MAPPER.writeValueAsString(this.schema); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } - - return null; - } - - public void setSchema(String schema) { - if (ObjectHelper.isNotEmpty(schema)) { - try { - this.schema = Json.MAPPER.readTree(schema); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } else { - this.schema = null; - } - } - - public String getContentClass() { - return contentClass; - } - - public void setContentClass(String contentClass) { - if (ObjectHelper.isNotEmpty(contentClass)) { - this.contentClass = contentClass; - } else { - this.contentClass = null; - } - } - - @Override - public void process(Exchange exchange) throws Exception { - Object payload = exchange.getMessage().getBody(); - if (payload == null) { - return; - } - - JsonNode answer = computeIfAbsent(exchange); - - if (answer != null) { - exchange.setProperty(SchemaHelper.CONTENT_SCHEMA, answer); - exchange.setProperty(SchemaHelper.CONTENT_SCHEMA_TYPE, SchemaType.JSON.type()); - exchange.setProperty(SchemaHelper.CONTENT_CLASS, SchemaHelper.resolveContentClass(exchange, this.contentClass)); - } - } - - private JsonNode computeIfAbsent(Exchange exchange) { - if (this.schema != null) { - return this.schema; - } - - JsonNode answer = exchange.getProperty(SchemaHelper.CONTENT_SCHEMA, JsonNode.class); - - if (answer == null && exchange.getProperties().containsKey(SchemaHelper.SCHEMA)) { - String schemaJson = exchange.getProperty(SchemaHelper.SCHEMA, String.class); - try { - answer = Json.MAPPER.readTree(schemaJson); - } catch (JsonProcessingException e) { - throw new RuntimeException("Unable to load Json schema", e); - } - } - - if (answer == null) { - String contentClass = SchemaHelper.resolveContentClass(exchange, this.contentClass); - if (contentClass != null) { - answer = this.schemes.computeIfAbsent(contentClass, t -> { - Resource res = PluginHelper.getResourceLoader(exchange.getContext()) - .resolveResource("classpath:schemas/" + SchemaType.JSON.type() + "/" + t + "." + SchemaType.JSON.type()); - - try { - if (res.exists()) { - try (InputStream is = res.getInputStream()) { - if (is != null) { - return Json.MAPPER.readTree(is); - } - } - } - } catch (Exception e) { - throw new RuntimeException( - "Unable to load Json schema for type: " + t + ", resource: " + res.getLocation(), e); - } - - return null; - }); - } - } - - if (answer != null) { - this.schema = answer; - } - - return answer; - } - - @Override - public FormatSchema resolve(Exchange exchange) { - JsonNode answer = exchange.getProperty(SchemaHelper.CONTENT_SCHEMA, JsonNode.class); - if (answer == null) { - answer = computeIfAbsent(exchange); - } - - return new JsonFormatSchema(answer); - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonStructDataType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonStructDataType.java deleted file mode 100644 index 948fa704b..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonStructDataType.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.json; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; - -import com.fasterxml.jackson.databind.JsonNode; -import org.apache.camel.CamelExecutionException; -import org.apache.camel.Exchange; -import org.apache.camel.InvalidPayloadException; -import org.apache.camel.Message; -import org.apache.camel.kamelets.utils.format.MimeType; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.DataTypeTransformer; -import org.apache.camel.spi.Transformer; - -/** - * Data type uses Jackson data format to unmarshal Exchange body to generic JsonNode representation. - */ -@DataTypeTransformer(name = "application-x-struct") -public class JsonStructDataType extends Transformer { - - @Override - public void transform(Message message, DataType fromType, DataType toType) { - try { - Object unmarshalled = Json.MAPPER.reader().forType(JsonNode.class).readValue(getBodyAsStream(message)); - message.setBody(unmarshalled); - - message.setHeader(Exchange.CONTENT_TYPE, MimeType.STRUCT.type()); - } catch (InvalidPayloadException | IOException e) { - throw new CamelExecutionException("Failed to apply Json input data type on exchange", message.getExchange(), e); - } - } - - private InputStream getBodyAsStream(Message message) throws InvalidPayloadException { - if (message.getBody() == null) { - return new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)); - } - - InputStream bodyStream = message.getBody(InputStream.class); - - if (bodyStream == null) { - bodyStream = new ByteArrayInputStream(message.getMandatoryBody(byte[].class)); - } - - return bodyStream; - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/pojo/JavaObjectDataType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/pojo/JavaObjectDataType.java deleted file mode 100644 index 80de04727..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/pojo/JavaObjectDataType.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.pojo; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -import com.fasterxml.jackson.core.FormatSchema; -import org.apache.camel.CamelContext; -import org.apache.camel.CamelContextAware; -import org.apache.camel.CamelExecutionException; -import org.apache.camel.Exchange; -import org.apache.camel.InvalidPayloadException; -import org.apache.camel.Message; -import org.apache.camel.kamelets.utils.format.MimeType; -import org.apache.camel.kamelets.utils.format.SchemaType; -import org.apache.camel.kamelets.utils.format.converter.avro.Avro; -import org.apache.camel.kamelets.utils.format.converter.json.Json; -import org.apache.camel.kamelets.utils.format.converter.utils.SchemaHelper; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.DataTypeTransformer; -import org.apache.camel.spi.Transformer; -import org.apache.camel.util.ObjectHelper; - -/** - * Data type able to unmarshal Exchange body to Java object. Supports both Avro and Json schema types and uses respective - * Jackson implementation for the unmarshal operation. - * Requires proper setting of content schema, class and schema type in Exchange properties - * (usually resolved via Avro or Json schema resolver Kamelet action). - */ -@DataTypeTransformer(name = "application-x-java-object") -public class JavaObjectDataType extends Transformer implements CamelContextAware { - - private CamelContext camelContext; - - @Override - public void transform(Message message, DataType fromType, DataType toType) { - ObjectHelper.notNull(camelContext, "camelContext"); - - FormatSchema schema = message.getExchange().getProperty(SchemaHelper.CONTENT_SCHEMA, FormatSchema.class); - if (schema == null) { - throw new CamelExecutionException("Missing proper schema for Java object data type processing", message.getExchange()); - } - - String contentClass = SchemaHelper.resolveContentClass(message.getExchange(), null); - if (contentClass == null) { - throw new CamelExecutionException("Missing content class information for Java object data type processing", - message.getExchange()); - } - - SchemaType schemaType = SchemaType.of(message.getExchange().getProperty(SchemaHelper.CONTENT_SCHEMA_TYPE, SchemaType.JSON.type(), String.class)); - - try { - Class contentType = camelContext.getClassResolver().resolveMandatoryClass(contentClass); - Object unmarshalled; - - if (schemaType == SchemaType.AVRO) { - unmarshalled = Avro.MAPPER.reader().forType(contentType).with(schema).readValue(getBodyAsStream(message)); - } else if (schemaType == SchemaType.JSON) { - unmarshalled = Json.MAPPER.reader().forType(contentType).with(schema).readValue(getBodyAsStream(message)); - } else { - throw new CamelExecutionException(String.format("Unsupported schema type '%s'", schemaType), message.getExchange()); - } - - message.setBody(unmarshalled); - - message.setHeader(Exchange.CONTENT_TYPE, MimeType.STRUCT.type()); - } catch (InvalidPayloadException | IOException | ClassNotFoundException e) { - throw new CamelExecutionException("Failed to apply Java object data type on exchange", message.getExchange(), e); - } - } - - private InputStream getBodyAsStream(Message message) throws InvalidPayloadException { - InputStream bodyStream = message.getBody(InputStream.class); - - if (bodyStream == null) { - bodyStream = new ByteArrayInputStream(message.getMandatoryBody(byte[].class)); - } - - return bodyStream; - } - - @Override - public CamelContext getCamelContext() { - return camelContext; - } - - @Override - public void setCamelContext(CamelContext camelContext) { - this.camelContext = camelContext; - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/utils/CloudEvents.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/utils/CloudEvents.java deleted file mode 100644 index d88ef661f..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/utils/CloudEvents.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.utils; - -import java.time.Instant; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; - -import org.apache.camel.Exchange; - -/** - * Helper class to manage CloudEvents specific Camel message headers and other utilities. - */ -public class CloudEvents { - - public static final String CAMEL_CLOUD_EVENT_ID = "CamelCloudEventID"; - public static final String CAMEL_CLOUD_EVENT_VERSION = "CamelCloudEventVersion"; - public static final String CAMEL_CLOUD_EVENT_TYPE = "CamelCloudEventType"; - public static final String CAMEL_CLOUD_EVENT_SOURCE = "CamelCloudEventSource"; - public static final String CAMEL_CLOUD_EVENT_SUBJECT = "CamelCloudEventSubject"; - public static final String CAMEL_CLOUD_EVENT_TIME = "CamelCloudEventTime"; - public static final String CAMEL_CLOUD_EVENT_CONTENT_TYPE = Exchange.CONTENT_TYPE; - - public static String getEventTime(Exchange exchange) { - final ZonedDateTime created - = ZonedDateTime.ofInstant(Instant.ofEpochMilli(exchange.getCreated()), ZoneId.systemDefault()); - return DateTimeFormatter.ISO_INSTANT.format(created); - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/utils/PojoHelper.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/utils/PojoHelper.java deleted file mode 100644 index 17f222801..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/utils/PojoHelper.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.utils; - -import java.util.Objects; - -import org.apache.camel.Exchange; - -public final class PojoHelper { - private PojoHelper() { - } - - public static boolean isString(Class type) { - return String.class.isAssignableFrom(type); - } - - public static boolean isNumber(Class type) { - return Number.class.isAssignableFrom(type) - || int.class.isAssignableFrom(type) - || long.class.isAssignableFrom(type) - || short.class.isAssignableFrom(type) - || char.class.isAssignableFrom(type) - || float.class.isAssignableFrom(type) - || double.class.isAssignableFrom(type); - } - - public static boolean isPrimitive(Class type) { - return type.isPrimitive() - || (type.isArray() && type.getComponentType().isPrimitive()) - || char.class.isAssignableFrom(type) || Character.class.isAssignableFrom(type) - || byte.class.isAssignableFrom(type) || Byte.class.isAssignableFrom(type) - || boolean.class.isAssignableFrom(type) || Boolean.class.isAssignableFrom(type); - } - - public static boolean isPojo(Class type) { - Package pkg = type.getPackage(); - if (pkg != null) { - if (pkg.getName().startsWith("java") - || pkg.getName().startsWith("javax") - || pkg.getName().startsWith("com.sun") - || pkg.getName().startsWith("com.oracle")) { - return false; - } - } - - if (isNumber(type)) { - return false; - } - if (isPrimitive(type)) { - return false; - } - if (isString(type)) { - return false; - } - - return true; - } - - public static boolean hasProperty(Exchange exchange, String name) { - return exchange.getProperties().containsKey(name); - } - - public static boolean hasProperty(Exchange exchange, String name, Object value) { - return Objects.equals( - value, - exchange.getProperty(name, value.getClass())); - } - - public static boolean hasHeader(Exchange exchange, String name, Object value) { - return Objects.equals( - value, - exchange.getMessage().getHeader(name, value.getClass())); - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/utils/SchemaHelper.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/utils/SchemaHelper.java deleted file mode 100644 index 87dea3f69..000000000 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/utils/SchemaHelper.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.camel.kamelets.utils.format.converter.utils; - -import org.apache.camel.Exchange; - -public class SchemaHelper { - - public static final String SCHEMA = "schema"; - public static final String VALIDATE = "validate"; - public static final String CONTENT_SCHEMA = "X-Content-Schema"; - public static final String CONTENT_SCHEMA_TYPE = "X-Content-Schema-Type"; - public static final String CONTENT_CLASS = "X-Content-Class"; - - private SchemaHelper() { - } - - /** - * Helper resolves content class from exchange properties and as a fallback tries to retrieve the content class - * from the payload body type. - * @param exchange the Camel exchange eventually holding content class information in its properties. - * @param fallback the fallback content class information when no exchange property is set. - * @return the content class as String representation. - */ - public static String resolveContentClass(Exchange exchange, String fallback) { - String contentClass = exchange.getProperty(CONTENT_CLASS, fallback, String.class); - if (contentClass == null) { - Object payload = exchange.getMessage().getBody(); - if (payload != null && PojoHelper.isPojo(payload.getClass())) { - contentClass = payload.getClass().getName(); - } - } - - return contentClass; - } -} diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/schema/DelegatingSchemaResolver.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/schema/DelegatingSchemaResolver.java index 26b541ee8..dba0fae2e 100644 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/schema/DelegatingSchemaResolver.java +++ b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/schema/DelegatingSchemaResolver.java @@ -19,10 +19,10 @@ import org.apache.camel.Exchange; import org.apache.camel.Processor; +import org.apache.camel.component.jackson.avro.transform.AvroSchemaResolver; +import org.apache.camel.component.jackson.transform.JsonSchemaResolver; import org.apache.camel.kamelets.utils.format.MimeType; -import org.apache.camel.kamelets.utils.format.converter.avro.AvroSchemaResolver; -import org.apache.camel.kamelets.utils.format.converter.json.JsonSchemaResolver; -import org.apache.camel.kamelets.utils.format.converter.protobuf.ProtobufSchemaResolver; +import org.apache.camel.kamelets.utils.format.schema.protobuf.ProtobufSchemaResolver; import org.apache.camel.util.ObjectHelper; /** diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/protobuf/Protobuf.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/schema/protobuf/Protobuf.java similarity index 94% rename from library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/protobuf/Protobuf.java rename to library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/schema/protobuf/Protobuf.java index 1bb5d1c18..2cb446898 100644 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/protobuf/Protobuf.java +++ b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/schema/protobuf/Protobuf.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.camel.kamelets.utils.format.converter.protobuf; +package org.apache.camel.kamelets.utils.format.schema.protobuf; import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper; diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/protobuf/ProtobufSchemaResolver.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/schema/protobuf/ProtobufSchemaResolver.java similarity index 97% rename from library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/protobuf/ProtobufSchemaResolver.java rename to library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/schema/protobuf/ProtobufSchemaResolver.java index 9fba10912..dfa37609e 100644 --- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/protobuf/ProtobufSchemaResolver.java +++ b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/schema/protobuf/ProtobufSchemaResolver.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.camel.kamelets.utils.format.converter.protobuf; +package org.apache.camel.kamelets.utils.format.schema.protobuf; import java.io.IOException; import java.io.InputStream; @@ -29,9 +29,9 @@ import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.RuntimeCamelException; +import org.apache.camel.component.jackson.SchemaHelper; import org.apache.camel.component.jackson.SchemaResolver; import org.apache.camel.kamelets.utils.format.SchemaType; -import org.apache.camel.kamelets.utils.format.converter.utils.SchemaHelper; import org.apache.camel.spi.Resource; import org.apache.camel.support.PluginHelper; import org.apache.camel.util.ObjectHelper; diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/DataTypeConverter b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/DataTypeConverter deleted file mode 100644 index 96cc4b098..000000000 --- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/DataTypeConverter +++ /dev/null @@ -1,25 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -org.apache.camel.kamelets.utils.format.converter.bytes -org.apache.camel.kamelets.utils.format.converter.text -org.apache.camel.kamelets.utils.format.converter.pojo -org.apache.camel.kamelets.utils.format.converter.avro -org.apache.camel.kamelets.utils.format.converter.json -org.apache.camel.kamelets.utils.format.converter.aws2.s3 -org.apache.camel.kamelets.utils.format.converter.aws2.ddb -org.apache.camel.kamelets.utils.format.converter.http diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/application-json b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/application-json deleted file mode 100644 index 18aebea05..000000000 --- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/application-json +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.kamelets.utils.format.converter.json.JsonDataType diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/application-x-java-object b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/application-x-java-object deleted file mode 100644 index 3f8079835..000000000 --- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/application-x-java-object +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.kamelets.utils.format.converter.pojo.JavaObjectDataType diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/application-x-struct b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/application-x-struct deleted file mode 100644 index fef2aab83..000000000 --- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/application-x-struct +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.kamelets.utils.format.converter.json.JsonStructDataType diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/avro-binary b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/avro-binary deleted file mode 100644 index 69fc53091..000000000 --- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/avro-binary +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.kamelets.utils.format.converter.avro.AvroBinaryDataType diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/avro-x-struct b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/avro-x-struct deleted file mode 100644 index 070e3147c..000000000 --- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/avro-x-struct +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.kamelets.utils.format.converter.avro.AvroStructDataType diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-ddb-application-json b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-ddb-application-json deleted file mode 100644 index f0194cc41..000000000 --- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-ddb-application-json +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.kamelets.utils.format.converter.aws2.ddb.Ddb2JsonInputType \ No newline at end of file diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-s3-application-cloudevents b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-s3-application-cloudevents deleted file mode 100644 index fafdd926a..000000000 --- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-s3-application-cloudevents +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.kamelets.utils.format.converter.aws2.s3.AWS2S3CloudEventOutputType \ No newline at end of file diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-sqs-application-cloudevents b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-sqs-application-cloudevents deleted file mode 100644 index 14d4df6f1..000000000 --- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-sqs-application-cloudevents +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.kamelets.utils.format.converter.aws2.sqs.AWS2SQSCloudEventOutputType \ No newline at end of file diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/azure-storage-blob-application-cloudevents b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/azure-storage-blob-application-cloudevents deleted file mode 100644 index b3efe4e95..000000000 --- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/azure-storage-blob-application-cloudevents +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.kamelets.utils.format.converter.azure.storage.blob.AzureStorageBlobCloudEventOutputType \ No newline at end of file diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/google-sheets-application-x-struct b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/google-sheets-application-x-struct deleted file mode 100644 index 0af4a3fea..000000000 --- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/google-sheets-application-x-struct +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.kamelets.utils.format.converter.google.sheets.GoogleSheetsJsonStructDataType diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/google-storage-application-cloudevents b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/google-storage-application-cloudevents deleted file mode 100644 index 8f85fc34b..000000000 --- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/google-storage-application-cloudevents +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.kamelets.utils.format.converter.google.storage.GoogleStorageCloudEventOutputType \ No newline at end of file diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/http-application-cloudevents b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/http-application-cloudevents deleted file mode 100644 index e74fe8e21..000000000 --- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/http-application-cloudevents +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.kamelets.utils.format.converter.http.HttpCloudEventOutputType diff --git a/library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/aws2/ddb/Ddb2JsonInputTypeTest.java b/library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/aws2/ddb/Ddb2JsonInputTypeTest.java deleted file mode 100644 index efa600b0d..000000000 --- a/library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/aws2/ddb/Ddb2JsonInputTypeTest.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.aws2.ddb; - -import java.util.Map; - -import org.apache.camel.CamelExecutionException; -import org.apache.camel.Exchange; -import org.apache.camel.component.aws2.ddb.Ddb2Constants; -import org.apache.camel.component.aws2.ddb.Ddb2Operations; -import org.apache.camel.impl.DefaultCamelContext; -import org.apache.camel.impl.engine.TransformerKey; -import org.apache.camel.kamelets.utils.format.converter.json.Json; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.Transformer; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import software.amazon.awssdk.services.dynamodb.model.AttributeAction; -import software.amazon.awssdk.services.dynamodb.model.AttributeValue; -import software.amazon.awssdk.services.dynamodb.model.AttributeValueUpdate; -import software.amazon.awssdk.services.dynamodb.model.ReturnValue; - -public class Ddb2JsonInputTypeTest { - - public static final String AWS_2_DDB_APPLICATION_JSON_TRANSFORMER = "aws2-ddb:application-json"; - private DefaultCamelContext camelContext; - - private final Ddb2JsonInputType inputType = new Ddb2JsonInputType(); - - private final String keyJson = "{" + - "\"name\": \"Rajesh Koothrappali\"" + - "}"; - - private final String itemJson = "{" + - "\"name\": \"Rajesh Koothrappali\"," + - "\"age\": 29," + - "\"super-heroes\": [\"batman\", \"spiderman\", \"wonderwoman\"]," + - "\"issues\": [5, 3, 9, 1]," + - "\"girlfriend\": null," + - "\"doctorate\": true" + - "}"; - - @BeforeEach - void setup() { - this.camelContext = new DefaultCamelContext(); - } - - @Test - @SuppressWarnings("unchecked") - void shouldMapPutItemHeaders() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - - exchange.getMessage().setBody(Json.MAPPER.readTree(itemJson)); - exchange.setProperty("operation", Ddb2Operations.PutItem.name()); - inputType.transform(exchange.getMessage(), DataType.ANY, new DataType(AWS_2_DDB_APPLICATION_JSON_TRANSFORMER)); - - Assertions.assertTrue(exchange.getMessage().hasHeaders()); - Assertions.assertEquals(Ddb2Operations.PutItem, exchange.getMessage().getHeader(Ddb2Constants.OPERATION)); - Assertions.assertEquals(ReturnValue.ALL_OLD.toString(), exchange.getMessage().getHeader(Ddb2Constants.RETURN_VALUES)); - - assertAttributeValueMap(exchange.getMessage().getHeader(Ddb2Constants.ITEM, Map.class)); - } - - @Test - @SuppressWarnings("unchecked") - void shouldMapUpdateItemHeaders() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - - exchange.getMessage().setBody(Json.MAPPER.readTree("{\"operation\": \"" + Ddb2Operations.UpdateItem.name() + "\", \"key\": " - + keyJson + ", \"item\": " + itemJson + "}")); - - inputType.transform(exchange.getMessage(), DataType.ANY, new DataType(AWS_2_DDB_APPLICATION_JSON_TRANSFORMER)); - - Assertions.assertTrue(exchange.getMessage().hasHeaders()); - Assertions.assertEquals(Ddb2Operations.UpdateItem, exchange.getMessage().getHeader(Ddb2Constants.OPERATION)); - Assertions.assertEquals(ReturnValue.ALL_NEW.toString(), exchange.getMessage().getHeader(Ddb2Constants.RETURN_VALUES)); - - Map attributeValueMap = exchange.getMessage().getHeader(Ddb2Constants.KEY, Map.class); - Assertions.assertEquals(1L, attributeValueMap.size()); - Assertions.assertEquals(AttributeValue.builder().s("Rajesh Koothrappali").build(), attributeValueMap.get("name")); - - assertAttributeValueUpdateMap(exchange.getMessage().getHeader(Ddb2Constants.UPDATE_VALUES, Map.class)); - } - - @Test - @SuppressWarnings("unchecked") - void shouldMapDeleteItemHeaders() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - - exchange.getMessage().setBody(Json.MAPPER.readTree("{\"key\": " + keyJson + "}")); - exchange.setProperty("operation", Ddb2Operations.DeleteItem.name()); - - inputType.transform(exchange.getMessage(), DataType.ANY, new DataType(AWS_2_DDB_APPLICATION_JSON_TRANSFORMER)); - - Assertions.assertTrue(exchange.getMessage().hasHeaders()); - Assertions.assertEquals(Ddb2Operations.DeleteItem, exchange.getMessage().getHeader(Ddb2Constants.OPERATION)); - Assertions.assertEquals(ReturnValue.ALL_OLD.toString(), exchange.getMessage().getHeader(Ddb2Constants.RETURN_VALUES)); - - Map attributeValueMap = exchange.getMessage().getHeader(Ddb2Constants.KEY, Map.class); - Assertions.assertEquals(1L, attributeValueMap.size()); - Assertions.assertEquals(AttributeValue.builder().s("Rajesh Koothrappali").build(), attributeValueMap.get("name")); - } - - @Test - @SuppressWarnings("unchecked") - void shouldMapNestedObjects() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - - exchange.getMessage().setBody(Json.MAPPER.readTree("{\"user\":" + itemJson + "}")); - exchange.setProperty("operation", Ddb2Operations.PutItem.name()); - inputType.transform(exchange.getMessage(), DataType.ANY, new DataType(AWS_2_DDB_APPLICATION_JSON_TRANSFORMER)); - - Assertions.assertTrue(exchange.getMessage().hasHeaders()); - Assertions.assertEquals(Ddb2Operations.PutItem, exchange.getMessage().getHeader(Ddb2Constants.OPERATION)); - Assertions.assertEquals(ReturnValue.ALL_OLD.toString(), exchange.getMessage().getHeader(Ddb2Constants.RETURN_VALUES)); - - Map attributeValueMap = exchange.getMessage().getHeader(Ddb2Constants.ITEM, Map.class); - Assertions.assertEquals(1L, attributeValueMap.size()); - - Assertions.assertEquals("AttributeValue(M={name=AttributeValue(S=Rajesh Koothrappali), " + - "age=AttributeValue(N=29), " + - "super-heroes=AttributeValue(SS=[batman, spiderman, wonderwoman]), " + - "issues=AttributeValue(NS=[5, 3, 9, 1]), " + - "girlfriend=AttributeValue(NUL=true), " + - "doctorate=AttributeValue(BOOL=true)})", - attributeValueMap.get("user").toString()); - } - - @Test - @SuppressWarnings("unchecked") - void shouldMapEmptyJson() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - - exchange.getMessage().setBody("{}"); - exchange.getMessage().setHeader(Ddb2Constants.OPERATION, Ddb2Operations.PutItem.name()); - - inputType.transform(exchange.getMessage(), DataType.ANY, new DataType(AWS_2_DDB_APPLICATION_JSON_TRANSFORMER)); - - Assertions.assertTrue(exchange.getMessage().hasHeaders()); - Assertions.assertEquals(Ddb2Operations.PutItem, exchange.getMessage().getHeader(Ddb2Constants.OPERATION)); - Assertions.assertEquals(ReturnValue.ALL_OLD.toString(), exchange.getMessage().getHeader(Ddb2Constants.RETURN_VALUES)); - - Map attributeValueMap = exchange.getMessage().getHeader(Ddb2Constants.ITEM, Map.class); - Assertions.assertEquals(0L, attributeValueMap.size()); - } - - @Test - void shouldFailForWrongBodyType() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - - exchange.getMessage().setBody("Hello"); - - Assertions.assertThrows(CamelExecutionException.class, () -> inputType.transform(exchange.getMessage(), DataType.ANY, new DataType(AWS_2_DDB_APPLICATION_JSON_TRANSFORMER))); - } - - @Test - void shouldFailForUnsupportedOperation() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - - exchange.getMessage().setBody(Json.MAPPER.readTree("{}")); - exchange.setProperty("operation", Ddb2Operations.BatchGetItems.name()); - - Assertions.assertThrows(UnsupportedOperationException.class, () -> inputType.transform(exchange.getMessage(), DataType.ANY, new DataType(AWS_2_DDB_APPLICATION_JSON_TRANSFORMER))); - } - - @Test - public void shouldLookupDataType() throws Exception { - Transformer transformer = camelContext.getTransformerRegistry().resolveTransformer(new TransformerKey(DataType.ANY, new DataType(AWS_2_DDB_APPLICATION_JSON_TRANSFORMER))); - Assertions.assertNotNull(transformer); - } - - private void assertAttributeValueMap(Map attributeValueMap) { - Assertions.assertEquals(6L, attributeValueMap.size()); - Assertions.assertEquals(AttributeValue.builder().s("Rajesh Koothrappali").build(), attributeValueMap.get("name")); - Assertions.assertEquals(AttributeValue.builder().n("29").build(), attributeValueMap.get("age")); - Assertions.assertEquals(AttributeValue.builder().ss("batman", "spiderman", "wonderwoman").build(), - attributeValueMap.get("super-heroes")); - Assertions.assertEquals(AttributeValue.builder().ns("5", "3", "9", "1").build(), attributeValueMap.get("issues")); - Assertions.assertEquals(AttributeValue.builder().nul(true).build(), attributeValueMap.get("girlfriend")); - Assertions.assertEquals(AttributeValue.builder().bool(true).build(), attributeValueMap.get("doctorate")); - } - - private void assertAttributeValueUpdateMap(Map attributeValueMap) { - Assertions.assertEquals(6L, attributeValueMap.size()); - Assertions.assertEquals(AttributeValueUpdate.builder().value(AttributeValue.builder().s("Rajesh Koothrappali").build()) - .action(AttributeAction.PUT).build(), attributeValueMap.get("name")); - Assertions.assertEquals(AttributeValueUpdate.builder().value(AttributeValue.builder().n("29").build()) - .action(AttributeAction.PUT).build(), attributeValueMap.get("age")); - Assertions.assertEquals( - AttributeValueUpdate.builder().value(AttributeValue.builder().ss("batman", "spiderman", "wonderwoman").build()) - .action(AttributeAction.PUT).build(), - attributeValueMap.get("super-heroes")); - Assertions.assertEquals(AttributeValueUpdate.builder().value(AttributeValue.builder().ns("5", "3", "9", "1").build()) - .action(AttributeAction.PUT).build(), attributeValueMap.get("issues")); - Assertions.assertEquals(AttributeValueUpdate.builder().value(AttributeValue.builder().nul(true).build()) - .action(AttributeAction.PUT).build(), attributeValueMap.get("girlfriend")); - Assertions.assertEquals(AttributeValueUpdate.builder().value(AttributeValue.builder().bool(true).build()) - .action(AttributeAction.PUT).build(), attributeValueMap.get("doctorate")); - } -} diff --git a/library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/GoogleSheetsJsonStructDataTypeTest.java b/library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/GoogleSheetsJsonStructDataTypeTest.java deleted file mode 100644 index 3ceba8aac..000000000 --- a/library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/google/sheets/GoogleSheetsJsonStructDataTypeTest.java +++ /dev/null @@ -1,429 +0,0 @@ -package org.apache.camel.kamelets.utils.format.converter.google.sheets; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; -import java.util.stream.Stream; - -import com.google.api.services.sheets.v4.model.ValueRange; -import org.apache.camel.Exchange; -import org.apache.camel.component.google.sheets.internal.GoogleSheetsConstants; -import org.apache.camel.component.google.sheets.stream.GoogleSheetsStreamConstants; -import org.apache.camel.impl.DefaultCamelContext; -import org.apache.camel.spi.DataType; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; - -public class GoogleSheetsJsonStructDataTypeTest { - - private final GoogleSheetsJsonStructDataType dataType = new GoogleSheetsJsonStructDataType(); - private DefaultCamelContext camelContext; - - private String spreadsheetId; - - @BeforeEach - void setup() { - this.camelContext = new DefaultCamelContext(); - this.spreadsheetId = UUID.randomUUID().toString(); - } - - public static Stream transformFromSplitValuesData() { - return Stream.of( - Arguments.of("A1", "Sheet1", RangeCoordinate.DIMENSION_ROWS, "A", Collections.singletonList("a1"), - "{\"spreadsheetId\":\"%s\", \"A\":\"a1\"}"), - Arguments.of("A1:A5", "Sheet1", RangeCoordinate.DIMENSION_COLUMNS, "A", Arrays.asList("a1", "a2", "a3", "a4", "a5"), - "{\"spreadsheetId\":\"%s\", \"#1\":\"a1\",\"#2\":\"a2\",\"#3\":\"a3\",\"#4\":\"a4\",\"#5\":\"a5\"}"), - Arguments.of("A1:B2", "Sheet1", RangeCoordinate.DIMENSION_ROWS, "A", Arrays.asList("a1", "b1"), - "{\"spreadsheetId\":\"%s\", \"A\":\"a1\",\"B\":\"b1\"}"), - Arguments.of("A1:B2", "Sheet1", RangeCoordinate.DIMENSION_ROWS, "Foo,Bar", Arrays.asList("a1", "b1"), - "{\"spreadsheetId\":\"%s\", \"Foo\":\"a1\",\"Bar\":\"b1\"}"), - Arguments.of("A1:B2", "Sheet1", RangeCoordinate.DIMENSION_COLUMNS, "A", Arrays.asList("a1", "a2"), - "{\"spreadsheetId\":\"%s\", \"#1\":\"a1\",\"#2\":\"a2\"}") - ); - } - - public static Stream transformFromValueRangeData() { - return Stream.of( - Arguments.of("A1:A5", "Sheet1", RangeCoordinate.DIMENSION_ROWS, "A", - Arrays.asList(Collections.singletonList("a1"), - Collections.singletonList("a2"), - Collections.singletonList("a3"), - Collections.singletonList("a4"), - Collections.singletonList("a5")), - Arrays.asList("{\"spreadsheetId\":\"%s\", \"A\":\"a1\"}", - "{\"spreadsheetId\":\"%s\", \"A\":\"a2\"}", - "{\"spreadsheetId\":\"%s\", \"A\":\"a3\"}", - "{\"spreadsheetId\":\"%s\", \"A\":\"a4\"}", - "{\"spreadsheetId\":\"%s\", \"A\":\"a5\"}")), - Arguments.of("A1:A5", "Sheet1", RangeCoordinate.DIMENSION_ROWS, "Foo", - Arrays.asList(Collections.singletonList("a1"), - Collections.singletonList("a2"), - Collections.singletonList("a3"), - Collections.singletonList("a4"), - Collections.singletonList("a5")), - Arrays.asList("{\"spreadsheetId\":\"%s\", \"Foo\":\"a1\"}", - "{\"spreadsheetId\":\"%s\", \"Foo\":\"a2\"}", - "{\"spreadsheetId\":\"%s\", \"Foo\":\"a3\"}", - "{\"spreadsheetId\":\"%s\", \"Foo\":\"a4\"}", - "{\"spreadsheetId\":\"%s\", \"Foo\":\"a5\"}")), - Arguments.of("A1:A5", "Sheet1", RangeCoordinate.DIMENSION_COLUMNS, "A", - Collections.singletonList(Arrays.asList("a1", "a2", "a3", "a4", "a5")), - Collections.singletonList("{\"spreadsheetId\":\"%s\", \"#1\":\"a1\",\"#2\":\"a2\",\"#3\":\"a3\",\"#4\":\"a4\",\"#5\":\"a5\"}")), - Arguments.of("A1:B2", "Sheet1", RangeCoordinate.DIMENSION_ROWS, "A", - Arrays.asList(Arrays.asList("a1", "b1"), Arrays.asList("a2", "b2")), - Arrays.asList("{\"spreadsheetId\":\"%s\", \"A\":\"a1\",\"B\":\"b1\"}", - "{\"spreadsheetId\":\"%s\", \"A\":\"a2\",\"B\":\"b2\"}")), - Arguments.of("A1:B2", "Sheet1", RangeCoordinate.DIMENSION_ROWS, "Foo,Bar", - Arrays.asList(Arrays.asList("a1", "b1"), Arrays.asList("a2", "b2")), - Arrays.asList("{\"spreadsheetId\":\"%s\", \"Foo\":\"a1\",\"Bar\":\"b1\"}", - "{\"spreadsheetId\":\"%s\", \"Foo\":\"a2\",\"Bar\":\"b2\"}")), - Arguments.of("A1:B2", "Sheet1", RangeCoordinate.DIMENSION_COLUMNS, "A", - Arrays.asList(Arrays.asList("a1", "a2"), Arrays.asList("b1", "b2")), - Arrays.asList("{\"spreadsheetId\":\"%s\", \"#1\":\"a1\",\"#2\":\"a2\"}", - "{\"spreadsheetId\":\"%s\", \"#1\":\"b1\",\"#2\":\"b2\"}")) - ); - } - - @ParameterizedTest - @MethodSource("transformFromSplitValuesData") - public void testTransformFromSplitValues(String range, String sheetName, String majorDimension, String columnNames, - List> values, String expectedValueModel) throws Exception { - Exchange inbound = new DefaultExchange(camelContext); - - inbound.getMessage().setBody(values); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "splitResults", true); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "spreadsheetId", spreadsheetId); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", sheetName + "!" + range); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "majorDimension", majorDimension); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "columnNames", columnNames); - dataType.transform(inbound.getMessage(), DataType.ANY, DataType.ANY); - - - String model = inbound.getMessage().getBody(String.class); - JSONAssert.assertEquals(String.format(expectedValueModel, spreadsheetId), model, JSONCompareMode.STRICT); - } - - @ParameterizedTest - @MethodSource("transformFromValueRangeData") - public void testTransformFromValueRange(String range, String sheetName, String majorDimension, String columnNames, - List> values, List expectedValueModel) throws Exception { - Exchange inbound = new DefaultExchange(camelContext); - - ValueRange valueRange = new ValueRange(); - valueRange.setRange(sheetName + "!" + range); - valueRange.setMajorDimension(majorDimension); - valueRange.setValues(values); - - inbound.getMessage().setBody(valueRange); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "spreadsheetId", spreadsheetId); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "columnNames", columnNames); - dataType.transform(inbound.getMessage(), DataType.ANY, DataType.ANY); - - @SuppressWarnings("unchecked") - List model = inbound.getMessage().getBody(List.class); - Assertions.assertEquals(expectedValueModel.size(), model.size()); - Iterator modelIterator = model.iterator(); - for (String expected : expectedValueModel) { - JSONAssert.assertEquals(String.format(expected, spreadsheetId), modelIterator.next(), JSONCompareMode.STRICT); - } - } - - @Test - public void testTransformToEmptyValueRange() throws Exception { - Exchange inbound = new DefaultExchange(camelContext); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "spreadsheetId", spreadsheetId); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", "A1"); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption", "RAW"); - - dataType.transform(inbound.getMessage(), DataType.ANY, DataType.ANY); - - Assertions.assertEquals(spreadsheetId, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); - Assertions.assertEquals("A1", inbound.getMessage().getHeader(GoogleSheetsStreamConstants.RANGE)); - Assertions.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); - Assertions.assertEquals("RAW", inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); - - ValueRange valueRange = (ValueRange) inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); - Assertions.assertEquals(0L, valueRange.getValues().size()); - } - - @Test - public void testTransformToValueRangeRowDimension() throws Exception { - Exchange inbound = new DefaultExchange(camelContext); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", "A1:B1"); - - String model = "{" + - "\"spreadsheetId\": \"" + spreadsheetId + "\"," + - "\"A\": \"a1\"," + - "\"B\": \"b1\"" + - "}"; - inbound.getMessage().setBody(model); - - dataType.transform(inbound.getMessage(), DataType.ANY, DataType.ANY); - - Assertions.assertEquals(spreadsheetId, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); - Assertions.assertEquals("A1:B1", inbound.getMessage().getHeader(GoogleSheetsStreamConstants.RANGE)); - Assertions.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); - Assertions.assertEquals("USER_ENTERED", inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); - - ValueRange valueRange = (ValueRange) inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); - Assertions.assertEquals(1L, valueRange.getValues().size()); - Assertions.assertEquals("a1", valueRange.getValues().get(0).get(0)); - Assertions.assertEquals("b1", valueRange.getValues().get(0).get(1)); - } - - @Test - public void testTransformToValueRangeColumnNames() throws Exception { - Exchange inbound = new DefaultExchange(camelContext); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", "A1:B1"); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "columnNames", "Foo,Bar"); - - String model = "{" + - "\"spreadsheetId\": \"" + spreadsheetId + "\"," + - "\"Foo\": \"a1\"," + - "\"Bar\": \"b1\"" + - "}"; - inbound.getMessage().setBody(model); - - dataType.transform(inbound.getMessage(), DataType.ANY, DataType.ANY); - - Assertions.assertEquals(spreadsheetId, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); - Assertions.assertEquals("A1:B1", inbound.getMessage().getHeader(GoogleSheetsStreamConstants.RANGE)); - Assertions.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); - Assertions.assertEquals("USER_ENTERED", inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); - - ValueRange valueRange = (ValueRange) inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); - Assertions.assertEquals(1L, valueRange.getValues().size()); - Assertions.assertEquals("a1", valueRange.getValues().get(0).get(0)); - Assertions.assertEquals("b1", valueRange.getValues().get(0).get(1)); - } - - @Test - public void testTransformToValueRangeColumnDimension() throws Exception { - Exchange inbound = new DefaultExchange(camelContext); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", "A1:A2"); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "majorDimension", RangeCoordinate.DIMENSION_COLUMNS); - - String model = "{" + - "\"spreadsheetId\": \"" + spreadsheetId + "\"," + - "\"#1\": \"a1\"," + - "\"#2\": \"a2\"" + - "}"; - inbound.getMessage().setBody(model); - - dataType.transform(inbound.getMessage(), DataType.ANY, DataType.ANY); - - Assertions.assertEquals(spreadsheetId, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); - Assertions.assertEquals("A1:A2", inbound.getMessage().getHeader(GoogleSheetsStreamConstants.RANGE)); - Assertions.assertEquals(RangeCoordinate.DIMENSION_COLUMNS, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); - Assertions.assertEquals("USER_ENTERED", inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); - - ValueRange valueRange = (ValueRange) inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); - Assertions.assertEquals(1L, valueRange.getValues().size()); - Assertions.assertEquals("a1", valueRange.getValues().get(0).get(0)); - Assertions.assertEquals("a2", valueRange.getValues().get(0).get(1)); - } - - @Test - public void testTransformToValueRangeMultipleRows() throws Exception { - Exchange inbound = new DefaultExchange(camelContext); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", "A1:B2"); - - List model = Arrays.asList("{" + - "\"spreadsheetId\": \"" + spreadsheetId + "\"," + - "\"A\": \"a1\"," + - "\"B\": \"b1\"" + - "}", - "{" + - "\"spreadsheetId\": \"" + spreadsheetId + "\"," + - "\"A\": \"a2\"," + - "\"B\": \"b2\"" + - "}"); - inbound.getMessage().setBody(model); - - dataType.transform(inbound.getMessage(), DataType.ANY, DataType.ANY); - - Assertions.assertEquals("A1:B2", inbound.getMessage().getHeader(GoogleSheetsStreamConstants.RANGE)); - Assertions.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); - Assertions.assertEquals("USER_ENTERED", inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); - - ValueRange valueRange = (ValueRange) inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); - Assertions.assertEquals(2L, valueRange.getValues().size()); - Assertions.assertEquals(2L, valueRange.getValues().get(0).size()); - Assertions.assertEquals("a1", valueRange.getValues().get(0).get(0)); - Assertions.assertEquals("b1", valueRange.getValues().get(0).get(1)); - Assertions.assertEquals(2L, valueRange.getValues().get(1).size()); - Assertions.assertEquals("a2", valueRange.getValues().get(1).get(0)); - Assertions.assertEquals("b2", valueRange.getValues().get(1).get(1)); - } - - @Test - public void testTransformToValueRangeMultipleColumns() throws Exception { - Exchange inbound = new DefaultExchange(camelContext); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", "A1:B2"); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "majorDimension", RangeCoordinate.DIMENSION_COLUMNS); - - List model = Arrays.asList("{" + - "\"spreadsheetId\": \"" + spreadsheetId + "\"," + - "\"#1\": \"a1\"," + - "\"#2\": \"a2\"" + - "}", - "{" + - "\"spreadsheetId\": \"" + spreadsheetId + "\"," + - "\"#1\": \"b1\"," + - "\"#2\": \"b2\"" + - "}"); - - inbound.getMessage().setBody(model); - - dataType.transform(inbound.getMessage(), DataType.ANY, DataType.ANY); - - Assertions.assertEquals("A1:B2", inbound.getMessage().getHeader(GoogleSheetsStreamConstants.RANGE)); - Assertions.assertEquals(RangeCoordinate.DIMENSION_COLUMNS, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); - Assertions.assertEquals("USER_ENTERED", inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); - - ValueRange valueRange = (ValueRange) inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); - Assertions.assertEquals(2L, valueRange.getValues().size()); - Assertions.assertEquals(2L, valueRange.getValues().get(0).size()); - Assertions.assertEquals("a1", valueRange.getValues().get(0).get(0)); - Assertions.assertEquals("a2", valueRange.getValues().get(0).get(1)); - Assertions.assertEquals(2L, valueRange.getValues().get(1).size()); - Assertions.assertEquals("b1", valueRange.getValues().get(1).get(0)); - Assertions.assertEquals("b2", valueRange.getValues().get(1).get(1)); - } - - @Test - public void testTransformToValueRangeAutoFillColumnValues() throws Exception { - Exchange inbound = new DefaultExchange(camelContext); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", "A1:C2"); - - List model = Arrays.asList("{" + - "\"spreadsheetId\": \"" + spreadsheetId + "\"," + - "\"A\": \"a1\"," + - "\"C\": \"c1\"" + - "}", - "{" + - "\"spreadsheetId\": \"" + spreadsheetId + "\"," + - "\"A\": \"a2\"," + - "\"B\": \"b2\"" + - "}"); - - inbound.getMessage().setBody(model); - - dataType.transform(inbound.getMessage(), DataType.ANY, DataType.ANY); - - Assertions.assertEquals("A1:C2", inbound.getMessage().getHeader(GoogleSheetsStreamConstants.RANGE)); - Assertions.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); - Assertions.assertEquals("USER_ENTERED", inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); - - ValueRange valueRange = (ValueRange) inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); - Assertions.assertEquals(2L, valueRange.getValues().size()); - Assertions.assertEquals(3L, valueRange.getValues().get(0).size()); - Assertions.assertEquals("a1", valueRange.getValues().get(0).get(0)); - Assertions.assertNull(valueRange.getValues().get(0).get(1)); - Assertions.assertEquals("c1", valueRange.getValues().get(0).get(2)); - Assertions.assertEquals(3L, valueRange.getValues().get(1).size()); - Assertions.assertEquals("a2", valueRange.getValues().get(1).get(0)); - Assertions.assertEquals("b2", valueRange.getValues().get(1).get(1)); - Assertions.assertNull(valueRange.getValues().get(1).get(2)); - } - - @Test - public void testTransformToValueRangeAutoFillRowValues() throws Exception { - Exchange inbound = new DefaultExchange(camelContext); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", "A1:C3"); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "majorDimension", RangeCoordinate.DIMENSION_COLUMNS); - - List model = Arrays.asList("{" + - "\"spreadsheetId\": \"" + spreadsheetId + "\"," + - "\"#1\": \"a1\"," + - "\"#3\": \"c1\"" + - "}", - "{" + - "\"spreadsheetId\": \"" + spreadsheetId + "\"," + - "\"#1\": \"a2\"," + - "\"#2\": \"b2\"" + - "}"); - - inbound.getMessage().setBody(model); - - dataType.transform(inbound.getMessage(), DataType.ANY, DataType.ANY); - - Assertions.assertEquals("A1:C3", inbound.getMessage().getHeader(GoogleSheetsStreamConstants.RANGE)); - Assertions.assertEquals(RangeCoordinate.DIMENSION_COLUMNS, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); - Assertions.assertEquals("USER_ENTERED", inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); - - ValueRange valueRange = (ValueRange) inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); - Assertions.assertEquals(2L, valueRange.getValues().size()); - Assertions.assertEquals(3L, valueRange.getValues().get(0).size()); - Assertions.assertEquals("a1", valueRange.getValues().get(0).get(0)); - Assertions.assertNull(valueRange.getValues().get(0).get(1)); - Assertions.assertEquals("c1", valueRange.getValues().get(0).get(2)); - Assertions.assertEquals(3L, valueRange.getValues().get(1).size()); - Assertions.assertEquals("a2", valueRange.getValues().get(1).get(0)); - Assertions.assertEquals("b2", valueRange.getValues().get(1).get(1)); - Assertions.assertNull(valueRange.getValues().get(1).get(2)); - } - - @Test - public void testTransformToValueRangeWithJsonArray() throws Exception { - Exchange inbound = new DefaultExchange(camelContext); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", "A1:B2"); - - String body = "[{" + - "\"spreadsheetId\": \"" + spreadsheetId + "\"," + - "\"A\": \"a1\"," + - "\"B\": \"b1\"" + - "}," + - "{" + - "\"spreadsheetId\": \"" + spreadsheetId + "\"," + - "\"A\": \"a2\"," + - "\"B\": \"b2\"" + - "}]"; - inbound.getMessage().setBody(body); - - dataType.transform(inbound.getMessage(), DataType.ANY, DataType.ANY); - - Assertions.assertEquals("A1:B2", inbound.getMessage().getHeader(GoogleSheetsStreamConstants.RANGE)); - Assertions.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); - Assertions.assertEquals("USER_ENTERED", inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); - - ValueRange valueRange = (ValueRange) inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); - Assertions.assertEquals(2L, valueRange.getValues().size()); - Assertions.assertEquals(2L, valueRange.getValues().get(0).size()); - Assertions.assertEquals("a1", valueRange.getValues().get(0).get(0)); - Assertions.assertEquals("b1", valueRange.getValues().get(0).get(1)); - Assertions.assertEquals(2L, valueRange.getValues().get(1).size()); - Assertions.assertEquals("a2", valueRange.getValues().get(1).get(0)); - Assertions.assertEquals("b2", valueRange.getValues().get(1).get(1)); - } - - @Test - public void testTransformToValueRangeWithJsonObject() throws Exception { - Exchange inbound = new DefaultExchange(camelContext); - inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", "A1:B2"); - - String body = "{\"spreadsheetId\": \"" + spreadsheetId + "\", \"A\": \"a1\", \"B\": \"b1\" }"; - inbound.getMessage().setBody(body); - - dataType.transform(inbound.getMessage(), DataType.ANY, DataType.ANY); - - Assertions.assertEquals("A1:B2", inbound.getMessage().getHeader(GoogleSheetsStreamConstants.RANGE)); - Assertions.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getMessage().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); - Assertions.assertEquals("USER_ENTERED", inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); - - ValueRange valueRange = (ValueRange) inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); - Assertions.assertEquals(1L, valueRange.getValues().size()); - Assertions.assertEquals(2L, valueRange.getValues().get(0).size()); - Assertions.assertEquals("a1", valueRange.getValues().get(0).get(0)); - Assertions.assertEquals("b1", valueRange.getValues().get(0).get(1)); - } -} diff --git a/library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/http/HttpCloudEventOutputTypeTest.java b/library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/http/HttpCloudEventOutputTypeTest.java deleted file mode 100644 index ac6821d5e..000000000 --- a/library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/http/HttpCloudEventOutputTypeTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.kamelets.utils.format.converter.http; - -import java.io.ByteArrayInputStream; -import java.nio.charset.StandardCharsets; - -import org.apache.camel.Exchange; -import org.apache.camel.impl.DefaultCamelContext; -import org.apache.camel.impl.engine.TransformerKey; -import org.apache.camel.kamelets.utils.format.converter.utils.CloudEvents; -import org.apache.camel.spi.DataType; -import org.apache.camel.spi.Transformer; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -class HttpCloudEventOutputTypeTest { - - private final DefaultCamelContext camelContext = new DefaultCamelContext(); - - private final HttpCloudEventOutputType outputType = new HttpCloudEventOutputType(); - - @Test - void shouldMapToHttpCloudEvent() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - - exchange.getMessage().setHeader(CloudEvents.CAMEL_CLOUD_EVENT_SUBJECT, "test1.txt"); - exchange.getMessage().setHeader(CloudEvents.CAMEL_CLOUD_EVENT_TYPE, "org.apache.camel.event"); - exchange.getMessage().setHeader(CloudEvents.CAMEL_CLOUD_EVENT_SOURCE, "org.apache.camel.test"); - exchange.getMessage().setHeader(CloudEvents.CAMEL_CLOUD_EVENT_CONTENT_TYPE, "text/plain"); - exchange.getMessage().setBody(new ByteArrayInputStream("Test1".getBytes(StandardCharsets.UTF_8))); - - outputType.transform(exchange.getMessage(), DataType.ANY, new DataType("http:application-cloudevents")); - - assertTrue(exchange.getMessage().hasHeaders()); - assertEquals(exchange.getExchangeId(), exchange.getMessage().getHeader("ce-id")); - assertEquals("1.0", exchange.getMessage().getHeader("ce-specversion")); - assertEquals("org.apache.camel.event", exchange.getMessage().getHeader("ce-type")); - assertEquals("test1.txt", exchange.getMessage().getHeader("ce-subject")); - assertEquals("org.apache.camel.test", exchange.getMessage().getHeader("ce-source")); - assertTrue(exchange.getMessage().getHeaders().containsKey("ce-time")); - assertEquals("text/plain", exchange.getMessage().getHeader(Exchange.CONTENT_TYPE)); - assertEquals("Test1", exchange.getMessage().getBody(String.class)); - } - - @Test - public void shouldLookupDataType() throws Exception { - Transformer transformer = camelContext.getTransformerRegistry().resolveTransformer(new TransformerKey(DataType.ANY, new DataType("http:application-cloudevents"))); - Assertions.assertNotNull(transformer); - } -} diff --git a/library/camel-kamelets/src/main/resources/kamelets/avro-deserialize-action.kamelet.yaml b/library/camel-kamelets/src/main/resources/kamelets/avro-deserialize-action.kamelet.yaml index 31620ff9b..2115ab061 100644 --- a/library/camel-kamelets/src/main/resources/kamelets/avro-deserialize-action.kamelet.yaml +++ b/library/camel-kamelets/src/main/resources/kamelets/avro-deserialize-action.kamelet.yaml @@ -47,14 +47,13 @@ spec: x-descriptors: - 'urn:alm:descriptor:com.tectonic.ui:checkbox' dependencies: - - "mvn:org.apache.camel.kamelets:camel-kamelets-utils:4.2.0-SNAPSHOT" - "camel:kamelet" - "camel:core" - "camel:jackson-avro" template: beans: - name: schemaResolver - type: "#class:org.apache.camel.kamelets.utils.format.converter.avro.AvroSchemaResolver" + type: "#class:org.apache.camel.component.jackson.avro.transform.AvroSchemaResolver" property: - key: validate value: '{{validate}}' diff --git a/library/camel-kamelets/src/main/resources/kamelets/avro-serialize-action.kamelet.yaml b/library/camel-kamelets/src/main/resources/kamelets/avro-serialize-action.kamelet.yaml index 4a70cc531..6cfbe17f3 100644 --- a/library/camel-kamelets/src/main/resources/kamelets/avro-serialize-action.kamelet.yaml +++ b/library/camel-kamelets/src/main/resources/kamelets/avro-serialize-action.kamelet.yaml @@ -47,14 +47,13 @@ spec: x-descriptors: - 'urn:alm:descriptor:com.tectonic.ui:checkbox' dependencies: - - "mvn:org.apache.camel.kamelets:camel-kamelets-utils:4.2.0-SNAPSHOT" - "camel:kamelet" - "camel:core" - "camel:jackson-avro" template: beans: - name: schemaResolver - type: "#class:org.apache.camel.kamelets.utils.format.converter.avro.AvroSchemaResolver" + type: "#class:org.apache.camel.component.jackson.avro.transform.AvroSchemaResolver" property: - key: validate value: '{{validate}}' diff --git a/library/camel-kamelets/src/main/resources/kamelets/data-type-action.kamelet.yaml b/library/camel-kamelets/src/main/resources/kamelets/data-type-action.kamelet.yaml index 35e9124e6..1cc13943c 100644 --- a/library/camel-kamelets/src/main/resources/kamelets/data-type-action.kamelet.yaml +++ b/library/camel-kamelets/src/main/resources/kamelets/data-type-action.kamelet.yaml @@ -45,7 +45,6 @@ spec: description: Defines the data type that will be applied by this action. Apache Camel and the Kamelet catalog support different data types and performs automatic message conversion according to the given type. type: string dependencies: - - "mvn:org.apache.camel.kamelets:camel-kamelets-utils:4.2.0-SNAPSHOT" - "camel:kamelet" - "camel:core" template: diff --git a/library/camel-kamelets/src/main/resources/kamelets/protobuf-deserialize-action.kamelet.yaml b/library/camel-kamelets/src/main/resources/kamelets/protobuf-deserialize-action.kamelet.yaml index 41c87d2e6..084505d9d 100644 --- a/library/camel-kamelets/src/main/resources/kamelets/protobuf-deserialize-action.kamelet.yaml +++ b/library/camel-kamelets/src/main/resources/kamelets/protobuf-deserialize-action.kamelet.yaml @@ -46,7 +46,7 @@ spec: template: beans: - name: schemaResolver - type: "#class:org.apache.camel.kamelets.utils.format.converter.protobuf.ProtobufSchemaResolver" + type: "#class:org.apache.camel.kamelets.utils.format.schema.protobuf.ProtobufSchemaResolver" property: - key: schema value: '{{schema:}}' diff --git a/library/camel-kamelets/src/main/resources/kamelets/protobuf-serialize-action.kamelet.yaml b/library/camel-kamelets/src/main/resources/kamelets/protobuf-serialize-action.kamelet.yaml index d201ddd8b..598bff37b 100644 --- a/library/camel-kamelets/src/main/resources/kamelets/protobuf-serialize-action.kamelet.yaml +++ b/library/camel-kamelets/src/main/resources/kamelets/protobuf-serialize-action.kamelet.yaml @@ -46,7 +46,7 @@ spec: template: beans: - name: schemaResolver - type: "#class:org.apache.camel.kamelets.utils.format.converter.protobuf.ProtobufSchemaResolver" + type: "#class:org.apache.camel.kamelets.utils.format.schema.protobuf.ProtobufSchemaResolver" property: - key: schema value: '{{schema:}}' diff --git a/pom.xml b/pom.xml index 23bbd11f2..b1139293c 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ 0.15 2.7.10 - 4.1.0 + 4.2.0 2.0.1 @@ -318,7 +318,7 @@ "version.io.apicurio.apicurio-registry-serdes-avro-serde": "${version.io.apicurio.apicurio-registry-serdes-avro-serde}", "version.com.azure.azure-identity": "${version.com.azure.azure-identity}", "version.com.azure.azure-data-schemaregistry-apacheavro": "${version.com.azure.azure-data-schemaregistry-apacheavro}", - "version.com.microsoft.azure.azure-schemaregistry-kafka-avro": "${version.com.microsoft.azure.azure-schemaregistry-kafka-avro}" + "version.com.microsoft.azure.azure-schemaregistry-kafka-avro": "${version.com.microsoft.azure.azure-schemaregistry-kafka-avro}" ]) diff --git a/test/Makefile b/test/Makefile index 76f94b99f..f0b07b65f 100644 --- a/test/Makefile +++ b/test/Makefile @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -camel-version := 4.1.0 +camel-version := 4.2.0 camel-kamelets-version := 4.2.0-SNAPSHOT kamelets-local-dir := ../../../kamelets test := . diff --git a/test/avro-data-type/avro-to-log-pipe.yaml b/test/avro-data-type/avro-to-log-pipe.yaml index 91fee5c20..992113263 100644 --- a/test/avro-data-type/avro-to-log-pipe.yaml +++ b/test/avro-data-type/avro-to-log-pipe.yaml @@ -20,6 +20,9 @@ kind: Pipe metadata: name: avro-to-log-pipe spec: + integration: + dependencies: + - "camel:jackson-avro" source: ref: kind: Kamelet @@ -28,6 +31,12 @@ spec: properties: subpath: user steps: + - ref: + kind: Kamelet + apiVersion: camel.apache.org/v1 + name: data-type-action + properties: + format: "application-octet-stream" - ref: kind: Kamelet apiVersion: camel.apache.org/v1 diff --git a/test/avro-data-type/json-to-avro-pipe.yaml b/test/avro-data-type/json-to-avro-pipe.yaml index 9ecb5836a..d74304050 100644 --- a/test/avro-data-type/json-to-avro-pipe.yaml +++ b/test/avro-data-type/json-to-avro-pipe.yaml @@ -20,6 +20,9 @@ kind: Pipe metadata: name: json-to-avro-pipe spec: + integration: + dependencies: + - "camel:jackson-avro" source: ref: kind: Kamelet diff --git a/test/aws-s3/aws-s3-knative-broker.feature b/test/aws-s3/aws-s3-knative-broker.feature index 3c77627bd..3974e7035 100644 --- a/test/aws-s3/aws-s3-knative-broker.feature +++ b/test/aws-s3/aws-s3-knative-broker.feature @@ -5,7 +5,7 @@ Feature: AWS S3 Kamelet - Knative broker binding Given Knative event consumer timeout is 20000 ms Given variables | aws.s3.scheme | camel | - | aws.s3.format | plain-text | + | aws.s3.format | text-plain | | aws.s3.bucketNameOrArn | mybucket | | aws.s3.message | Hello from S3 Kamelet | | aws.s3.key | hello.txt | diff --git a/test/data-type-action/data-type-action-pipe.yaml b/test/data-type-action/data-type-action-pipe.yaml index 777149677..3abac9770 100644 --- a/test/data-type-action/data-type-action-pipe.yaml +++ b/test/data-type-action/data-type-action-pipe.yaml @@ -20,6 +20,9 @@ kind: Pipe metadata: name: data-type-action-pipe spec: + integration: + dependencies: + - "camel:cloudevents" source: ref: kind: Kamelet