aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2021-11-23 21:35:12 +0000
committerMichael Morris <michael.morris@est.tech>2021-11-26 14:49:11 +0000
commitf2eb0c84057d745b8cc7e77a027dcd47122a7a5b (patch)
tree9c0a10e55391637f1d5c3d5a6a945be1d536bd4e /catalog-be/src/main
parent5a92b1a1a74db13771947f3175682095bd91b7e3 (diff)
Set default base type when none is provided
Sets a default base type (substitution type) when no base type is provided during the creation of a service with a category that requires a base type. Previous to the introduction of the optional base type, the system would always add a base type to a Service. Change-Id: I32e892fc23719fd569062ee806eb0be7b5af4ac6 Issue-ID: SDC-3791 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java38
2 files changed, 38 insertions, 3 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
index e51aeefa55..24ba0ead46 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
@@ -701,7 +701,8 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
createMandatoryArtifactsData(service, user);
createServiceApiArtifactsData(service, user);
setToscaArtifactsPlaceHolders(service, user);
- if (service.isSubstituteCandidate()) {
+
+ if (service.isSubstituteCandidate() || genericTypeBusinessLogic.hasMandatorySubstitutionType(service)) {
final Resource genericType = fetchAndSetDerivedFromGenericType(service);
generatePropertiesFromGenericType(service, genericType);
generateAndAddInputsFromGenericTypeProperties(service, genericType);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java
index 07d71eabb4..600f7fa3eb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java
@@ -22,9 +22,12 @@ package org.openecomp.sdc.be.components.impl.generic;
import fj.data.Either;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.config.CategoryBaseTypeConfig;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
@@ -33,6 +36,7 @@ import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -42,7 +46,7 @@ import org.springframework.beans.factory.annotation.Autowired;
@org.springframework.stereotype.Component
public class GenericTypeBusinessLogic {
- private final static Logger log = Logger.getLogger(GenericTypeBusinessLogic.class);
+ private static final Logger log = Logger.getLogger(GenericTypeBusinessLogic.class);
private final ComponentsUtils componentsUtils;
private final ToscaOperationFacade toscaOperationFacade;
@@ -66,7 +70,7 @@ public class GenericTypeBusinessLogic {
Either<Resource, StorageOperationStatus> genericType;
if (StringUtils.isEmpty(component.getDerivedFromGenericVersion())){
genericType = toscaOperationFacade
- .getLatestCertifiedNodeTypeByToscaResourceName(genericTypeToscaName);
+ .getLatestCertifiedNodeTypeByToscaResourceName(genericTypeToscaName);
if (genericType.isRight()) {
log.debug("Failed to fetch certified node type by tosca resource name {}", genericTypeToscaName);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType(), genericTypeToscaName));
@@ -92,6 +96,36 @@ public class GenericTypeBusinessLogic {
}
/**
+ * Checks if the component requires a substitution type.
+ *
+ * @param component the component to test
+ * @return {@code true} if the component requires a substitution type, {@code false} otherwise.
+ */
+ public boolean hasMandatorySubstitutionType(final Component component) {
+ if (!component.isService()) {
+ return true;
+ }
+
+ final Map<String, CategoryBaseTypeConfig> serviceBaseNodeTypes =
+ ConfigurationManager.getConfigurationManager().getConfiguration().getServiceBaseNodeTypes();
+ if (serviceBaseNodeTypes == null) {
+ return true;
+ }
+
+ if (CollectionUtils.isEmpty(component.getCategories())) {
+ throw new IllegalArgumentException("The Service must contain at least one category");
+ }
+ final CategoryDefinition categoryDefinition = component.getCategories().get(0);
+
+ final CategoryBaseTypeConfig categoryBaseTypeConfig = serviceBaseNodeTypes.get(categoryDefinition.getName());
+ if (categoryBaseTypeConfig == null) {
+ return true;
+ }
+
+ return categoryBaseTypeConfig.isRequired();
+ }
+
+ /**
* @param genericType the generic node type
* @return the generic type properties as inputs
*/