summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java31
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java20
4 files changed, 62 insertions, 3 deletions
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
index 0530298219..fe32ad0b22 100644
--- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
+++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
@@ -2869,4 +2869,11 @@ errors:
code: 400,
message: "Cannot change this properties constraints as the resource is an instance.",
messageId: "SVC4015"
+ }
+
+ #---------SVC4016-----------------------------
+ INPUT_NAME_ALREADY_EXIST: {
+ code: 400,
+ message: "Input name already exist.",
+ messageId: "SVC4016"
} \ No newline at end of file
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
index 12a6936895..b632abfcca 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
@@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
@@ -398,6 +399,11 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
try {
validateUserExists(userId);
component = getAndValidateComponentForCreate(userId, componentId, componentType, shouldLockComp);
+ StorageOperationStatus status = validateInputName(component, componentInstInputsMapUi);
+ if (status != StorageOperationStatus.OK) {
+ log.debug("Input name already exist");
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INPUT_NAME_ALREADY_EXIST));
+ }
result = propertyDeclarationOrchestrator.declarePropertiesToInputs(component, componentInstInputsMapUi).left()
.bind(inputsToCreate -> prepareInputsForCreation(userId, componentId, inputsToCreate)).right()
.map(componentsUtils::getResponseFormat);
@@ -423,6 +429,31 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
}
+ private StorageOperationStatus validateInputName(final Component component, final ComponentInstInputsMap componentInstInputsMap) {
+ AtomicReference<StorageOperationStatus> storageOperationStatus = new AtomicReference<>(StorageOperationStatus.OK);
+ Map<String, List<ComponentInstancePropInput>> inputDeclaredProperties = new HashMap<>();
+ if (MapUtils.isNotEmpty(componentInstInputsMap.getComponentInstanceProperties())) {
+ inputDeclaredProperties = componentInstInputsMap.getComponentInstanceProperties();
+ } else if (MapUtils.isNotEmpty(componentInstInputsMap.getServiceProperties())) {
+ inputDeclaredProperties = componentInstInputsMap.getServiceProperties();
+ }
+
+ if (MapUtils.isNotEmpty(inputDeclaredProperties) && CollectionUtils.isNotEmpty(component.getInputs())) {
+ inputDeclaredProperties.values()
+ .forEach(componentInstancePropInputs ->
+ componentInstancePropInputs
+ .forEach(componentInstancePropInput -> component.getInputs()
+ .forEach(existingInput -> {
+ if (existingInput.getName().equals(componentInstancePropInput.getInputName())) {
+ storageOperationStatus.set(StorageOperationStatus.INVALID_VALUE);
+ }
+ })
+ )
+ );
+ }
+ return storageOperationStatus.get();
+ }
+
/**
* Creates a list input with a data type which has properties specified.
*
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java
index eba66d271a..31a27b0457 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java
@@ -255,7 +255,12 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
generatedInputPrefix =
generatedInputPrefix == null || generatedInputPrefix.isEmpty() ? capName : generatedInputPrefix + UNDERSCORE + capName;
}
- String generatedInputName = generateInputName(generatedInputPrefix, propInput);
+ String generatedInputName = null;
+ if (StringUtils.isNotEmpty(propInput.getInputName())) {
+ generatedInputName = propInput.getInputName();
+ } else {
+ generatedInputName = generateInputName(generatedInputPrefix, propInput);
+ }
log.debug("createInput: propOwner.uniqueId={}, propInput.parentUniqueId={}", propertiesOwner.getUniqueId(), propInput.getParentUniqueId());
return createInputFromProperty(component.getUniqueId(), propertiesOwner, generatedInputName, propInput, prop);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index 245fec39b0..186bcd2987 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -1764,8 +1764,24 @@ public class ToscaExportHandler {
if (component == null || CollectionUtils.isEmpty(component.getInputs())) {
return Collections.emptyMap();
}
- return component.getInputs().stream().filter(InputDefinition::isMappedToComponentProperty).map(PropertyDataDefinition::getName)
- .collect(Collectors.toMap(inputName -> inputName, inputName -> new String[]{inputName}, (inputName1, inputName2) -> inputName1));
+ Map<String, String[]> propertyMapping = new HashMap<>();
+ List<InputDefinition> propertyMappedInputList = component.getInputs().stream().filter(InputDefinition::isMappedToComponentProperty).collect(
+ Collectors.toList());
+
+ if (CollectionUtils.isNotEmpty(propertyMappedInputList)) {
+ propertyMappedInputList.forEach(inputDefinition -> {
+ if (StringUtils.isNotEmpty(inputDefinition.getPropertyId())) {
+ Optional<PropertyDefinition> property = component.getProperties().stream()
+ .filter(propertyDefinition -> propertyDefinition.getUniqueId().equals(inputDefinition.getPropertyId())).findFirst();
+ if (property.isPresent()) {
+ propertyMapping.put(property.get().getName(), new String[]{inputDefinition.getName()});
+ }
+ } else {
+ propertyMapping.put(inputDefinition.getName(), new String[]{inputDefinition.getName()});
+ }
+ });
+ }
+ return propertyMapping;
}
private Map<String, String[]> buildSubstitutionMappingAttributesMapping(final Component component) {