From 76f1573d6c4986e9ccb86eaec339bd139933f6b9 Mon Sep 17 00:00:00 2001 From: Andrea Cosentino Date: Fri, 7 May 2021 18:43:58 +0200 Subject: [PATCH] Add group label methods to Kamelets Catalog --- .../kamelets/catalog/KameletsCatalog.java | 11 ++++++++- .../model/KameletAnnotationsNames.java | 24 +++++++++++++++++++ .../catalog/model/KameletLabelNames.java | 2 -- .../kamelets/catalog/KameletsCatalogTest.java | 21 ++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/model/KameletAnnotationsNames.java 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 99416ab91..e71020c59 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 @@ -24,6 +24,7 @@ import io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaProps; import io.github.classgraph.ClassGraph; import io.github.classgraph.ScanResult; +import org.apache.camel.kamelets.catalog.model.KameletAnnotationsNames; import org.apache.camel.kamelets.catalog.model.KameletLabelNames; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,6 +102,14 @@ public List getKameletsByType(String type) { return collect; } + public List getKameletsByGroups(String group) { + List collect = kameletModels.entrySet().stream() + .filter(x -> x.getValue().getMetadata().getAnnotations().get(KameletAnnotationsNames.KAMELET_ANNOTATION_GROUP).contains(group)) + .map(Map.Entry::getValue) + .collect(Collectors.toList()); + return collect; + } + public JSONSchemaProps getKameletDefinition(String name) { Kamelet kamelet = kameletModels.get(name); if (kamelet != null) { @@ -112,7 +121,7 @@ public JSONSchemaProps getKameletDefinition(String name) { public List getKameletByProvider(String provider) { List collect = kameletModels.entrySet().stream() - .filter(x -> x.getValue().getMetadata().getAnnotations().get(KameletLabelNames.KAMELET_LABEL_PROVIDER).equalsIgnoreCase(provider)) + .filter(x -> x.getValue().getMetadata().getAnnotations().get(KameletAnnotationsNames.KAMELET_ANNOTATION_PROVIDER).equalsIgnoreCase(provider)) .map(Map.Entry::getValue) .collect(Collectors.toList()); if (!collect.isEmpty()) { diff --git a/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/model/KameletAnnotationsNames.java b/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/model/KameletAnnotationsNames.java new file mode 100644 index 000000000..8ace82d67 --- /dev/null +++ b/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/model/KameletAnnotationsNames.java @@ -0,0 +1,24 @@ +/* + * 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.catalog.model; + +public interface KameletAnnotationsNames { + + String KAMELET_ANNOTATION_ICON = "camel.apache.org/kamelet.icon"; + String KAMELET_ANNOTATION_PROVIDER = "camel.apache.org/provider"; + String KAMELET_ANNOTATION_GROUP = "camel.apache.org/kamelet.group"; +} diff --git a/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/model/KameletLabelNames.java b/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/model/KameletLabelNames.java index 4fc811ba2..1f2be261b 100644 --- a/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/model/KameletLabelNames.java +++ b/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/model/KameletLabelNames.java @@ -19,7 +19,5 @@ public interface KameletLabelNames { String KAMELET_LABEL_TYPE = "camel.apache.org/kamelet.type"; - String KAMELET_LABEL_PROVIDER = "camel.apache.org/provider"; - String KAMELET_LABEL_ICON = "camel.apache.org/kamelet.icon"; } 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 6dfafbb63..b56bbc9fe 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 @@ -21,6 +21,7 @@ import io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaProps; import io.github.classgraph.ClassGraph; +import org.apache.camel.kamelets.catalog.model.KameletTypeEnum; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -80,6 +81,26 @@ void testGetKameletsByProvider() throws Exception { assertTrue(c.isEmpty()); } + @Test + void testGetKameletsByType() throws Exception { + List c = catalog.getKameletsByType(KameletTypeEnum.SOURCE.type()); + assertTrue(!c.isEmpty()); + c = catalog.getKameletsByType(KameletTypeEnum.SINK.type()); + assertTrue(!c.isEmpty()); + c = catalog.getKameletsByType(KameletTypeEnum.ACTION.type()); + assertTrue(!c.isEmpty()); + } + + @Test + void testGetKameletsByGroup() throws Exception { + List c = catalog.getKameletsByGroups("AWS S3"); + assertTrue(!c.isEmpty()); + c = catalog.getKameletsByGroups("AWS SQS"); + assertTrue(!c.isEmpty()); + c = catalog.getKameletsByGroups("Not-existing-group"); + assertTrue(c.isEmpty()); + } + @Test void testGetKameletsDependencies() throws Exception { List deps = catalog.getKameletDependencies("aws-sqs-source");