summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org
diff options
context:
space:
mode:
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>2023-02-10 18:41:01 +0000
committerVasyl Razinkov <vasyl.razinkov@est.tech>2023-03-10 11:25:05 +0000
commitd03be99cba81d17bfb8681c18acf212eec9549ea (patch)
tree8838525a2bdf1caba2d441741534e94f95e6ae60 /catalog-be/src/main/java/org
parent4ec39782a9f8fe7188f38fc39953f277a8284618 (diff)
Provide input name when declaring service property as input
Issue-ID: SDC-4385 Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech> Change-Id: I2b71e04b97ba69195380d2aa29d9d98a3bd5e981
Diffstat (limited to 'catalog-be/src/main/java/org')
-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
3 files changed, 55 insertions, 3 deletions
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) {