diff options
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java | 63 |
1 files changed, 29 insertions, 34 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java index db4bef40b1..71c41caf3a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,10 +17,10 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.components.lifecycle; import fj.data.Either; +import java.util.Arrays; import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic; import org.openecomp.sdc.be.components.impl.version.VesionUpdateHandler; import org.openecomp.sdc.be.config.BeEcompErrorManager; @@ -44,24 +44,21 @@ import org.openecomp.sdc.be.user.Role; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; -import java.util.Arrays; - public class CheckinTransition extends LifeCycleTransition { private static final Logger log = Logger.getLogger(CheckinTransition.class); - private VesionUpdateHandler vesionUpdateHandler; - public CheckinTransition(ComponentsUtils componentUtils, ToscaElementLifecycleOperation lifecycleOperation, ToscaOperationFacade toscaOperationFacade, JanusGraphDao janusGraphDao, VesionUpdateHandler groupUpdateHandler) { + public CheckinTransition(ComponentsUtils componentUtils, ToscaElementLifecycleOperation lifecycleOperation, + ToscaOperationFacade toscaOperationFacade, JanusGraphDao janusGraphDao, VesionUpdateHandler groupUpdateHandler) { super(componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao); this.vesionUpdateHandler = groupUpdateHandler; // authorized roles - Role[] resourceServiceCheckoutRoles = { Role.ADMIN, Role.DESIGNER }; - Role[] productCheckoutRoles = { Role.ADMIN, Role.PRODUCT_MANAGER }; + Role[] resourceServiceCheckoutRoles = {Role.ADMIN, Role.DESIGNER}; + Role[] productCheckoutRoles = {Role.ADMIN, Role.PRODUCT_MANAGER}; addAuthorizedRoles(ComponentTypeEnum.RESOURCE, Arrays.asList(resourceServiceCheckoutRoles)); addAuthorizedRoles(ComponentTypeEnum.SERVICE, Arrays.asList(resourceServiceCheckoutRoles)); addAuthorizedRoles(ComponentTypeEnum.PRODUCT, Arrays.asList(productCheckoutRoles)); - } @Override @@ -75,32 +72,28 @@ public class CheckinTransition extends LifeCycleTransition { } @Override - public Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock, boolean inTransaction) { + public Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component, + ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock, + boolean inTransaction) { log.debug("start performing checkin for {} {}", componentType, component.getUniqueId()); - Either<? extends Component, ResponseFormat> result = null; - try{ - Either<ToscaElement, StorageOperationStatus> checkinResourceResult = lifeCycleOperation. - checkinToscaELement(component.getLifecycleState(), component.getUniqueId(), modifier.getUserId(), owner.getUserId()); - + try { + Either<ToscaElement, StorageOperationStatus> checkinResourceResult = lifeCycleOperation + .checkinToscaELement(component.getLifecycleState(), component.getUniqueId(), modifier.getUserId(), owner.getUserId()); if (checkinResourceResult.isRight()) { log.debug("checkout failed on graph"); StorageOperationStatus response = checkinResourceResult.right().value(); ActionStatus actionStatus = componentUtils.convertFromStorageResponse(response); - if (response.equals(StorageOperationStatus.ENTITY_ALREADY_EXISTS)) { actionStatus = ActionStatus.COMPONENT_VERSION_ALREADY_EXIST; } ResponseFormat responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType); - result = Either.right(responseFormat); - } - else { + result = Either.right(responseFormat); + } else { updateCalculatedCapabilitiesRequirements(checkinResourceResult.left().value()); Component r = ModelConverter.convertFromToscaElement(checkinResourceResult.left().value()); updateGroupsAndPolicesVersion(r); - result = Either.left(r); - - + result = Either.left(r); } } finally { if (result == null || result.isRight()) { @@ -124,35 +117,37 @@ public class CheckinTransition extends LifeCycleTransition { } @Override - public Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo) { + public Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, + LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo) { String componentName = component.getComponentMetadataDefinition().getMetadataDataDefinition().getName(); log.debug("validate before checkin. component name={}, oldState={}, owner userId={}", componentName, oldState, owner.getUserId()); - // validate user - Either<Boolean, ResponseFormat> userValidationResponse = userRoleValidation(modifier,component, componentType, lifecycleChangeInfo); + Either<Boolean, ResponseFormat> userValidationResponse = userRoleValidation(modifier, component, componentType, lifecycleChangeInfo); if (userValidationResponse.isRight()) { return userValidationResponse; } - if (!oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) { ActionStatus action = ActionStatus.COMPONENT_ALREADY_CHECKED_IN; - if (oldState.equals(LifecycleStateEnum.CERTIFIED)){ + if (oldState.equals(LifecycleStateEnum.CERTIFIED)) { action = ActionStatus.COMPONENT_ALREADY_CERTIFIED; } - ResponseFormat error = componentUtils.getResponseFormat(action, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId()); + ResponseFormat error = componentUtils + .getResponseFormat(action, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), + owner.getUserId()); return Either.right(error); } - - if (oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) && !modifier.getUserId().equals(owner.getUserId()) && !modifier.getRole().equals(Role.ADMIN.name())) { - ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_CHECKOUT_BY_ANOTHER_USER, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId()); + if (oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) && !modifier.getUserId().equals(owner.getUserId()) && !modifier.getRole() + .equals(Role.ADMIN.name())) { + ResponseFormat error = componentUtils + .getResponseFormat(ActionStatus.COMPONENT_CHECKOUT_BY_ANOTHER_USER, componentName, componentType.name().toLowerCase(), + owner.getFirstName(), owner.getLastName(), owner.getUserId()); return Either.right(error); } - return Either.left(true); } private void updateCalculatedCapabilitiesRequirements(ToscaElement toscaElement) { - if(toscaElement.getToscaType() == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE && toscaElement.getResourceType() != ResourceTypeEnum.CVFC){ + if (toscaElement.getToscaType() == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE && toscaElement.getResourceType() != ResourceTypeEnum.CVFC) { toscaOperationFacade.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement.getUniqueId()); } } |