From f02c8a02bf45824ef7f8bb76b55462960f561ec3 Mon Sep 17 00:00:00 2001 From: mojahidi Date: Wed, 19 Sep 2018 12:54:50 +0530 Subject: User is unable to modify name of VF User is unable to modify name of VF having operations which was created via Heat Flow Change-Id: I42b666137b26755cccf71028b220560f42b0c0f7 Issue-ID: SDC-1771 Signed-off-by: mojahidi --- .../sdc/be/components/impl/BaseBusinessLogic.java | 4 ++ .../impl/InterfaceOperationBusinessLogic.java | 50 +++++++++++++-- .../be/components/impl/ResourceBusinessLogic.java | 73 +--------------------- .../be/components/impl/ServiceBusinessLogic.java | 7 ++- .../components/impl/ResourceBusinessLogicTest.java | 3 + 5 files changed, 60 insertions(+), 77 deletions(-) (limited to 'catalog-be') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java index fee386ab29..453564e2f8 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java @@ -166,6 +166,10 @@ public abstract class BaseBusinessLogic { public void setInterfaceOperation(InterfaceOperation interfaceOperation) { this.interfaceOperation = interfaceOperation; } + public void setInterfaceOperationBusinessLogic(InterfaceOperationBusinessLogic interfaceOperationBusinessLogic) { + this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic; + } + User validateUserNotEmpty(User user, String ecompErrorContext) { return userValidations.validateUserNotEmpty(user, ecompErrorContext); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java index 792e23af3b..6f822fd7e3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java @@ -18,12 +18,9 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; -import java.util.Collections; -import java.util.Map; -import java.util.Optional; -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.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; @@ -39,6 +36,12 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; + @Component("interfaceOperationBusinessLogic") public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { @@ -273,4 +276,43 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } return Either.left(true); } + + public Either validateComponentNameAndUpdateInterfaces(org.openecomp.sdc.be.model.Component oldComponent, + org.openecomp.sdc.be.model.Component newComponent) { + if(!oldComponent.getName().equals(newComponent.getName()) ) { + Collection interfaceDefinitionListFromToscaName = InterfaceUtils + .getInterfaceDefinitionListFromToscaName(oldComponent.getInterfaces().values(), + oldComponent.getName()); + for (InterfaceDefinition interfaceDefinition : interfaceDefinitionListFromToscaName) { + + Either interfaceDefinitionResponseEither = updateInterfaceDefinition(oldComponent, + newComponent, interfaceDefinition); + if(interfaceDefinitionResponseEither.isRight()) { + return Either.right(interfaceDefinitionResponseEither.right().value()); + } + } + } + return Either.left(Boolean.TRUE); + } + private Either updateInterfaceDefinition(org.openecomp.sdc.be.model.Component oldComponent, + org.openecomp.sdc.be.model.Component newComponent, + InterfaceDefinition interfaceDefinition) { + InterfaceUtils.createInterfaceToscaResourceName(newComponent.getName()); + interfaceDefinition.setToscaResourceName(InterfaceUtils + .createInterfaceToscaResourceName(newComponent.getName())); + try { + Either interfaceUpdate = interfaceOperation + .updateInterface(oldComponent.getUniqueId(), interfaceDefinition); + if (interfaceUpdate.isRight()) { + LOGGER.error("Failed to Update interface {}. Response is {}. ", newComponent.getName(), interfaceUpdate.right().value()); + titanDao.rollback(); + return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(interfaceUpdate.right().value(), ComponentTypeEnum.RESOURCE))); + } + } catch (Exception e) { + LOGGER.error("Exception occurred during update interface toscaResourceName : {}", e); + titanDao.rollback(); + return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); + } + return Either.left( interfaceDefinition); + } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 492f5bf850..6bb8c5c613 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -63,8 +63,6 @@ import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.category.SubCategoryDefinition; -import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation; -import org.openecomp.sdc.be.model.jsontitan.utils.InterfaceUtils; import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter; import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.model.operations.api.*; @@ -171,13 +169,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { @Autowired private CsarBusinessLogic csarBusinessLogic; - @Autowired - private InterfaceOperation interfaceOperation; - - public void setInterfaceOperation(InterfaceOperation interfaceOperation) { - this.interfaceOperation = interfaceOperation; - } - public LifecycleBusinessLogic getLifecycleBusinessLogic() { return lifecycleBusinessLogic; } @@ -3987,7 +3978,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { newResource.setDerivedFrom(null); } - Either validateAndUpdateInterfacesEither = validateAndUpdateInterfaces(resourceIdToUpdate, newResource); + Either validateAndUpdateInterfacesEither = + interfaceOperationBusinessLogic.validateComponentNameAndUpdateInterfaces(currentResource, newResource); if (validateAndUpdateInterfacesEither.isRight()) { log.error("failed to validate and update Interfaces"); rollbackNeeded = true; @@ -5172,65 +5164,4 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return super.shouldUpgradeToLatestDerived(clonedComponent); } } - - private Either validateAndUpdateInterfaces(String resourceId, Resource resourceUpdate) { - Either resourceStorageOperationStatusEither = - toscaOperationFacade.getToscaElement(resourceId); - if (resourceStorageOperationStatusEither.isRight()) { - StorageOperationStatus errorStatus = resourceStorageOperationStatusEither.right().value(); - log.error("Failed to fetch resource information by resource id {}, error {}", resourceId, errorStatus); - return Either.right(componentsUtils - .getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus))); - } - - Resource storedResource = resourceStorageOperationStatusEither.left().value(); - Map storedResourceInterfaces = storedResource.getInterfaces(); - - if(!storedResource.getName().equals(resourceUpdate.getName()) ) { - Collection interfaceDefinitionListFromToscaName = InterfaceUtils - .getInterfaceDefinitionListFromToscaName(storedResource.getInterfaces().values(), - storedResource.getName()); - - for (InterfaceDefinition interfaceDefinition : storedResourceInterfaces.values()) { - Either updateInterfaceDefinitionEither = updateInterfaceDefinition(resourceUpdate, - interfaceDefinition, - interfaceDefinitionListFromToscaName); - if(updateInterfaceDefinitionEither.isRight()) { - return Either.right(updateInterfaceDefinitionEither.right().value()); - } - } - } - - return Either.left(Boolean.TRUE); - } - - private Either updateInterfaceDefinition(Resource resourceUpdate, - InterfaceDefinition interfaceDefinition, - Collection interfaceDefinitionListFromToscaName) { - interfaceDefinitionListFromToscaName.forEach(interfaceDefinitionFromList -> { - if(interfaceDefinitionFromList.getToscaResourceName().equals(interfaceDefinition.getToscaResourceName())) { - log.info("Going to Update interface definition toscaResourceName {} to {}", - interfaceDefinitionFromList.getToscaResourceName(), - InterfaceUtils.createInterfaceToscaResourceName(resourceUpdate.getName())); - interfaceDefinition.setToscaResourceName(InterfaceUtils - .createInterfaceToscaResourceName(resourceUpdate.getName())); - } - } ); - try { - Either interfaceUpdate = interfaceOperation - .updateInterface(resourceUpdate.getUniqueId(), interfaceDefinition); - if (interfaceUpdate.isRight()) { - log.error("Failed to Update interface {}. Response is {}. ", resourceUpdate.getName(), interfaceUpdate.right().value()); - titanDao.rollback(); - return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(interfaceUpdate.right().value(), ComponentTypeEnum.RESOURCE))); - } - } catch (Exception e) { - log.error("Exception occurred during update interface toscaResourceName : {}", e); - titanDao.rollback(); - return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); - } - - return Either.left( interfaceDefinition); - } - } \ No newline at end of file diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java index f30088ce9c..e85afdc48f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java @@ -518,7 +518,11 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { log.info("Restricted operation for user: {}, on service: {}", user.getUserId(), currentService.getCreatorUserId()); return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)); } - + Either validateAndUpdateInterfacesEither = interfaceOperationBusinessLogic.validateComponentNameAndUpdateInterfaces(currentService, serviceUpdate); + if (validateAndUpdateInterfacesEither.isRight()) { + log.info("failed to validate and update Interfaces on service {}", currentService.getCreatorUserId()); + return Either.right(validateAndUpdateInterfacesEither.right().value()); + } Either validationRsponse = validateAndUpdateServiceMetadata(user, currentService, serviceUpdate); if (validationRsponse.isRight()) { log.info("service update metadata: validations field."); @@ -789,7 +793,6 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { validateAndUpdateEcompNaming(currentService, serviceUpdate); currentService.setEnvironmentContext(serviceUpdate.getEnvironmentContext()); - return Either.left(currentService); } catch (ComponentException exception) { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java index f7e95867ec..13d0665e35 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java @@ -154,6 +154,7 @@ public class ResourceBusinessLogicTest { WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class); IInterfaceLifecycleOperation interfaceTypeOperation = Mockito.mock(IInterfaceLifecycleOperation.class); InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class); + InterfaceOperationBusinessLogic interfaceOperationBl = Mockito.mock(InterfaceOperationBusinessLogic.class); @InjectMocks ResourceBusinessLogic bl = new ResourceBusinessLogic(); @@ -239,6 +240,7 @@ public class ResourceBusinessLogicTest { Map emptyDataTypes = new HashMap<>(); when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes)); when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK); + when(interfaceOperationBl.validateComponentNameAndUpdateInterfaces(any(Component.class), any(Component.class))).thenReturn(Either.left(true)); // BL object artifactManager.setNodeTemplateOperation(nodeTemplateOperation); @@ -261,6 +263,7 @@ public class ResourceBusinessLogicTest { bl.setUserValidations(userValidations); bl.setInterfaceTypeOperation(interfaceTypeOperation); bl.setInterfaceOperation(interfaceOperation); + bl.setInterfaceOperationBusinessLogic(interfaceOperationBl); csarBusinessLogic.setCsarOperation(csarOperation); Resource resourceCsar = createResourceObjectCsar(true); -- cgit 1.2.3-korg