From d03be99cba81d17bfb8681c18acf212eec9549ea Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Fri, 10 Feb 2023 18:41:01 +0000 Subject: Provide input name when declaring service property as input Issue-ID: SDC-4385 Signed-off-by: KrupaNagabhushan Change-Id: I2b71e04b97ba69195380d2aa29d9d98a3bd5e981 --- .../files/default/error-configuration.yaml | 7 +++++ .../be/components/impl/InputsBusinessLogic.java | 31 ++++++++++++++++++++++ .../property/DefaultPropertyDeclarator.java | 7 ++++- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 20 ++++++++++++-- 4 files changed, 62 insertions(+), 3 deletions(-) (limited to 'catalog-be') 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 = new AtomicReference<>(StorageOperationStatus.OK); + Map> 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 inputName, inputName -> new String[]{inputName}, (inputName1, inputName2) -> inputName1)); + Map propertyMapping = new HashMap<>(); + List propertyMappedInputList = component.getInputs().stream().filter(InputDefinition::isMappedToComponentProperty).collect( + Collectors.toList()); + + if (CollectionUtils.isNotEmpty(propertyMappedInputList)) { + propertyMappedInputList.forEach(inputDefinition -> { + if (StringUtils.isNotEmpty(inputDefinition.getPropertyId())) { + Optional 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 buildSubstitutionMappingAttributesMapping(final Component component) { -- cgit 1.2.3-korg