2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.model.operations.utils;
23 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
24 import org.openecomp.sdc.be.model.Component;
25 import org.openecomp.sdc.be.model.LifecycleStateEnum;
26 import org.openecomp.sdc.be.model.Resource;
27 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
28 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import fj.data.Either;
34 public class ComponentValidationUtils {
36 private static Logger log = LoggerFactory.getLogger(ComponentValidationUtils.class.getName());
38 public static boolean canWorkOnResource(Resource resource, String userId) {
39 // verify resource is checked-out
40 if (resource.getLifecycleState() != LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) {
41 log.debug("resource is not checked-out");
44 // verify resource is not deleted
45 if ((resource.getIsDeleted() != null) && (resource.getIsDeleted() == true)) {
46 log.debug("resource is marked as delete");
49 // verify resource last update user is the current user
50 if (!userId.equals(resource.getLastUpdaterUserId())) {
51 log.debug("resource last update is not {}", userId);
57 public static boolean canWorkOnComponent(String componentId, ToscaOperationFacade toscaOperationFacade, String userId) {
59 Either<Component, StorageOperationStatus> getResourceResult = toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata);
61 if (getResourceResult.isRight()) {
62 log.debug("Failed to retrieve component, component id {}", componentId);
65 Component component = getResourceResult.left().value();
67 return canWorkOnComponent(component, userId);
70 public static boolean canWorkOnComponent(Component component, String userId) {
71 return canWorkOnComponent(component.getLifecycleState(), component.getLastUpdaterUserId(), userId);
74 private static boolean canWorkOnComponent(LifecycleStateEnum lifecycleState, String lastUpdaterUserId, String userId) {
75 // verify resource is checked-out
76 if (lifecycleState != LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) {
77 log.debug("resource is not checked-out");
81 // verify userId is not null
83 log.debug("current user userId is null");
87 // verify resource last update user is the current user
88 if (!userId.equals(lastUpdaterUserId)) {
89 log.debug("resource last updater userId is not {}", userId);