diff options
5 files changed, 113 insertions, 311 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentAttributeDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentAttributeDeclarator.java index 56dec5d93a..47fd74e8ce 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentAttributeDeclarator.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentAttributeDeclarator.java @@ -17,124 +17,90 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.components.attribute; import fj.data.Either; -import java.util.Collections; import java.util.List; import java.util.Optional; import org.apache.commons.collections.CollectionUtils; -import org.openecomp.sdc.be.components.impl.AttributeBusinessLogic; import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GetOutputValueDataDefinition; -import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.AttributeDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.OutputDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.openecomp.sdc.be.model.operations.impl.AttributeOperation; @org.springframework.stereotype.Component public class ComponentAttributeDeclarator extends DefaultAttributeDeclarator<Component, AttributeDataDefinition> { - private final ToscaOperationFacade toscaOperationFacade; - private final AttributeBusinessLogic attributeBusinessLogic; - - public ComponentAttributeDeclarator(final ComponentsUtils componentsUtils, - final AttributeOperation attributeOperation, - final ToscaOperationFacade toscaOperationFacade, - final AttributeBusinessLogic attributeBusinessLogic) { -// super(componentsUtils, attributeOperation); - this.toscaOperationFacade = toscaOperationFacade; - this.attributeBusinessLogic = attributeBusinessLogic; - } - - @Override - public AttributeDataDefinition createDeclaredAttribute(final AttributeDataDefinition attributeDataDefinition) { - return new AttributeDataDefinition(attributeDataDefinition); - } + private final ToscaOperationFacade toscaOperationFacade; - @Override - public Either<?, StorageOperationStatus> updateAttributesValues(final Component component, - final String propertiesOwnerId, - final List<AttributeDataDefinition> attributetypeList) { - if (CollectionUtils.isNotEmpty(attributetypeList)) { - for (AttributeDataDefinition attribute : attributetypeList) { - Either<AttributeDefinition, StorageOperationStatus> - storageStatus = toscaOperationFacade - .updateAttributeOfComponent(component, new AttributeDefinition(attribute)); - if (storageStatus.isRight()) { - return Either.right(storageStatus.right().value()); - } - } + public ComponentAttributeDeclarator(final ToscaOperationFacade toscaOperationFacade) { + this.toscaOperationFacade = toscaOperationFacade; } - return Either.left(attributetypeList); - } - - @Override - public Optional<Component> resolvePropertiesOwner(final Component component, final String propertiesOwnerId) { - return Optional.of(component); - } - @Override - public StorageOperationStatus unDeclareAttributesAsOutputs(final Component component, - final OutputDefinition output) { - AttributeDefinition attributeDefinition = new AttributeDefinition(output); - - // TODO - do we need this one - if (attributeBusinessLogic.isAttributeUsedByOperation(component, attributeDefinition)) { - return StorageOperationStatus.DECLARED_INPUT_USED_BY_OPERATION; + @Override + public AttributeDataDefinition createDeclaredAttribute(final AttributeDataDefinition attributeDataDefinition) { + return new AttributeDataDefinition(attributeDataDefinition); } - Optional<AttributeDefinition> attributeToUpdateCandidate = - getDeclaredAttributeByOutputId(component, output.getUniqueId()); - - if (attributeToUpdateCandidate.isPresent()) { - AttributeDefinition attributeToUpdate = attributeToUpdateCandidate.get(); - return unDeclareOutput(component, output, attributeToUpdate); + @Override + public Either<?, StorageOperationStatus> updateAttributesValues(final Component component, final String propertiesOwnerId, + final List<AttributeDataDefinition> attributetypeList) { + if (CollectionUtils.isNotEmpty(attributetypeList)) { + for (AttributeDataDefinition attribute : attributetypeList) { + Either<AttributeDefinition, StorageOperationStatus> storageStatus = toscaOperationFacade + .updateAttributeOfComponent(component, new AttributeDefinition(attribute)); + if (storageStatus.isRight()) { + return Either.right(storageStatus.right().value()); + } + } + } + return Either.left(attributetypeList); } - return StorageOperationStatus.OK; - } - - private StorageOperationStatus unDeclareOutput(final Component component, - final OutputDefinition output, - final AttributeDefinition attributeToUpdate) { - prepareValueBeforeDelete(output, attributeToUpdate, Collections.emptyList()); - attributeToUpdate.setValue(output.getDefaultValue()); - Either<AttributeDefinition, StorageOperationStatus> status = toscaOperationFacade - .updateAttributeOfComponent(component, attributeToUpdate); - if (status.isRight()) { - return status.right().value(); + @Override + public Optional<Component> resolvePropertiesOwner(final Component component, final String propertiesOwnerId) { + return Optional.of(component); } - return StorageOperationStatus.OK; - } - - private Optional<AttributeDefinition> getDeclaredAttributeByOutputId(final Component component, final String outputId) { - List<AttributeDefinition> attributes = component.getAttributes(); - - if (CollectionUtils.isEmpty(attributes)) { - return Optional.empty(); + @Override + public StorageOperationStatus unDeclareAttributesAsOutputs(final Component component, final OutputDefinition output) { + final Optional<AttributeDefinition> attributeToUpdateCandidate = getDeclaredAttributeByOutputId(component, output.getUniqueId()); + if (attributeToUpdateCandidate.isPresent()) { + AttributeDefinition attributeToUpdate = attributeToUpdateCandidate.get(); + return unDeclareOutput(component, output, attributeToUpdate); + } + return StorageOperationStatus.OK; } - for (AttributeDefinition attributeDefinition : attributes) { - List<GetOutputValueDataDefinition> getOutputValues = attributeDefinition.getGetOutputValues(); - if (CollectionUtils.isEmpty(getOutputValues)) { - continue; - } - - Optional<GetOutputValueDataDefinition> getOutputCandidate = - getOutputValues.stream().filter(getOutput -> getOutput.getOutputId().equals(outputId)).findAny(); - - if (getOutputCandidate.isPresent()) { - return Optional.of(attributeDefinition); - } + private StorageOperationStatus unDeclareOutput(final Component component, final OutputDefinition output, + final AttributeDefinition attributeToUpdate) { + attributeToUpdate.setValue(output.getDefaultValue()); + Either<AttributeDefinition, StorageOperationStatus> status = toscaOperationFacade.updateAttributeOfComponent(component, attributeToUpdate); + if (status.isRight()) { + return status.right().value(); + } + return StorageOperationStatus.OK; } - return Optional.empty(); - } - + private Optional<AttributeDefinition> getDeclaredAttributeByOutputId(final Component component, final String outputId) { + List<AttributeDefinition> attributes = component.getAttributes(); + if (CollectionUtils.isEmpty(attributes)) { + return Optional.empty(); + } + for (AttributeDefinition attributeDefinition : attributes) { + List<GetOutputValueDataDefinition> getOutputValues = attributeDefinition.getGetOutputValues(); + if (CollectionUtils.isEmpty(getOutputValues)) { + continue; + } + Optional<GetOutputValueDataDefinition> getOutputCandidate = getOutputValues.stream() + .filter(getOutput -> getOutput.getOutputId().equals(outputId)).findAny(); + if (getOutputCandidate.isPresent()) { + return Optional.of(attributeDefinition); + } + } + return Optional.empty(); + } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceAttributeDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceAttributeDeclarator.java index 8981515ea4..4c75624ec1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceAttributeDeclarator.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceAttributeDeclarator.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.components.attribute; import fj.data.Either; @@ -28,29 +27,23 @@ import java.util.Optional; import org.apache.commons.collections4.CollectionUtils; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition; -import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.ComponentInstanceAttribute; import org.openecomp.sdc.be.model.OutputDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.openecomp.sdc.be.model.operations.impl.AttributeOperation; import org.openecomp.sdc.common.log.wrappers.Logger; @org.springframework.stereotype.Component -public class ComponentInstanceAttributeDeclarator extends - DefaultAttributeDeclarator<ComponentInstance, ComponentInstanceAttribute> { +public class ComponentInstanceAttributeDeclarator extends DefaultAttributeDeclarator<ComponentInstance, ComponentInstanceAttribute> { private static final Logger log = Logger.getLogger(ComponentInstanceAttributeDeclarator.class); private ToscaOperationFacade toscaOperationFacade; private ComponentInstanceBusinessLogic componentInstanceBusinessLogic; - public ComponentInstanceAttributeDeclarator(final ComponentsUtils componentsUtils, - final AttributeOperation attributeOperation, - final ToscaOperationFacade toscaOperationFacade, + public ComponentInstanceAttributeDeclarator(final ToscaOperationFacade toscaOperationFacade, final ComponentInstanceBusinessLogic componentInstanceBusinessLogic) { -// super(componentsUtils, attributeOperation); this.toscaOperationFacade = toscaOperationFacade; this.componentInstanceBusinessLogic = componentInstanceBusinessLogic; } @@ -61,8 +54,7 @@ public class ComponentInstanceAttributeDeclarator extends } @Override - public Either<?, StorageOperationStatus> updateAttributesValues(final Component component, - final String cmptInstanceId, + public Either<?, StorageOperationStatus> updateAttributesValues(final Component component, final String cmptInstanceId, final List<ComponentInstanceAttribute> attributetypeList) { log.debug("#updateAttributesValues - updating component instance attributes for instance {} on component {}", cmptInstanceId, component.getUniqueId()); @@ -78,17 +70,13 @@ public class ComponentInstanceAttributeDeclarator extends @Override public StorageOperationStatus unDeclareAttributesAsOutputs(final Component component, final OutputDefinition output) { - - final List<ComponentInstanceAttribute> componentInstancePropertiesDeclaredAsInput - = componentInstanceBusinessLogic.getComponentInstanceAttributesByOutputId(component, output.getUniqueId()); + final List<ComponentInstanceAttribute> componentInstancePropertiesDeclaredAsInput = componentInstanceBusinessLogic + .getComponentInstanceAttributesByOutputId(component, output.getUniqueId()); if (CollectionUtils.isEmpty(componentInstancePropertiesDeclaredAsInput)) { return StorageOperationStatus.OK; } - componentInstancePropertiesDeclaredAsInput.forEach(cmptInstanceProperty -> prepareValueBeforeDelete(output, - cmptInstanceProperty, cmptInstanceProperty.getPath())); - return toscaOperationFacade.updateComponentInstanceAttributes(component, - componentInstancePropertiesDeclaredAsInput.get(0).getComponentInstanceId(), - componentInstancePropertiesDeclaredAsInput); + return toscaOperationFacade + .updateComponentInstanceAttributes(component, componentInstancePropertiesDeclaredAsInput.get(0).getComponentInstanceId(), + componentInstancePropertiesDeclaredAsInput); } - } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceOutputAttributeDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceOutputAttributeDeclarator.java index 7ded7c1209..9ad7c2a9e3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceOutputAttributeDeclarator.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/ComponentInstanceOutputAttributeDeclarator.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.components.attribute; import static org.apache.commons.collections4.CollectionUtils.isEmpty; @@ -29,14 +28,12 @@ import java.util.Map; import java.util.Optional; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition; -import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.ComponentInstanceOutput; import org.openecomp.sdc.be.model.OutputDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.openecomp.sdc.be.model.operations.impl.AttributeOperation; import org.openecomp.sdc.common.log.wrappers.Logger; @org.springframework.stereotype.Component @@ -46,11 +43,8 @@ public class ComponentInstanceOutputAttributeDeclarator extends DefaultAttribute private final ToscaOperationFacade toscaOperationFacade; private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic; - public ComponentInstanceOutputAttributeDeclarator(final ComponentsUtils componentsUtils, - final AttributeOperation attributeOperation, - final ToscaOperationFacade toscaOperationFacade, + public ComponentInstanceOutputAttributeDeclarator(final ToscaOperationFacade toscaOperationFacade, final ComponentInstanceBusinessLogic componentInstanceBusinessLogic) { -// super(componentsUtils, attributeOperation); this.toscaOperationFacade = toscaOperationFacade; this.componentInstanceBusinessLogic = componentInstanceBusinessLogic; } @@ -61,8 +55,7 @@ public class ComponentInstanceOutputAttributeDeclarator extends DefaultAttribute } @Override - public Either<?, StorageOperationStatus> updateAttributesValues(final Component component, - final String cmptInstanceId, + public Either<?, StorageOperationStatus> updateAttributesValues(final Component component, final String cmptInstanceId, final List<ComponentInstanceOutput> attributetypeList) { log.debug("#updateAttributesValues - updating component instance outputs for instance {} on component {}", cmptInstanceId, component.getUniqueId()); @@ -78,15 +71,11 @@ public class ComponentInstanceOutputAttributeDeclarator extends DefaultAttribute public StorageOperationStatus unDeclareAttributesAsOutputs(final Component component, final OutputDefinition output) { List<ComponentInstanceOutput> componentInstanceInputsByInputId = componentInstanceBusinessLogic - .getComponentInstanceOutputsByOutputId(component, output - .getUniqueId()); + .getComponentInstanceOutputsByOutputId(component, output.getUniqueId()); if (isEmpty(componentInstanceInputsByInputId)) { return StorageOperationStatus.OK; } - componentInstanceInputsByInputId - .forEach(cmptInstanceInput -> prepareValueBeforeDelete(output, cmptInstanceInput, cmptInstanceInput.getPath())); return toscaOperationFacade.updateComponentInstanceOutputs(component, componentInstanceInputsByInputId.get(0).getComponentInstanceId(), componentInstanceInputsByInputId); } - } 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 e53a362508..62f4211925 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 @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.components.attribute; import static org.openecomp.sdc.common.api.Constants.GET_ATTRIBUTE; @@ -50,14 +49,12 @@ import org.openecomp.sdc.be.model.OutputDefinition; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.common.log.wrappers.Logger; -import org.openecomp.sdc.exception.ResponseFormat; import org.yaml.snakeyaml.Yaml; -public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends PropertiesOwner, ATTRIBUTETYPE extends AttributeDataDefinition> - implements AttributeDeclarator { +public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends PropertiesOwner, ATTRIBUTETYPE extends AttributeDataDefinition> implements + AttributeDeclarator { private static final Logger log = Logger.getLogger(DefaultAttributeDeclarator.class); - private static final short LOOP_PROTECTION_LEVEL = 10; private static final String UNDERSCORE = "_"; private final Gson gson = new Gson(); @@ -68,9 +65,8 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie public Either<List<OutputDefinition>, StorageOperationStatus> declareAttributesAsOutputs(final Component component, final String propertiesOwnerId, final List<ComponentInstanceAttribOutput> attribsToDeclare) { - log.debug( - "#declarePropertiesAsInputs - declaring properties as inputs for component {} from properties owner {}", - component.getUniqueId(), propertiesOwnerId); + log.debug("#declarePropertiesAsInputs - declaring properties as inputs for component {} from properties owner {}", component.getUniqueId(), + propertiesOwnerId); return resolvePropertiesOwner(component, propertiesOwnerId) .map(propertyOwner -> declareAttributesAsOutputs(component, propertyOwner, attribsToDeclare)) .orElse(Either.right(onPropertiesOwnerNotFound(component.getUniqueId(), propertiesOwnerId))); @@ -78,31 +74,26 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie protected abstract ATTRIBUTETYPE createDeclaredAttribute(final AttributeDataDefinition attributeDataDefinition); - protected abstract Either<?, StorageOperationStatus> updateAttributesValues(final Component component, - final String propertiesOwnerId, + protected abstract Either<?, StorageOperationStatus> updateAttributesValues(final Component component, final String propertiesOwnerId, final List<ATTRIBUTETYPE> attributetypeList); protected abstract Optional<PROPERTYOWNER> resolvePropertiesOwner(final Component component, final String propertiesOwnerId); private StorageOperationStatus onPropertiesOwnerNotFound(final String componentId, final String propertiesOwnerId) { - log.debug("#declarePropertiesAsInputs - properties owner {} was not found on component {}", propertiesOwnerId, - componentId); + log.debug("#declarePropertiesAsInputs - properties owner {} was not found on component {}", propertiesOwnerId, componentId); return StorageOperationStatus.NOT_FOUND; } private Either<List<OutputDefinition>, StorageOperationStatus> declareAttributesAsOutputs(final Component component, final PROPERTYOWNER propertiesOwner, final List<ComponentInstanceAttribOutput> attributesToDeclare) { - final AttributesDeclarationData attributesDeclarationData - = createOutputsAndOverrideAttributesValues(component, propertiesOwner, attributesToDeclare); - return updateAttributesValues(component, propertiesOwner.getUniqueId(), - attributesDeclarationData.getAttributesToUpdate()) - .left() + final AttributesDeclarationData attributesDeclarationData = createOutputsAndOverrideAttributesValues(component, propertiesOwner, + attributesToDeclare); + return updateAttributesValues(component, propertiesOwner.getUniqueId(), attributesDeclarationData.getAttributesToUpdate()).left() .map(updatePropsRes -> attributesDeclarationData.getOutputsToCreate()); } - private AttributesDeclarationData createOutputsAndOverrideAttributesValues(final Component component, - final PROPERTYOWNER propertiesOwner, + private AttributesDeclarationData createOutputsAndOverrideAttributesValues(final Component component, final PROPERTYOWNER propertiesOwner, final List<ComponentInstanceAttribOutput> attributesToDeclare) { final List<ATTRIBUTETYPE> declaredAttributes = new ArrayList<>(); final List<OutputDefinition> createdInputs = attributesToDeclare.stream() @@ -111,10 +102,8 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie return new AttributesDeclarationData(createdInputs, declaredAttributes); } - private OutputDefinition declareAttributeOutput(final Component component, - final PROPERTYOWNER propertiesOwner, - final List<ATTRIBUTETYPE> declaredAttributes, - final ComponentInstanceAttribOutput attribOutput) { + private OutputDefinition declareAttributeOutput(final Component component, final PROPERTYOWNER propertiesOwner, + final List<ATTRIBUTETYPE> declaredAttributes, final ComponentInstanceAttribOutput attribOutput) { final AttributeDataDefinition attribute = resolveAttribute(declaredAttributes, attribOutput); final OutputDefinition outputDefinition = createOutput(component, propertiesOwner, attribOutput, attribute); final ATTRIBUTETYPE declaredAttribute = createDeclaredAttribute(attribute); @@ -124,40 +113,34 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie return outputDefinition; } - private OutputDefinition createOutput(final Component component, - final PROPERTYOWNER propertiesOwner, - final ComponentInstanceAttribOutput attribOutput, - final AttributeDataDefinition attributeDataDefinition) { + private OutputDefinition createOutput(final Component component, final PROPERTYOWNER propertiesOwner, + final ComponentInstanceAttribOutput attribOutput, final AttributeDataDefinition attributeDataDefinition) { String generatedInputPrefix = propertiesOwner.getNormalizedName(); if (propertiesOwner.getUniqueId().equals(attribOutput.getParentUniqueId())) { //Creating input from property create on self using add property..Do not add the prefix generatedInputPrefix = null; } - final String generatedOutputName = generateOutputName(generatedInputPrefix, attribOutput); - log.debug("createInput: propOwner.uniqueId={}, attribOutput.parentUniqueId={}", - propertiesOwner.getUniqueId(), attribOutput.getParentUniqueId()); + log.debug("createInput: propOwner.uniqueId={}, attribOutput.parentUniqueId={}", propertiesOwner.getUniqueId(), + attribOutput.getParentUniqueId()); return createOutputFromAttribute(component.getUniqueId(), propertiesOwner, generatedOutputName, attribOutput, attributeDataDefinition); } private String generateOutputName(final String outputName, final ComponentInstanceAttribOutput attribOutput) { final String declaredInputName; final String[] parsedPropNames = attribOutput.getParsedAttribNames(); - if (parsedPropNames != null) { declaredInputName = handleInputName(outputName, parsedPropNames); } else { final String[] propName = {attribOutput.getName()}; declaredInputName = handleInputName(outputName, propName); } - return declaredInputName; } private String handleInputName(final String outputName, final String[] parsedPropNames) { final StringBuilder prefix = new StringBuilder(); int startingIndex; - if (Objects.isNull(outputName)) { prefix.append(parsedPropNames[0]); startingIndex = 1; @@ -165,29 +148,22 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie prefix.append(outputName); startingIndex = 0; } - while (startingIndex < parsedPropNames.length) { prefix.append(UNDERSCORE); prefix.append(parsedPropNames[startingIndex]); startingIndex++; } - return prefix.toString(); } - private AttributeDataDefinition resolveAttribute(final List<ATTRIBUTETYPE> attributesToCreate, - final ComponentInstanceAttribOutput attribOutput) { - final Optional<ATTRIBUTETYPE> resolvedAttribute = attributesToCreate.stream() - .filter(p -> p.getName().equals(attribOutput.getName())) + private AttributeDataDefinition resolveAttribute(final List<ATTRIBUTETYPE> attributesToCreate, final ComponentInstanceAttribOutput attribOutput) { + final Optional<ATTRIBUTETYPE> resolvedAttribute = attributesToCreate.stream().filter(p -> p.getName().equals(attribOutput.getName())) .findFirst(); return resolvedAttribute.isPresent() ? resolvedAttribute.get() : attribOutput; } - OutputDefinition createOutputFromAttribute(final String componentId, - final PROPERTYOWNER propertiesOwner, - final String outputName, - final ComponentInstanceAttribOutput attributeOutput, - final AttributeDataDefinition attribute) { + OutputDefinition createOutputFromAttribute(final String componentId, final PROPERTYOWNER propertiesOwner, final String outputName, + final ComponentInstanceAttribOutput attributeOutput, final AttributeDataDefinition attribute) { final String attributesName = attributeOutput.getAttributesName(); final AttributeDefinition selectedAttrib = attributeOutput.getOutput(); final String[] parsedAttribNames = attributeOutput.getParsedAttribNames(); @@ -207,7 +183,6 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie outputDefinition.setInstanceUniqueId(propertiesOwner.getUniqueId()); outputDefinition.setAttributeId(attributeOutput.getUniqueId()); outputDefinition.setAttributes(Arrays.asList(attributeOutput)); - if (attribute instanceof IComponentInstanceConnectedElement) { ((IComponentInstanceConnectedElement) attribute).setComponentInstanceId(propertiesOwner.getUniqueId()); ((IComponentInstanceConnectedElement) attribute).setComponentInstanceName(propertiesOwner.getName()); @@ -216,11 +191,8 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie return outputDefinition; } - private void changeOutputValueToGetAttributeValue(final String outputName, - final String[] parsedPropNames, - final OutputDefinition output, - final AttributeDataDefinition attributeDataDefinition, - final boolean complexProperty) { + private void changeOutputValueToGetAttributeValue(final String outputName, final String[] parsedPropNames, final OutputDefinition output, + final AttributeDataDefinition attributeDataDefinition, final boolean complexProperty) { JSONObject jsonObject = new JSONObject(); final String value = attributeDataDefinition.getValue(); if (StringUtils.isEmpty(value)) { @@ -228,36 +200,32 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie jsonObject = createJSONValueForProperty(parsedPropNames.length - 1, parsedPropNames, jsonObject, outputName); attributeDataDefinition.setValue(jsonObject.toJSONString()); } else { - jsonObject.put( - GET_ATTRIBUTE, Arrays.asList(output.getAttributes().get(0).getComponentInstanceName(), attributeDataDefinition.getName())); + jsonObject + .put(GET_ATTRIBUTE, Arrays.asList(output.getAttributes().get(0).getComponentInstanceName(), attributeDataDefinition.getName())); output.setValue(jsonObject.toJSONString()); } } else { final Object objValue = new Yaml().load(value); if (objValue instanceof Map || objValue instanceof List) { if (!complexProperty) { - jsonObject.put( - GET_ATTRIBUTE, Arrays.asList(output.getAttributes().get(0).getComponentInstanceName(), attributeDataDefinition.getName())); + jsonObject.put(GET_ATTRIBUTE, + Arrays.asList(output.getAttributes().get(0).getComponentInstanceName(), attributeDataDefinition.getName())); output.setValue(jsonObject.toJSONString()); } else { final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue; createOutputValue(mappedToscaTemplate, 1, parsedPropNames, outputName); - output.setValue(gson.toJson(mappedToscaTemplate)); } - } else { - jsonObject.put( - GET_ATTRIBUTE, Arrays.asList(output.getAttributes().get(0).getComponentInstanceName(), attributeDataDefinition.getName())); + jsonObject + .put(GET_ATTRIBUTE, Arrays.asList(output.getAttributes().get(0).getComponentInstanceName(), attributeDataDefinition.getName())); output.setValue(jsonObject.toJSONString()); } } - if (CollectionUtils.isEmpty(attributeDataDefinition.getGetOutputValues())) { attributeDataDefinition.setGetOutputValues(new ArrayList<>()); } final List<GetOutputValueDataDefinition> getOutputValues = attributeDataDefinition.getGetOutputValues(); - final GetOutputValueDataDefinition getOutputValueDataDefinition = new GetOutputValueDataDefinition(); getOutputValueDataDefinition.setOutputId(output.getUniqueId()); getOutputValueDataDefinition.setOutputName(output.getName()); @@ -265,7 +233,6 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie } private JSONObject createJSONValueForProperty(int i, final String[] parsedPropNames, final JSONObject ooj, final String outputName) { - while (i >= 1) { if (i == parsedPropNames.length - 1) { final JSONObject jobProp = new JSONObject(); @@ -280,7 +247,6 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie return createJSONValueForProperty(i, parsedPropNames, res, outputName); } } - return ooj; } @@ -319,78 +285,6 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie return lhm1; } - private class AttributesDeclarationData { - - private final List<OutputDefinition> outputsToCreate; - private final List<ATTRIBUTETYPE> attributesToUpdate; - - AttributesDeclarationData(final List<OutputDefinition> outputsToCreate, - final List<ATTRIBUTETYPE> attributesToUpdate) { - this.outputsToCreate = outputsToCreate; - this.attributesToUpdate = attributesToUpdate; - } - - List<OutputDefinition> getOutputsToCreate() { - return outputsToCreate; - } - - List<ATTRIBUTETYPE> getAttributesToUpdate() { - return attributesToUpdate; - } - } - - Either<OutputDefinition, ResponseFormat> prepareValueBeforeDelete(final OutputDefinition inputForDelete, - final AttributeDataDefinition inputValue, - final List<String> pathOfComponentInstances) { - final Either<OutputDefinition, ResponseFormat> deleteEither = prepareValueBeforeDelete(inputForDelete, inputValue); - -// Either<String, JanusGraphOperationStatus> findDefaultValue = propertyOperation -// .findDefaultValueFromSecondPosition(pathOfComponentInstances, inputValue.getUniqueId(), -// (String) inputValue.get_default()); -// if (findDefaultValue.isRight()) { -// deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils -// .convertFromStorageResponse( -// DaoStatusConverter.convertJanusGraphStatusToStorageStatus(findDefaultValue.right().value())))); -// return deleteEither; -// -// } -// String defaultValue = findDefaultValue.left().value(); -// inputValue.set_default(defaultValue); -// log.debug("The returned default value in ResourceInstanceProperty is {}", defaultValue); - return deleteEither; - } - - private Either<OutputDefinition, ResponseFormat> prepareValueBeforeDelete(final OutputDefinition outputForDelete, - final AttributeDataDefinition outputValue) { - final Either<OutputDefinition, ResponseFormat> deleteEither = Either.left(outputForDelete); - String value = outputValue.getValue(); - final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(value); - - resetOutputName(mappedToscaTemplate, outputForDelete.getName()); - - value = ""; - if (MapUtils.isNotEmpty(mappedToscaTemplate)) { - final Either result = cleanNestedMap(mappedToscaTemplate, true); - Map modifiedMappedToscaTemplate = mappedToscaTemplate; - if (result.isLeft()) { - modifiedMappedToscaTemplate = (Map) result.left().value(); - } else { - log.warn("Map cleanup failed -> {}", result.right().value()); //continue, don't break operation - } - value = gson.toJson(modifiedMappedToscaTemplate); - } - outputValue.setValue(value); - - final List<GetOutputValueDataDefinition> getInputsValues = outputValue.getGetOutputValues(); - if (getInputsValues != null && !getInputsValues.isEmpty()) { - final Optional<GetOutputValueDataDefinition> op = - getInputsValues.stream().filter(gi -> gi.getOutputId().equals(outputForDelete.getUniqueId())).findAny(); - op.ifPresent(getInputsValues::remove); - } - outputValue.setGetOutputValues(getInputsValues); - return deleteEither; - } - private void resetOutputName(final Map<String, Object> lhm1, final String outputName) { for (final Map.Entry<String, Object> entry : lhm1.entrySet()) { final String key = entry.getKey(); @@ -406,24 +300,6 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie } } - private Either cleanNestedMap(Map mappedToscaTemplate, final boolean deepClone) { - if (MapUtils.isNotEmpty(mappedToscaTemplate)) { - if (deepClone) { - if (!(mappedToscaTemplate instanceof HashMap)) { - return Either.right( - "expecting mappedToscaTemplate as HashMap ,recieved " + mappedToscaTemplate.getClass() - .getSimpleName()); - } else { - mappedToscaTemplate = (HashMap) ((HashMap) mappedToscaTemplate).clone(); - } - } - return Either.left((Map) cleanEmptyNestedValuesInMap(mappedToscaTemplate, LOOP_PROTECTION_LEVEL)); - } else { - log.debug("mappedToscaTemplate is empty "); - return Either.right("mappedToscaTemplate is empty "); - } - } - /* Mutates the object * Tail recurse -> traverse the tosca elements and remove nested empty map properties * this only handles nested maps, other objects are left untouched (even a Set containing a map) since behaviour is unexpected @@ -449,7 +325,6 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie if (CollectionUtils.isNotEmpty(set)) { set.removeAll(keysToRemove); } - if (isEmptyNestedMap(toscaElement)) { return null; } @@ -480,4 +355,22 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie return isEmpty; } + private class AttributesDeclarationData { + + private final List<OutputDefinition> outputsToCreate; + private final List<ATTRIBUTETYPE> attributesToUpdate; + + AttributesDeclarationData(final List<OutputDefinition> outputsToCreate, final List<ATTRIBUTETYPE> attributesToUpdate) { + this.outputsToCreate = outputsToCreate; + this.attributesToUpdate = attributesToUpdate; + } + + List<OutputDefinition> getOutputsToCreate() { + return outputsToCreate; + } + + List<ATTRIBUTETYPE> getAttributesToUpdate() { + return attributesToUpdate; + } + } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java index a44ed3c8c7..f07752986b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java @@ -408,38 +408,4 @@ public class AttributeBusinessLogic extends BaseBusinessLogic { return Either.left(status.left().value().getAttributes()); } - public boolean isAttributeUsedByOperation(Component component, - AttributeDefinition propertyDefinitionEntry) { - // TODO - do we need this one - return false; - -// // Component's own interfaces -// Map<String, InterfaceDefinition> interfaces = component.getInterfaces(); -// if(MapUtils.isNotEmpty(interfaces)){ -// for(Map.Entry<String, InterfaceDefinition> interfaceEntry : interfaces.entrySet()) { -// if (isPropertyExistInOperationInterface(propertyDefinitionEntry, interfaceEntry.getValue())) { -// return true; -// } -// } -// } -// -// // Component's child's component interfaces -// if(isPropertyUsedInCIInterfaces(component.getComponentInstancesInterfaces(), propertyDefinitionEntry)){ -// return true; -// } -// -// // Component's parent's component interfaces -// Either<List<Component>, StorageOperationStatus> componentList = toscaOperationFacade.getParentComponents(component.getUniqueId()); -// if(componentList.isLeft()){ -// for (Component parentComponent : componentList.left().value()) { -// if(isPropertyUsedInCIInterfaces(parentComponent.getComponentInstancesInterfaces(), propertyDefinitionEntry)){ -// return true; -// } -// } -// } -// -// return false; - } - - } |