aboutsummaryrefslogtreecommitdiffstats
path: root/common-app-api/src
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2020-01-29 17:25:21 +0000
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-04-19 16:35:32 +0000
commitcd6f933375c412c2f79a12e909821322d58a8499 (patch)
tree758ff2e742b514169bbc84a8433d68fe221ef5c9 /common-app-api/src
parentdc56692a4a307f378c827f017d2efbf754c223e0 (diff)
Configure a new Artifact Type
Centralizes artifact configuration in one yaml entry. Allow the configuration of a new artifact type without the need of code changes. The configuration file now is used as a source of artifacts types instead the artifact type enum. The enum will be used as a source of base artifact types and also in hard coded business rules. Change-Id: Id0383d9fca9bce0519a4d52a4ecb3a68c8713f0f Issue-ID: SDC-2754 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'common-app-api/src')
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/be/config/ArtifactConfigManager.java138
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/be/config/ArtifactConfiguration.java68
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/be/config/ComponentType.java36
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java66
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/api/ArtifactTypeEnum.java91
-rw-r--r--common-app-api/src/test/java/org/openecomp/sdc/common/api/ArtifactTypeEnumTest.java47
6 files changed, 331 insertions, 115 deletions
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/be/config/ArtifactConfigManager.java b/common-app-api/src/main/java/org/openecomp/sdc/be/config/ArtifactConfigManager.java
new file mode 100644
index 0000000000..e3327cc696
--- /dev/null
+++ b/common-app-api/src/main/java/org/openecomp/sdc/be/config/ArtifactConfigManager.java
@@ -0,0 +1,138 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.config;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+
+/**
+ * Singleton that manages the artifact type configuration
+ */
+public class ArtifactConfigManager {
+
+ public static final ArtifactConfigManager INSTANCE = new ArtifactConfigManager();
+
+ private ArtifactConfigManager() {
+
+ }
+
+ public static ArtifactConfigManager getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Find an artifact configuration by artifact type.
+ *
+ * @param type the artifact type
+ * @return the artifact configuration if the type exists
+ */
+ public Optional<ArtifactConfiguration> find(final String type) {
+ final List<ArtifactConfiguration> artifactConfigurationList = getConfiguration();
+ return artifactConfigurationList.stream()
+ .filter(artifactConfiguration -> artifactConfiguration.getType().equals(type))
+ .findFirst();
+ }
+
+ /**
+ * Find an artifact configuration by artifact type, that supports the artifact category/group and component type.
+ *
+ * @param type the artifact type
+ * @param artifactGroup the artifact category/group
+ * @param componentType the component type
+ * @return the artifact configuration if it matches the provided filter
+ */
+ public Optional<ArtifactConfiguration> find(final String type, final ArtifactGroupTypeEnum artifactGroup,
+ final ComponentType componentType) {
+ final ArtifactConfiguration artifactConfiguration = find(type).orElse(null);
+ if (artifactConfiguration == null) {
+ return Optional.empty();
+ }
+
+ final boolean hasCategory = artifactConfiguration.hasSupport(artifactGroup);
+ if (!hasCategory) {
+ return Optional.empty();
+ }
+ final boolean hasComponentType = artifactConfiguration.hasSupport(componentType);
+ if (!hasComponentType) {
+ return Optional.empty();
+ }
+
+ return Optional.of(artifactConfiguration);
+ }
+
+ /**
+ * Find all artifact configuration that supports an artifact category/group and a component type.
+ *
+ * @param artifactGroup the artifact group/category
+ * @param componentType the component type
+ * @return the artifact configurations that matches the filter
+ */
+ public List<ArtifactConfiguration> findAll(final ArtifactGroupTypeEnum artifactGroup,
+ final ComponentType componentType) {
+ final List<ArtifactConfiguration> artifactConfigurationList =
+ ConfigurationManager.getConfigurationManager().getConfiguration().getArtifacts();
+
+ return artifactConfigurationList.stream()
+ .filter(artifactConfiguration1 ->
+ artifactConfiguration1.hasSupport(artifactGroup) && artifactConfiguration1.hasSupport(componentType))
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Find all artifact configuration that supports an artifact category/group.
+ *
+ * @param artifactGroup the artifact category/group
+ * @return the artifact configurations that matches the filter
+ */
+ public List<ArtifactConfiguration> findAll(final ArtifactGroupTypeEnum artifactGroup) {
+ final List<ArtifactConfiguration> artifactConfigurationList =
+ ConfigurationManager.getConfigurationManager().getConfiguration().getArtifacts();
+
+ return artifactConfigurationList.stream()
+ .filter(artifactConfiguration1 -> artifactConfiguration1.hasSupport(artifactGroup))
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Find all artifact configuration that supports a component type.
+ *
+ * @param componentType the component type
+ * @return the artifact configurations that matches the filter
+ */
+ public List<ArtifactConfiguration> findAll(final ComponentType componentType) {
+ final List<ArtifactConfiguration> artifactConfigurationList =
+ ConfigurationManager.getConfigurationManager().getConfiguration().getArtifacts();
+
+ return artifactConfigurationList.stream()
+ .filter(artifactConfiguration1 -> artifactConfiguration1.hasSupport(componentType))
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Gets the artifact configuration list.
+ *
+ * @return the artifact configuration list.
+ */
+ public List<ArtifactConfiguration> getConfiguration() {
+ return ConfigurationManager.getConfigurationManager().getConfiguration().getArtifacts();
+ }
+}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/be/config/ArtifactConfiguration.java b/common-app-api/src/main/java/org/openecomp/sdc/be/config/ArtifactConfiguration.java
new file mode 100644
index 0000000000..1656b4abb1
--- /dev/null
+++ b/common-app-api/src/main/java/org/openecomp/sdc/be/config/ArtifactConfiguration.java
@@ -0,0 +1,68 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.config;
+
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.apache.commons.collections.CollectionUtils;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+
+/**
+ * Represents an artifact type configuration
+ */
+@Getter
+@Setter
+@ToString
+public class ArtifactConfiguration {
+
+ private String type;
+ private List<ArtifactGroupTypeEnum> categories;
+ private List<ComponentType> componentTypes;
+ private List<String> acceptedTypes;
+ private List<String> resourceTypes;
+
+ /**
+ * Checks if the configuration supports a component type.
+ *
+ * @param componentType the component type
+ * @return {@code true} if the component type is supported, {@code false} otherwise
+ */
+ public boolean hasSupport(final ComponentType componentType) {
+ if (CollectionUtils.isEmpty(componentTypes)) {
+ return false;
+ }
+ return componentTypes.contains(componentType);
+ }
+
+ /**
+ * Checks if the configuration supports an artifact group/category.
+ *
+ * @param groupType the artifact category/group type
+ * @return {@code true} if the artifact group/category is supported, {@code false} otherwise
+ */
+ public boolean hasSupport(final ArtifactGroupTypeEnum groupType) {
+ if (CollectionUtils.isEmpty(categories)) {
+ return false;
+ }
+ return categories.contains(groupType);
+ }
+}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/be/config/ComponentType.java b/common-app-api/src/main/java/org/openecomp/sdc/be/config/ComponentType.java
new file mode 100644
index 0000000000..2f28687620
--- /dev/null
+++ b/common-app-api/src/main/java/org/openecomp/sdc/be/config/ComponentType.java
@@ -0,0 +1,36 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.config;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum ComponentType {
+
+ RESOURCE("Resource"),
+ SERVICE("Service"),
+ RESOURCE_INSTANCE("Resource Instance"),
+ SERVICE_INSTANCE("Service Instance");
+
+ private final String value;
+
+}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java b/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java
index 0bc0707822..f9f4bc14ae 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java
@@ -20,16 +20,15 @@
package org.openecomp.sdc.be.config;
-import org.apache.commons.collections.map.CaseInsensitiveMap;
-import org.openecomp.sdc.common.api.BasicConfiguration;
+import static java.lang.String.format;
+import static java.util.Collections.emptyMap;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
-import static java.lang.String.format;
-import static java.util.Collections.emptyMap;
+import org.apache.commons.collections.map.CaseInsensitiveMap;
+import org.openecomp.sdc.common.api.BasicConfiguration;
public class Configuration extends BasicConfiguration {
@@ -91,14 +90,9 @@ public class Configuration extends BasicConfiguration {
private Map<String, Object> toscaArtifacts;
private Map<String, Object> informationalResourceArtifacts;
private Map<String, Object> informationalServiceArtifacts;
- private Map<String, ArtifactTypeConfig> resourceDeploymentArtifacts;
- private Map<String, ArtifactTypeConfig> serviceDeploymentArtifacts;
- private Map<String, ArtifactTypeConfig> resourceInstanceDeploymentArtifacts;
- private Map<String, ArtifactTypeConfig> resourceInformationalArtifacts;
private Map<String, Object> serviceApiArtifacts;
private List<String> excludeServiceCategory;
- private List<String> artifactTypes;
private List<String> licenseTypes;
private List<String> definedResourceNamespace;
@@ -161,6 +155,15 @@ public class Configuration extends BasicConfiguration {
private EnvironmentContext environmentContext;
private List<GabConfig> gabConfig;
private EcompPortalConfig ecompPortal;
+ private List<ArtifactConfiguration> artifacts;
+
+ public List<ArtifactConfiguration> getArtifacts() {
+ return artifacts;
+ }
+
+ public void setArtifacts(List<ArtifactConfiguration> artifacts) {
+ this.artifacts = artifacts;
+ }
public String getAutoHealingOwner() {
return autoHealingOwner;
@@ -437,14 +440,6 @@ public class Configuration extends BasicConfiguration {
this.janusGraphReconnectIntervalInSeconds = janusGraphReconnectIntervalInSeconds;
}
- public List<String> getArtifactTypes() {
- return artifactTypes;
- }
-
- public void setArtifactTypes(List<String> artifactTypes) {
- this.artifactTypes = artifactTypes;
- }
-
public List<String> getExcludeResourceCategory() {
return excludeResourceCategory;
}
@@ -509,31 +504,6 @@ public class Configuration extends BasicConfiguration {
this.serviceApiArtifacts = serviceApiArtifacts;
}
- public Map<String, ArtifactTypeConfig> getServiceDeploymentArtifacts() {
- return serviceDeploymentArtifacts;
- }
-
- public void setServiceDeploymentArtifacts(Map<String, ArtifactTypeConfig> serviceDeploymentArtifacts) {
- this.serviceDeploymentArtifacts = serviceDeploymentArtifacts;
- }
-
- public Map<String, ArtifactTypeConfig> getResourceDeploymentArtifacts() {
- return resourceDeploymentArtifacts;
- }
-
- public void setResourceDeploymentArtifacts(Map<String, ArtifactTypeConfig> resourceDeploymentArtifacts) {
- this.resourceDeploymentArtifacts = resourceDeploymentArtifacts;
- }
-
- public void setResourceInstanceDeploymentArtifacts(
- Map<String, ArtifactTypeConfig> resourceInstanceDeploymentArtifacts) {
- this.resourceInstanceDeploymentArtifacts = resourceInstanceDeploymentArtifacts;
- }
-
- public Map<String, ArtifactTypeConfig> getResourceInstanceDeploymentArtifacts() {
- return resourceInstanceDeploymentArtifacts;
- }
-
public List<String> getExcludeServiceCategory() {
return excludeServiceCategory;
}
@@ -1529,7 +1499,7 @@ public class Configuration extends BasicConfiguration {
.append(format("informationalResourceArtifacts: %s%n", informationalResourceArtifacts))
.append(format("deploymentResourceArtifacts: %s%n", deploymentResourceArtifacts))
.append(format("informationalServiceArtifacts: %s%n", informationalServiceArtifacts))
- .append(format("Supported artifacts types: %s%n", artifactTypes))
+ .append(format("Supported artifacts types: %s%n", artifacts))
.append(format("Supported license types: %s%n", licenseTypes))
.append(format("Additional information Maximum number of preoperties: %s%n",
additionalInformationMaxNumberOfKeys))
@@ -1653,14 +1623,6 @@ public class Configuration extends BasicConfiguration {
this.disableAudit = enableAudit;
}
- public Map<String, ArtifactTypeConfig> getResourceInformationalArtifacts() {
- return resourceInformationalArtifacts;
- }
-
- public void setResourceInformationalArtifacts(Map<String, ArtifactTypeConfig> resourceInformationalArtifacts) {
- this.resourceInformationalArtifacts = resourceInformationalArtifacts;
- }
-
public Map<String, VfModuleProperty> getVfModuleProperties() {
return vfModuleProperties;
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/api/ArtifactTypeEnum.java b/common-app-api/src/main/java/org/openecomp/sdc/common/api/ArtifactTypeEnum.java
index 9d0ff1c083..affa2d32e0 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/api/ArtifactTypeEnum.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/api/ArtifactTypeEnum.java
@@ -7,9 +7,9 @@
* Licensed 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.
@@ -20,50 +20,69 @@
package org.openecomp.sdc.common.api;
-import java.util.ArrayList;
-import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
- * Enum That Represents possible Artifacts Types.
- *
+ * Represents an artifact type that is used for hard-coded type representation. All artifacts must be configured in the
+ * SDC configuration file.
*/
@Getter
@AllArgsConstructor
public enum ArtifactTypeEnum {
- CHEF("CHEF"), PUPPET("PUPPET"), YANG("YANG"), SHELL_SCRIPT("SHELL_SCRIPT"), SHELL("SHELL"), ICON("ICON"), UNKNOWN("UNKNOWN"), HEAT("HEAT"), DG_XML("DG_XML"), MURANO_PKG("MURANO_PKG"), HEAT_ENV("HEAT_ENV"), YANG_XML("YANG_XML"), HEAT_VOL("HEAT_VOL"),
- HEAT_NET("HEAT_NET"), OTHER("OTHER"), WORKFLOW("WORKFLOW"), NETWORK_CALL_FLOW("NETWORK_CALL_FLOW"), TOSCA_TEMPLATE("TOSCA_TEMPLATE"), TOSCA_CSAR("TOSCA_CSAR"), VNF_CATALOG("VNF_CATALOG"), VF_LICENSE("VF_LICENSE"), BPEL("BPEL"),
- VENDOR_LICENSE("VENDOR_LICENSE"), MODEL_INVENTORY_PROFILE("MODEL_INVENTORY_PROFILE"), MODEL_QUERY_SPEC("MODEL_QUERY_SPEC"), APPC_CONFIG("APPC_CONFIG"), HEAT_NESTED("HEAT_NESTED"), HEAT_ARTIFACT("HEAT_ARTIFACT"), CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT("CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT"),
- VF_MODULES_METADATA("VF_MODULES_METADATA"), LIFECYCLE_OPERATIONS("LIFECYCLE_OPERATIONS"), VES_EVENTS("VES_EVENTS"), PERFORMANCE_COUNTER("PERFORMANCE_COUNTER"),UCPE_LAYER_2_CONFIGURATION("UCPE_LAYER_2_CONFIGURATION"),
- CONTROLLER_BLUEPRINT_ARCHIVE("CONTROLLER_BLUEPRINT_ARCHIVE"),
- // DCAE Artifacts
- DCAE_TOSCA("DCAE_TOSCA"), DCAE_JSON("DCAE_JSON"), DCAE_POLICY("DCAE_POLICY"), DCAE_DOC("DCAE_DOC"), DCAE_EVENT("DCAE_EVENT"), DCAE_INVENTORY_TOSCA("DCAE_INVENTORY_TOSCA"), DCAE_INVENTORY_JSON("DCAE_INVENTORY_JSON"),
- DCAE_INVENTORY_POLICY("DCAE_INVENTORY_POLICY"), DCAE_INVENTORY_DOC("DCAE_INVENTORY_DOC"), DCAE_INVENTORY_BLUEPRINT("DCAE_INVENTORY_BLUEPRINT"), DCAE_INVENTORY_EVENT("DCAE_INVENTORY_EVENT"),
- // AAI Artifacts
- AAI_SERVICE_MODEL("AAI_SERVICE_MODEL"), AAI_VF_MODEL("AAI_VF_MODEL"), AAI_VF_MODULE_MODEL("AAI_VF_MODULE_MODEL"), AAI_VF_INSTANCE_MODEL("AAI_VF_INSTANCE_MODEL"),
- // MIB artifacts
- SNMP_POLL ("SNMP_POLL"), SNMP_TRAP("SNMP_TRAP"), GUIDE("GUIDE"),
- PLAN("PLAN"), PM_DICTIONARY("PM_DICTIONARY"), YANG_MODULE("YANG_MODULE"),
- ANSIBLE_PLAYBOOK("ANSIBLE_PLAYBOOK"), ONBOARDED_PACKAGE("ONBOARDED_PACKAGE"), PNF_SW_INFORMATION("PNF_SW_INFORMATION");
+ AAI_SERVICE_MODEL("AAI_SERVICE_MODEL"),
+ ANSIBLE_PLAYBOOK("ANSIBLE_PLAYBOOK"),
+ CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT("CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT"),
+ DCAE_INVENTORY_JSON("DCAE_INVENTORY_JSON"),
+ DCAE_INVENTORY_TOSCA("DCAE_INVENTORY_TOSCA"),
+ GUIDE("GUIDE"),
+ HEAT("HEAT"),
+ HEAT_ARTIFACT("HEAT_ARTIFACT"),
+ HEAT_ENV("HEAT_ENV"),
+ HEAT_NESTED("HEAT_NESTED"),
+ HEAT_NET("HEAT_NET"),
+ HEAT_VOL("HEAT_VOL"),
+ LIFECYCLE_OPERATIONS("LIFECYCLE_OPERATIONS"),
+ MODEL_INVENTORY_PROFILE("MODEL_INVENTORY_PROFILE"),
+ MODEL_QUERY_SPEC("MODEL_QUERY_SPEC"),
+ OTHER("OTHER"),
+ PM_DICTIONARY("PM_DICTIONARY"),
+ PUPPET("PUPPET"),
+ SNMP_POLL("SNMP_POLL"),
+ SNMP_TRAP("SNMP_TRAP"),
+ TOSCA_CSAR("TOSCA_CSAR"),
+ TOSCA_TEMPLATE("TOSCA_TEMPLATE"),
+ UCPE_LAYER_2_CONFIGURATION("UCPE_LAYER_2_CONFIGURATION"),
+ VENDOR_LICENSE("VENDOR_LICENSE"),
+ VES_EVENTS("VES_EVENTS"),
+ VF_LICENSE("VF_LICENSE"),
+ VF_MODULES_METADATA("VF_MODULES_METADATA"),
+ VNF_CATALOG("VNF_CATALOG"),
+ WORKFLOW("WORKFLOW"),
+ YANG_XML("YANG_XML"),
+ CHEF("CHEF"), YANG("YANG"), SHELL_SCRIPT("SHELL_SCRIPT"), SHELL("SHELL"), ICON("ICON"), UNKNOWN("UNKNOWN"), DG_XML("DG_XML"), MURANO_PKG("MURANO_PKG"),
+ NETWORK_CALL_FLOW("NETWORK_CALL_FLOW"), BPEL("BPEL"), APPC_CONFIG("APPC_CONFIG"), PERFORMANCE_COUNTER("PERFORMANCE_COUNTER"), CONTROLLER_BLUEPRINT_ARCHIVE("CONTROLLER_BLUEPRINT_ARCHIVE"),
+ DCAE_TOSCA("DCAE_TOSCA"), DCAE_JSON("DCAE_JSON"), DCAE_POLICY("DCAE_POLICY"), DCAE_DOC("DCAE_DOC"), DCAE_EVENT("DCAE_EVENT"),
+ DCAE_INVENTORY_POLICY("DCAE_INVENTORY_POLICY"), DCAE_INVENTORY_DOC("DCAE_INVENTORY_DOC"), DCAE_INVENTORY_BLUEPRINT("DCAE_INVENTORY_BLUEPRINT"), DCAE_INVENTORY_EVENT("DCAE_INVENTORY_EVENT"),
+ AAI_VF_MODEL("AAI_VF_MODEL"), AAI_VF_MODULE_MODEL("AAI_VF_MODULE_MODEL"), AAI_VF_INSTANCE_MODEL("AAI_VF_INSTANCE_MODEL"),
+ PLAN("PLAN"), YANG_MODULE("YANG_MODULE"), ONBOARDED_PACKAGE("ONBOARDED_PACKAGE"), PNF_SW_INFORMATION("PNF_SW_INFORMATION");
- private final String type;
+ private final String type;
- public static ArtifactTypeEnum findType(final String type) {
- for (final ArtifactTypeEnum ate : ArtifactTypeEnum.values()) {
- if (ate.getType().equalsIgnoreCase(type)) {
- return ate;
- }
- }
- return null;
- }
+ /**
+ * Parse a string to a {@link ArtifactTypeEnum}, ignoring the case.
+ *
+ * @param type the artifact type
+ * @return The artifact type if its represented in the present enum, otherwise {@code null}.
+ */
+ public static ArtifactTypeEnum parse(final String type) {
+ for (final ArtifactTypeEnum artifactType : ArtifactTypeEnum.values()) {
+ if (artifactType.getType().equalsIgnoreCase(type)) {
+ return artifactType;
+ }
+ }
+ return null;
+ }
- public static List<String> getAllTypes() {
- final List<String> types = new ArrayList<>();
- for (final ArtifactTypeEnum ate : ArtifactTypeEnum.values()) {
- types.add(ate.getType());
- }
- return types;
- }
}
diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/api/ArtifactTypeEnumTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/api/ArtifactTypeEnumTest.java
index 86cdeaafa8..86f1f86bb0 100644
--- a/common-app-api/src/test/java/org/openecomp/sdc/common/api/ArtifactTypeEnumTest.java
+++ b/common-app-api/src/test/java/org/openecomp/sdc/common/api/ArtifactTypeEnumTest.java
@@ -20,43 +20,36 @@
package org.openecomp.sdc.common.api;
-import java.util.List;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
import org.junit.Test;
public class ArtifactTypeEnumTest {
-
- private ArtifactTypeEnum createTestSubject() {
- return ArtifactTypeEnum.AAI_SERVICE_MODEL;
- }
-
@Test
- public void testGetType() throws Exception {
- ArtifactTypeEnum testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getType();
+ public void testGetType() {
+ assertThat("The artifact type should match", ArtifactTypeEnum.WORKFLOW.getType(), is("WORKFLOW"));
+ assertThat("The artifact type should match", ArtifactTypeEnum.OTHER.getType(), is("OTHER"));
+ assertThat("The artifact type should match", ArtifactTypeEnum.HEAT.getType(), is("HEAT"));
}
@Test
- public void testFindType() throws Exception {
- String type = "";
- ArtifactTypeEnum result;
-
- // default test
- result = ArtifactTypeEnum.findType(type);
+ public void testParse() {
+ ArtifactTypeEnum actual = ArtifactTypeEnum.parse("HEAT");
+ assertThat("The artifact type should not be null", actual, notNullValue());
+ assertThat("The artifact type should match", actual, is(ArtifactTypeEnum.HEAT));
+ actual = ArtifactTypeEnum.parse("OTHER");
+ assertThat("The artifact type should not be null", actual, notNullValue());
+ assertThat("The artifact type should match", actual, is(ArtifactTypeEnum.OTHER));
+ actual = ArtifactTypeEnum.parse("WORKFLOW");
+ assertThat("The artifact type should not be null", actual, notNullValue());
+ assertThat("The artifact type should match", actual, is(ArtifactTypeEnum.WORKFLOW));
+ actual = ArtifactTypeEnum.parse("anyNotKnownType");
+ assertThat("The artifact type should be null", actual, nullValue());
}
-
- @Test
- public void testGetAllTypes() throws Exception {
- List<String> result;
-
- // default test
- result = ArtifactTypeEnum.getAllTypes();
- }
}