2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.be.model.jsontitan.operations;
19 import fj.data.Either;
20 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
21 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
22 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
23 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
24 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
25 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
26 import org.openecomp.sdc.be.model.InterfaceDefinition;
27 import org.openecomp.sdc.be.model.Resource;
28 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
29 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
30 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
31 import org.openecomp.sdc.common.log.wrappers.Logger;
35 @org.springframework.stereotype.Component("interfaces-operation")
36 public class InterfaceOperation extends BaseOperation {
38 private static final Logger logger = Logger.getLogger(InterfaceOperation.class.getName());
41 public Either<Set<String>, StorageOperationStatus> deleteInterface(Resource resource,
42 Set<String> interfacesToDelete) {
43 Either<Set<String>, StorageOperationStatus> result = null;
44 Either<GraphVertex, TitanOperationStatus> getComponentVertex;
45 StorageOperationStatus status = null;
48 getComponentVertex = titanDao.getVertexById(resource.getUniqueId(), JsonParseFlagEnum.NoParse);
49 if (getComponentVertex.isRight()) {
51 .right(DaoStatusConverter.convertTitanStatusToStorageStatus(getComponentVertex.right().value()));
56 status = deleteToscaDataElements(resource.getUniqueId(), EdgeLabelEnum.INTERFACE_ARTIFACTS,
57 new ArrayList<>(interfacesToDelete));
59 if (status != StorageOperationStatus.OK) {
60 result = Either.right(status);
65 result = Either.left(interfacesToDelete);
70 public Either<InterfaceDefinition, StorageOperationStatus> addInterface(String resourceId,
71 InterfaceDefinition interfaceDefinition) {
72 return addOrUpdateInterface(false, resourceId, interfaceDefinition);
75 public Either<InterfaceDefinition, StorageOperationStatus> updateInterface(String resourceId,
76 InterfaceDefinition interfaceDefinition) {
77 return addOrUpdateInterface(true, resourceId, interfaceDefinition);
80 private Either<InterfaceDefinition, StorageOperationStatus> addOrUpdateInterface(
81 boolean isUpdateAction, String resourceId, InterfaceDefinition interfaceDefinition) {
83 StorageOperationStatus statusRes;
84 Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
86 getToscaElementRes = titanDao.getVertexById(resourceId, JsonParseFlagEnum.NoParse);
87 if (getToscaElementRes.isRight()) {
88 TitanOperationStatus status = getToscaElementRes.right().value();
89 CommonUtility.addRecordToLog(logger, CommonUtility.LogLevelEnum.DEBUG,
90 "Failed to get tosca element {} upon adding the properties. Status is {}. ", resourceId, status);
91 statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
92 return Either.right(statusRes);
94 GraphVertex resourceVertex = getToscaElementRes.left().value();
95 if (!isUpdateAction) {
96 interfaceDefinition.setUniqueId(UUID.randomUUID().toString());
98 statusRes = performUpdateToscaAction(isUpdateAction, resourceVertex, Arrays.asList(interfaceDefinition),
99 JsonPresentationFields.INTERFACE);
100 if (!statusRes.equals(StorageOperationStatus.OK)) {
101 logger.error("Failed to find the parent capability of capability type {}. status is {}", resourceId,
103 return Either.right(statusRes);
105 return Either.left(interfaceDefinition);
108 private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, GraphVertex graphVertex,
109 List<InterfaceDefinition> toscaDataList, JsonPresentationFields mapKeyField) {
111 return updateToscaDataOfToscaElement(graphVertex, EdgeLabelEnum.INTERFACE_ARTIFACTS,
112 VertexTypeEnum.INTERFACE_ARTIFACTS, toscaDataList, JsonPresentationFields.UNIQUE_ID);
114 return addToscaDataToToscaElement(graphVertex, EdgeLabelEnum.INTERFACE_ARTIFACTS,
115 VertexTypeEnum.INTERFACE_ARTIFACTS, toscaDataList, JsonPresentationFields.UNIQUE_ID);