Interface operations Bug Fixes 41/59741/1
authorpriyanshu <pagarwal@amdocs.com>
Wed, 8 Aug 2018 21:27:47 +0000 (02:57 +0530)
committerpriyanshu <pagarwal@amdocs.com>
Wed, 8 Aug 2018 21:27:47 +0000 (02:57 +0530)
1. create and modify operation bug fix
2. Get and Delete negative use case handling
3. refactored code

Change-Id: I472abb7f487cb0399e63e413e616a03143a1e2ac
Issue-ID: SDC-1535
Signed-off-by: priyanshu <pagarwal@amdocs.com>
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java

index 803cdbf..2f4519b 100644 (file)
 package org.openecomp.sdc.be.components.impl;
 
 import fj.data.Either;
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.List;
+import java.util.Map;
 import java.util.Optional;
-import org.apache.commons.lang.StringUtils;
+import java.util.UUID;
 import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
 import org.openecomp.sdc.be.model.InterfaceDefinition;
 import org.openecomp.sdc.be.model.Operation;
 import org.openecomp.sdc.be.model.Resource;
@@ -37,7 +33,8 @@ import org.openecomp.sdc.be.model.User;
 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.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
 import org.openecomp.sdc.exception.ResponseFormat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -45,23 +42,22 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 @Component("interfaceOperationBusinessLogic")
-public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
+public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationBusinessLogic.class);
-    public static final String FAILED_TO_LOCK_COMPONENT_RESPONSE_IS = "Failed to lock component {}. Response is {}. ";
+    private static final String FAILED_TO_LOCK_COMPONENT_RESPONSE_IS = "Failed to lock component {}. Response is {}";
+    private static final String EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION = "Exception occurred during {}. Response is {}";
+    private static final String DELETE_INTERFACE_OPERATION = "deleteInterfaceOperation";
+    private static final String GET_INTERFACE_OPERATION = "getInterfaceOperation";
+    private static final String CREATE_INTERFACE_OPERATION = "createInterfaceOperation";
+    private static final String UPDATE_INTERFACE_OPERATION = "updateInterfaceOperation";
 
     @Autowired
     private InterfaceOperationValidation interfaceOperationValidation;
 
-    @Autowired
-    private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
-
     @Autowired
     private InterfaceOperation interfaceOperation;
 
-    @Autowired
-    private UiComponentDataConverter uiComponentDataConverter;
-
     public void setInterfaceOperation(InterfaceOperation interfaceOperation) {
         this.interfaceOperation = interfaceOperation;
     }
@@ -71,20 +67,16 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
     }
 
     public Either<Operation, ResponseFormat> deleteInterfaceOperation(String componentId, String interfaceOperationToDelete, User user, boolean lock) {
-        if (StringUtils.isEmpty(interfaceOperationToDelete)){
-            LOGGER.debug("Invalid parameter interfaceOperationToDelete was empty");
-            return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY));
-        }
-
         Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
         if (componentEither.isRight()){
             return Either.right(componentEither.right().value());
         }
         org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
-        validateUserAndRole(storedComponent, user, "deleteInterfaceOperation");
+        validateUserExists(user.getUserId(), DELETE_INTERFACE_OPERATION, true);
 
+        Either<Boolean, ResponseFormat> lockResult = null;
         if (lock) {
-            Either<Boolean, ResponseFormat> lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, "Delete interface Operation on a storedComponent");
+            lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, DELETE_INTERFACE_OPERATION);
             if (lockResult.isRight()) {
                 LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage());
                 titanDao.rollback();
@@ -94,43 +86,49 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
 
         try {
             Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
-            Either<InterfaceDefinition, ResponseFormat> sValue = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
-            if (sValue.isRight()) {
-                return Either.right(sValue.right().value());
+            Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
+            if (getInterfaceEither.isRight()) {
+                return Either.right(getInterfaceEither.right().value());
+            }
+            InterfaceDefinition interfaceDefinition = getInterfaceEither.left().value();
+
+            Either<Operation, ResponseFormat> getOperationEither = getOperationFromInterfaceDef(storedComponent, interfaceDefinition, interfaceOperationToDelete);
+            if (getOperationEither.isRight()){
+                return Either.right(getOperationEither.right().value());
             }
-            InterfaceDefinition interfaceDefinition = sValue.left().value();
 
             Either<Operation, StorageOperationStatus> deleteEither = interfaceOperation.deleteInterfaceOperation(componentId, interfaceDefinition, interfaceOperationToDelete);
             if (deleteEither.isRight()){
-                LOGGER.error("Failed to delete interface operation from storedComponent {}. Response is {}. ", storedComponent.getName(), deleteEither.right().value());
-                return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteEither.right().value(), ComponentTypeEnum.RESOURCE)));
+                LOGGER.error("Failed to delete interface operation from component {}. Response is {}", storedComponent.getName(), deleteEither.right().value());
+                return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteEither.right().value(), storedComponent.getComponentType())));
             }
+
             titanDao.commit();
             return Either.left(deleteEither.left().value());
-        } catch (Exception e){
-            LOGGER.error("Exception occurred during delete interface operation : {}", e.getMessage(), e);
+        }
+        catch (Exception e){
+            LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "delete", e);
             titanDao.rollback();
-            return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
-        } finally {
-            graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.Resource);
+            return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_DELETED));
+        }
+        finally {
+            if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+                graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
+            }
         }
     }
 
     public Either<Operation, ResponseFormat> getInterfaceOperation(String componentId, String interfaceOperationToGet, User user, boolean lock) {
-        if (StringUtils.isEmpty(interfaceOperationToGet)){
-            LOGGER.debug("Invalid parameter interfaceOperationToGet was empty");
-            return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY));
-        }
-
         Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
         if (componentEither.isRight()){
             return Either.right(componentEither.right().value());
         }
         org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
-        validateUserAndRole(storedComponent, user, "getInterfaceOperation");
+        validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true);
 
+        Either<Boolean, ResponseFormat> lockResult = null;
         if (lock) {
-            Either<Boolean, ResponseFormat> lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, "Get interface Operation on a storedComponent");
+            lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, GET_INTERFACE_OPERATION);
             if (lockResult.isRight()) {
                 LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage());
                 titanDao.rollback();
@@ -140,25 +138,29 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
 
         try {
             Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
-            Either<InterfaceDefinition, ResponseFormat> sValue = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
-            if (sValue.isRight()) {
-                return Either.right(sValue.right().value());
+            Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
+            if (getInterfaceEither.isRight()) {
+                return Either.right(getInterfaceEither.right().value());
             }
-            InterfaceDefinition interfaceDefinition = sValue.left().value();
+            InterfaceDefinition interfaceDefinition = getInterfaceEither.left().value();
 
-            Either<Operation, StorageOperationStatus> getEither = interfaceOperation.getInterfaceOperation(interfaceDefinition, interfaceOperationToGet);
-            if (getEither.isRight()){
-                LOGGER.error("Failed to get interface operation from storedComponent {}. Response is {}. ", storedComponent.getName(), getEither.right().value());
-                return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getEither.right().value(), ComponentTypeEnum.RESOURCE)));
+            Either<Operation, ResponseFormat> getOperationEither = getOperationFromInterfaceDef(storedComponent, interfaceDefinition, interfaceOperationToGet);
+            if (getOperationEither.isRight()){
+                return Either.right(getOperationEither.right().value());
             }
+
             titanDao.commit();
-            return Either.left(getEither.left().value());
-        } catch (Exception e){
-            LOGGER.error("Exception occurred during get interface operation : {}", e.getMessage(), e);
+            return Either.left(getOperationEither.left().value());
+        }
+        catch (Exception e){
+            LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "get", e);
             titanDao.rollback();
-            return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
-        } finally {
-            graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.Resource);
+            return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId));
+        }
+        finally {
+            if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+                graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
+            }
         }
     }
 
@@ -171,19 +173,19 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
             Either<InterfaceDefinition, StorageOperationStatus> interfaceCreateEither = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition);
             if (interfaceCreateEither.isRight()){
                 StorageOperationStatus sValue = interfaceCreateEither.right().value();
-                return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(sValue,
-                    ComponentTypeEnum.RESOURCE), ""));
+                LOGGER.error("Failed to get interface from component {}. Response is {}", component.getName(), sValue);
+                return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(sValue, component.getComponentType()), ""));
             }
             return Either.left(interfaceCreateEither.left().value());
         }
     }
 
     public Either<Operation, ResponseFormat> createInterfaceOperation(String componentId, Operation operation, User user, boolean lock) {
-        return createOrUpdateInterfaceOperation(componentId, operation, user, false, "createInterfaceOperation", lock);
+        return createOrUpdateInterfaceOperation(componentId, operation, user, false, CREATE_INTERFACE_OPERATION, lock);
     }
 
     public Either<Operation, ResponseFormat> updateInterfaceOperation(String componentId, Operation operation, User user, boolean lock) {
-        return createOrUpdateInterfaceOperation(componentId, operation, user, true, "updateInterfaceOperation", lock);
+        return createOrUpdateInterfaceOperation(componentId, operation, user, true, UPDATE_INTERFACE_OPERATION, lock);
     }
 
     private Either<Operation, ResponseFormat> createOrUpdateInterfaceOperation(String componentId, Operation operation, User user, boolean isUpdate, String errorContext, boolean lock) {
@@ -192,18 +194,18 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
             return Either.right(componentEither.right().value());
         }
         org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
-        validateUserAndRole(storedComponent, user, errorContext);
+        validateUserExists(user.getUserId(), errorContext, true);
 
-        InterfaceUtils.createInputOutput(operation, storedComponent.getInputs());
+        InterfaceUtils.createInputOutput(operation, storedComponent.getInputs(), storedComponent.getInputs());
         Either<Boolean, ResponseFormat> interfaceOperationValidationResponseEither = interfaceOperationValidation
-            .validateInterfaceOperations(Arrays.asList(operation), componentId, isUpdate);
+            .validateInterfaceOperations(Arrays.asList(operation), storedComponent, isUpdate);
         if(interfaceOperationValidationResponseEither.isRight()) {
             return     Either.right(interfaceOperationValidationResponseEither.right().value());
         }
 
         Either<Boolean, ResponseFormat> lockResult = null;
         if (lock) {
-            lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, "Create or Update interface Operation on Component");
+            lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, errorContext);
             if (lockResult.isRight()) {
                 LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage());
                 titanDao.rollback();
@@ -211,24 +213,32 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
             }
         }
 
-        Either<Operation, StorageOperationStatus> result;
         try {
             Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
-            Either<InterfaceDefinition, ResponseFormat> sValue = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
-            if (sValue.isRight()) {
-                return Either.right(sValue.right().value());
+            Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
+            if (getInterfaceEither.isRight()) {
+                return Either.right(getInterfaceEither.right().value());
             }
-            InterfaceDefinition interfaceDefinition = sValue.left().value();
+            InterfaceDefinition interfaceDefinition = getInterfaceEither.left().value();
 
-            if (isUpdate) {
-                result = interfaceOperation.updateInterfaceOperation(componentId, interfaceDefinition, operation);
-            } else {
+            Either<Operation, StorageOperationStatus> result;
+            if(!isUpdate){
+                initNewOperation(operation);
                 result = interfaceOperation.addInterfaceOperation(componentId, interfaceDefinition, operation);
             }
+            else {
+                Either<Operation, ResponseFormat> getOperationEither = getOperationFromInterfaceDef(storedComponent, interfaceDefinition, operation.getUniqueId());
+                if (getOperationEither.isRight()){
+                    return Either.right(getOperationEither.right().value());
+                }
+                operation.setImplementation(getOperationEither.left().value().getImplementation());
+                result = interfaceOperation.updateInterfaceOperation(componentId, interfaceDefinition, operation);
+            }
+
             if (result.isRight()) {
                 titanDao.rollback();
-                LOGGER.debug("Failed to add/update interface operation on component {}. Response is {}. ", storedComponent.getName(), result.right().value());
-                return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value(), ComponentTypeEnum.RESOURCE)));
+                LOGGER.debug("Failed to addOrUpdate interface operation on component {}. Response is {}", storedComponent.getName(), result.right().value());
+                return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value(), storedComponent.getComponentType())));
             }
 
             titanDao.commit();
@@ -236,64 +246,45 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
         }
         catch (Exception e) {
             titanDao.rollback();
-            LOGGER.error("Exception occurred during add or update interface operation property values:{}", e.getMessage(), e);
+            LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "addOrUpdate", e);
             return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
         }
         finally {
             if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
-                graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.Resource);
+                graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
             }
         }
     }
 
-    private void validateUserAndRole(org.openecomp.sdc.be.model.Component component, User user, String errorContext) {
-        user = validateUser(user, errorContext, component, null, false);
-        validateUserRole(user, component, new ArrayList<>(), null, null);
-    }
-
     private Either<org.openecomp.sdc.be.model.Component, ResponseFormat> getComponentDetails(String componentId){
         Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentStorageOperationStatusEither = toscaOperationFacade.getToscaElement(componentId);
         if (componentStorageOperationStatusEither.isRight()) {
             StorageOperationStatus errorStatus = componentStorageOperationStatusEither.right().value();
-            LOGGER.error("Failed to fetch component information by component id {}, error {}", componentId, errorStatus);
+            LOGGER.error("Failed to fetch component information by component id {}, Response is {}", componentId, errorStatus);
             return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus)));
         }
         return Either.left(componentStorageOperationStatusEither.left().value());
     }
 
-    @Override
-    public Either<UiComponentDataTransfer, ResponseFormat> getUiComponentDataTransferByComponentId(String componentId, List<String> dataParamsToReturn) {
-        ComponentParametersView paramsToRetuen = new ComponentParametersView(dataParamsToReturn);
-        Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentResultEither = toscaOperationFacade.getToscaElement(componentId, paramsToRetuen);
-
-        if (componentResultEither.isRight()) {
-            if (componentResultEither.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
-                LOGGER.error("Failed to found component with id {} ", componentId);
-                Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, componentId));
-            }
-            LOGGER.error("failed to get component by id {} with filters {}", componentId, dataParamsToReturn);
-            return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(componentResultEither.right().value()), ""));
+    private Either<Operation, ResponseFormat> getOperationFromInterfaceDef(
+        org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDefinition, String operationToFetch) {
+        Optional<Map.Entry<String, Operation>> operationMap = interfaceDefinition.getOperationsMap().entrySet().stream()
+            .filter(entry -> entry.getValue().getUniqueId().equals(operationToFetch)).findAny();
+        if (!operationMap.isPresent()) {
+            LOGGER.error("Failed to get interface operation from component {}. Response is {}", component.getUniqueId(), ActionStatus.INTERFACE_OPERATION_NOT_FOUND);
+            return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, component.getUniqueId()));
         }
-
-        org.openecomp.sdc.be.model.Component component = componentResultEither.left().value();
-        UiComponentDataTransfer dataTransfer = uiComponentDataConverter.getUiDataTransferFromResourceByParams((Resource)component, dataParamsToReturn);
-        return Either.left(dataTransfer);
+        return Either.left(operationMap.get().getValue());
     }
 
-    @Override
-    public Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(
-        String componentId, String userId) {
-        return null;
+    private void initNewOperation(Operation operation){
+        ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+        String artifactUUID = UUID.randomUUID().toString();
+        artifactDefinition.setArtifactUUID(artifactUUID);
+        artifactDefinition.setUniqueId(artifactUUID);
+        artifactDefinition.setArtifactType(ArtifactTypeEnum.PLAN.getType());
+        artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.LIFE_CYCLE);
+        operation.setUniqueId(UUID.randomUUID().toString());
+        operation.setImplementation(artifactDefinition);
     }
-
-    @Override
-    public Either<List<String>, ResponseFormat> deleteMarkedComponents() {
-        return deleteMarkedComponents(ComponentTypeEnum.RESOURCE);
-    }
-
-    @Override
-    public ComponentInstanceBusinessLogic getComponentInstanceBL() {
-        return componentInstanceBusinessLogic;
-    }
-
 }
index 9225f36..affafae 100644 (file)
 package org.openecomp.sdc.be.components.validation;
 
 import fj.data.Either;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.common.Strings;
 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.model.ComponentParametersView;
 import org.openecomp.sdc.be.model.InterfaceDefinition;
 import org.openecomp.sdc.be.model.Operation;
 import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
 import org.openecomp.sdc.exception.ResponseFormat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.*;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
 @Component("interfaceOperationValidation")
 public class InterfaceOperationValidation {
 
-    @Autowired
-    private ToscaOperationFacade toscaOperationFacade;
     private static final String TYPE_VALIDATION_REGEX = "^[a-zA-Z]{1,200}$";
     private static final int DESCRIPTION_MAX_LENGTH = 200;
 
     private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationValidation.class);
 
     public Either<Boolean, ResponseFormat> validateInterfaceOperations(
-            Collection<Operation> interfaceOperations,
-            String resourceId, boolean isUpdate) {
+        Collection<Operation> interfaceOperations, org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
 
         for(Operation interfaceOperation : interfaceOperations) {
             Either<Boolean, ResponseFormat> interfaceOperationValidatorResponse = validateInterfaceOperation(
-                    interfaceOperation, resourceId, isUpdate);
+                interfaceOperation, component, isUpdate);
             if (interfaceOperationValidatorResponse.isRight()) {
                 return interfaceOperationValidatorResponse;
             }
@@ -64,29 +62,29 @@ public class InterfaceOperationValidation {
     }
 
     private Either<Boolean, ResponseFormat> validateInterfaceOperation(Operation interfaceOperation,
-                                                                       String resourceId, boolean isUpdate) {
+        org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
         ResponseFormatManager responseFormatManager = getResponseFormatManager();
 
         Either<Boolean, ResponseFormat> interfaceOperationTypeResponse = isInterfaceOperationTypeValid(interfaceOperation,
-                responseFormatManager, resourceId, isUpdate);
+            responseFormatManager, component, isUpdate);
         if (interfaceOperationTypeResponse.isRight()) {
             return Either.right(interfaceOperationTypeResponse.right().value());
         }
 
         Either<Boolean, ResponseFormat> descriptionResponseEither = isValidDescription(responseFormatManager,
-                interfaceOperation.getDescription());
+            interfaceOperation.getDescription());
         if (descriptionResponseEither.isRight()) {
             return Either.right(descriptionResponseEither.right().value());
         }
 
         Either<Boolean, ResponseFormat> inputParametersResponse = validateInputParameters(interfaceOperation,
-                responseFormatManager);
+            responseFormatManager);
         if(inputParametersResponse.isRight()) {
             return Either.right(inputParametersResponse.right().value());
         }
 
         Either<Boolean, ResponseFormat> outputParametersResponse = validateOutputParameters(interfaceOperation,
-                responseFormatManager);
+            responseFormatManager);
         if(outputParametersResponse.isRight()) {
             return Either.right(outputParametersResponse.right().value());
         }
@@ -95,64 +93,64 @@ public class InterfaceOperationValidation {
     }
 
     private Either<Boolean, ResponseFormat> isInterfaceOperationTypeValid(Operation interfaceOperation,
-                                                                          ResponseFormatManager responseFormatManager,
-                                                                          String resourceId, boolean isUpdate) {
+        ResponseFormatManager responseFormatManager,
+        org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
 
-        Either<Boolean, ResponseFormat> operationTypeEmptyEither = isOperationTypeEmpty(responseFormatManager,
-                interfaceOperation.getName());  // treating name as type for now
+        Either<Boolean, ResponseFormat> operationTypeEmptyEither =
+            isOperationTypeEmpty(responseFormatManager, interfaceOperation.getName());
         if (operationTypeEmptyEither.isRight()) {
             return Either.right(operationTypeEmptyEither.right().value());
         }
 
         Either<Boolean, ResponseFormat> operationTypeRegexValidationResponse =
-                isOperationTypeRegexValid(responseFormatManager, interfaceOperation.getName());
+            isOperationTypeRegexValid(responseFormatManager, interfaceOperation.getName());
         if (operationTypeRegexValidationResponse.isRight()) {
             return Either.right(operationTypeRegexValidationResponse.right().value());
         }
 
         Either<Boolean, ResponseFormat> operationTypeUniqueResponse = validateOperationTypeUnique(interfaceOperation,
-                resourceId, isUpdate, responseFormatManager );
+            component, isUpdate, responseFormatManager );
         if(operationTypeUniqueResponse.isRight()) {
             return Either.right(operationTypeUniqueResponse.right().value());
         }
         if (!operationTypeUniqueResponse.left().value()) {
             LOGGER.error("Interface Operation type  {} already in use ", interfaceOperation.getName());
             ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
-                    .INTERFACE_OPERATION_TYPE_ALREADY_IN_USE, interfaceOperation.getName());
+                .INTERFACE_OPERATION_TYPE_ALREADY_IN_USE, interfaceOperation.getName());
             return Either.right(errorResponse);
         }
         return Either.left(Boolean.TRUE);
     }
 
     private Either<Boolean, ResponseFormat> isOperationTypeRegexValid(ResponseFormatManager responseFormatManager,
-                                                                      String operationType) {
+        String operationType) {
         if (!isValidOperationType(operationType)) {
             LOGGER.error("Interface Operation type {} is invalid, Operation type should not contain" +
-                    "Special character, space, numbers and  should not be greater than 200 characters", operationType);
+                "Special character, space, numbers and  should not be greater than 200 characters", operationType);
             ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
-                    .INTERFACE_OPERATION_TYPE_INVALID, operationType);
+                .INTERFACE_OPERATION_TYPE_INVALID, operationType);
             return Either.right(errorResponse);
         }
         return Either.left(Boolean.TRUE);
     }
 
     private Either<Boolean, ResponseFormat> isOperationTypeEmpty(ResponseFormatManager responseFormatManager,
-                                                                 String operationType) {
+        String operationType) {
         if (StringUtils.isEmpty(operationType)) {
             LOGGER.error("Interface Operation type is mandatory");
             ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
-                    .INTERFACE_OPERATION_TYPE_MANDATORY);
+                .INTERFACE_OPERATION_TYPE_MANDATORY);
             return Either.right(errorResponse);
         }
         return Either.left(Boolean.TRUE);
     }
 
     private Either<Boolean, ResponseFormat> isValidDescription(ResponseFormatManager responseFormatManager,
-                                                               String description) {
+        String description) {
         if (!Strings.isNullOrEmpty(description) && description.length() > DESCRIPTION_MAX_LENGTH) {
             LOGGER.error("Interface Operation description {} is invalid, maximum 200 characters allowed", description);
             ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
-                    .INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH);
+                .INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH);
             return Either.right(errorResponse);
         }
         return Either.left(Boolean.TRUE);
@@ -163,63 +161,57 @@ public class InterfaceOperationValidation {
     }
 
     private Either<Boolean, ResponseFormat> validateOperationTypeUnique(
-            Operation interfaceOperation,
-            String resourceId,
-            boolean isUpdate,
-            ResponseFormatManager responseFormatManager) {
+        Operation interfaceOperation,
+        org.openecomp.sdc.be.model.Component component,
+        boolean isUpdate,
+        ResponseFormatManager responseFormatManager) {
         boolean isOperationTypeUnique = false;
-        ComponentParametersView filter = new ComponentParametersView(true);
-        filter.setIgnoreInterfaces(false);
-        Either<Resource, StorageOperationStatus> interfaceOperationOrigin = toscaOperationFacade
-                .getToscaElement(resourceId, filter);
-        if (interfaceOperationOrigin.isRight()){
-            LOGGER.error("Failed to fetch interface operation information by resource id {} ", resourceId);
-            return Either.right(responseFormatManager.getResponseFormat(ActionStatus.GENERAL_ERROR));
-        }
 
-        Collection<InterfaceDefinition> interfaceDefinitions = interfaceOperationOrigin.left().value()
-                .getInterfaces().values();
-        if(CollectionUtils.isEmpty(interfaceDefinitions)){
+        Map<String, InterfaceDefinition> interfaceDefinitionMap = ((Resource)component).getInterfaces();
+        if(interfaceDefinitionMap.isEmpty()){
             isOperationTypeUnique = true;
             return Either.left(isOperationTypeUnique);
         }
-        Collection<Operation> allOperations = interfaceDefinitions.stream()
-                .filter(a -> MapUtils.isNotEmpty(a.getOperationsMap()))
-                .map(a -> a.getOperationsMap().values()).flatMap(Collection::stream)
-                .collect(Collectors.toList());
+
+        Collection<Operation> allOperations = interfaceDefinitionMap.values().stream()
+            .filter(a -> MapUtils.isNotEmpty(a.getOperationsMap()))
+            .map(a -> a.getOperationsMap().values()).flatMap(Collection::stream)
+            .collect(Collectors.toList());
         if(CollectionUtils.isEmpty(allOperations)){
             isOperationTypeUnique = true;
             return Either.left(isOperationTypeUnique);
         }
 
         Map<String, String> operationTypes = new HashMap<>();
-        allOperations.forEach(operationType -> operationTypes.put(operationType.getUniqueId(),
-                operationType.getName()) );
+        allOperations.forEach(operationType -> operationTypes.put(operationType.getUniqueId(), operationType.getName()));
 
-        if (isUpdate){
-            isOperationTypeUnique = validateOperationTypeUniqueForUpdate(interfaceOperation, operationTypes);
-        }
-        else
         if (!operationTypes.values().contains(interfaceOperation.getName())){
             isOperationTypeUnique = true;
         }
+        if (!isOperationTypeUnique && isUpdate){
+            Optional<String> id = operationTypes.entrySet().stream().filter(entry -> Objects.equals(entry.getValue(), interfaceOperation.getName()))
+                .map(Map.Entry::getKey).findAny();
+            if(id.isPresent() && id.get().equalsIgnoreCase(interfaceOperation.getUniqueId())){
+                isOperationTypeUnique = true;
+            }
+        }
+
         return Either.left(isOperationTypeUnique);
     }
     private Either<Boolean, ResponseFormat> validateInputParameters(Operation interfaceOperation,
-                                                                    ResponseFormatManager responseFormatManager) {
+        ResponseFormatManager responseFormatManager) {
         if (isInputParameterNameEmpty(interfaceOperation)) {
-            LOGGER.error("Interface operation input  parameter name can't be empty");
-            ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
-                    .INTERFACE_OPERATION_INPUT_NAME_MANDATORY);
+            LOGGER.error("Interface operation input parameter name can't be empty");
+            ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_INPUT_NAME_MANDATORY);
             return Either.right(inputResponse);
         }
 
         Either<Boolean, Set<String>> validateInputParametersUniqueResponse = isInputParametersUnique(interfaceOperation);
         if(validateInputParametersUniqueResponse.isRight()) {
-            LOGGER.error("Interface operation input  parameter names {} already in use",
-                    validateInputParametersUniqueResponse.right().value().toString());
+            LOGGER.error("Interface operation input parameter names {} already in use",
+                validateInputParametersUniqueResponse.right().value());
             ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
-                    .INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE, validateInputParametersUniqueResponse.right().value().toString());
+                .INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE, validateInputParametersUniqueResponse.right().value().toString());
             return Either.right(inputResponse);
         }
         return Either.left(Boolean.TRUE);
@@ -227,20 +219,19 @@ public class InterfaceOperationValidation {
 
 
     private Either<Boolean, ResponseFormat> validateOutputParameters(Operation interfaceOperation,
-                                                                    ResponseFormatManager responseFormatManager) {
+        ResponseFormatManager responseFormatManager) {
         if (isOutputParameterNameEmpty(interfaceOperation)) {
-            LOGGER.error("Interface operation output  parameter name can't be empty");
-            ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
-                    .INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY);
+            LOGGER.error("Interface operation output parameter name can't be empty");
+            ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY);
             return Either.right(inputResponse);
         }
 
         Either<Boolean, Set<String>> validateOutputParametersUniqueResponse = isOutputParametersUnique(interfaceOperation);
         if(validateOutputParametersUniqueResponse.isRight()) {
-            LOGGER.error("Interface operation output  parameter names {} already in use",
-                    validateOutputParametersUniqueResponse.right().value().toString());
+            LOGGER.error("Interface operation output parameter names {} already in use",
+                validateOutputParametersUniqueResponse.right().value());
             ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
-                    .INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE, validateOutputParametersUniqueResponse.right().value().toString());
+                .INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE, validateOutputParametersUniqueResponse.right().value().toString());
             return Either.right(inputResponse);
         }
         return Either.left(Boolean.TRUE);
@@ -251,11 +242,11 @@ public class InterfaceOperationValidation {
         Set<String> inputParamNamesSet = new HashSet<>();
         Set<String> duplicateParamNamesToReturn = new HashSet<>();
         operationDataDefinition.getInputs().getListToscaDataDefinition()
-                .forEach(inputParam -> {
-                    if(!inputParamNamesSet.add(inputParam.getName().trim())) {
-                        duplicateParamNamesToReturn.add(inputParam.getName().trim());
-                    }
-                });
+            .forEach(inputParam -> {
+                if(!inputParamNamesSet.add(inputParam.getName().trim())) {
+                    duplicateParamNamesToReturn.add(inputParam.getName().trim());
+                }
+            });
         if(!duplicateParamNamesToReturn.isEmpty()) {
             return Either.right(duplicateParamNamesToReturn);
         }
@@ -266,11 +257,11 @@ public class InterfaceOperationValidation {
         Set<String> outputParamNamesSet = new HashSet<>();
         Set<String> duplicateParamNamesToReturn = new HashSet<>();
         operationDataDefinition.getOutputs().getListToscaDataDefinition()
-                .forEach(outputParam -> {
-                    if(!outputParamNamesSet.add(outputParam.getName().trim())) {
-                        duplicateParamNamesToReturn.add(outputParam.getName().trim());
-                    }
-                });
+            .forEach(outputParam -> {
+                if(!outputParamNamesSet.add(outputParam.getName().trim())) {
+                    duplicateParamNamesToReturn.add(outputParam.getName().trim());
+                }
+            });
         if(!duplicateParamNamesToReturn.isEmpty()) {
             return Either.right(duplicateParamNamesToReturn);
         }
@@ -279,26 +270,19 @@ public class InterfaceOperationValidation {
 
     private Boolean isInputParameterNameEmpty(Operation operationDataDefinition) {
         return operationDataDefinition.getInputs().getListToscaDataDefinition().stream()
-                .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
+            .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
     }
     private Boolean isOutputParameterNameEmpty(Operation operationDataDefinition) {
         return operationDataDefinition.getInputs().getListToscaDataDefinition().stream()
-                .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
+            .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
     }
 
-    private boolean validateOperationTypeUniqueForUpdate(Operation interfaceOperation,
-                                                         Map<String, String> operationTypes) {
+    private boolean validateOperationTypeUniqueForUpdate(Operation interfaceOperation, Map<String, String> operationTypes) {
         boolean isOperationTypeUnique = false;
-        for(Map.Entry<String, String> entry : operationTypes.entrySet()){
-            if (entry.getKey().equals(interfaceOperation.getUniqueId()) && entry.getValue().
-                    equals(interfaceOperation.getName())) {
-                isOperationTypeUnique = true;
-            }
-
-            if(entry.getKey().equals(interfaceOperation.getUniqueId()) && !operationTypes.values()
-                    .contains(interfaceOperation.getName())){
-                isOperationTypeUnique = true;
-            }
+        Optional<String> id = operationTypes.entrySet().stream().filter(entry -> Objects.equals(entry.getValue(), interfaceOperation.getName()))
+            .map(Map.Entry::getKey).findAny();
+        if(id.isPresent() && id.get().equalsIgnoreCase(interfaceOperation.getUniqueId())){
+            isOperationTypeUnique = true;
         }
         return isOperationTypeUnique;
     }
index 4d84e2c..3e43dd7 100644 (file)
@@ -139,17 +139,14 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
     modifier.setUserId(userId);
     log.debug("Start get request of {} with modifier id {}", url, userId);
 
-    Response response;
-
     try {
       String resourceIdLower = resourceId.toLowerCase();
       InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
 
       Either<Operation, ResponseFormat> actionResponse = businessLogic.getInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true);
       if (actionResponse.isRight()) {
-        log.debug("failed to get interface operation");
-        response = buildErrorResponse(actionResponse.right().value());
-        return response;
+        log.error("failed to get interface operation");
+        return buildErrorResponse(actionResponse.right().value());
       }
 
       InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value());
@@ -158,7 +155,7 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
     }
     catch (Exception e) {
       BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource interface operations");
-      log.debug("get resource interface operations failed with exception", e);
+      log.error("get resource interface operations failed with exception", e);
       return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
     }
   }
@@ -173,17 +170,14 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
     modifier.setUserId(userId);
     log.debug("Start delete request of {} with modifier id {}", url, userId);
 
-    Response response;
-
     try {
       String resourceIdLower = resourceId.toLowerCase();
       InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
 
       Either<Operation, ResponseFormat> actionResponse = businessLogic.deleteInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true);
       if (actionResponse.isRight()) {
-        log.debug("failed to delete interface operation");
-        response = buildErrorResponse(actionResponse.right().value());
-        return response;
+        log.error("failed to delete interface operation");
+        return buildErrorResponse(actionResponse.right().value());
       }
 
       InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value());
@@ -192,9 +186,8 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
     }
     catch (Exception e) {
       BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Interface Operation");
-      log.debug("Delete interface operation with an error", e);
-      response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-      return response;
+      log.error("Delete interface operation with an error", e);
+      return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
     }
   }
 
@@ -206,7 +199,6 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
     modifier.setUserId(userId);
     log.debug("Start create or update request of {} with modifier id {}", url, userId);
 
-    Response response;
     try {
       String resourceIdLower = resourceId.toLowerCase();
       InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
@@ -220,9 +212,8 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
       }
 
       if (actionResponse.isRight()) {
-        log.debug("failed to update or create interface operation");
-        response = buildErrorResponse(actionResponse.right().value());
-        return response;
+        log.error("failed to update or create interface operation");
+        return buildErrorResponse(actionResponse.right().value());
       }
 
       InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value());
@@ -231,9 +222,8 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
     }
     catch (Exception e) {
       BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Interface Operation Creation or update");
-      log.debug("create or update interface Operation with an error", e);
-      response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-      return response;
+      log.error("create or update interface Operation with an error", e);
+      return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
     }
   }
 
index b9e0b59..eb17d56 100644 (file)
 
 package org.openecomp.sdc.be.components.impl;
 
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyCollection;
+import static org.mockito.ArgumentMatchers.anyObject;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
 import fj.data.Either;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.servlet.ServletContext;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -25,7 +40,6 @@ import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.openecomp.sdc.ElementOperationMock;
 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
-import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
 import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
 import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
 import org.openecomp.sdc.be.components.validation.UserValidations;
@@ -40,10 +54,19 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
 import org.openecomp.sdc.be.impl.ComponentsUtils;
 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
-import org.openecomp.sdc.be.model.jsontitan.operations.*;
-import org.openecomp.sdc.be.model.jsontitan.utils.InterfaceUtils;
+import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
 import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -55,16 +78,9 @@ import org.openecomp.sdc.common.api.Constants;
 import org.openecomp.sdc.common.impl.ExternalConfiguration;
 import org.openecomp.sdc.common.impl.FSConfigurationSource;
 import org.openecomp.sdc.exception.ResponseFormat;
+import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
 import org.springframework.web.context.WebApplicationContext;
 
-import javax.servlet.ServletContext;
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.when;
-
 public class InterfaceOperationBusinessLogicTest {
 
     public static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
@@ -166,12 +182,11 @@ public class InterfaceOperationBusinessLogicTest {
         when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
 
         //InterfaceOperation
-        when(operationValidator.validateInterfaceOperations(anyCollection(), anyString(), anyBoolean())).thenReturn(Either.left(true));
+        when(operationValidator.validateInterfaceOperations(anyCollection(), anyObject(), anyBoolean())).thenReturn(Either.left(true));
         when(interfaceOperation.addInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
         when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
         when(interfaceOperation.addInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME)));
         when(interfaceOperation.updateInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME)));
-        when(interfaceOperation.getInterfaceOperation(anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME)));
         when(interfaceOperation.deleteInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME)));
         when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME)));
         when(interfaceOperation.updateInterface(any(),any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
@@ -185,7 +200,6 @@ public class InterfaceOperationBusinessLogicTest {
         bl.setComponentsUtils(componentsUtils);
         bl.setGraphLockOperation(graphLockOperation);
         bl.setTitanGenericDao(mockTitanDao);
-        bl.setGenericTypeBusinessLogic(genericTypeBusinessLogic);
         toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
         toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
         bl.setToscaOperationFacade(toscaOperationFacade);
index 3d3447d..d41294b 100644 (file)
 
 package org.openecomp.sdc.be.components.validation;
 
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
 import com.google.common.collect.Sets;
 import fj.data.Either;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
-import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
-import org.openecomp.sdc.be.model.*;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.Resource;
 import org.openecomp.sdc.exception.ResponseFormat;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
+import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
 
 public class InterfaceOperationValidationTest {
 
-    private Resource  resource = (Resource) getToscaFullElement().left().value();
-
-    ResponseFormatManager mock;
-    @Mock
-    ToscaOperationFacade toscaOperationFacade;
+    private Resource resource = setUpResourceMock();
+    ResponseFormatManager responseFormatManagerMock;
 
-    @InjectMocks
     InterfaceOperationValidationUtilTest interfaceOperationValidationUtilTest = new InterfaceOperationValidationUtilTest();
-    private static final String RESOURCE_ID = "resource1";
     ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
     ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>();
+
     @Before
     public void init() {
         MockitoAnnotations.initMocks(this);
-        mock = Mockito.mock(ResponseFormatManager.class);
-        when(toscaOperationFacade.getToscaElement(any(), any(ComponentParametersView.class))).thenReturn(Either.left(resource));
-        when(mock.getResponseFormat(any())).thenReturn(new ResponseFormat());
-        when(mock.getResponseFormat(any(), any())).thenReturn(new ResponseFormat());
-        when(mock.getResponseFormat(any(), any(), any())).thenReturn(new ResponseFormat());
+        responseFormatManagerMock = Mockito.mock(ResponseFormatManager.class);
+        when(responseFormatManagerMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
+        when(responseFormatManagerMock.getResponseFormat(any(), any())).thenReturn(new ResponseFormat());
+        when(responseFormatManagerMock.getResponseFormat(any(), any(), any())).thenReturn(new ResponseFormat());
     }
 
-
     @Test
     public void testValidInterfaceOperation() {
         operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
@@ -75,7 +67,7 @@ public class InterfaceOperationValidationTest {
                 "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
                         operationOutputDefinitionList,"upgrade");
         Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
-                .validateInterfaceOperations(operations, RESOURCE_ID, false);
+                .validateInterfaceOperations(operations, resource, false);
         Assert.assertTrue(booleanResponseFormatEither.isLeft());
     }
 
@@ -89,7 +81,7 @@ public class InterfaceOperationValidationTest {
                         "with web, data access (relational and NoSQL datastores), cloud, or messaging support",
                 new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update");
         Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
-                .validateInterfaceOperations(operations, RESOURCE_ID, false);
+                .validateInterfaceOperations(operations, resource, false);
         Assert.assertTrue(booleanResponseFormatEither.isRight());
     }
 
@@ -103,7 +95,7 @@ public class InterfaceOperationValidationTest {
                 "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
                 operationOutputDefinitionList, "");
         Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
-                .validateInterfaceOperations(operations, RESOURCE_ID, false);
+                .validateInterfaceOperations(operations, resource, false);
         Assert.assertTrue(booleanResponseFormatEither.isRight());
     }
 
@@ -115,7 +107,7 @@ public class InterfaceOperationValidationTest {
                 "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
                 operationOutputDefinitionList,"input2");
         Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
-                .validateInterfaceOperations(operations, RESOURCE_ID, false);
+                .validateInterfaceOperations(operations, resource, false);
         Assert.assertTrue(booleanResponseFormatEither.isRight());
     }
 
@@ -127,7 +119,7 @@ public class InterfaceOperationValidationTest {
                 "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
                 operationOutputDefinitionList,"CREATE");
         Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
-                .validateInterfaceOperations(operations, RESOURCE_ID, false);
+                .validateInterfaceOperations(operations, resource, false);
         Assert.assertTrue(booleanResponseFormatEither.isRight());
     }
 
@@ -142,7 +134,7 @@ public class InterfaceOperationValidationTest {
                         "productive with the certain technology stack from the beginning. You can create a skeleton project" +
                         "with web, data access (relational and NoSQL datastores), cloud, or messaging support");
         Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
-                .validateInterfaceOperations(operations, RESOURCE_ID, false);
+                .validateInterfaceOperations(operations, resource, false);
         Assert.assertTrue(booleanResponseFormatEither.isRight());
     }
 
@@ -159,7 +151,7 @@ public class InterfaceOperationValidationTest {
                 operationOutputDefinitionList,"create");
 
         Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
-                .validateInterfaceOperations(operations, RESOURCE_ID, false);
+                .validateInterfaceOperations(operations, resource, false);
         Assert.assertTrue(booleanResponseFormatEither.isRight());
     }
 
@@ -174,7 +166,7 @@ public class InterfaceOperationValidationTest {
 
 
         Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
-                .validateInterfaceOperations(operations, RESOURCE_ID, false);
+                .validateInterfaceOperations(operations, resource, false);
         Assert.assertTrue(booleanResponseFormatEither.isLeft());
     }
 
@@ -189,7 +181,7 @@ public class InterfaceOperationValidationTest {
 
 
         Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
-                .validateInterfaceOperations(operations, RESOURCE_ID, false);
+                .validateInterfaceOperations(operations, resource, false);
         Assert.assertTrue(booleanResponseFormatEither.isRight());
     }
 
@@ -199,15 +191,9 @@ public class InterfaceOperationValidationTest {
         return Sets.newHashSet(InterfaceOperationTestUtils.createInterfaceOperation(uniqueID, description, artifactDefinition, inputs, outputs, name));
     }
 
-    private  <T extends Component> Either<T, StorageOperationStatus> getToscaFullElement() {
-
-        return Either.left((T) setUpResourceMock());
-    }
-
     private Resource setUpResourceMock(){
         Resource resource = new Resource();
         resource.setInterfaces(createMockInterfaceDefinition());
-
         return  resource;
     }
 
@@ -223,7 +209,7 @@ public class InterfaceOperationValidationTest {
     private class InterfaceOperationValidationUtilTest extends InterfaceOperationValidation {
 
         protected ResponseFormatManager getResponseFormatManager() {
-            return mock;
+            return responseFormatManagerMock;
         }
     }
 }
index 3b1b6e5..18bd13d 100644 (file)
@@ -30,7 +30,6 @@ import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
 import org.openecomp.sdc.be.model.ArtifactDefinition;
@@ -38,16 +37,11 @@ import org.openecomp.sdc.be.model.InterfaceDefinition;
 import org.openecomp.sdc.be.model.Operation;
 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
-import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
-import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-import org.openecomp.sdc.common.log.wrappers.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 
 @org.springframework.stereotype.Component("interfaces-operation")
 public class InterfaceOperation extends BaseOperation {
 
-  private static final Logger logger = Logger.getLogger(InterfaceOperation.class.getName());
-
   @Autowired
   private ArtifactCassandraDao artifactCassandraDao;
 
@@ -70,7 +64,6 @@ public class InterfaceOperation extends BaseOperation {
     getToscaElementRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
     if (getToscaElementRes.isRight()) {
       TitanOperationStatus status = getToscaElementRes.right().value();
-      logger.debug("Failed to get tosca element {} while adding or updating interface. Status is {}. ", componentId, status);
       statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
       return Either.right(statusRes);
     }
@@ -80,7 +73,6 @@ public class InterfaceOperation extends BaseOperation {
     }
     statusRes = performUpdateToscaAction(isUpdateAction, componentVertex, Arrays.asList(interfaceDefinition), EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE);
     if (!statusRes.equals(StorageOperationStatus.OK)) {
-      logger.debug("Failed to add or update interface of component {}. status is {}", componentId, statusRes);
       return Either.right(statusRes);
     }
     return Either.left(interfaceDefinition);
@@ -103,7 +95,6 @@ public class InterfaceOperation extends BaseOperation {
     getToscaElementRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
     if (getToscaElementRes.isRight()) {
       TitanOperationStatus status = getToscaElementRes.right().value();
-      logger.debug("Failed to get tosca element {} while adding or updating operation. Status is {}. ", componentId, status);
       statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
       return Either.right(statusRes);
     }
@@ -111,27 +102,20 @@ public class InterfaceOperation extends BaseOperation {
     getToscaElementInt = titanDao.getChildVertex(componentVertex, EdgeLabelEnum.INTERFACE, JsonParseFlagEnum.NoParse);
     if (getToscaElementInt.isRight()) {
       TitanOperationStatus status = getToscaElementInt.right().value();
-      logger.debug("Failed to get tosca element {} while adding or updating operation. Status is {}. ", interfaceDef.getUniqueId(), status);
       statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
       return Either.right(statusRes);
     }
     GraphVertex interfaceVertex = getToscaElementInt.left().value();
-    if (!isUpdateAction)
-      initNewOperation(operation);
-    else
-      operation.setImplementation(getArtifactImplFromOperation(operation, interfaceDef));
 
     statusRes = performUpdateToscaAction(isUpdateAction, interfaceVertex, Arrays.asList(operation),
         EdgeLabelEnum.INTERFACE_OPERATION, VertexTypeEnum.INTERFACE_OPERATION);
     if (!statusRes.equals(StorageOperationStatus.OK)) {
-      logger.debug("Failed to add or update operation of interface {}. status is {}", interfaceDef.getUniqueId(), statusRes);
       return Either.right(statusRes);
     }
 
     getUpdatedInterfaceDef(interfaceDef, operation, operation.getUniqueId());
     Either<InterfaceDefinition, StorageOperationStatus> intUpdateStatus = updateInterface(componentId, interfaceDef);
     if (intUpdateStatus.isRight() && !intUpdateStatus.right().value().equals(StorageOperationStatus.OK)) {
-      logger.debug("Failed to update interface details on component {}. status is {}", componentId, statusRes);
       return Either.right(statusRes);
     }
 
@@ -163,7 +147,6 @@ public class InterfaceOperation extends BaseOperation {
       String artifactUUID = implementationArtifact.getArtifactUUID();
       CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUUID);
       if (cassandraStatus != CassandraOperationStatus.OK) {
-        logger.debug("Failed to delete the artifact {} from the database. ", artifactUUID);
         return Either.right(DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraStatus));
       }
 
@@ -181,6 +164,10 @@ public class InterfaceOperation extends BaseOperation {
 
       getUpdatedInterfaceDef(interfaceDef, null, operationToDelete);
       if (interfaceDef.getOperations().isEmpty()) {
+        status = deleteToscaDataElements(getComponentVertex.left().value(), EdgeLabelEnum.INTERFACE, Arrays.asList(interfaceDef.getUniqueId()));
+        if (status != StorageOperationStatus.OK) {
+          return Either.right(status);
+        }
         status = removeToscaDataVertex(getComponentVertex.left().value(), EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE);
         if (status != StorageOperationStatus.OK) {
           return Either.right(status);
@@ -196,17 +183,6 @@ public class InterfaceOperation extends BaseOperation {
     return Either.left(operation);
   }
 
-  public Either<Operation, StorageOperationStatus> getInterfaceOperation(InterfaceDefinition interfaceDef, String operationToGet) {
-    Operation operation = new Operation();
-    Optional<Entry<String, Operation>> operationToFetch = interfaceDef.getOperationsMap().entrySet().stream()
-        .filter(entry -> entry.getValue().getUniqueId().equals(operationToGet)).findAny();
-    if (operationToFetch.isPresent()){
-      Map.Entry<String, Operation> stringOperationEntry = operationToFetch.get();
-      operation = stringOperationEntry.getValue();
-    }
-    return Either.left(operation);
-  }
-
   private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, GraphVertex graphVertex,
       List<ToscaDataDefinition> toscaDataList, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel) {
     if (isUpdate) {
@@ -216,29 +192,9 @@ public class InterfaceOperation extends BaseOperation {
     }
   }
 
-  private ArtifactDefinition createNewArtifactDefForOperation(){
-    ArtifactDefinition artifactDefinition = new ArtifactDefinition();
-    String artifactUUID = UUID.randomUUID().toString();
-    artifactDefinition.setArtifactUUID(artifactUUID);
-    artifactDefinition.setUniqueId(artifactUUID);
-    artifactDefinition.setArtifactType(ArtifactTypeEnum.PLAN.getType());
-    artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.LIFE_CYCLE);
-    return artifactDefinition;
-  }
-
-  private ArtifactDataDefinition getArtifactImplFromOperation(Operation operation, InterfaceDefinition interfaceDef){
-    Either<Operation, StorageOperationStatus> operationData = getInterfaceOperation(interfaceDef, operation.getUniqueId());
-    return operationData.isLeft()? operationData.left().value().getImplementation() : createNewArtifactDefForOperation();
-  }
-
-  private void initNewOperation(Operation operation){
-    operation.setUniqueId(UUID.randomUUID().toString());
-    operation.setImplementation(createNewArtifactDefForOperation());
-  }
-
   private InterfaceDefinition getUpdatedInterfaceDef(InterfaceDefinition interfaceDef, Operation operation, String operationId){
     Map<String, Operation> operationMap = interfaceDef.getOperationsMap();
-    if(operation != null && !operation.isEmpty()){
+    if(operation != null){
       operationMap.put(operationId, operation);
       interfaceDef.setOperationsMap(operationMap);
     }
index 249de97..5fa64d6 100644 (file)
  */
 package org.openecomp.sdc.be.model.jsontitan.utils;
 
+import java.util.Collection;
+import java.util.Formatter;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
 import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
 import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
@@ -24,10 +28,6 @@ import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
 import org.openecomp.sdc.be.model.InputDefinition;
 import org.openecomp.sdc.be.model.InterfaceDefinition;
 import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.model.Resource;
-
-import java.util.*;
-import java.util.stream.Collectors;
 
 public class InterfaceUtils {
 
@@ -47,15 +47,15 @@ public class InterfaceUtils {
     }
 
     public static Collection<InterfaceDefinition> getInterfaceDefinitionListFromToscaName(Collection<InterfaceDefinition> interfaces,
-                                                                                          String resourceName) {
+        String resourceName) {
         if(CollectionUtils.isEmpty(interfaces)){
             return CollectionUtils.EMPTY_COLLECTION;
         }
 
         String toscaName = createInterfaceToscaResourceName(resourceName);
         return interfaces.stream().filter(
-                interfaceDefinition -> interfaceDefinition.getToscaResourceName() != null && interfaceDefinition
-                        .getToscaResourceName().equals(toscaName)).collect(Collectors.toList());
+            interfaceDefinition -> interfaceDefinition.getToscaResourceName() != null && interfaceDefinition
+                .getToscaResourceName().equals(toscaName)).collect(Collectors.toList());
     }
 
     public static String createInterfaceToscaResourceName(String resourceName) {
@@ -65,14 +65,13 @@ public class InterfaceUtils {
         }
     }
 
-    public static void createInputOutput(Operation operation, List<InputDefinition> inputs) throws IllegalStateException {
+    public static void createInputOutput(Operation operation, List<InputDefinition> inputs, List<InputDefinition> outputs) throws IllegalStateException {
         ListDataDefinition<OperationInputDefinition> inputDefinitionListDataDefinition = operation.getInputs();
         if (inputDefinitionListDataDefinition != null) {
             return;
         }
-        List<OperationInputDefinition> listToscaDataDefinition = inputDefinitionListDataDefinition
-            .getListToscaDataDefinition();
-        List<OperationInputDefinition> convertedInputs = listToscaDataDefinition.stream()
+        List<OperationInputDefinition> inputListToscaDataDefinition = inputDefinitionListDataDefinition.getListToscaDataDefinition();
+        List<OperationInputDefinition> convertedInputs = inputListToscaDataDefinition.stream()
             .map(input -> convertInput(input, inputs))
             .collect(Collectors.toList());
 
@@ -80,11 +79,11 @@ public class InterfaceUtils {
         if (outputDefinitionListDataDefinition != null) {
             return;
         }
-        List<OperationOutputDefinition> outListToscaDefinition = outputDefinitionListDataDefinition
-                .getListToscaDataDefinition();
-        List<OperationOutputDefinition> convertedOutputs = outListToscaDefinition.stream()
-                .map(operationOutputDefinition -> convertOutput(operationOutputDefinition, inputs) )
-                .collect(Collectors.toList());
+        List<OperationOutputDefinition> outputListToscaDataDefinition = outputDefinitionListDataDefinition.getListToscaDataDefinition();
+        List<OperationOutputDefinition> convertedOutputs = outputListToscaDataDefinition.stream()
+            .map(output -> convertOutput(output, outputs) )
+            .collect(Collectors.toList());
+
         inputDefinitionListDataDefinition.getListToscaDataDefinition().clear();
         inputDefinitionListDataDefinition.getListToscaDataDefinition().addAll(convertedInputs);
         outputDefinitionListDataDefinition.getListToscaDataDefinition().clear();
@@ -92,7 +91,7 @@ public class InterfaceUtils {
     }
 
     private static OperationInputDefinition convertInput(OperationInputDefinition input,
-                                                         List<InputDefinition> inputs) throws IllegalStateException {
+        List<InputDefinition> inputs) throws IllegalStateException {
         Optional<InputDefinition> anyInputDefinition = inputs.stream()
             .filter(inp -> inp.getUniqueId().equals(input.getUniqueId())).findAny();
         if (anyInputDefinition.isPresent()) {
@@ -102,9 +101,9 @@ public class InterfaceUtils {
     }
 
     private static OperationOutputDefinition convertOutput(OperationOutputDefinition output,
-                                                         List<InputDefinition> outputs) throws IllegalStateException {
+        List<InputDefinition> outputs) throws IllegalStateException {
         Optional<InputDefinition> anyOutputDefinition = outputs.stream()
-                .filter(inp -> inp.getUniqueId().equals(output.getUniqueId())).findAny();
+            .filter(op -> op.getUniqueId().equals(output.getUniqueId())).findAny();
         if (anyOutputDefinition.isPresent()) {
             return new OperationOutputDefinition(output.getLabel(),new InputDataDefinition(anyOutputDefinition.get()));
         }