From b8cea3e1099d47a61c95709d26d1742446d8e2c5 Mon Sep 17 00:00:00 2001 From: Francis Toth Date: Wed, 6 May 2020 17:54:27 -0400 Subject: Remove wildcard pattern when retrieving components This commit aims to remove a redundant cast while preparing the field for some Either refactoring in ArtifactsBusinessLogic. The reasons for removing the wildcard pattern are explained in SDC-3040 (a sub-task of SDC-2812). Signed-off-by: Francis Toth Change-Id: I573c01eca56f096ccb54e564d0144291121bde22 Issue-ID: SDC-2812 --- .../lifecycle/CertificationChangeTransition.java | 10 ++- .../components/lifecycle/LifeCycleTransition.java | 7 +- .../lifecycle/LifecycleBusinessLogic.java | 94 +++++++++++++--------- 3 files changed, 71 insertions(+), 40 deletions(-) (limited to 'catalog-be/src/main/java/org') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java index 9a5e9d266c..7adc77f1b2 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java @@ -134,10 +134,14 @@ public class CertificationChangeTransition extends LifeCycleTransition { } @Override - public Either changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock, boolean inTransaction) { + public Either changeState( + ComponentTypeEnum componentType, + Component component, + ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock, boolean inTransaction + ) { log.info("start performing certification change for resource {}", component.getUniqueId()); - Either result = null; + Either result = null; try { handleValidationsAndArtifactsGenerationBeforeCertifying(componentType, component, componentBl, modifier, shouldLock, inTransaction); @@ -151,7 +155,7 @@ public class CertificationChangeTransition extends LifeCycleTransition { } ToscaElement certificationResult = certificationChangeResult.left().value(); - Component componentAfterCertification = ModelConverter.convertFromToscaElement(certificationResult); + T componentAfterCertification = ModelConverter.convertFromToscaElement(certificationResult); if ( result == null || result.isLeft() ){ //update edges for allotted resource StorageOperationStatus status = handleConnectionsForAllotted(componentAfterCertification); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifeCycleTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifeCycleTransition.java index 180b7f0286..65fd1b8d42 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifeCycleTransition.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifeCycleTransition.java @@ -107,7 +107,12 @@ public abstract class LifeCycleTransition { this.resourceAuthorizedRoles.put(resourceType, authorizedRoles); } - public abstract Either changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean needLock, boolean inTransaction); + public abstract Either changeState( + ComponentTypeEnum componentType, + Component component, + ComponentBusinessLogic componentBl, + User modifier, User owner, boolean needLock, boolean inTransaction + ); public abstract Either validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java index ebd3e21d9d..43714f2756 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java @@ -24,6 +24,9 @@ package org.openecomp.sdc.be.components.lifecycle; import com.google.common.annotations.VisibleForTesting; import fj.data.Either; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.PostConstruct; import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum; import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic; import org.openecomp.sdc.be.components.impl.ProductBusinessLogic; @@ -36,10 +39,8 @@ import org.openecomp.sdc.be.components.impl.version.VesionUpdateHandler; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.facade.operations.CatalogOperation; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.Component; @@ -64,10 +65,6 @@ import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; -import javax.annotation.PostConstruct; -import java.util.HashMap; -import java.util.Map; - @org.springframework.stereotype.Component("lifecycleBusinessLogic") public class LifecycleBusinessLogic { @@ -144,21 +141,17 @@ public class LifecycleBusinessLogic { // TODO: rhalili - should use changeComponentState when possible public Either changeState(String resourceId, User modifier, LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction, boolean needLock) { - return (Either) changeComponentState(ComponentTypeEnum.RESOURCE, resourceId, modifier, transitionEnum, changeInfo, inTransaction, needLock); - } - - private boolean isComponentVFCMT(Component component, ComponentTypeEnum componentType) { - if (componentType.equals(ComponentTypeEnum.RESOURCE)) { - ResourceTypeEnum resourceType = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getResourceType(); - if (resourceType.equals(ResourceTypeEnum.VFCMT)) { - return true; - } - } - return false; + return changeComponentState(ComponentTypeEnum.RESOURCE, resourceId, modifier, transitionEnum, changeInfo, inTransaction, needLock); } - public Either changeComponentState(ComponentTypeEnum componentType, String componentId, User modifier, LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction, - boolean needLock) { + public Either changeComponentState( + ComponentTypeEnum componentType, + String componentId, + User modifier, + LifeCycleTransitionEnum transitionEnum, + LifecycleChangeInfoWithAction changeInfo, + boolean inTransaction, + boolean needLock) { LifeCycleTransition lifeCycleTransition = stateTransitions.get(transitionEnum.name()); if (lifeCycleTransition == null) { @@ -166,15 +159,16 @@ public class LifecycleBusinessLogic { ResponseFormat error = componentUtils.getInvalidContentErrorAndAudit(modifier, componentId, AuditingActionEnum.CHECKOUT_RESOURCE); return Either.right(error); } - Component component; log.debug("get resource from graph"); ResponseFormat errorResponse; - Either eitherResourceResponse = getComponentForChange(componentType, componentId, modifier, lifeCycleTransition, changeInfo); + Either eitherResourceResponse = getComponentForChange( + componentType, componentId, modifier, lifeCycleTransition, changeInfo + ); if (eitherResourceResponse.isRight()) { return eitherResourceResponse; } - component = eitherResourceResponse.left().value(); + T component = eitherResourceResponse.left().value(); String resourceCurrVersion = component.getVersion(); LifecycleStateEnum resourceCurrState = component.getLifecycleState(); @@ -218,8 +212,10 @@ public class LifecycleBusinessLogic { return Either.right(validateHighestVersion.right().value()); } log.debug("after validate Highest Version"); - final Component oldComponent = component; - Either checkedInComponentEither = checkInBeforeCertifyIfNeeded(componentType, modifier, transitionEnum, changeInfo, inTransaction, component); + final T oldComponent = component; + Either checkedInComponentEither = + checkInBeforeCertifyIfNeeded(componentType, modifier, transitionEnum, changeInfo, inTransaction, + component); if(checkedInComponentEither.isRight()) { return Either.right(checkedInComponentEither.right().value()); } @@ -242,39 +238,58 @@ public class LifecycleBusinessLogic { } - private Either updateCatalog(Component component, Component oldComponent, ChangeTypeEnum changeStatus){ + private Either updateCatalog( + T component, + T oldComponent, + ChangeTypeEnum changeStatus + ){ log.debug("updateCatalog start"); - Component result = component == null? oldComponent : component; + T result = component == null? oldComponent : component; if(component != null){ ActionStatus status = catalogOperations.updateCatalog(changeStatus,component); if(status != ActionStatus.OK){ - return Either.right( componentUtils.getResponseFormat(status)); + return Either.right(componentUtils.getResponseFormat(status)); } } return Either.left(result); } - private Either checkInBeforeCertifyIfNeeded(ComponentTypeEnum componentType, User modifier, LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction, - Component component) { + private Either checkInBeforeCertifyIfNeeded( + ComponentTypeEnum componentType, + User modifier, + LifeCycleTransitionEnum transitionEnum, + LifecycleChangeInfoWithAction changeInfo, + boolean inTransaction, + T component + ) { LifecycleStateEnum oldState = component.getLifecycleState(); - Component updatedComponent = component; log.debug("Certification request for resource {} ", component.getUniqueId()); if (oldState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT && transitionEnum == LifeCycleTransitionEnum.CERTIFY) { log.debug("Resource {} is in Checkout state perform checkin", component.getUniqueId()); - Either actionResponse = changeState(component, stateTransitions.get(LifeCycleTransitionEnum.CHECKIN.name()), componentType, modifier, changeInfo, inTransaction); + Either actionResponse = changeState( + component, + stateTransitions.get(LifeCycleTransitionEnum.CHECKIN.name()), + componentType, modifier, changeInfo, inTransaction); if (actionResponse.isRight()) { log.debug("Failed to check in Resource {} error {}", component.getUniqueId(), actionResponse.right().value()); } return actionResponse; } - return Either.left(updatedComponent); + return Either.left(component); } - private Either changeState(Component component, LifeCycleTransition lifeCycleTransition, ComponentTypeEnum componentType, User modifier, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction) { + private Either changeState( + T component, + LifeCycleTransition lifeCycleTransition, + ComponentTypeEnum componentType, + User modifier, + LifecycleChangeInfoWithAction changeInfo, + boolean inTransaction + ) { ResponseFormat errorResponse; LifecycleStateEnum oldState = component.getLifecycleState(); @@ -302,7 +317,8 @@ public class LifecycleBusinessLogic { return Either.right(errorResponse); } - Either operationResult = lifeCycleTransition.changeState(componentType, component, bl, modifier, owner, false, inTransaction); + Either operationResult = lifeCycleTransition.changeState( + componentType, component, bl, modifier, owner, false, inTransaction); if (operationResult.isRight()) { errorResponse = operationResult.right().value(); @@ -328,9 +344,15 @@ public class LifecycleBusinessLogic { } - private Either getComponentForChange(ComponentTypeEnum componentType, String componentId, User modifier, LifeCycleTransition lifeCycleTransition, LifecycleChangeInfoWithAction changeInfo) { + private Either getComponentForChange( + ComponentTypeEnum componentType, + String componentId, + User modifier, + LifeCycleTransition lifeCycleTransition, + LifecycleChangeInfoWithAction changeInfo + ) { - Either eitherResourceResponse = toscaOperationFacade.getToscaElement(componentId); + Either eitherResourceResponse = toscaOperationFacade.getToscaElement(componentId); ResponseFormat errorResponse; if (eitherResourceResponse.isRight()) { -- cgit 1.2.3-korg