diff --git a/library/camel-kamelets-utils/pom.xml b/library/camel-kamelets-utils/pom.xml index e5d799b98..b4f56daa7 100644 --- a/library/camel-kamelets-utils/pom.xml +++ b/library/camel-kamelets-utils/pom.xml @@ -92,6 +92,11 @@ camel-azure-storage-blob provided + + org.apache.camel + camel-google-storage + provided + 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 new file mode 100644 index 000000000..51604958c --- /dev/null +++ b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/google/storage/GoogleStorageCloudEventOutputType.java @@ -0,0 +1,47 @@ +/* + * 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/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 new file mode 100644 index 000000000..8f85fc34b --- /dev/null +++ b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/google-storage-application-cloudevents @@ -0,0 +1,18 @@ +# +# 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