Revert "Delete workflow artifact
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / InterfaceOperationBusinessLogic.java
index c04eb29..05e7fe0 100644 (file)
@@ -19,14 +19,9 @@ package org.openecomp.sdc.be.components.impl;
 
 import com.google.common.collect.Sets;
 import fj.data.Either;
-import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang3.tuple.Pair;
 import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
-import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
 import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -41,6 +36,7 @@ import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
 import org.openecomp.sdc.be.model.jsontitan.utils.InterfaceUtils;
 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
 import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
+import org.openecomp.sdc.be.user.Role;
 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
 import org.openecomp.sdc.exception.ResponseFormat;
@@ -57,6 +53,8 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
 import java.util.UUID;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 @Component("interfaceOperationBusinessLogic")
 public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
@@ -70,9 +68,6 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
     @Autowired
     private InterfaceOperation interfaceOperation;
 
-    @Autowired
-    private ArtifactCassandraDao artifactCassandraDao;
-
     public void setInterfaceOperation(InterfaceOperation interfaceOperation) {
         this.interfaceOperation = interfaceOperation;
     }
@@ -87,29 +82,19 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
     }
 
 
-    public void setArtifactCassandraDao(ArtifactCassandraDao artifactCassandraDao) {
-        this.artifactCassandraDao = artifactCassandraDao;
-    }
-
     public Either<Resource, ResponseFormat> deleteInterfaceOperation(String resourceId, Set<String> interfaceOperationToDelete, User user, boolean lock) {
         Resource resourceToDelete = initResourceToDeleteWFOp(resourceId, interfaceOperationToDelete);
         Either<Resource, ResponseFormat> eitherDelete = validateUserAndRole(resourceToDelete, user, "deleteInterfaceOperation");
         if (eitherDelete != null)
             return eitherDelete;
-        if (CollectionUtils.isEmpty(interfaceOperationToDelete)){
-            LOGGER.debug("Invalid parameter interfaceOperationToDelete was empty");
-            return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY));
-        }
 
         Either<Resource, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(resourceId);
         if (storageStatus.isRight()) {
-            return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(),
-                    ComponentTypeEnum.RESOURCE), StringUtils.EMPTY));
+            return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.RESOURCE),""));
         }
         Resource resource = storageStatus.left().value();
         if (lock) {
-            Either<Boolean, ResponseFormat> lockResult = lockComponent(resource.getUniqueId(), resource,
-                    "Delete interface Operation on a resource");
+            Either<Boolean, ResponseFormat> lockResult = lockComponent(resource.getUniqueId(), resource, "Delete interface Operation on a resource");
             if (lockResult.isRight()) {
                 LOGGER.debug("Failed to lock resource {}. Response is {}. ", resource.getName(), lockResult.right().value().getFormattedMessage());
                 titanDao.rollback();
@@ -125,26 +110,14 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
                 return Either.right(sValue.right().value());
             }
             InterfaceDefinition interfaceDefinition = sValue.left().value();
+            Either<InterfaceDefinition, ResponseFormat> deleteEither;
 
             for(String operationToDelete : interfaceOperationToDelete) {
-                Either<Pair<InterfaceDefinition, Operation>, ResponseFormat> deleteEither = deleteOperationFromInterface(interfaceDefinition, operationToDelete);
+                deleteEither = deleteOperationFromInterface(interfaceDefinition, operationToDelete);
                 if (deleteEither.isRight()){
                     return Either.right(deleteEither.right().value());
                 }
-
-                Operation deletedOperation = deleteEither.left().value().getValue();
-                ArtifactDefinition implementationArtifact = deletedOperation.getImplementationArtifact();
-                String artifactUUID = implementationArtifact.getArtifactUUID();
-                CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUUID);
-                if (cassandraStatus != CassandraOperationStatus.OK) {
-                    LOGGER.debug("Failed to delete the artifact {} from the database. ", artifactUUID);
-                    ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
-                            componentsUtils.convertFromStorageResponse(componentsUtils.convertToStorageOperationStatus(cassandraStatus)),
-                            implementationArtifact.getArtifactDisplayName());
-                    return Either.right(responseFormatByArtifactId);
-                }
-
-
+                interfaceDefinition = deleteEither.left().value();
             }
 
             Either<InterfaceDefinition, StorageOperationStatus> interfaceUpdate = interfaceOperation.updateInterface(resource.getUniqueId(), interfaceDefinition);
@@ -154,14 +127,16 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
                 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(interfaceUpdate.right().value(), ComponentTypeEnum.RESOURCE)));
             }
 
-            if(interfaceDefinition.getOperationsMap().isEmpty()){
-                Either<Set<String>, StorageOperationStatus> deleteInterface = interfaceOperation.deleteInterface(resource, Sets.newHashSet(interfaceDefinition.getUniqueId()));
+            InterfaceDefinition interfaceDef = interfaceUpdate.left().value();
+            if(interfaceDef.getOperationsMap().isEmpty()){
+                Either<Set<String>, StorageOperationStatus> deleteInterface = interfaceOperation.deleteInterface(resource, Sets.newHashSet(interfaceDef.getUniqueId()));
                 if (deleteInterface.isRight()) {
                     LOGGER.debug("Failed to delete interface from resource {}. Response is {}. ", resource.getName(), deleteInterface.right().value());
                     titanDao.rollback();
                     return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteInterface.right().value(), ComponentTypeEnum.RESOURCE)));
                 }
             }
+
             titanDao.commit();
 
         } catch (Exception e){
@@ -193,7 +168,7 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
         }
     }
 
-    private Either<Pair<InterfaceDefinition, Operation>,ResponseFormat> deleteOperationFromInterface(InterfaceDefinition interfaceDefinition, String operationId){
+    private Either<InterfaceDefinition,ResponseFormat> deleteOperationFromInterface(InterfaceDefinition interfaceDefinition, String operationId){
         Optional<Map.Entry<String, Operation>> operationToRemove = interfaceDefinition.getOperationsMap().entrySet().stream()
                 .filter(entry -> entry.getValue().getUniqueId().equals(operationId)).findAny();
         if (operationToRemove.isPresent()){
@@ -201,13 +176,12 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
             Map<String, Operation> tempMap = interfaceDefinition.getOperationsMap();
             tempMap.remove(stringOperationEntry.getKey());
             interfaceDefinition.setOperationsMap(tempMap);
-            return Either.left(Pair.of(interfaceDefinition,stringOperationEntry.getValue()));
+            return Either.left(interfaceDefinition);
         }
         LOGGER.debug("Failed to delete interface operation");
         return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND));
     }
 
-
     private Either<InterfaceDefinition,ResponseFormat> addOperationToInterface(InterfaceDefinition interfaceDefinition, Operation interfaceOperation){
         if(interfaceOperation.getUniqueId() == null)
             interfaceOperation.setUniqueId(UUID.randomUUID().toString());
@@ -256,10 +230,6 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
             return eitherCreator;
 
         Either<Resource, ResponseFormat> resourceEither = getResourceDetails(resourceId);
-        if (resourceEither.isRight()){
-            return resourceEither;
-        }
-
         Resource storedResource = resourceEither.left().value();
 
         Map<String, Operation> interfaceOperations = InterfaceUtils
@@ -416,13 +386,13 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
 
     @Override
     public Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(String componentId,
-                                                                                                              ComponentTypeEnum componentTypeEnum, String userId, String searchText) {
+                                                      ComponentTypeEnum componentTypeEnum, String userId, String searchText) {
         return null;
     }
 
     @Override
     public Either<UiComponentDataTransfer, ResponseFormat> getUiComponentDataTransferByComponentId(String resourceId,
-                                                                                                   List<String> dataParamsToReturn) {
+                                                                    List<String> dataParamsToReturn) {
         ComponentParametersView paramsToRetuen = new ComponentParametersView(dataParamsToReturn);
         Either<Resource, StorageOperationStatus> resourceResultEither = toscaOperationFacade.getToscaElement(resourceId,
                 paramsToRetuen);