Reformat catalog-be
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / lifecycle / LifecycleBusinessLogic.java
index 43714f2..6f4c641 100644 (file)
@@ -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.
@@ -19,7 +19,6 @@
  * Modifications copyright (c) 2019 Nokia
  * ================================================================================
  */
-
 package org.openecomp.sdc.be.components.lifecycle;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -69,67 +68,51 @@ import org.springframework.context.annotation.Lazy;
 public class LifecycleBusinessLogic {
 
     private static final String COMMENT = "comment";
-
+    private static final Logger log = Logger.getLogger(LifecycleBusinessLogic.class);
+    @Autowired
+    ToscaOperationFacade toscaOperationFacade;
+    @Autowired
+    NodeTemplateOperation nodeTemplateOperation;
+    @Autowired
+    CatalogOperation catalogOperations;
+    @Autowired
+    VesionUpdateHandler groupUpdateHandler;
     @Autowired
     private IGraphLockOperation graphLockOperation = null;
-
     @Autowired
     private JanusGraphDao janusGraphDao;
-
-    private static final Logger log = Logger.getLogger(LifecycleBusinessLogic.class);
-
     @javax.annotation.Resource
     private ComponentsUtils componentUtils;
-
     @javax.annotation.Resource
     private ToscaElementLifecycleOperation lifecycleOperation;
-
     @Autowired
     @Lazy
     private ServiceBusinessLogic serviceBusinessLogic;
-
     @Autowired
     @Lazy
     private ResourceBusinessLogic resourceBusinessLogic;
-
     @Autowired
     @Lazy
     private ProductBusinessLogic productBusinessLogic;
-
-    @Autowired
-    ToscaOperationFacade toscaOperationFacade;
-    
-    @Autowired
-    NodeTemplateOperation nodeTemplateOperation;
-
-    @Autowired
-    CatalogOperation catalogOperations;
-
-    @Autowired
-    VesionUpdateHandler groupUpdateHandler;
-
     private Map<String, LifeCycleTransition> stateTransitions;
 
     @PostConstruct
     public void init() {
-       initStateOperations();
+        initStateOperations();
     }
 
     private void initStateOperations() {
         stateTransitions = new HashMap<>();
-
-        LifeCycleTransition checkoutOp = new CheckoutTransition(componentUtils, lifecycleOperation, toscaOperationFacade,
-            janusGraphDao);
+        LifeCycleTransition checkoutOp = new CheckoutTransition(componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao);
         stateTransitions.put(checkoutOp.getName().name(), checkoutOp);
-
         UndoCheckoutTransition undoCheckoutOp = new UndoCheckoutTransition(componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao);
         undoCheckoutOp.setCatalogOperations(catalogOperations);
         stateTransitions.put(undoCheckoutOp.getName().name(), undoCheckoutOp);
-
-        LifeCycleTransition checkinOp = new CheckinTransition(componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao, groupUpdateHandler);
+        LifeCycleTransition checkinOp = new CheckinTransition(componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao,
+            groupUpdateHandler);
         stateTransitions.put(checkinOp.getName().name(), checkinOp);
-
-        CertificationChangeTransition successCertification = new CertificationChangeTransition(serviceBusinessLogic, LifeCycleTransitionEnum.CERTIFY, componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao);
+        CertificationChangeTransition successCertification = new CertificationChangeTransition(serviceBusinessLogic, LifeCycleTransitionEnum.CERTIFY,
+            componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao);
         successCertification.setNodeTemplateOperation(nodeTemplateOperation);
         stateTransitions.put(successCertification.getName().name(), successCertification);
     }
@@ -140,19 +123,15 @@ 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) {
+    public Either<Resource, ResponseFormat> changeState(String resourceId, User modifier, LifeCycleTransitionEnum transitionEnum,
+                                                        LifecycleChangeInfoWithAction changeInfo, boolean inTransaction, boolean needLock) {
         return changeComponentState(ComponentTypeEnum.RESOURCE, resourceId, modifier, transitionEnum, changeInfo, inTransaction, needLock);
     }
 
-    public <T extends Component> Either<T, 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) {
             log.debug("state operation is not valid. operations allowed are: {}", LifeCycleTransitionEnum.valuesAsString());
@@ -161,32 +140,24 @@ public class LifecycleBusinessLogic {
         }
         log.debug("get resource from graph");
         ResponseFormat errorResponse;
-
-        Either<T, ResponseFormat> eitherResourceResponse = getComponentForChange(
-            componentType, componentId, modifier, lifeCycleTransition, changeInfo
-        );
+        Either<T, ResponseFormat> eitherResourceResponse = getComponentForChange(componentType, componentId, modifier, lifeCycleTransition,
+            changeInfo);
         if (eitherResourceResponse.isRight()) {
             return eitherResourceResponse;
         }
         T component = eitherResourceResponse.left().value();
         String resourceCurrVersion = component.getVersion();
         LifecycleStateEnum resourceCurrState = component.getLifecycleState();
-
         // lock resource
         if (!inTransaction && needLock) {
             log.debug("lock component {}", componentId);
             try {
                 lockComponent(componentType, component);
-            }catch (ComponentException e){
+            } catch (ComponentException e) {
                 errorResponse = e.getResponseFormat();
                 componentUtils.auditComponent(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(),
-                        new ResourceCommonInfo(componentType.getValue()),
-                        ResourceVersionInfo.newBuilder()
-                                .state(resourceCurrState.name())
-                                .version(resourceCurrVersion)
-                                .build());
-
-
+                    new ResourceCommonInfo(componentType.getValue()),
+                    ResourceVersionInfo.newBuilder().state(resourceCurrState.name()).version(resourceCurrVersion).build());
                 log.error("lock component {} failed", componentId);
                 return Either.right(errorResponse);
             }
@@ -197,34 +168,28 @@ public class LifecycleBusinessLogic {
             if (commentValidationResult.isRight()) {
                 errorResponse = commentValidationResult.right().value();
                 componentUtils.auditComponent(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(),
-                        new ResourceCommonInfo(componentType.getValue()),
-                        ResourceVersionInfo.newBuilder()
-                                .state(resourceCurrState.name())
-                                .version(resourceCurrVersion)
-                                .build(),
-                        changeInfo.getUserRemarks());
+                    new ResourceCommonInfo(componentType.getValue()),
+                    ResourceVersionInfo.newBuilder().state(resourceCurrState.name()).version(resourceCurrVersion).build(),
+                    changeInfo.getUserRemarks());
                 return Either.right(errorResponse);
             }
             changeInfo.setUserRemarks(commentValidationResult.left().value());
             log.debug("after validate component");
-            Either<Boolean, ResponseFormat> validateHighestVersion = validateHighestVersion(modifier, lifeCycleTransition, component, resourceCurrVersion, componentType);
+            Either<Boolean, ResponseFormat> validateHighestVersion = validateHighestVersion(modifier, lifeCycleTransition, component,
+                resourceCurrVersion, componentType);
             if (validateHighestVersion.isRight()) {
                 return Either.right(validateHighestVersion.right().value());
             }
             log.debug("after validate Highest Version");
             final T oldComponent = component;
-            Either<T, ResponseFormat> checkedInComponentEither =
-                checkInBeforeCertifyIfNeeded(componentType, modifier, transitionEnum, changeInfo, inTransaction,
-                    component);
-            if(checkedInComponentEither.isRight()) {
+            Either<T, ResponseFormat> checkedInComponentEither = checkInBeforeCertifyIfNeeded(componentType, modifier, transitionEnum, changeInfo,
+                inTransaction, component);
+            if (checkedInComponentEither.isRight()) {
                 return Either.right(checkedInComponentEither.right().value());
             }
             component = checkedInComponentEither.left().value();
-            return changeState(component, lifeCycleTransition, componentType, modifier, changeInfo, inTransaction)
-                                        .left()
-                                        .bind(c -> updateCatalog(c, oldComponent, ChangeTypeEnum.LIFECYCLE));
-
-
+            return changeState(component, lifeCycleTransition, componentType, modifier, changeInfo, inTransaction).left()
+                .bind(c -> updateCatalog(c, oldComponent, ChangeTypeEnum.LIFECYCLE));
         } finally {
             component.setUniqueId(componentId);
             if (!inTransaction && needLock) {
@@ -232,152 +197,106 @@ public class LifecycleBusinessLogic {
                 NodeTypeEnum nodeType = componentType.getNodeType();
                 log.info("During change state, another component {} has been created/updated", componentId);
                 graphLockOperation.unlockComponent(componentId, nodeType);
-
             }
         }
-
     }
 
-    private <T extends Component> Either<T, ResponseFormat>  updateCatalog(
-        T component,
-        T oldComponent,
-        ChangeTypeEnum changeStatus
-    ){
-
+    private <T extends Component> Either<T, ResponseFormat> updateCatalog(T component, T oldComponent, ChangeTypeEnum changeStatus) {
         log.debug("updateCatalog start");
-        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));
-                }
+        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.left(result);
+        return Either.left(result);
     }
 
-    private <T extends Component> Either<T, ResponseFormat> checkInBeforeCertifyIfNeeded(
-        ComponentTypeEnum componentType,
-        User modifier,
-        LifeCycleTransitionEnum transitionEnum,
-        LifecycleChangeInfoWithAction changeInfo,
-        boolean inTransaction,
-        T 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();
         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<T, ResponseFormat> actionResponse = changeState(
-                component,
-                stateTransitions.get(LifeCycleTransitionEnum.CHECKIN.name()),
+            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(component);
     }
 
-    private <T extends Component> Either<T, ResponseFormat> changeState(
-        T 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();
         String resourceCurrVersion = component.getVersion();
         ComponentBusinessLogic bl = getComponentBL(componentType);
-
         Either<User, ResponseFormat> ownerResult = lifeCycleTransition.getComponentOwner(component, componentType);
         if (ownerResult.isRight()) {
             return Either.right(ownerResult.right().value());
         }
         User owner = ownerResult.left().value();
         log.info("owner of resource {} is {}", component.getUniqueId(), owner.getUserId());
-
-        Either<Boolean, ResponseFormat> stateValidationResult = lifeCycleTransition.validateBeforeTransition(component, componentType, modifier, owner, oldState, changeInfo);
+        Either<Boolean, ResponseFormat> stateValidationResult = lifeCycleTransition
+            .validateBeforeTransition(component, componentType, modifier, owner, oldState, changeInfo);
         if (stateValidationResult.isRight()) {
             log.error("Failed to validateBeforeTransition");
             errorResponse = stateValidationResult.right().value();
             componentUtils.auditComponent(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(),
-                    new ResourceCommonInfo(componentType.getValue()),
-                    ResourceVersionInfo.newBuilder()
-                            .version(resourceCurrVersion)
-                            .state(oldState.name())
-                            .build(),
-                    changeInfo.getUserRemarks());
+                new ResourceCommonInfo(componentType.getValue()),
+                ResourceVersionInfo.newBuilder().version(resourceCurrVersion).state(oldState.name()).build(), changeInfo.getUserRemarks());
             return Either.right(errorResponse);
         }
-        
-        Either<T, 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();
             log.info("audit before sending error response");
             componentUtils.auditComponentAdmin(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(), componentType,
-                     ResourceVersionInfo.newBuilder()
-                             .state(oldState.name())
-                             .version(resourceCurrVersion)
-                             .build());
-
+                ResourceVersionInfo.newBuilder().state(oldState.name()).version(resourceCurrVersion).build());
             return Either.right(errorResponse);
         }
-        Component resourceAfterOperation = operationResult.left().value() == null? component: operationResult.left().value() ;
+        Component resourceAfterOperation = operationResult.left().value() == null ? component : operationResult.left().value();
         componentUtils.auditComponent(componentUtils.getResponseFormat(ActionStatus.OK), modifier, resourceAfterOperation,
-                lifeCycleTransition.getAuditingAction(), new ResourceCommonInfo(componentType.getValue()),
-                ResourceVersionInfo.newBuilder()
-                        .state(oldState.name())
-                        .version(resourceCurrVersion)
-                        .build(),
-                changeInfo.getUserRemarks());
+            lifeCycleTransition.getAuditingAction(), new ResourceCommonInfo(componentType.getValue()),
+            ResourceVersionInfo.newBuilder().state(oldState.name()).version(resourceCurrVersion).build(), changeInfo.getUserRemarks());
         return operationResult;
-
     }
 
-
-       private <T extends Component> Either<T, 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<T, StorageOperationStatus> eitherResourceResponse = toscaOperationFacade.getToscaElement(componentId);
-
         ResponseFormat errorResponse;
         if (eitherResourceResponse.isRight()) {
             ActionStatus actionStatus = componentUtils.convertFromStorageResponse(eitherResourceResponse.right().value(), componentType);
             errorResponse = componentUtils.getResponseFormat(actionStatus, Constants.EMPTY_STRING);
             log.debug("audit before sending response");
             componentUtils.auditComponent(errorResponse, modifier, lifeCycleTransition.getAuditingAction(),
-                    new ResourceCommonInfo(componentId, componentType.getValue()), changeInfo.getUserRemarks());
-
+                new ResourceCommonInfo(componentId, componentType.getValue()), changeInfo.getUserRemarks());
             return Either.right(errorResponse);
         }
         return Either.left(eitherResourceResponse.left().value());
     }
 
-    private Either<Boolean, ResponseFormat> validateHighestVersion(User modifier, LifeCycleTransition lifeCycleTransition, Component component, String resourceCurrVersion, ComponentTypeEnum componentType) {
+    private Either<Boolean, ResponseFormat> validateHighestVersion(User modifier, LifeCycleTransition lifeCycleTransition, Component component,
+                                                                   String resourceCurrVersion, ComponentTypeEnum componentType) {
         ResponseFormat errorResponse;
         if (!component.isHighestVersion()) {
-            log.debug("Component version {} is not the last version of component {}", component.getComponentMetadataDefinition().getMetadataDataDefinition().getVersion(),
-                    component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
-            errorResponse = componentUtils.getResponseFormat(ActionStatus.COMPONENT_HAS_NEWER_VERSION, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName(), componentType.getValue().toLowerCase());
+            log.debug("Component version {} is not the last version of component {}",
+                component.getComponentMetadataDefinition().getMetadataDataDefinition().getVersion(),
+                component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
+            errorResponse = componentUtils.getResponseFormat(ActionStatus.COMPONENT_HAS_NEWER_VERSION,
+                component.getComponentMetadataDefinition().getMetadataDataDefinition().getName(), componentType.getValue().toLowerCase());
             componentUtils.auditComponentAdmin(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(), componentType,
-                    ResourceVersionInfo.newBuilder()
-                            .state(component.getLifecycleState().name())
-                            .version(resourceCurrVersion)
-                            .build());
+                ResourceVersionInfo.newBuilder().state(component.getLifecycleState().name()).version(resourceCurrVersion).build());
             return Either.right(errorResponse);
         }
         return Either.left(true);
@@ -386,35 +305,33 @@ public class LifecycleBusinessLogic {
     private Boolean lockComponent(ComponentTypeEnum componentType, Component component) {
         NodeTypeEnum nodeType = componentType.getNodeType();
         StorageOperationStatus lockResourceStatus = graphLockOperation.lockComponent(component.getUniqueId(), nodeType);
-
         if (lockResourceStatus.equals(StorageOperationStatus.OK)) {
             return true;
         } else {
             ActionStatus actionStatus = componentUtils.convertFromStorageResponse(lockResourceStatus);
-            throw new ByActionStatusComponentException(actionStatus, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
+            throw new ByActionStatusComponentException(actionStatus,
+                component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
         }
     }
 
     private Either<String, ResponseFormat> validateComment(LifecycleChangeInfoWithAction changeInfo, LifeCycleTransitionEnum transitionEnum) {
         String comment = changeInfo.getUserRemarks();
         if (LifeCycleTransitionEnum.CERTIFY == transitionEnum || LifeCycleTransitionEnum.CHECKIN == transitionEnum
-        // import?
+            // import?
         ) {
-
             if (!ValidationUtils.validateStringNotEmpty(comment)) {
                 log.debug("user comment cannot be empty or null.");
                 ResponseFormat errorResponse = componentUtils.getResponseFormat(ActionStatus.MISSING_DATA, COMMENT);
                 return Either.right(errorResponse);
             }
-
             comment = ValidationUtils.removeNoneUtf8Chars(comment);
             comment = ValidationUtils.removeHtmlTags(comment);
             comment = ValidationUtils.normaliseWhitespace(comment);
             comment = ValidationUtils.stripOctets(comment);
-
             if (!ValidationUtils.validateLength(comment, ValidationUtils.COMMENT_MAX_LENGTH)) {
                 log.debug("user comment exceeds limit.");
-                return Either.right(componentUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, COMMENT, String.valueOf(ValidationUtils.COMMENT_MAX_LENGTH)));
+                return Either
+                    .right(componentUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, COMMENT, String.valueOf(ValidationUtils.COMMENT_MAX_LENGTH)));
             }
             if (!ValidationUtils.validateIsEnglish(comment)) {
                 return Either.right(componentUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
@@ -426,39 +343,35 @@ public class LifecycleBusinessLogic {
     private ComponentBusinessLogic getComponentBL(ComponentTypeEnum componentTypeEnum) {
         ComponentBusinessLogic businessLogic;
         switch (componentTypeEnum) {
-        case RESOURCE:
-            businessLogic = this.resourceBusinessLogic;
-            break;
-        case SERVICE:
-            businessLogic = this.serviceBusinessLogic;
-            break;
-        case PRODUCT:
-            businessLogic = this.productBusinessLogic;
-            break;
-        default:
-            throw new IllegalArgumentException("Illegal component type:" + componentTypeEnum.getValue());
+            case RESOURCE:
+                businessLogic = this.resourceBusinessLogic;
+                break;
+            case SERVICE:
+                businessLogic = this.serviceBusinessLogic;
+                break;
+            case PRODUCT:
+                businessLogic = this.productBusinessLogic;
+                break;
+            default:
+                throw new IllegalArgumentException("Illegal component type:" + componentTypeEnum.getValue());
         }
         return businessLogic;
     }
 
     public Either<Component, ResponseFormat> getLatestComponentByUuid(ComponentTypeEnum componentTypeEnum, String uuid) {
-
         Either<Component, StorageOperationStatus> latestVersionEither = toscaOperationFacade.getLatestComponentByUuid(uuid);
-
         if (latestVersionEither.isRight()) {
-
-            return Either.right(componentUtils.getResponseFormat(componentUtils.convertFromStorageResponse(latestVersionEither.right().value(), componentTypeEnum), uuid));
+            return Either.right(componentUtils
+                .getResponseFormat(componentUtils.convertFromStorageResponse(latestVersionEither.right().value(), componentTypeEnum), uuid));
         }
-
         Component latestComponent = latestVersionEither.left().value();
-
         return Either.left(latestComponent);
     }
 
     /**
-     * Performs Force certification. Note that a Force certification is allowed for the first certification only, as only a state and a version is promoted due a Force certification, skipping other actions required if a previous certified version
-     * exists.
-     * 
+     * Performs Force certification. Note that a Force certification is allowed for the first certification only, as only a state and a version is
+     * promoted due a Force certification, skipping other actions required if a previous certified version exists.
+     *
      * @param resource
      * @param user
      * @param lifecycleChangeInfo
@@ -466,7 +379,8 @@ public class LifecycleBusinessLogic {
      * @param needLock
      * @return
      */
-    public Resource forceResourceCertification(Resource resource, User user, LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) {
+    public Resource forceResourceCertification(Resource resource, User user, LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction,
+                                               boolean needLock) {
         Resource result = null;
         Either<ToscaElement, StorageOperationStatus> certifyResourceRes = null;
         if (lifecycleChangeInfo.getAction() != LifecycleChanceActionEnum.CREATE_FROM_CSAR) {
@@ -474,7 +388,8 @@ public class LifecycleBusinessLogic {
             throw new ByActionStatusComponentException(ActionStatus.NOT_ALLOWED);
         }
         if (!isFirstCertification(resource.getVersion())) {
-            log.debug("Failed to perform a force certification of resource{}. Force certification is allowed for the first certification only. ", resource.getName());
+            log.debug("Failed to perform a force certification of resource{}. Force certification is allowed for the first certification only. ",
+                resource.getName());
             throw new ByActionStatusComponentException(ActionStatus.NOT_ALLOWED);
         }
         // lock resource
@@ -484,11 +399,13 @@ public class LifecycleBusinessLogic {
             log.info("after lock component {}", resource.getUniqueId());
         }
         try {
-            certifyResourceRes = lifecycleOperation.forceCerificationOfToscaElement(resource.getUniqueId(), user.getUserId(), user.getUserId(), resource.getVersion());
+            certifyResourceRes = lifecycleOperation
+                .forceCerificationOfToscaElement(resource.getUniqueId(), user.getUserId(), user.getUserId(), resource.getVersion());
             if (certifyResourceRes.isRight()) {
                 StorageOperationStatus status = certifyResourceRes.right().value();
                 log.debug("Failed to perform a force certification of resource {}. The status is {}. ", resource.getName(), status);
-                throw new ByResponseFormatComponentException(componentUtils.getResponseFormatByResource(componentUtils.convertFromStorageResponse(status), resource));
+                throw new ByResponseFormatComponentException(
+                    componentUtils.getResponseFormatByResource(componentUtils.convertFromStorageResponse(status), resource));
             }
             result = ModelConverter.convertFromToscaElement(certifyResourceRes.left().value());
             resource.setComponentMetadataDefinition(result.getComponentMetadataDefinition());
@@ -513,5 +430,4 @@ public class LifecycleBusinessLogic {
     public boolean isFirstCertification(String previousVersion) {
         return previousVersion.split("\\.")[0].equals("0");
     }
-
 }