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.model.Component;
24 import org.openecomp.sdc.be.model.LifecycleStateEnum;
25 import org.openecomp.sdc.be.model.Resource;
26 import org.openecomp.sdc.be.model.Service;
27 import org.openecomp.sdc.be.model.operations.api.IComponentOperation;
28 import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
29 import org.openecomp.sdc.be.model.operations.api.IServiceOperation;
30 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 import fj.data.Either;
36 public class ComponentValidationUtils {
38 private static Logger log = LoggerFactory.getLogger(ComponentValidationUtils.class.getName());
40 public static boolean canWorkOnResource(Resource resource, String userId) {
41 // verify resource is checked-out
42 if (resource.getLifecycleState() != LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) {
43 log.debug("resource is not checked-out");
46 // verify resource is not deleted
47 if ((resource.getIsDeleted() != null) && (resource.getIsDeleted() == true)) {
48 log.debug("resource is marked as delete");
51 // verify resource last update user is the current user
52 if (!userId.equals(resource.getLastUpdaterUserId())) {
53 log.debug("resource last update is not {}", userId);
59 public static boolean canWorkOnResource(String resourceId, IResourceOperation resourceOperation,
61 Either<Resource, StorageOperationStatus> getResourceResult = resourceOperation.getLightComponent(resourceId,
64 if (getResourceResult.isRight()) {
65 log.debug("Failed to retrive resource, resource id {}", resourceId);
68 Resource resource = getResourceResult.left().value();
70 return canWorkOnResource(resource, userId);
74 public static boolean canWorkOnService(String serviceId, IServiceOperation serviceOperation, String userId) {
75 Either<Service, StorageOperationStatus> getResourceResult = serviceOperation.getLightComponent(serviceId,
78 if (getResourceResult.isRight()) {
79 log.debug("Failed to retrieve service, service id {}", serviceId);
82 Service service = getResourceResult.left().value();
84 return canWorkOnComponent(service, userId);
88 public static boolean canWorkOnComponent(String componentId, IComponentOperation componentOperation,
90 Either<Component, StorageOperationStatus> getResourceResult = componentOperation.getLightComponent(componentId,
93 if (getResourceResult.isRight()) {
94 log.debug("Failed to retrieve component, component id {}", componentId);
97 Component service = getResourceResult.left().value();
99 return canWorkOnComponent(service, userId);
102 public static boolean canWorkOnComponent(Component component, String userId) {
103 // verify resource is checked-out
104 if (component.getLifecycleState() != LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) {
105 log.debug("resource is not checked-out");
109 // verify userId is not null
110 if (userId == null) {
111 log.debug("current user userId is null");
115 // verify resource last update user is the current user
116 if (!userId.equals(component.getLastUpdaterUserId())) {
117 log.debug("resource last updater userId is not {}", userId);