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.jsontitan.operations;
23 import com.google.gson.Gson;
24 import com.google.gson.reflect.TypeToken;
25 import fj.data.Either;
26 import org.apache.commons.collections.CollectionUtils;
27 import org.apache.tinkerpop.gremlin.structure.Direction;
28 import org.apache.tinkerpop.gremlin.structure.Edge;
29 import org.apache.tinkerpop.gremlin.structure.Vertex;
30 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
31 import org.openecomp.sdc.be.config.ConfigurationManager;
32 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
33 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
34 import org.openecomp.sdc.be.dao.jsongraph.types.EdgePropertyEnum;
35 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
36 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
37 import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils;
38 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
39 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
40 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
41 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
42 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
43 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
44 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
45 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
46 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
47 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
48 import org.openecomp.sdc.be.model.ComponentParametersView;
49 import org.openecomp.sdc.be.model.LifecycleStateEnum;
50 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
51 import org.openecomp.sdc.be.model.category.CategoryDefinition;
52 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
53 import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType;
54 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
55 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
56 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
57 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
58 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
59 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
60 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
61 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
62 import org.openecomp.sdc.common.log.wrappers.Logger;
63 import org.openecomp.sdc.common.util.ValidationUtils;
64 import org.springframework.beans.factory.annotation.Autowired;
65 import org.springframework.util.StopWatch;
67 import java.lang.reflect.Type;
69 import java.util.Map.Entry;
70 import java.util.stream.Collectors;
71 import java.util.Iterator;
72 import java.util.List;
76 public abstract class ToscaElementOperation extends BaseOperation {
77 private static final String FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR = "failed to fetch {} for tosca element with id {}, error {}";
79 private static final String CANNOT_FIND_USER_IN_THE_GRAPH_STATUS_IS = "Cannot find user {} in the graph. status is {}";
81 private static final String FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS = "Failed to create edge with label {} from user vertex {} to tosca element vertex {} on graph. Status is {}. ";
83 private static Logger log = Logger.getLogger(ToscaElementOperation.class.getName());
85 private static final Gson gson = new Gson();
87 protected Gson getGson() {
92 protected CategoryOperation categoryOperation;
94 protected Either<GraphVertex, StorageOperationStatus> getComponentByLabelAndId(String uniqueId, ToscaElementTypeEnum nodeType, JsonParseFlagEnum parseFlag) {
96 Map<GraphPropertyEnum, Object> propertiesToMatch = new HashMap<>();
97 propertiesToMatch.put(GraphPropertyEnum.UNIQUE_ID, uniqueId);
99 VertexTypeEnum vertexType = ToscaElementTypeEnum.getVertexTypeByToscaType(nodeType);
100 Either<List<GraphVertex>, TitanOperationStatus> getResponse = titanDao.getByCriteria(vertexType, propertiesToMatch, parseFlag);
101 if (getResponse.isRight()) {
102 log.debug("Couldn't fetch component with type {} and unique id {}, error: {}", vertexType, uniqueId, getResponse.right().value());
103 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getResponse.right().value()));
106 List<GraphVertex> componentList = getResponse.left().value();
107 if (componentList.isEmpty()) {
108 log.debug("Component with type {} and unique id {} was not found", vertexType, uniqueId);
109 return Either.right(StorageOperationStatus.NOT_FOUND);
111 GraphVertex vertexG = componentList.get(0);
112 return Either.left(vertexG);
115 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId) {
116 return getToscaElement(uniqueId, new ComponentParametersView());
119 public Either<GraphVertex, StorageOperationStatus> markComponentToDelete(GraphVertex componentToDelete) {
120 Either<GraphVertex, StorageOperationStatus> result = null;
122 Boolean isDeleted = (Boolean) componentToDelete.getMetadataProperty(GraphPropertyEnum.IS_DELETED);
123 if (isDeleted != null && isDeleted && !(Boolean) componentToDelete.getMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION)) {
124 // component already marked for delete
125 result = Either.left(componentToDelete);
129 componentToDelete.addMetadataProperty(GraphPropertyEnum.IS_DELETED, Boolean.TRUE);
130 componentToDelete.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, System.currentTimeMillis());
132 Either<GraphVertex, TitanOperationStatus> updateNode = titanDao.updateVertex(componentToDelete);
134 StorageOperationStatus updateComponent;
135 if (updateNode.isRight()) {
136 log.debug("Failed to update component {}. status is {}", componentToDelete.getUniqueId(), updateNode.right().value());
137 updateComponent = DaoStatusConverter.convertTitanStatusToStorageStatus(updateNode.right().value());
138 result = Either.right(updateComponent);
142 result = Either.left(componentToDelete);
148 * Performs a shadow clone of previousToscaElement
150 * @param previousToscaElement
151 * @param nextToscaElement
155 public Either<GraphVertex, StorageOperationStatus> cloneToscaElement(GraphVertex previousToscaElement, GraphVertex nextToscaElement, GraphVertex user) {
157 Either<GraphVertex, StorageOperationStatus> result = null;
158 GraphVertex createdToscaElementVertex = null;
159 TitanOperationStatus status;
161 Either<GraphVertex, TitanOperationStatus> createNextVersionRes = titanDao.createVertex(nextToscaElement);
162 if (createNextVersionRes.isRight()) {
163 status = createNextVersionRes.right().value();
164 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create tosca element vertex {} with version {} on graph. Status is {}. ", previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME),
165 previousToscaElement.getMetadataProperty(GraphPropertyEnum.VERSION), status);
166 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
168 if (result == null) {
169 createdToscaElementVertex = createNextVersionRes.left().value();
170 Map<EdgePropertyEnum, Object> properties = new HashMap<>();
171 properties.put(EdgePropertyEnum.STATE, createdToscaElementVertex.getMetadataProperty(GraphPropertyEnum.STATE));
172 status = titanDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.STATE, properties);
173 if (status != TitanOperationStatus.OK) {
174 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS, EdgeLabelEnum.STATE, user.getUniqueId(),
175 previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
176 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
179 if (result == null) {
180 status = titanDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.LAST_MODIFIER, new HashMap<>());
181 if (status != TitanOperationStatus.OK) {
182 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS, EdgeLabelEnum.LAST_MODIFIER, user.getUniqueId(),
183 nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
184 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
187 if (result == null) {
188 status = titanDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.CREATOR, new HashMap<>());
189 if (status != TitanOperationStatus.OK) {
190 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS, EdgeLabelEnum.CREATOR, user.getUniqueId(),
191 nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
192 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
195 if (result == null) {
196 Iterator<Edge> edgesToCopyIter = previousToscaElement.getVertex().edges(Direction.OUT);
197 while (edgesToCopyIter.hasNext()) {
198 Edge currEdge = edgesToCopyIter.next();
199 Vertex currVertex = currEdge.inVertex();
200 status = titanDao.createEdge(createdToscaElementVertex.getVertex(), currVertex, EdgeLabelEnum.getEdgeLabelEnum(currEdge.label()), currEdge);
201 if (status != TitanOperationStatus.OK) {
202 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create edge with label {} from tosca element vertex {} to vertex with label {} on graph. Status is {}. ", currEdge.label(), createdToscaElementVertex.getUniqueId(),
203 currVertex.property(GraphPropertyEnum.LABEL.getProperty()), status);
204 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
210 if (result == null) {
211 result = Either.left(createdToscaElementVertex);
213 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to clone tosca element {} with the name {}. ", previousToscaElement.getUniqueId(), previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME));
218 protected TitanOperationStatus setLastModifierFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
219 Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(componentV, EdgeLabelEnum.LAST_MODIFIER, JsonParseFlagEnum.NoParse);
220 if (parentVertex.isRight()) {
221 log.debug("Failed to fetch last modifier for tosca element with id {} error {}", componentV.getUniqueId(), parentVertex.right().value());
222 return parentVertex.right().value();
224 GraphVertex userV = parentVertex.left().value();
225 String userId = (String) userV.getMetadataProperty(GraphPropertyEnum.USERID);
226 toscaElement.setLastUpdaterUserId(userId);
227 toscaElement.setLastUpdaterFullName(buildFullName(userV));
228 return TitanOperationStatus.OK;
231 public String buildFullName(GraphVertex userV) {
233 String fullName = (String) userV.getMetadataProperty(GraphPropertyEnum.FIRST_NAME);
234 if (fullName == null) {
237 fullName = fullName + " ";
239 String lastName = (String) userV.getMetadataProperty(GraphPropertyEnum.LAST_NAME);
240 if (lastName != null) {
241 fullName += lastName;
246 protected TitanOperationStatus setCreatorFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
247 Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(componentV, EdgeLabelEnum.CREATOR, JsonParseFlagEnum.NoParse);
248 if (parentVertex.isRight()) {
249 log.debug("Failed to fetch creator for tosca element with id {} error {}", componentV.getUniqueId(), parentVertex.right().value());
250 return parentVertex.right().value();
252 GraphVertex userV = parentVertex.left().value();
253 String creatorUserId = (String) userV.getMetadataProperty(GraphPropertyEnum.USERID);
254 toscaElement.setCreatorUserId(creatorUserId);
255 toscaElement.setCreatorFullName(buildFullName(userV));
257 return TitanOperationStatus.OK;
260 protected <T extends ToscaElement> T getResourceMetaDataFromResource(T toscaElement) {
261 if (toscaElement.getNormalizedName() == null || toscaElement.getNormalizedName().isEmpty()) {
262 toscaElement.setNormalizedName(ValidationUtils.normaliseComponentName(toscaElement.getName()));
264 if (toscaElement.getSystemName() == null || toscaElement.getSystemName().isEmpty()) {
265 toscaElement.setSystemName(ValidationUtils.convertToSystemName(toscaElement.getName()));
268 LifecycleStateEnum lifecycleStateEnum = toscaElement.getLifecycleState();
269 if (lifecycleStateEnum == null) {
270 toscaElement.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
272 long currentDate = System.currentTimeMillis();
273 if (toscaElement.getCreationDate() == null) {
274 toscaElement.setCreationDate(currentDate);
276 toscaElement.setLastUpdateDate(currentDate);
281 protected void fillCommonMetadata(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
282 if (toscaElement.isHighestVersion() == null) {
283 toscaElement.setHighestVersion(true);
285 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_DELETED, toscaElement.getMetadataValue(JsonPresentationFields.IS_DELETED));
286 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION, toscaElement.getMetadataValueOrDefault(JsonPresentationFields.HIGHEST_VERSION, Boolean.TRUE));
287 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.STATE, toscaElement.getMetadataValue(JsonPresentationFields.LIFECYCLE_STATE));
288 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.RESOURCE_TYPE, toscaElement.getMetadataValue(JsonPresentationFields.RESOURCE_TYPE));
289 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.VERSION, toscaElement.getMetadataValue(JsonPresentationFields.VERSION));
290 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME, toscaElement.getMetadataValue(JsonPresentationFields.NORMALIZED_NAME));
291 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, toscaElement.getMetadataValue(JsonPresentationFields.UNIQUE_ID));
292 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaElement.getMetadataValue(JsonPresentationFields.TOSCA_RESOURCE_NAME));
293 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.UUID, toscaElement.getMetadataValue(JsonPresentationFields.UUID));
294 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_ABSTRACT, toscaElement.getMetadataValue(JsonPresentationFields.IS_ABSTRACT));
295 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.INVARIANT_UUID, toscaElement.getMetadataValue(JsonPresentationFields.INVARIANT_UUID));
296 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.NAME, toscaElement.getMetadataValue(JsonPresentationFields.NAME));
297 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.SYSTEM_NAME, toscaElement.getMetadataValue(JsonPresentationFields.SYSTEM_NAME));
298 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_ARCHIVED, toscaElement.getMetadataValue(JsonPresentationFields.IS_ARCHIVED));
299 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.ARCHIVE_TIME, toscaElement.getMetadataValue(JsonPresentationFields.ARCHIVE_TIME));
300 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_VSP_ARCHIVED, toscaElement.getMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED));
301 toscaElement.getMetadata().entrySet().stream().filter(e -> e.getValue() != null).forEach(e -> nodeTypeVertex.setJsonMetadataField(JsonPresentationFields.getByPresentation(e.getKey()), e.getValue()));
303 nodeTypeVertex.setUniqueId(toscaElement.getUniqueId());
304 nodeTypeVertex.setType(toscaElement.getComponentType());
308 protected StorageOperationStatus assosiateToUsers(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
310 String userId = toscaElement.getCreatorUserId();
312 Either<GraphVertex, TitanOperationStatus> findUser = findUserVertex(userId);
314 if (findUser.isRight()) {
315 TitanOperationStatus status = findUser.right().value();
316 log.error(CANNOT_FIND_USER_IN_THE_GRAPH_STATUS_IS, userId, status);
317 return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
320 GraphVertex creatorVertex = findUser.left().value();
321 GraphVertex updaterVertex = creatorVertex;
322 String updaterId = toscaElement.getLastUpdaterUserId();
323 if (updaterId != null && !updaterId.equals(userId)) {
324 findUser = findUserVertex(updaterId);
325 if (findUser.isRight()) {
326 TitanOperationStatus status = findUser.right().value();
327 log.error(CANNOT_FIND_USER_IN_THE_GRAPH_STATUS_IS, userId, status);
328 return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
330 updaterVertex = findUser.left().value();
333 Map<EdgePropertyEnum, Object> props = new HashMap<>();
334 props.put(EdgePropertyEnum.STATE, (String) toscaElement.getMetadataValue(JsonPresentationFields.LIFECYCLE_STATE));
336 TitanOperationStatus result = titanDao.createEdge(updaterVertex, nodeTypeVertex, EdgeLabelEnum.STATE, props);
337 log.debug("After associating user {} to resource {}. Edge type is {}", updaterVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.STATE);
338 if (TitanOperationStatus.OK != result) {
339 return DaoStatusConverter.convertTitanStatusToStorageStatus(result);
341 result = titanDao.createEdge(updaterVertex, nodeTypeVertex, EdgeLabelEnum.LAST_MODIFIER, null);
342 log.debug("After associating user {} to resource {}. Edge type is {}", updaterVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.LAST_MODIFIER);
343 if (!result.equals(TitanOperationStatus.OK)) {
344 log.error("Failed to associate user {} to resource {}. Edge type is {}", updaterVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.LAST_MODIFIER);
345 return DaoStatusConverter.convertTitanStatusToStorageStatus(result);
348 toscaElement.setLastUpdaterUserId(toscaElement.getCreatorUserId());
349 toscaElement.setLastUpdaterFullName(toscaElement.getCreatorFullName());
351 result = titanDao.createEdge(creatorVertex, nodeTypeVertex, EdgeLabelEnum.CREATOR, null);
352 log.debug("After associating user {} to resource {}. Edge type is {} ", creatorVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.CREATOR);
353 if (!result.equals(TitanOperationStatus.OK)) {
354 log.error("Failed to associate user {} to resource {}. Edge type is {} ", creatorVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.CREATOR);
355 return DaoStatusConverter.convertTitanStatusToStorageStatus(result);
357 return StorageOperationStatus.OK;
360 protected StorageOperationStatus assosiateResourceMetadataToCategory(GraphVertex nodeTypeVertex, ToscaElement nodeType) {
361 String subcategoryName = nodeType.getCategories().get(0).getSubcategories().get(0).getName();
362 String categoryName = nodeType.getCategories().get(0).getName();
363 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = getResourceCategoryVertex(nodeType.getUniqueId(), subcategoryName, categoryName);
365 if (getCategoryVertex.isRight()) {
366 return getCategoryVertex.right().value();
369 GraphVertex subCategoryV = getCategoryVertex.left().value();
371 TitanOperationStatus createEdge = titanDao.createEdge(nodeTypeVertex, subCategoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
372 if (createEdge != TitanOperationStatus.OK) {
373 log.trace("Failed to associate resource {} to category {} with id {}", nodeType.getUniqueId(), subcategoryName, subCategoryV.getUniqueId());
374 return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
376 return StorageOperationStatus.OK;
379 protected Either<GraphVertex, StorageOperationStatus> getResourceCategoryVertex(String elementId, String subcategoryName, String categoryName) {
380 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
381 if (category.isRight()) {
382 log.trace("Failed to fetch category {} for resource {} error {}", categoryName, elementId, category.right().value());
383 return Either.right(category.right().value());
385 GraphVertex categoryV = category.left().value();
387 if (subcategoryName != null) {
388 Either<GraphVertex, StorageOperationStatus> subCategory = categoryOperation.getSubCategoryForCategory(categoryV, subcategoryName);
389 if (subCategory.isRight()) {
390 log.trace("Failed to fetch subcategory {} of category for resource {} error {}", subcategoryName, categoryName, elementId, subCategory.right().value());
391 return Either.right(subCategory.right().value());
394 GraphVertex subCategoryV = subCategory.left().value();
395 return Either.left(subCategoryV);
397 return Either.left(categoryV);
400 private StorageOperationStatus associateArtifactsToResource(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
401 Map<String, ArtifactDataDefinition> artifacts = toscaElement.getArtifacts();
402 Either<GraphVertex, StorageOperationStatus> status;
403 if (artifacts != null) {
404 artifacts.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
405 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
406 a.setUniqueId(uniqueId);
408 status = associateElementToData(nodeTypeVertex, VertexTypeEnum.ARTIFACTS, EdgeLabelEnum.ARTIFACTS, artifacts);
409 if (status.isRight()) {
410 return status.right().value();
413 Map<String, ArtifactDataDefinition> toscaArtifacts = toscaElement.getToscaArtifacts();
414 if (toscaArtifacts != null) {
415 toscaArtifacts.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
416 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
417 a.setUniqueId(uniqueId);
419 status = associateElementToData(nodeTypeVertex, VertexTypeEnum.TOSCA_ARTIFACTS, EdgeLabelEnum.TOSCA_ARTIFACTS, toscaArtifacts);
420 if (status.isRight()) {
421 return status.right().value();
424 Map<String, ArtifactDataDefinition> deploymentArtifacts = toscaElement.getDeploymentArtifacts();
425 if (deploymentArtifacts != null) {
426 deploymentArtifacts.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
427 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
428 a.setUniqueId(uniqueId);
430 status = associateElementToData(nodeTypeVertex, VertexTypeEnum.DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS, deploymentArtifacts);
431 if (status.isRight()) {
432 return status.right().value();
435 return StorageOperationStatus.OK;
438 protected TitanOperationStatus disassociateAndDeleteCommonElements(GraphVertex toscaElementVertex) {
439 TitanOperationStatus status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.ARTIFACTS);
440 if (status != TitanOperationStatus.OK) {
441 log.debug("Failed to disaccociate artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
444 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.TOSCA_ARTIFACTS);
445 if (status != TitanOperationStatus.OK) {
446 log.debug("Failed to disaccociate tosca artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
449 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS);
450 if (status != TitanOperationStatus.OK) {
451 log.debug("Failed to deployment artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
454 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.PROPERTIES);
455 if (status != TitanOperationStatus.OK) {
456 log.debug("Failed to disaccociate properties for {} error {}", toscaElementVertex.getUniqueId(), status);
459 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.ATTRIBUTES);
460 if (status != TitanOperationStatus.OK) {
461 log.debug("Failed to disaccociate attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
464 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.ADDITIONAL_INFORMATION);
465 if (status != TitanOperationStatus.OK) {
466 log.debug("Failed to disaccociate additional information for {} error {}", toscaElementVertex.getUniqueId(), status);
469 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES);
470 if (status != TitanOperationStatus.OK) {
471 log.debug("Failed to disaccociate capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
474 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.REQUIREMENTS);
475 if (status != TitanOperationStatus.OK) {
476 log.debug("Failed to disaccociate requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
479 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
480 if (status != TitanOperationStatus.OK) {
481 log.debug("Failed to disaccociate requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
484 return TitanOperationStatus.OK;
487 protected StorageOperationStatus assosiateCommonForToscaElement(GraphVertex nodeTypeVertex, ToscaElement toscaElement, List<GraphVertex> derivedResources) {
489 StorageOperationStatus associateUsers = assosiateToUsers(nodeTypeVertex, toscaElement);
490 if (associateUsers != StorageOperationStatus.OK) {
491 return associateUsers;
493 StorageOperationStatus associateArtifacts = associateArtifactsToResource(nodeTypeVertex, toscaElement);
494 if (associateArtifacts != StorageOperationStatus.OK) {
495 return associateArtifacts;
497 StorageOperationStatus associateProperties = associatePropertiesToResource(nodeTypeVertex, toscaElement, derivedResources);
498 if (associateProperties != StorageOperationStatus.OK) {
499 return associateProperties;
501 StorageOperationStatus associateAdditionaInfo = associateAdditionalInfoToResource(nodeTypeVertex, toscaElement);
502 if (associateAdditionaInfo != StorageOperationStatus.OK) {
503 return associateAdditionaInfo;
505 if (needConnectToCatalog(toscaElement)) {
506 StorageOperationStatus associateToCatalog = associateToCatalogRoot(nodeTypeVertex);
507 if (associateToCatalog != StorageOperationStatus.OK) {
508 return associateToCatalog;
511 return StorageOperationStatus.OK;
514 private boolean needConnectToCatalog(ToscaElement toscaElement) {
515 Boolean isAbstract = (Boolean) toscaElement.getMetadataValue(JsonPresentationFields.IS_ABSTRACT);
516 if (isAbstract != null && isAbstract) {
519 return toscaElement.isHighestVersion();
522 private StorageOperationStatus associateToCatalogRoot(GraphVertex nodeTypeVertex) {
523 Either<GraphVertex, TitanOperationStatus> catalog = titanDao.getVertexByLabel(VertexTypeEnum.CATALOG_ROOT);
524 if (catalog.isRight()) {
525 log.debug("Failed to fetch catalog vertex. error {}", catalog.right().value());
526 return DaoStatusConverter.convertTitanStatusToStorageStatus(catalog.right().value());
528 TitanOperationStatus createEdge = titanDao.createEdge(catalog.left().value(), nodeTypeVertex, EdgeLabelEnum.CATALOG_ELEMENT, null);
530 return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
533 protected StorageOperationStatus associatePropertiesToResource(GraphVertex nodeTypeVertex, ToscaElement nodeType, List<GraphVertex> derivedResources) {
534 // Note : currently only one derived supported!!!!
535 Either<Map<String, PropertyDataDefinition>, StorageOperationStatus> dataFromDerived = getDataFromDerived(derivedResources, EdgeLabelEnum.PROPERTIES);
536 if (dataFromDerived.isRight()) {
537 return dataFromDerived.right().value();
539 Map<String, PropertyDataDefinition> propertiesAll = dataFromDerived.left().value();
541 Map<String, PropertyDataDefinition> properties = nodeType.getProperties();
543 if (properties != null) {
544 properties.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
545 String uid = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId(), p.getName());
549 Either<Map<String, PropertyDataDefinition>, String> eitherMerged = ToscaDataDefinition.mergeDataMaps(propertiesAll, properties);
550 if (eitherMerged.isRight()) {
551 // TODO re-factor error handling - moving BL to operation resulted in loss of info about the invalid property
552 log.debug("property {} cannot be overriden", eitherMerged.right().value());
553 return StorageOperationStatus.INVALID_PROPERTY;
556 if (!propertiesAll.isEmpty()) {
557 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.PROPERTIES, EdgeLabelEnum.PROPERTIES, propertiesAll);
558 if (assosiateElementToData.isRight()) {
559 return assosiateElementToData.right().value();
562 return StorageOperationStatus.OK;
565 private StorageOperationStatus associateAdditionalInfoToResource(GraphVertex nodeTypeVertex, ToscaElement nodeType) {
566 Map<String, AdditionalInfoParameterDataDefinition> additionalInformation = nodeType.getAdditionalInformation();
567 if (additionalInformation != null) {
568 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, additionalInformation);
569 if (assosiateElementToData.isRight()) {
570 return assosiateElementToData.right().value();
573 return StorageOperationStatus.OK;
576 protected <T extends ToscaDataDefinition> Either<Map<String, T>, StorageOperationStatus> getDataFromDerived(List<GraphVertex> derivedResources, EdgeLabelEnum edge) {
577 Map<String, T> propertiesAll = new HashMap<>();
579 if (derivedResources != null && !derivedResources.isEmpty()) {
580 for (GraphVertex derived : derivedResources) {
581 Either<List<GraphVertex>, TitanOperationStatus> derivedProperties = titanDao.getChildrenVertecies(derived, edge, JsonParseFlagEnum.ParseJson);
582 if (derivedProperties.isRight()) {
583 if (derivedProperties.right().value() != TitanOperationStatus.NOT_FOUND) {
584 log.debug("Failed to get properties for derived from {} error {}", derived.getUniqueId(), derivedProperties.right().value());
585 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(derivedProperties.right().value()));
590 List<GraphVertex> propList = derivedProperties.left().value();
591 for (GraphVertex propV : propList) {
592 Map<String, T> propertiesFromDerived = (Map<String, T>) propV.getJson();
593 if (propertiesFromDerived != null) {
594 propertiesFromDerived.entrySet().forEach(x -> x.getValue().setOwnerIdIfEmpty(derived.getUniqueId()));
595 propertiesAll.putAll(propertiesFromDerived);
600 return Either.left(propertiesAll);
603 protected TitanOperationStatus setArtifactsFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
604 Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.ARTIFACTS);
605 if (result.isLeft()) {
606 toscaElement.setArtifacts(result.left().value());
608 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
609 return result.right().value();
612 result = getDataFromGraph(componentV, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS);
613 if (result.isLeft()) {
614 toscaElement.setDeploymentArtifacts(result.left().value());
616 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
617 return result.right().value();
620 result = getDataFromGraph(componentV, EdgeLabelEnum.TOSCA_ARTIFACTS);
621 if (result.isLeft()) {
622 toscaElement.setToscaArtifacts(result.left().value());
624 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
625 return result.right().value();
628 return TitanOperationStatus.OK;
631 protected TitanOperationStatus setAllVersions(GraphVertex componentV, ToscaElement toscaElement) {
632 Map<String, String> allVersion = new HashMap<>();
634 allVersion.put((String) componentV.getMetadataProperty(GraphPropertyEnum.VERSION), componentV.getUniqueId());
635 ArrayList<GraphVertex> allChildrenAndParants = new ArrayList<>();
636 Either<GraphVertex, TitanOperationStatus> childResourceRes = titanDao.getChildVertex(componentV, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
637 while (childResourceRes.isLeft()) {
638 GraphVertex child = childResourceRes.left().value();
639 allChildrenAndParants.add(child);
640 childResourceRes = titanDao.getChildVertex(child, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
642 TitanOperationStatus operationStatus = childResourceRes.right().value();
644 if (operationStatus != TitanOperationStatus.NOT_FOUND) {
645 return operationStatus;
647 Either<GraphVertex, TitanOperationStatus> parentResourceRes = titanDao.getParentVertex(componentV, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
648 while (parentResourceRes.isLeft()) {
649 GraphVertex parent = parentResourceRes.left().value();
650 allChildrenAndParants.add(parent);
651 parentResourceRes = titanDao.getParentVertex(parent, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
653 operationStatus = parentResourceRes.right().value();
654 if (operationStatus != TitanOperationStatus.NOT_FOUND) {
655 return operationStatus;
657 allChildrenAndParants.stream().filter(vertex -> {
658 Boolean isDeleted = (Boolean) vertex.getMetadataProperty(GraphPropertyEnum.IS_DELETED);
659 return (isDeleted == null || !isDeleted);
660 }).forEach(vertex -> allVersion.put((String) vertex.getMetadataProperty(GraphPropertyEnum.VERSION), vertex.getUniqueId()));
662 toscaElement.setAllVersions(allVersion);
663 return TitanOperationStatus.OK;
668 protected <T extends ToscaElement> Either<List<T>, StorageOperationStatus> getFollowedComponent(String userId, Set<LifecycleStateEnum> lifecycleStates, Set<LifecycleStateEnum> lastStateStates, ComponentTypeEnum neededType) {
670 Either<List<T>, StorageOperationStatus> result = null;
672 Map<GraphPropertyEnum, Object> props = null;
674 if (userId != null) {
675 props = new HashMap<>();
676 // for Designer retrieve specific user
677 props.put(GraphPropertyEnum.USERID, userId);
679 // in case of user id == null -> get all users by label
680 // for Tester and Admin retrieve all users
681 Either<List<GraphVertex>, TitanOperationStatus> usersByCriteria = titanDao.getByCriteria(VertexTypeEnum.USER, props, JsonParseFlagEnum.NoParse);
682 if (usersByCriteria.isRight()) {
683 log.debug("Failed to fetch users by criteria {} error {}", props, usersByCriteria.right().value());
684 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(usersByCriteria.right().value()));
686 List<GraphVertex> users = usersByCriteria.left().value();
688 List<T> components = new ArrayList<>();
689 List<T> componentsPerUser;
690 for (GraphVertex userV : users) {
692 HashSet<String> ids = new HashSet<>();
693 Either<List<GraphVertex>, TitanOperationStatus> childrenVertecies = titanDao.getChildrenVertecies(userV, EdgeLabelEnum.STATE, JsonParseFlagEnum.NoParse);
694 if (childrenVertecies.isRight() && childrenVertecies.right().value() != TitanOperationStatus.NOT_FOUND) {
695 log.debug("Failed to fetch children vertices for user {} by edge {} error {}", userV.getMetadataProperty(GraphPropertyEnum.USERID), EdgeLabelEnum.STATE, childrenVertecies.right().value());
696 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(childrenVertecies.right().value()));
699 // get all resource with current state
700 if (childrenVertecies.isLeft()) {
701 componentsPerUser = fetchComponents(lifecycleStates, childrenVertecies.left().value(), neededType, EdgeLabelEnum.STATE);
703 if (componentsPerUser != null) {
704 for (T comp : componentsPerUser) {
705 ids.add(comp.getUniqueId());
706 components.add(comp);
710 if (lastStateStates != null && !lastStateStates.isEmpty()) {
711 // get all resource with last state
712 childrenVertecies = titanDao.getChildrenVertecies(userV, EdgeLabelEnum.LAST_STATE, JsonParseFlagEnum.NoParse);
713 if (childrenVertecies.isRight() && childrenVertecies.right().value() != TitanOperationStatus.NOT_FOUND) {
714 log.debug("Failed to fetch children vertices for user {} by edge {} error {}", userV.getMetadataProperty(GraphPropertyEnum.USERID), EdgeLabelEnum.LAST_STATE, childrenVertecies.right().value());
715 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(childrenVertecies.right().value()));
717 if (childrenVertecies.isLeft()) {
719 componentsPerUser = fetchComponents(lastStateStates, childrenVertecies.left().value(), neededType, EdgeLabelEnum.LAST_STATE);
720 if (componentsPerUser != null) {
721 for (T comp : componentsPerUser) {
724 if (ids.contains(comp.getUniqueId())) {
728 components.add(comp);
738 result = Either.left(components);
743 private <T extends ToscaElement> List<T> fetchComponents(Set<LifecycleStateEnum> lifecycleStates, List<GraphVertex> vertices, ComponentTypeEnum neededType, EdgeLabelEnum edgelabel) {
744 List<T> components = new ArrayList<>();
745 for (GraphVertex node : vertices) {
747 Iterator<Edge> edges = node.getVertex().edges(Direction.IN, edgelabel.name());
748 while (edges.hasNext()) {
749 Edge edge = edges.next();
750 String stateStr = (String) titanDao.getProperty(edge, EdgePropertyEnum.STATE);
752 LifecycleStateEnum nodeState = LifecycleStateEnum.findState(stateStr);
753 if (nodeState == null) {
754 log.debug("no supported STATE {} for element {}", stateStr, node.getUniqueId());
757 if (lifecycleStates != null && lifecycleStates.contains(nodeState)) {
759 Boolean isDeleted = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_DELETED);
760 Boolean isArchived = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_ARCHIVED);
761 if (isDeleted != null && isDeleted || isArchived != null && isArchived) {
762 log.trace("Deleted/Archived element {}, discard", node.getUniqueId());
766 Boolean isHighest = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION);
769 ComponentTypeEnum componentType = node.getType();
770 // get only latest versions
772 if (componentType == null) {
773 log.debug("No supported type {} for vertex {}", componentType, node.getUniqueId());
776 if (neededType == componentType) {
777 switch (componentType) {
780 handleNode(components, node, componentType);
783 Boolean isAbtract = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_ABSTRACT);
784 if (isAbtract == null || !isAbtract) {
785 handleNode(components, node, componentType);
789 log.debug("not supported node type {}", componentType);
800 protected <T extends ToscaElement> void handleNode(List<T> components, GraphVertex vertexComponent, ComponentTypeEnum nodeType) {
802 Either<T, StorageOperationStatus> component = getLightComponent(vertexComponent, nodeType, new ComponentParametersView(true));
803 if (component.isRight()) {
804 log.debug("Failed to get component for id = {} error : {} skip resource", vertexComponent.getUniqueId(), component.right().value());
806 components.add(component.left().value());
810 protected <T extends ToscaElement> Either<T, StorageOperationStatus> getLightComponent(String componentUid, ComponentTypeEnum nodeType, ComponentParametersView parametersFilter) {
811 Either<GraphVertex, TitanOperationStatus> getVertexRes = titanDao.getVertexById(componentUid);
812 if (getVertexRes.isRight()) {
813 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexRes.right().value()));
815 return getLightComponent(getVertexRes.left().value(), nodeType, parametersFilter);
818 protected <T extends ToscaElement> Either<T, StorageOperationStatus> getLightComponent(GraphVertex vertexComponent, ComponentTypeEnum nodeType, ComponentParametersView parametersFilter) {
820 log.trace("Starting to build light component of type {}, id {}", nodeType, vertexComponent.getUniqueId());
822 titanDao.parseVertexProperties(vertexComponent, JsonParseFlagEnum.ParseMetadata);
824 T toscaElement = convertToComponent(vertexComponent);
826 TitanOperationStatus status = setCreatorFromGraph(vertexComponent, toscaElement);
827 if (status != TitanOperationStatus.OK) {
828 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
831 status = setLastModifierFromGraph(vertexComponent, toscaElement);
832 if (status != TitanOperationStatus.OK) {
833 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
835 status = setCategoriesFromGraph(vertexComponent, toscaElement);
836 if (status != TitanOperationStatus.OK) {
837 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
839 if (!parametersFilter.isIgnoreAllVersions()) {
840 status = setAllVersions(vertexComponent, toscaElement);
841 if (status != TitanOperationStatus.OK) {
842 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
845 if (!parametersFilter.isIgnoreCapabilities()) {
846 status = setCapabilitiesFromGraph(vertexComponent, toscaElement);
847 if (status != TitanOperationStatus.OK) {
848 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
851 if (!parametersFilter.isIgnoreRequirements()) {
852 status = setRequirementsFromGraph(vertexComponent, toscaElement);
853 if (status != TitanOperationStatus.OK) {
854 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
857 log.debug("Ended to build light component of type {}, id {}", nodeType, vertexComponent.getUniqueId());
858 return Either.left(toscaElement);
861 @SuppressWarnings("unchecked")
862 protected <T extends ToscaElement> T convertToComponent(GraphVertex componentV) {
863 ToscaElement toscaElement = null;
864 VertexTypeEnum label = componentV.getLabel();
867 toscaElement = new NodeType();
869 case TOPOLOGY_TEMPLATE:
870 toscaElement = new TopologyTemplate();
873 log.debug("Not supported tosca type {}", label);
877 Map<String, Object> jsonMetada = componentV.getMetadataJson();
878 if (toscaElement != null) {
879 toscaElement.setMetadata(jsonMetada);
881 return (T) toscaElement;
884 protected TitanOperationStatus setResourceCategoryFromGraphV(Vertex vertex, CatalogComponent catalogComponent) {
886 Either<Vertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(vertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
887 if (childVertex.isRight()) {
888 log.debug(FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR, EdgeLabelEnum.CATEGORY, catalogComponent.getUniqueId(), childVertex.right().value());
889 return childVertex.right().value();
891 Vertex subCategoryV = childVertex.left().value();
892 catalogComponent.setSubCategoryNormalizedName((String) subCategoryV.property(JsonPresentationFields.NORMALIZED_NAME.getPresentation()).value());
893 Either<Vertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
894 Vertex categoryV = parentVertex.left().value();
895 catalogComponent.setCategoryNormalizedName((String) categoryV.property(JsonPresentationFields.NORMALIZED_NAME.getPresentation()).value());
897 return TitanOperationStatus.OK;
900 protected TitanOperationStatus setServiceCategoryFromGraphV(Vertex vertex, CatalogComponent catalogComponent) {
901 Either<Vertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(vertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
902 if (childVertex.isRight()) {
903 log.debug(FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR, EdgeLabelEnum.CATEGORY, catalogComponent.getUniqueId(), childVertex.right().value());
904 return childVertex.right().value();
906 Vertex categoryV = childVertex.left().value();
907 catalogComponent.setCategoryNormalizedName((String) categoryV.property(JsonPresentationFields.NORMALIZED_NAME.getPresentation()).value());
909 return TitanOperationStatus.OK;
912 protected TitanOperationStatus setResourceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
913 List<CategoryDefinition> categories = new ArrayList<>();
914 SubCategoryDefinition subcategory;
916 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
917 if (childVertex.isRight()) {
918 log.debug(FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR, EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
919 return childVertex.right().value();
921 GraphVertex subCategoryV = childVertex.left().value();
922 Map<GraphPropertyEnum, Object> metadataProperties = subCategoryV.getMetadataProperties();
923 subcategory = new SubCategoryDefinition();
924 subcategory.setUniqueId(subCategoryV.getUniqueId());
925 subcategory.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
926 subcategory.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
928 Type listTypeSubcat = new TypeToken<List<String>>() {
930 List<String> iconsfromJsonSubcat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS), listTypeSubcat);
931 subcategory.setIcons(iconsfromJsonSubcat);
933 Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
934 if (parentVertex.isRight()) {
935 log.debug("failed to fetch {} for category with id {}, error {}", EdgeLabelEnum.SUB_CATEGORY, subCategoryV.getUniqueId(), parentVertex.right().value());
936 return childVertex.right().value();
938 GraphVertex categoryV = parentVertex.left().value();
939 metadataProperties = categoryV.getMetadataProperties();
941 CategoryDefinition category = new CategoryDefinition();
942 category.setUniqueId(categoryV.getUniqueId());
943 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
944 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
946 Type listTypeCat = new TypeToken<List<String>>() {
948 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS), listTypeCat);
949 category.setIcons(iconsfromJsonCat);
951 category.addSubCategory(subcategory);
952 categories.add(category);
953 toscaElement.setCategories(categories);
955 return TitanOperationStatus.OK;
958 public <T extends ToscaElement> Either<T, StorageOperationStatus> updateToscaElement(T toscaElementToUpdate, GraphVertex elementV, ComponentParametersView filterResult) {
959 Either<T, StorageOperationStatus> result = null;
961 log.debug("In updateToscaElement. received component uid = {}", (toscaElementToUpdate == null ? null : toscaElementToUpdate.getUniqueId()));
962 if (toscaElementToUpdate == null) {
963 log.error("Service object is null");
964 result = Either.right(StorageOperationStatus.BAD_REQUEST);
968 String modifierUserId = toscaElementToUpdate.getLastUpdaterUserId();
969 if (modifierUserId == null || modifierUserId.isEmpty()) {
970 log.error("UserId is missing in the request.");
971 result = Either.right(StorageOperationStatus.BAD_REQUEST);
974 Either<GraphVertex, TitanOperationStatus> findUser = findUserVertex(modifierUserId);
976 if (findUser.isRight()) {
977 TitanOperationStatus status = findUser.right().value();
978 log.error(CANNOT_FIND_USER_IN_THE_GRAPH_STATUS_IS, modifierUserId, status);
982 GraphVertex modifierV = findUser.left().value();
983 String toscaElementId = toscaElementToUpdate.getUniqueId();
985 Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(elementV, EdgeLabelEnum.LAST_MODIFIER, JsonParseFlagEnum.NoParse);
986 if (parentVertex.isRight()) {
987 log.debug("Failed to fetch last modifier for tosca element with id {} error {}", toscaElementId, parentVertex.right().value());
988 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(parentVertex.right().value()));
990 GraphVertex userV = parentVertex.left().value();
991 String currentModifier = (String) userV.getMetadataProperty(GraphPropertyEnum.USERID);
993 String prevSystemName = (String) elementV.getMetadataProperty(GraphPropertyEnum.SYSTEM_NAME);
995 if (currentModifier.equals(modifierUserId)) {
996 log.debug("Graph LAST MODIFIER edge should not be changed since the modifier is the same as the last modifier.");
998 log.debug("Going to update the last modifier user of the resource from {} to {}", currentModifier, modifierUserId);
999 StorageOperationStatus status = moveLastModifierEdge(elementV, modifierV);
1000 log.debug("Finish to update the last modifier user of the resource from {} to {}. status is {}", currentModifier, modifierUserId, status);
1001 if (status != StorageOperationStatus.OK) {
1002 result = Either.right(status);
1007 final long currentTimeMillis = System.currentTimeMillis();
1008 log.debug("Going to update the last Update Date of the resource from {} to {}", elementV.getJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE), currentTimeMillis);
1009 elementV.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, currentTimeMillis);
1011 StorageOperationStatus checkCategories = validateCategories(toscaElementToUpdate, elementV);
1012 if (checkCategories != StorageOperationStatus.OK) {
1013 result = Either.right(checkCategories);
1017 // update all data on vertex
1018 fillToscaElementVertexData(elementV, toscaElementToUpdate, JsonParseFlagEnum.ParseMetadata);
1020 Either<GraphVertex, TitanOperationStatus> updateElement = titanDao.updateVertex(elementV);
1022 if (updateElement.isRight()) {
1023 log.error("Failed to update resource {}. status is {}", toscaElementId, updateElement.right().value());
1024 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateElement.right().value()));
1027 GraphVertex updateElementV = updateElement.left().value();
1029 // DE230195 in case resource name changed update TOSCA artifacts
1030 // file names accordingly
1031 String newSystemName = (String) updateElementV.getMetadataProperty(GraphPropertyEnum.SYSTEM_NAME);
1032 if (newSystemName != null && !newSystemName.equals(prevSystemName)) {
1033 Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> resultToscaArt = getDataFromGraph(updateElementV, EdgeLabelEnum.TOSCA_ARTIFACTS);
1034 if (resultToscaArt.isRight()) {
1035 log.debug("Failed to get tosca artifact from graph for tosca element {} error {}", toscaElementId, resultToscaArt.right().value());
1036 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resultToscaArt.right().value()));
1039 Map<String, ArtifactDataDefinition> toscaArtifacts = resultToscaArt.left().value();
1040 if (toscaArtifacts != null) {
1041 for (Entry<String, ArtifactDataDefinition> artifact : toscaArtifacts.entrySet()) {
1042 generateNewToscaFileName(toscaElementToUpdate.getComponentType().getValue().toLowerCase(), newSystemName, artifact.getValue());
1044 // TODO call to new Artifact operation in order to update list of artifacts
1049 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.RESOURCE) {
1050 StorageOperationStatus resultDerived = updateDerived(toscaElementToUpdate, updateElementV);
1051 if (resultDerived != StorageOperationStatus.OK) {
1052 log.debug("Failed to update from derived data for element {} error {}", toscaElementId, resultDerived);
1053 return Either.right(resultDerived);
1057 Either<T, StorageOperationStatus> updatedResource = getToscaElement(updateElementV, filterResult);
1058 if (updatedResource.isRight()) {
1059 log.error("Failed to fetch tosca element {} after update , error {}", toscaElementId, updatedResource.right().value());
1060 result = Either.right(StorageOperationStatus.BAD_REQUEST);
1064 T updatedResourceValue = updatedResource.left().value();
1065 result = Either.left(updatedResourceValue);
1070 protected StorageOperationStatus moveLastModifierEdge(GraphVertex elementV, GraphVertex modifierV) {
1071 return DaoStatusConverter.convertTitanStatusToStorageStatus(titanDao.moveEdge(elementV, modifierV, EdgeLabelEnum.LAST_MODIFIER, Direction.IN));
1074 protected StorageOperationStatus moveCategoryEdge(GraphVertex elementV, GraphVertex categoryV) {
1075 return DaoStatusConverter.convertTitanStatusToStorageStatus(titanDao.moveEdge(elementV, categoryV, EdgeLabelEnum.CATEGORY, Direction.OUT));
1078 private void generateNewToscaFileName(String componentType, String componentName, ArtifactDataDefinition artifactInfo) {
1079 Map<String, Object> getConfig = (Map<String, Object>) ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts().entrySet().stream().filter(p -> p.getKey().equalsIgnoreCase(artifactInfo.getArtifactLabel()))
1080 .findAny().get().getValue();
1081 artifactInfo.setArtifactName(componentType + "-" + componentName + getConfig.get("artifactName"));
1084 protected <T extends ToscaElement> StorageOperationStatus validateResourceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1085 StorageOperationStatus status = StorageOperationStatus.OK;
1086 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1087 CategoryDefinition newCategory = newCategoryList.get(0);
1089 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1090 if (childVertex.isRight()) {
1091 log.debug(FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR, EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1092 return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
1094 GraphVertex subCategoryV = childVertex.left().value();
1095 Map<GraphPropertyEnum, Object> metadataProperties = subCategoryV.getMetadataProperties();
1096 String subCategoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1098 Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
1099 if (parentVertex.isRight()) {
1100 log.debug("failed to fetch {} for category with id {}, error {}", EdgeLabelEnum.SUB_CATEGORY, subCategoryV.getUniqueId(), parentVertex.right().value());
1101 return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
1103 GraphVertex categoryV = parentVertex.left().value();
1104 metadataProperties = categoryV.getMetadataProperties();
1105 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1107 boolean categoryWasChanged = false;
1109 String newCategoryName = newCategory.getName();
1110 SubCategoryDefinition newSubcategory = newCategory.getSubcategories().get(0);
1111 String newSubCategoryName = newSubcategory.getName();
1112 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1113 // the category was changed
1114 categoryWasChanged = true;
1116 // the sub-category was changed
1117 if (newSubCategoryName != null && !newSubCategoryName.equals(subCategoryNameCurrent)) {
1118 log.debug("Going to update the category of the resource from {} to {}", categoryNameCurrent, newCategory);
1119 categoryWasChanged = true;
1122 if (categoryWasChanged) {
1123 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = getResourceCategoryVertex(elementV.getUniqueId(), newSubCategoryName, newCategoryName);
1125 if (getCategoryVertex.isRight()) {
1126 return getCategoryVertex.right().value();
1128 GraphVertex newCategoryV = getCategoryVertex.left().value();
1129 status = moveCategoryEdge(elementV, newCategoryV);
1130 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1135 public <T extends ToscaElement> Either<List<T>, StorageOperationStatus> getElementCatalogData(ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes, boolean isHighestVersions) {
1136 Either<List<GraphVertex>, TitanOperationStatus> listOfComponents;
1137 if (isHighestVersions) {
1138 listOfComponents = getListOfHighestComponents(componentType, excludeTypes, JsonParseFlagEnum.NoParse);
1140 listOfComponents = getListOfHighestAndAllCertifiedComponents(componentType, excludeTypes);
1143 if (listOfComponents.isRight() && listOfComponents.right().value() != TitanOperationStatus.NOT_FOUND) {
1144 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(listOfComponents.right().value()));
1146 List<T> result = new ArrayList<>();
1147 if (listOfComponents.isLeft()) {
1148 List<GraphVertex> highestAndAllCertified = listOfComponents.left().value();
1149 if (highestAndAllCertified != null && !highestAndAllCertified.isEmpty()) {
1150 for (GraphVertex vertexComponent : highestAndAllCertified) {
1151 Either<T, StorageOperationStatus> component = getLightComponent(vertexComponent, componentType, new ComponentParametersView(true));
1152 if (component.isRight()) {
1153 log.debug("Failed to fetch light element for {} error {}", vertexComponent.getUniqueId(), component.right().value());
1154 return Either.right(component.right().value());
1156 result.add(component.left().value());
1161 return Either.left(result);
1164 public Either<List<CatalogComponent>, StorageOperationStatus> getElementCatalogData(boolean isCatalog, List<ResourceTypeEnum> excludeTypes) {
1165 StopWatch stopWatch = new StopWatch();
1168 Map<String, CatalogComponent> existInCatalog = new HashMap<>();
1169 Either<Iterator<Vertex>, TitanOperationStatus> verticesEither = titanDao.getCatalogOrArchiveVerticies(isCatalog);
1170 if (verticesEither.isRight()) {
1171 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(verticesEither.right().value()));
1173 Iterator<Vertex> vertices = verticesEither.left().value();
1174 while (vertices.hasNext()) {
1175 handleCatalogComponent(existInCatalog, vertices.next(), excludeTypes);
1178 String timeToFetchElements = stopWatch.prettyPrint();
1179 log.info("time to fetch all catalog elements: {}", timeToFetchElements);
1180 return Either.left(existInCatalog.values().stream().collect(Collectors.toList()));
1183 private void handleCatalogComponent(Map<String, CatalogComponent> existInCatalog, Vertex vertex, List<ResourceTypeEnum> excludeTypes) {
1184 VertexProperty<Object> property = vertex.property(GraphPropertiesDictionary.METADATA.getProperty());
1185 String json = (String) property.value();
1186 Map<String, Object> metadatObj = JsonParserUtils.toMap(json);
1188 String uniqueId = (String) metadatObj.get(JsonPresentationFields.UNIQUE_ID.getPresentation());
1189 Boolean isDeleted = (Boolean) metadatObj.get(JsonPresentationFields.IS_DELETED.getPresentation());
1192 if (isAddToCatalog(excludeTypes, metadatObj) && (existInCatalog.get(uniqueId) == null && (isDeleted == null || !isDeleted.booleanValue()))) {
1193 CatalogComponent catalogComponent = new CatalogComponent();
1194 catalogComponent.setUniqueId(uniqueId);
1196 catalogComponent.setComponentType(ComponentTypeEnum.valueOf((String) metadatObj.get(JsonPresentationFields.COMPONENT_TYPE.getPresentation())));
1197 catalogComponent.setVersion((String) metadatObj.get(JsonPresentationFields.VERSION.getPresentation()));
1198 catalogComponent.setName((String) metadatObj.get(JsonPresentationFields.NAME.getPresentation()));
1199 catalogComponent.setIcon((String) metadatObj.get(JsonPresentationFields.ICON.getPresentation()));
1200 catalogComponent.setLifecycleState((String) metadatObj.get(JsonPresentationFields.LIFECYCLE_STATE.getPresentation()));
1201 catalogComponent.setLastUpdateDate((Long) metadatObj.get(JsonPresentationFields.LAST_UPDATE_DATE.getPresentation()));
1202 catalogComponent.setDistributionStatus((String) metadatObj.get(JsonPresentationFields.DISTRIBUTION_STATUS.getPresentation()));
1203 Object resourceType = metadatObj.get(JsonPresentationFields.RESOURCE_TYPE.getPresentation());
1204 if (resourceType != null) {
1205 catalogComponent.setResourceType((String) resourceType);
1208 if (catalogComponent.getComponentType() == ComponentTypeEnum.SERVICE) {
1209 setServiceCategoryFromGraphV(vertex, catalogComponent);
1212 setResourceCategoryFromGraphV(vertex, catalogComponent);
1214 List<String> tags = (List<String>) metadatObj.get(JsonPresentationFields.TAGS.getPresentation());
1216 catalogComponent.setTags(tags);
1218 existInCatalog.put(uniqueId, catalogComponent);
1222 private boolean isAddToCatalog(List<ResourceTypeEnum> excludeTypes, Map<String, Object> metadatObj) {
1223 boolean isAddToCatalog = true;
1224 Object resourceTypeStr = metadatObj.get(JsonPresentationFields.RESOURCE_TYPE.getPresentation());
1225 if (resourceTypeStr != null) {
1226 ResourceTypeEnum resourceType = ResourceTypeEnum.getType((String) resourceTypeStr);
1227 if (!CollectionUtils.isEmpty(excludeTypes)) {
1228 Optional<ResourceTypeEnum> op = excludeTypes.stream().filter(rt -> rt == resourceType).findAny();
1230 isAddToCatalog = false;
1233 return isAddToCatalog;
1236 public Either<List<GraphVertex>, TitanOperationStatus> getListOfHighestComponents(ComponentTypeEnum
1237 componentType, List<ResourceTypeEnum> excludeTypes, JsonParseFlagEnum parseFlag) {
1238 Map<GraphPropertyEnum, Object> propertiesToMatch = new HashMap<>();
1239 Map<GraphPropertyEnum, Object> propertiesHasNotToMatch = new HashMap<>();
1240 propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
1241 propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
1243 if (componentType == ComponentTypeEnum.RESOURCE) {
1244 propertiesToMatch.put(GraphPropertyEnum.IS_ABSTRACT, false);
1245 propertiesHasNotToMatch.put(GraphPropertyEnum.RESOURCE_TYPE, excludeTypes);
1247 propertiesHasNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
1248 propertiesHasNotToMatch.put(GraphPropertyEnum.IS_ARCHIVED, true); //US382674, US382683
1250 return titanDao.getByCriteria(null, propertiesToMatch, propertiesHasNotToMatch, parseFlag);
1253 // highest + (certified && !highest)
1254 public Either<List<GraphVertex>, TitanOperationStatus> getListOfHighestAndAllCertifiedComponents
1255 (ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes) {
1256 long startFetchAllStates = System.currentTimeMillis();
1257 Either<List<GraphVertex>, TitanOperationStatus> highestNodes = getListOfHighestComponents(componentType, excludeTypes, JsonParseFlagEnum.ParseMetadata);
1259 Map<GraphPropertyEnum, Object> propertiesToMatchCertified = new HashMap<>();
1260 Map<GraphPropertyEnum, Object> propertiesHasNotToMatchCertified = new HashMap<>();
1261 propertiesToMatchCertified.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
1262 propertiesToMatchCertified.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
1263 if (componentType == ComponentTypeEnum.RESOURCE) {
1264 propertiesToMatchCertified.put(GraphPropertyEnum.IS_ABSTRACT, false);
1265 propertiesHasNotToMatchCertified.put(GraphPropertyEnum.RESOURCE_TYPE, excludeTypes);
1268 propertiesHasNotToMatchCertified.put(GraphPropertyEnum.IS_DELETED, true);
1269 propertiesHasNotToMatchCertified.put(GraphPropertyEnum.IS_ARCHIVED, true); //US382674, US382683
1270 propertiesHasNotToMatchCertified.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
1272 Either<List<GraphVertex>, TitanOperationStatus> certifiedNotHighestNodes = titanDao.getByCriteria(null, propertiesToMatchCertified, propertiesHasNotToMatchCertified, JsonParseFlagEnum.ParseMetadata);
1273 if (certifiedNotHighestNodes.isRight() && certifiedNotHighestNodes.right().value() != TitanOperationStatus.NOT_FOUND) {
1274 return Either.right(certifiedNotHighestNodes.right().value());
1277 long endFetchAllStates = System.currentTimeMillis();
1279 List<GraphVertex> allNodes = new ArrayList<>();
1281 if (certifiedNotHighestNodes.isLeft()) {
1282 allNodes.addAll(certifiedNotHighestNodes.left().value());
1284 if (highestNodes.isLeft()) {
1285 allNodes.addAll(highestNodes.left().value());
1288 log.debug("Fetch catalog {}s all states from graph took {} ms", componentType, endFetchAllStates - startFetchAllStates);
1289 return Either.left(allNodes);
1292 protected Either<List<GraphVertex>, StorageOperationStatus> getAllComponentsMarkedForDeletion(ComponentTypeEnum
1295 // get all components marked for delete
1296 Map<GraphPropertyEnum, Object> props = new HashMap<>();
1297 props.put(GraphPropertyEnum.IS_DELETED, true);
1298 props.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
1300 Either<List<GraphVertex>, TitanOperationStatus> componentsToDelete = titanDao.getByCriteria(null, props, JsonParseFlagEnum.NoParse);
1302 if (componentsToDelete.isRight()) {
1303 TitanOperationStatus error = componentsToDelete.right().value();
1304 if (error.equals(TitanOperationStatus.NOT_FOUND)) {
1305 log.trace("no components to delete");
1306 return Either.left(new ArrayList<>());
1308 log.info("failed to find components to delete. error : {}", error.name());
1309 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(error));
1312 return Either.left(componentsToDelete.left().value());
1315 protected TitanOperationStatus setAdditionalInformationFromGraph(GraphVertex componentV, ToscaElement
1317 Either<Map<String, AdditionalInfoParameterDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.ADDITIONAL_INFORMATION);
1318 if (result.isLeft()) {
1319 toscaElement.setAdditionalInformation(result.left().value());
1321 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1322 return result.right().value();
1325 return TitanOperationStatus.OK;
1328 // --------------------------------------------
1329 public abstract <T extends
1330 ToscaElement> Either<T, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView);
1332 public abstract <T extends
1333 ToscaElement> Either<T, StorageOperationStatus> getToscaElement(GraphVertex toscaElementVertex, ComponentParametersView componentParametersView);
1335 public abstract <T extends
1336 ToscaElement> Either<T, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex);
1338 public abstract <T extends
1339 ToscaElement> Either<T, StorageOperationStatus> createToscaElement(ToscaElement toscaElement);
1341 protected abstract <T extends ToscaElement> TitanOperationStatus
1342 setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement);
1344 protected abstract <T extends ToscaElement> TitanOperationStatus
1345 setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement);
1347 protected abstract <T extends ToscaElement> TitanOperationStatus
1348 setRequirementsFromGraph(GraphVertex componentV, T toscaElement);
1350 protected abstract <T extends ToscaElement> StorageOperationStatus
1351 validateCategories(T toscaElementToUpdate, GraphVertex elementV);
1353 protected abstract <T extends ToscaElement> StorageOperationStatus
1354 updateDerived(T toscaElementToUpdate, GraphVertex updateElementV);
1356 public abstract <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T
1357 toscaElementToUpdate, JsonParseFlagEnum flag);