This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch 1984 in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
commit 0b0e8532517db9f1190f62582aa4f11342a80bc1 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Mon Apr 22 09:38:09 2024 +0200 Kamelet Catalog: Provide a method in the catalog API to get DataType information for a Kamelet Signed-off-by: Andrea Cosentino <anco...@gmail.com> --- .../camel/kamelets/catalog/KameletsCatalog.java | 23 ++++++++++++++++++++++ .../kamelets/catalog/KameletsCatalogTest.java | 17 ++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/KameletsCatalog.java b/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/KameletsCatalog.java index 939dcb72..60dbbb0f 100644 --- a/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/KameletsCatalog.java +++ b/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/KameletsCatalog.java @@ -41,6 +41,7 @@ import org.apache.camel.kamelets.catalog.model.KameletTypeEnum; import org.apache.camel.tooling.model.ComponentModel; import org.apache.camel.util.ObjectHelper; import org.apache.camel.v1.Kamelet; +import org.apache.camel.v1.kameletspec.DataTypes; import org.apache.camel.v1.kameletspec.Definition; import org.apache.camel.v1.kameletspec.Template; import org.slf4j.Logger; @@ -175,6 +176,28 @@ public class KameletsCatalog { } } + public boolean hasDataTypes(String name) { + Kamelet kamelet = kameletModels.get(name); + if (kamelet != null) { + if (!kamelet.getSpec().getDataTypes().isEmpty()) { + return true; + } else { + return false; + } + } else { + return false; + } + } + + public Map<String, DataTypes> getDataTypes(String name) { + Kamelet kamelet = kameletModels.get(name); + if (kamelet != null) { + return kamelet.getSpec().getDataTypes(); + } else { + return null; + } + } + public void getAllKameletDependencies() { Map<String, Kamelet> treeMap = new TreeMap<>(kameletModels); for (Map.Entry<String, Kamelet> entry : treeMap.entrySet()) { 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 2fa5ae3c..2d70e0cd 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 @@ -24,6 +24,7 @@ import io.github.classgraph.ClassGraph; import org.apache.camel.kamelets.catalog.model.KameletTypeEnum; import org.apache.camel.tooling.model.ComponentModel; import org.apache.camel.v1.Kamelet; +import org.apache.camel.v1.kameletspec.DataTypes; import org.apache.camel.v1.kameletspec.Definition; import org.apache.camel.v1.kameletspec.Template; import org.junit.jupiter.api.BeforeAll; @@ -269,4 +270,20 @@ public class KameletsCatalogTest { assertEquals("aws2-sqs", catalog.getKameletScheme("aws-sqs")); assertNull(catalog.getKameletScheme("not-known")); } + + @Test + void testHasDataTypes() throws Exception { + assertTrue(catalog.hasDataTypes("aws-s3-source")); + assertFalse(catalog.hasDataTypes("splunk-hec-source")); + } + + @Test + void testGetDataTypes() throws Exception { + Map<String, DataTypes> dataTypes = catalog.getDataTypes("aws-s3-source"); + assertTrue(dataTypes.size() == 1); + assertNotNull(dataTypes.get("out").getTypes().get("binary")); + assertNotNull(dataTypes.get("out").getTypes().get("cloudevents")); + dataTypes = catalog.getDataTypes("splunk-hec-sink"); + assertNull(dataTypes); + } }