diff options
author | 2020-01-19 13:50:02 +0200 | |
---|---|---|
committer | 2020-01-22 12:33:31 +0000 | |
commit | 16a9fce0e104a38371a9e5a567ec611ae3fc7f33 (patch) | |
tree | 03a2aff3060ddb5bc26a90115805a04becbaffc9 /catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java | |
parent | aa83a2da4f911c3ac89318b8e9e8403b072942e1 (diff) |
Catalog alignment
Issue-ID: SDC-2724
Signed-off-by: ys9693 <ys9693@att.com>
Change-Id: I52b4aacb58cbd432ca0e1ff7ff1f7dd52099c6fe
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java | 102 |
1 files changed, 44 insertions, 58 deletions
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 add5df225c..a0ea5c9d04 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 @@ -17,33 +17,11 @@ package org.openecomp.sdc.be.components.impl; -import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedCapabilityPropertyDefaultValue; -import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedInputPropertyDefaultValue; -import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedOutputDefaultValue; -import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId; -import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType; -import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationFromInterfaceDefinition; -import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToComponentInput; -import static org.openecomp.sdc.be.components.utils.PropertiesUtils.getPropertyCapabilityFromAllCapProps; -import static org.openecomp.sdc.be.components.utils.PropertiesUtils.isCapabilityProperty; -import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.SELF; - import com.google.gson.Gson; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; -import java.util.stream.Collectors; - import fj.data.Either; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; +import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.utils.InterfaceOperationUtils; import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -77,6 +55,28 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; + +import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedCapabilityPropertyDefaultValue; +import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedInputPropertyDefaultValue; +import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedOutputDefaultValue; +import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId; +import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType; +import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationFromInterfaceDefinition; +import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToComponentInput; +import static org.openecomp.sdc.be.components.utils.PropertiesUtils.getPropertyCapabilityFromAllCapProps; +import static org.openecomp.sdc.be.components.utils.PropertiesUtils.isCapabilityProperty; +import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.SELF; + @Component("interfaceOperationBusinessLogic") public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { @@ -107,7 +107,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { public Either<List<InterfaceDefinition>, ResponseFormat> deleteInterfaceOperation(String componentId, String interfaceId, List<String> operationsToDelete, User user, boolean lock) { - validateUserExists(user.getUserId(), DELETE_INTERFACE_OPERATION, true); + validateUserExists(user.getUserId()); Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId); if (componentEither.isRight()) { @@ -115,11 +115,8 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); - Either<Boolean, ResponseFormat> lockResult = - lockComponentResult(lock, storedComponent, DELETE_INTERFACE_OPERATION); - if (lockResult.isRight()) { - return Either.right(lockResult.right().value()); - } + lockComponentResult(lock, storedComponent, DELETE_INTERFACE_OPERATION); + try { Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId( @@ -208,10 +205,8 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { janusGraphDao.rollback(); return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_DELETED)); } finally { - if (lockResult.isLeft() && lockResult.left().value()) { - graphLockOperation.unlockComponent(storedComponent.getUniqueId(), - NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue())); - } + graphLockOperation.unlockComponent(storedComponent.getUniqueId(), + NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue())); } } @@ -228,18 +223,19 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { private Either<Boolean, ResponseFormat> lockComponentResult(boolean lock, org.openecomp.sdc.be.model.Component component, String action) { if (lock) { - Either<Boolean, ResponseFormat> lockResult = lockComponent(component.getUniqueId(), component, action); - if (lockResult.isRight()) { - janusGraphDao.rollback(); - return Either.right(lockResult.right().value()); - } + try { + lockComponent(component.getUniqueId(), component, action); + } catch (ComponentException e) { + janusGraphDao.rollback(); + throw e; } + } return Either.left(true); } public Either<List<InterfaceDefinition>, ResponseFormat> getInterfaceOperation(String componentId, String interfaceId, List<String> operationsToGet, User user, boolean lock) { - validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true); + validateUserExists(user); Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId); if (componentEither.isRight()) { @@ -247,11 +243,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); - Either<Boolean, ResponseFormat> lockResult = - lockComponentResult(lock, storedComponent, GET_INTERFACE_OPERATION); - if (lockResult.isRight()) { - return Either.right(lockResult.right().value()); - } + lockComponentResult(lock, storedComponent, GET_INTERFACE_OPERATION); try { Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId( @@ -280,10 +272,8 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { return Either.right( componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId)); } finally { - if (lockResult.isLeft() && lockResult.left().value()) { - graphLockOperation.unlockComponent(storedComponent.getUniqueId(), - NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue())); - } + graphLockOperation.unlockComponent(storedComponent.getUniqueId(), + NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue())); } } @@ -296,7 +286,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { private Either<List<InterfaceDefinition>, ResponseFormat> createOrUpdateInterfaceOperation(String componentId, List<InterfaceDefinition> interfaceDefinitions, User user, boolean isUpdate, String errorContext, boolean lock) { - validateUserExists(user.getUserId(), errorContext, true); + validateUserExists(user); Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId); if (componentEither.isRight()) { @@ -304,10 +294,8 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); - Either<Boolean, ResponseFormat> lockResult = lockComponentResult(lock, storedComponent, errorContext); - if (lockResult.isRight()) { - return Either.right(lockResult.right().value()); - } + lockComponentResult(lock, storedComponent, errorContext); + Either<Map<String, InterfaceDefinition>, ResponseFormat> interfaceLifecycleTypes = getAllInterfaceLifecycleTypes(); @@ -416,10 +404,8 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "addOrUpdate", e); return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); } finally { - if (lockResult.isLeft() && lockResult.left().value()) { - graphLockOperation.unlockComponent(storedComponent.getUniqueId(), - NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue())); - } + graphLockOperation.unlockComponent(storedComponent.getUniqueId(), + NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue())); } } @@ -566,7 +552,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); - validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true); + validateUserExists(user.getUserId()); Either<Boolean, ResponseFormat> lockResult = lockComponentResult(true, storedComponent, GET_INTERFACE_OPERATION); if (lockResult.isRight()) { |