aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancis Toth <francis.toth@yoppworks.com>2020-05-06 17:54:27 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-05-20 09:21:42 +0000
commitb8cea3e1099d47a61c95709d26d1742446d8e2c5 (patch)
tree933a57fe3a7241b086802321501db559c835bec4
parent8366fcd262412e178ea331f17fe6144e95eb891a (diff)
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 <francis.toth@yoppworks.com> Change-Id: I573c01eca56f096ccb54e564d0144291121bde22 Issue-ID: SDC-2812
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifeCycleTransition.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java94
3 files changed, 71 insertions, 40 deletions
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<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock, boolean inTransaction) {
+ public <T extends Component> Either<T, ResponseFormat> 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<? extends Component, ResponseFormat> result = null;
+ Either<T, ResponseFormat> 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<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean needLock, boolean inTransaction);
+ public abstract <T extends Component> Either<T, ResponseFormat> changeState(
+ ComponentTypeEnum componentType,
+ Component component,
+ ComponentBusinessLogic componentBl,
+ User modifier, User owner, boolean needLock, boolean inTransaction
+ );
public abstract Either<Boolean, ResponseFormat> 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<Resource, ResponseFormat> changeState(String resourceId, User modifier, LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction, boolean needLock) {
- return (Either<Resource, ResponseFormat>) 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<? extends Component, ResponseFormat> changeComponentState(ComponentTypeEnum componentType, String componentId, User modifier, LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction,
- boolean needLock) {
+ public <T extends Component> Either<T, ResponseFormat> 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<? extends Component, ResponseFormat> eitherResourceResponse = getComponentForChange(componentType, componentId, modifier, lifeCycleTransition, changeInfo);
+ Either<T, ResponseFormat> 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<? extends Component, ResponseFormat> checkedInComponentEither = checkInBeforeCertifyIfNeeded(componentType, modifier, transitionEnum, changeInfo, inTransaction, component);
+ final T oldComponent = component;
+ Either<T, ResponseFormat> 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<Component, ResponseFormat> updateCatalog(Component component, Component oldComponent, ChangeTypeEnum changeStatus){
+ private <T extends Component> Either<T, ResponseFormat> 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<? extends Component, ResponseFormat> checkInBeforeCertifyIfNeeded(ComponentTypeEnum componentType, User modifier, LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction,
- Component component) {
+ private <T extends Component> Either<T, ResponseFormat> 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<? extends Component, ResponseFormat> actionResponse = changeState(component, stateTransitions.get(LifeCycleTransitionEnum.CHECKIN.name()), componentType, modifier, changeInfo, inTransaction);
+ Either<T, ResponseFormat> 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<? extends Component, ResponseFormat> changeState(Component component, LifeCycleTransition lifeCycleTransition, ComponentTypeEnum componentType, User modifier, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction) {
+ private <T extends Component> Either<T, ResponseFormat> 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<? extends Component, ResponseFormat> operationResult = lifeCycleTransition.changeState(componentType, component, bl, modifier, owner, false, inTransaction);
+ Either<T, ResponseFormat> 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<? extends Component, ResponseFormat> getComponentForChange(ComponentTypeEnum componentType, String componentId, User modifier, LifeCycleTransition lifeCycleTransition, LifecycleChangeInfoWithAction changeInfo) {
+ private <T extends Component> Either<T, ResponseFormat> getComponentForChange(
+ ComponentTypeEnum componentType,
+ String componentId,
+ User modifier,
+ LifeCycleTransition lifeCycleTransition,
+ LifecycleChangeInfoWithAction changeInfo
+ ) {
- Either<? extends Component, StorageOperationStatus> eitherResourceResponse = toscaOperationFacade.getToscaElement(componentId);
+ Either<T, StorageOperationStatus> eitherResourceResponse = toscaOperationFacade.getToscaElement(componentId);
ResponseFormat errorResponse;
if (eitherResourceResponse.isRight()) {