summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java')
-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
*/