From 5c1294eb8e2dc00cae4ef21d6111e0fa18fc2caa Mon Sep 17 00:00:00 2001 From: imamSidero Date: Tue, 5 Sep 2023 11:06:25 +0100 Subject: Provide user to specify the ouput name while declaring the atrributes User specified output name is provided on declare output functionality Issue-ID: SDC-4616 Signed-off-by: Imam hussain Change-Id: Ic0cd50f9dde2482f5fbb2363cdc83d8fcf09f48f --- .../files/default/error-configuration.yaml | 8 ++++++ .../attribute/DefaultAttributeDeclarator.java | 8 +++++- .../be/components/impl/OutputsBusinessLogic.java | 31 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) (limited to 'catalog-be/src/main') 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 c5b417d725..4d26e08831 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 @@ -2926,3 +2926,11 @@ errors: message: "Error: The following properties:\n%1\nused in the substitution mapping node type in CSAR are missing from the system. Please add these to the node in the SDC catalog prior to importing the template", messageId: "SVC4021" } + + # %1 - Output name + #---------SVC4022----------------------------- + OUTPUT_NAME_ALREADY_EXIST: { + code: 400, + message: "Output name '%1' already exist.", + messageId: "SVC4022" + } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java index 394d6b314b..e494934d4d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java @@ -119,7 +119,13 @@ public abstract class DefaultAttributeDeclarator status = validateOutputName(component, componentInstOutputsMapUi); + if (status.getLeft() != StorageOperationStatus.OK) { + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.OUTPUT_NAME_ALREADY_EXIST, status.getRight())); + } result = attributeDeclarationOrchestrator.declareAttributesToOutputs(component, componentInstOutputsMapUi).left() .bind(outputsToCreate -> prepareOutputsForCreation(userId, componentId, outputsToCreate)).right() .map(componentsUtils::getResponseFormat); @@ -155,6 +163,29 @@ public class OutputsBusinessLogic extends BaseBusinessLogic { } } + private ImmutablePair validateOutputName(final Component component, + final ComponentInstOutputsMap componentInstOutputsMapUi) { + final Map> outputDeclaredProperties = new HashMap<>(); + if (MapUtils.isNotEmpty(componentInstOutputsMapUi.getComponentInstanceOutputsMap())) { + outputDeclaredProperties.putAll(componentInstOutputsMapUi.getComponentInstanceOutputsMap()); + } else if (MapUtils.isNotEmpty(componentInstOutputsMapUi.getComponentInstanceAttributes())) { + outputDeclaredProperties.putAll(componentInstOutputsMapUi.getComponentInstanceAttributes()); + } + if (MapUtils.isNotEmpty(outputDeclaredProperties) && CollectionUtils.isNotEmpty(component.getOutputs())) { + for (final List componentInstancePropOutputs : outputDeclaredProperties.values()) { + for (final ComponentInstanceAttribOutput componentInstancePropOutput : componentInstancePropOutputs) { + final Optional outputDefinition = component.getOutputs().stream() + .filter(output -> output.getName().equals(componentInstancePropOutput.getOutputName()) + || output.getName().equals(componentInstancePropOutput.getName())).findAny(); + if (outputDefinition.isPresent()) { + return new ImmutablePair<>(StorageOperationStatus.INVALID_VALUE, outputDefinition.get().getName()); + } + } + } + } + return new ImmutablePair<>(StorageOperationStatus.OK, StringUtils.EMPTY); + } + private Component getAndValidateComponentForCreate(final String userId, final String componentId, final ComponentTypeEnum componentType, final boolean shouldLockComp) { -- cgit 1.2.3-korg