summaryrefslogtreecommitdiffstats
path: root/vid-app-common
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-11-21 09:31:36 +0200
committerEylon Malin <eylon.malin@intl.att.com>2019-11-21 15:48:02 +0200
commitc1777f478aa421c35667a99fd2199569bc9e4a8a (patch)
tree9332e0d0e6454a7799d6b3d20857b52ad82094db /vid-app-common
parentf7312c11d3aef1684bf211b34092e094336d4b22 (diff)
VidNotionBuilder can use configuration file to identify macro services
Issue-ID: VID-701 Change-Id: I23c89ed500d6d1663b07fa909b16eda30e63e36c Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-app-common')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java31
-rw-r--r--vid-app-common/src/main/resources/macro_services_by_invariant_uuid.json1
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java19
-rw-r--r--vid-app-common/src/test/resources/macro_services_by_invariant_uuid.json4
4 files changed, 55 insertions, 0 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java
index 76e911b4e..3f18a5ace 100644
--- a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java
+++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java
@@ -20,18 +20,26 @@
package org.onap.vid.asdc.parser;
+import static java.util.stream.Collectors.toSet;
import static org.apache.commons.lang3.StringUtils.equalsAnyIgnoreCase;
import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
import static org.apache.commons.lang3.StringUtils.isEmpty;
+import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER;
import com.google.common.collect.ImmutableMap;
+import java.io.IOException;
import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.stream.Stream;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.toscaparser.api.NodeTemplate;
import org.onap.sdc.toscaparser.api.elements.Metadata;
+import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.vid.model.ServiceModel;
import org.onap.vid.model.VidNotions;
import org.onap.vid.model.VidNotions.InstantiationUI;
@@ -42,6 +50,7 @@ import org.togglz.core.manager.FeatureManager;
public class VidNotionsBuilder {
private final FeatureManager featureManager;
+ private final Set<UUID> invariantToMacro;
//map of service type that are always macro services, and their relevant featureFlag
private static final Map<VidNotions.ModelCategory, Features> macroServicesByModelCategory = ImmutableMap.of(
@@ -52,6 +61,19 @@ public class VidNotionsBuilder {
public VidNotionsBuilder(FeatureManager featureManager) {
this.featureManager = featureManager;
+ invariantToMacro = loadInvariantMacroUUIDsFromFile();
+ }
+
+ @NotNull
+ private Set<UUID> loadInvariantMacroUUIDsFromFile() {
+ try {
+ return Stream.of(JACKSON_OBJECT_MAPPER.readValue(
+ VidNotionsBuilder.class.getResource("/macro_services_by_invariant_uuid.json"),
+ String[].class
+ )).map(UUID::fromString).collect(toSet());
+ } catch (IOException e) {
+ throw new GenericUncheckedException(e);
+ }
}
VidNotions buildVidNotions(ISdcCsarHelper csarHelper, ServiceModel serviceModel) {
@@ -267,4 +289,13 @@ public class VidNotionsBuilder {
);
}
+
+ protected boolean isMacroByInvariantUuid(String uuid) {
+ try {
+ return invariantToMacro.contains(UUID.fromString(uuid));
+ }
+ catch (IllegalArgumentException | NullPointerException e) { //not a uuid
+ return false;
+ }
+ }
}
diff --git a/vid-app-common/src/main/resources/macro_services_by_invariant_uuid.json b/vid-app-common/src/main/resources/macro_services_by_invariant_uuid.json
new file mode 100644
index 000000000..fe51488c7
--- /dev/null
+++ b/vid-app-common/src/main/resources/macro_services_by_invariant_uuid.json
@@ -0,0 +1 @@
+[]
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java
index c136f36e4..c32dd2141 100644
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java
@@ -534,4 +534,23 @@ public class VidNotionsBuilderTest {
assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel, ModelCategory.OTHER));
}
+
+ @DataProvider
+ public static Object[][] invariantUuidToMacroDataProvider() {
+ return new Object[][]{
+ {"117f5f1a-1b47-4ae1-ae04-489c9a7ada28", true},
+ {"117F5f1a-1b47-4AE1-ae04-489C9A7ada28", true},
+ {"2efab359-cdd4-4da2-9b79-61df990796c2", true},
+ {"67e09a1f-9e42-4b63-8dee-bc60bae50de1", false},
+ {"67e09A1F-9E42-4b63-8Dee-bc60bae50de1", false},
+ {"5d854f6b-759c-4aa6-b472-7e4bb1c003d4", false},
+ {"I'm not a uuid", false},
+ {null, false},
+ };
+ }
+
+ @Test(dataProvider = "invariantUuidToMacroDataProvider")
+ public void testIsMacroByInvariantUuid(String uuid, boolean expectedIsMacro) {
+ assertEquals(expectedIsMacro, vidNotionsBuilder.isMacroByInvariantUuid(uuid));
+ }
}
diff --git a/vid-app-common/src/test/resources/macro_services_by_invariant_uuid.json b/vid-app-common/src/test/resources/macro_services_by_invariant_uuid.json
new file mode 100644
index 000000000..3afb9321a
--- /dev/null
+++ b/vid-app-common/src/test/resources/macro_services_by_invariant_uuid.json
@@ -0,0 +1,4 @@
+[
+ "117f5f1a-1b47-4ae1-ae04-489c9a7ada28",
+ "2efab359-cdd4-4da2-9b79-61df990796c2"
+]