X-Git-Url: https://gerrit.onap.org/r/gitweb?p=sdc.git;a=blobdiff_plain;f=catalog-be%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Fcomponents%2Fimpl%2FOutputsBusinessLogic.java;h=58baad1a583595e37d8ab61b372aa9839837f348;hp=62ef98b9856863301c8f6911d28e1ca8c8478e79;hb=5c1294eb8e2dc00cae4ef21d6111e0fa18fc2caa;hpb=6531ae8151c52407d61b380534026e2d67f62753 diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java index 62ef98b985..58baad1a58 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java @@ -23,10 +23,14 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import org.apache.commons.collections.MapUtils; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; import org.jetbrains.annotations.NotNull; import org.openecomp.sdc.be.components.attribute.AttributeDeclarationOrchestrator; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; @@ -130,6 +134,10 @@ public class OutputsBusinessLogic extends BaseBusinessLogic { try { validateUserExists(userId); component = getAndValidateComponentForCreate(userId, componentId, componentType, shouldLockComp); + ImmutablePair 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) {