Fix 'not deleting Outputs' 70/118170/6
authorvasraz <vasyl.razinkov@est.tech>
Wed, 17 Feb 2021 12:45:11 +0000 (12:45 +0000)
committerChristophe Closset <christophe.closset@intl.att.com>
Thu, 25 Feb 2021 13:09:03 +0000 (13:09 +0000)
Change-Id: I1a5ab1dec4ab7ec381df157e9c12dc8fa00e82c4
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3448

catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java

index 5729d24..a18d8dc 100644 (file)
@@ -93,6 +93,7 @@ import org.openecomp.sdc.be.model.GroupDefinition;
 import org.openecomp.sdc.be.model.InputDefinition;
 import org.openecomp.sdc.be.model.InterfaceDefinition;
 import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.OutputDefinition;
 import org.openecomp.sdc.be.model.PolicyDefinition;
 import org.openecomp.sdc.be.model.PropertyDefinition;
 import org.openecomp.sdc.be.model.RelationshipInfo;
@@ -1559,6 +1560,17 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
                 }
             }
         }
+        if (CollectionUtils.isNotEmpty(containerComponent.getOutputs())) {
+            final List<OutputDefinition> outputsToDelete = containerComponent.getOutputs().stream().filter(i -> i.getInstanceUniqueId() != null && i.getInstanceUniqueId().equals(componentInstanceId)).collect(Collectors.toList());
+            if (CollectionUtils.isNotEmpty(outputsToDelete)) {
+                final StorageOperationStatus deleteOutputsRes = toscaOperationFacade.deleteComponentInstanceOutputsFromTopologyTemplate(containerComponent, outputsToDelete);
+                if (deleteOutputsRes != StorageOperationStatus.OK) {
+                    log.debug("Failed to delete outputs of the component instance {} from container component. ", componentInstanceId);
+                    throw new ByActionStatusComponentException(
+                            componentsUtils.convertFromStorageResponse(deleteOutputsRes, containerComponentType), componentInstanceId);
+                }
+            }
+        }
         return deletedInstance;
     }
 
@@ -3342,25 +3354,23 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
                 String sourceAttributeName = sourceAttribute.getName();
                 for (ComponentInstanceAttribute destAttribute : destAttributeList) {
                     if (sourceAttributeName.equals(destAttribute.getName())) {
-//                        if (sourceAttribute.getValue() != null && !sourceAttribute.getValue().isEmpty()) {
-                            log.debug("Start to copy the attribute exists {}", sourceAttributeName);
-
-                            sourceAttribute.setUniqueId(
-                                    UniqueIdBuilder.buildResourceInstanceUniuqeId(
-                                            "attribute" , destComponentInstanceId.split("\\.")[1] , sourceAttributeName));
-
-                            Either<ComponentInstanceAttribute, ResponseFormat> updateAttributeValueEither =
-                                    createOrUpdateAttributeValueForCopyPaste(ComponentTypeEnum.SERVICE,
-                                            destComponent.getUniqueId(), destComponentInstanceId, sourceAttribute,
-                                            userId);
-                            if (updateAttributeValueEither.isRight()) {
-                                log.error("Failed to copy the attribute");
-                                return Either.right(componentsUtils
-                                        .getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM,
-                                                "Failed to paste component instance to the canvas, attribute copy"));
-                            }
-                            break;
-//                        }
+                        log.debug("Start to copy the attribute exists {}", sourceAttributeName);
+
+                        sourceAttribute.setUniqueId(
+                            UniqueIdBuilder.buildResourceInstanceUniuqeId(
+                                "attribute", destComponentInstanceId.split("\\.")[1], sourceAttributeName));
+
+                        Either<ComponentInstanceAttribute, ResponseFormat> updateAttributeValueEither =
+                            createOrUpdateAttributeValueForCopyPaste(ComponentTypeEnum.SERVICE,
+                                destComponent.getUniqueId(), destComponentInstanceId, sourceAttribute,
+                                userId);
+                        if (updateAttributeValueEither.isRight()) {
+                            log.error("Failed to copy the attribute");
+                            return Either.right(componentsUtils
+                                .getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM,
+                                    "Failed to paste component instance to the canvas, attribute copy"));
+                        }
+                        break;
                     }
                 }
             }
index b4517e4..083483b 100644 (file)
@@ -60,6 +60,7 @@ import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
@@ -3060,6 +3061,12 @@ public class ToscaOperationFacade {
             inputsToDelete.stream().map(PropertyDataDefinition::getName).collect(Collectors.toList()));
     }
 
+    public StorageOperationStatus deleteComponentInstanceOutputsFromTopologyTemplate(final Component containerComponent,
+                                                                                     final List<OutputDefinition> outputsToDelete) {
+        return topologyTemplateOperation.deleteToscaDataElements(containerComponent.getUniqueId(), EdgeLabelEnum.OUTPUTS,
+            outputsToDelete.stream().map(AttributeDataDefinition::getName).collect(Collectors.toList()));
+    }
+
     public StorageOperationStatus updateComponentInstanceCapabiltyProperty(Component containerComponent, String componentInstanceUniqueId,
                                                                            String capabilityPropertyKey,
                                                                            ComponentInstanceProperty property) {