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();
88 protected CategoryOperation categoryOperation;
90 protected Gson getGson() {
95 protected Either<GraphVertex, StorageOperationStatus> getComponentByLabelAndId(String uniqueId, ToscaElementTypeEnum nodeType, JsonParseFlagEnum parseFlag) {
97 Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
98 propertiesToMatch.put(GraphPropertyEnum.UNIQUE_ID, uniqueId);
100 VertexTypeEnum vertexType = ToscaElementTypeEnum.getVertexTypeByToscaType(nodeType);
101 Either<List<GraphVertex>, TitanOperationStatus> getResponse = titanDao.getByCriteria(vertexType, propertiesToMatch, parseFlag);
102 if (getResponse.isRight()) {
103 log.debug("Couldn't fetch component with type {} and unique id {}, error: {}", vertexType, uniqueId, getResponse.right().value());
104 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getResponse.right().value()));
107 List<GraphVertex> componentList = getResponse.left().value();
108 if (componentList.isEmpty()) {
109 log.debug("Component with type {} and unique id {} was not found", vertexType, uniqueId);
110 return Either.right(StorageOperationStatus.NOT_FOUND);
112 GraphVertex vertexG = componentList.get(0);
113 return Either.left(vertexG);
116 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId) {
117 return getToscaElement(uniqueId, new ComponentParametersView());
120 public Either<GraphVertex, StorageOperationStatus> markComponentToDelete(GraphVertex componentToDelete) {
121 Either<GraphVertex, StorageOperationStatus> result = null;
123 Boolean isDeleted = (Boolean) componentToDelete.getMetadataProperty(GraphPropertyEnum.IS_DELETED);
124 if (isDeleted != null && isDeleted && !(Boolean) componentToDelete.getMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION)) {
125 // component already marked for delete
126 result = Either.left(componentToDelete);
130 componentToDelete.addMetadataProperty(GraphPropertyEnum.IS_DELETED, Boolean.TRUE);
131 componentToDelete.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, System.currentTimeMillis());
133 Either<GraphVertex, TitanOperationStatus> updateNode = titanDao.updateVertex(componentToDelete);
135 StorageOperationStatus updateComponent;
136 if (updateNode.isRight()) {
137 log.debug("Failed to update component {}. status is {}", componentToDelete.getUniqueId(), updateNode.right().value());
138 updateComponent = DaoStatusConverter.convertTitanStatusToStorageStatus(updateNode.right().value());
139 result = Either.right(updateComponent);
143 result = Either.left(componentToDelete);
149 * Performs a shadow clone of previousToscaElement
151 * @param previousToscaElement
152 * @param nextToscaElement
156 public Either<GraphVertex, StorageOperationStatus> cloneToscaElement(GraphVertex previousToscaElement, GraphVertex nextToscaElement, GraphVertex user) {
158 Either<GraphVertex, StorageOperationStatus> result = null;
159 GraphVertex createdToscaElementVertex = null;
160 TitanOperationStatus status;
162 Either<GraphVertex, TitanOperationStatus> createNextVersionRes = titanDao.createVertex(nextToscaElement);
163 if (createNextVersionRes.isRight()) {
164 status = createNextVersionRes.right().value();
165 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create tosca element vertex {} with version {} on graph. Status is {}. ", previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME),
166 previousToscaElement.getMetadataProperty(GraphPropertyEnum.VERSION), status);
167 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
169 if (result == null) {
170 createdToscaElementVertex = createNextVersionRes.left().value();
171 Map<EdgePropertyEnum, Object> properties = new HashMap<>();
172 properties.put(EdgePropertyEnum.STATE, createdToscaElementVertex.getMetadataProperty(GraphPropertyEnum.STATE));
173 status = titanDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.STATE, properties);
174 if (status != TitanOperationStatus.OK) {
175 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(),
176 previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
177 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
180 if (result == null) {
181 status = titanDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.LAST_MODIFIER, new HashMap<>());
182 if (status != TitanOperationStatus.OK) {
183 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(),
184 nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
185 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
188 if (result == null) {
189 status = titanDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.CREATOR, new HashMap<>());
190 if (status != TitanOperationStatus.OK) {
191 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(),
192 nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
193 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
196 if (result == null) {
197 Iterator<Edge> edgesToCopyIter = previousToscaElement.getVertex().edges(Direction.OUT);
198 while (edgesToCopyIter.hasNext()) {
199 Edge currEdge = edgesToCopyIter.next();
200 Vertex currVertex = currEdge.inVertex();
201 status = titanDao.createEdge(createdToscaElementVertex.getVertex(), currVertex, EdgeLabelEnum.getEdgeLabelEnum(currEdge.label()), currEdge);
202 if (status != TitanOperationStatus.OK) {
203 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(),
204 currVertex.property(GraphPropertyEnum.LABEL.getProperty()), status);
205 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
211 if (result == null) {
212 result = Either.left(createdToscaElementVertex);
214 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to clone tosca element {} with the name {}. ", previousToscaElement.getUniqueId(), previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME));
219 protected TitanOperationStatus setLastModifierFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
220 Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(componentV, EdgeLabelEnum.LAST_MODIFIER, JsonParseFlagEnum.NoParse);
221 if (parentVertex.isRight()) {
222 log.debug("Failed to fetch last modifier for tosca element with id {} error {}", componentV.getUniqueId(), parentVertex.right().value());
223 return parentVertex.right().value();
225 GraphVertex userV = parentVertex.left().value();
226 String userId = (String) userV.getMetadataProperty(GraphPropertyEnum.USERID);
227 toscaElement.setLastUpdaterUserId(userId);
228 toscaElement.setLastUpdaterFullName(buildFullName(userV));
229 return TitanOperationStatus.OK;
232 public String buildFullName(GraphVertex userV) {
234 String fullName = (String) userV.getMetadataProperty(GraphPropertyEnum.FIRST_NAME);
235 if (fullName == null) {
238 fullName = fullName + " ";
240 String lastName = (String) userV.getMetadataProperty(GraphPropertyEnum.LAST_NAME);
241 if (lastName != null) {
242 fullName += lastName;
247 protected TitanOperationStatus setCreatorFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
248 Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(componentV, EdgeLabelEnum.CREATOR, JsonParseFlagEnum.NoParse);
249 if (parentVertex.isRight()) {
250 log.debug("Failed to fetch creator for tosca element with id {} error {}", componentV.getUniqueId(), parentVertex.right().value());
251 return parentVertex.right().value();
253 GraphVertex userV = parentVertex.left().value();
254 String creatorUserId = (String) userV.getMetadataProperty(GraphPropertyEnum.USERID);
255 toscaElement.setCreatorUserId(creatorUserId);
256 toscaElement.setCreatorFullName(buildFullName(userV));
258 return TitanOperationStatus.OK;
261 protected <T extends ToscaElement> T getResourceMetaDataFromResource(T toscaElement) {
262 if (toscaElement.getNormalizedName() == null || toscaElement.getNormalizedName().isEmpty()) {
263 toscaElement.setNormalizedName(ValidationUtils.normaliseComponentName(toscaElement.getName()));
265 if (toscaElement.getSystemName() == null || toscaElement.getSystemName().isEmpty()) {
266 toscaElement.setSystemName(ValidationUtils.convertToSystemName(toscaElement.getName()));
269 LifecycleStateEnum lifecycleStateEnum = toscaElement.getLifecycleState();
270 if (lifecycleStateEnum == null) {
271 toscaElement.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
273 long currentDate = System.currentTimeMillis();
274 if (toscaElement.getCreationDate() == null) {
275 toscaElement.setCreationDate(currentDate);
277 toscaElement.setLastUpdateDate(currentDate);
282 protected void fillCommonMetadata(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
283 if (toscaElement.isHighestVersion() == null) {
284 toscaElement.setHighestVersion(true);
286 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_DELETED, toscaElement.getMetadataValue(JsonPresentationFields.IS_DELETED));
287 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION, toscaElement.getMetadataValueOrDefault(JsonPresentationFields.HIGHEST_VERSION, Boolean.TRUE));
288 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.STATE, toscaElement.getMetadataValue(JsonPresentationFields.LIFECYCLE_STATE));
289 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.RESOURCE_TYPE, toscaElement.getMetadataValue(JsonPresentationFields.RESOURCE_TYPE));
290 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.VERSION, toscaElement.getMetadataValue(JsonPresentationFields.VERSION));
291 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME, toscaElement.getMetadataValue(JsonPresentationFields.NORMALIZED_NAME));
292 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, toscaElement.getMetadataValue(JsonPresentationFields.UNIQUE_ID));
293 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaElement.getMetadataValue(JsonPresentationFields.TOSCA_RESOURCE_NAME));
294 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.UUID, toscaElement.getMetadataValue(JsonPresentationFields.UUID));
295 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_ABSTRACT, toscaElement.getMetadataValue(JsonPresentationFields.IS_ABSTRACT));
296 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.INVARIANT_UUID, toscaElement.getMetadataValue(JsonPresentationFields.INVARIANT_UUID));
297 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.NAME, toscaElement.getMetadataValue(JsonPresentationFields.NAME));
298 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.SYSTEM_NAME, toscaElement.getMetadataValue(JsonPresentationFields.SYSTEM_NAME));
299 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_ARCHIVED, toscaElement.getMetadataValue(JsonPresentationFields.IS_ARCHIVED));
300 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.ARCHIVE_TIME, toscaElement.getMetadataValue(JsonPresentationFields.ARCHIVE_TIME));
301 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_VSP_ARCHIVED, toscaElement.getMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED));
302 toscaElement.getMetadata().entrySet().stream().filter(e -> e.getValue() != null).forEach(e -> nodeTypeVertex.setJsonMetadataField(JsonPresentationFields.getByPresentation(e.getKey()), e.getValue()));
304 nodeTypeVertex.setUniqueId(toscaElement.getUniqueId());
305 nodeTypeVertex.setType(toscaElement.getComponentType());
309 protected StorageOperationStatus assosiateToUsers(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
311 String userId = toscaElement.getCreatorUserId();
313 Either<GraphVertex, TitanOperationStatus> findUser = findUserVertex(userId);
315 if (findUser.isRight()) {
316 TitanOperationStatus status = findUser.right().value();
317 log.error(CANNOT_FIND_USER_IN_THE_GRAPH_STATUS_IS, userId, status);
318 return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
321 GraphVertex creatorVertex = findUser.left().value();
322 GraphVertex updaterVertex = creatorVertex;
323 String updaterId = toscaElement.getLastUpdaterUserId();
324 if (updaterId != null && !updaterId.equals(userId)) {
325 findUser = findUserVertex(updaterId);
326 if (findUser.isRight()) {
327 TitanOperationStatus status = findUser.right().value();
328 log.error(CANNOT_FIND_USER_IN_THE_GRAPH_STATUS_IS, userId, status);
329 return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
331 updaterVertex = findUser.left().value();
334 Map<EdgePropertyEnum, Object> props = new EnumMap<>(EdgePropertyEnum.class);
335 props.put(EdgePropertyEnum.STATE, (String) toscaElement.getMetadataValue(JsonPresentationFields.LIFECYCLE_STATE));
337 TitanOperationStatus result = titanDao.createEdge(updaterVertex, nodeTypeVertex, EdgeLabelEnum.STATE, props);
338 log.debug("After associating user {} to resource {}. Edge type is {}", updaterVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.STATE);
339 if (TitanOperationStatus.OK != result) {
340 return DaoStatusConverter.convertTitanStatusToStorageStatus(result);
342 result = titanDao.createEdge(updaterVertex, nodeTypeVertex, EdgeLabelEnum.LAST_MODIFIER, null);
343 log.debug("After associating user {} to resource {}. Edge type is {}", updaterVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.LAST_MODIFIER);
344 if (!result.equals(TitanOperationStatus.OK)) {
345 log.error("Failed to associate user {} to resource {}. Edge type is {}", updaterVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.LAST_MODIFIER);
346 return DaoStatusConverter.convertTitanStatusToStorageStatus(result);
349 toscaElement.setLastUpdaterUserId(toscaElement.getCreatorUserId());
350 toscaElement.setLastUpdaterFullName(toscaElement.getCreatorFullName());
352 result = titanDao.createEdge(creatorVertex, nodeTypeVertex, EdgeLabelEnum.CREATOR, null);
353 log.debug("After associating user {} to resource {}. Edge type is {} ", creatorVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.CREATOR);
354 if (!result.equals(TitanOperationStatus.OK)) {
355 log.error("Failed to associate user {} to resource {}. Edge type is {} ", creatorVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.CREATOR);
356 return DaoStatusConverter.convertTitanStatusToStorageStatus(result);
358 return StorageOperationStatus.OK;
361 protected StorageOperationStatus assosiateResourceMetadataToCategory(GraphVertex nodeTypeVertex, ToscaElement nodeType) {
362 String subcategoryName = nodeType.getCategories().get(0).getSubcategories().get(0).getName();
363 String categoryName = nodeType.getCategories().get(0).getName();
364 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = getResourceCategoryVertex(nodeType.getUniqueId(), subcategoryName, categoryName);
366 if (getCategoryVertex.isRight()) {
367 return getCategoryVertex.right().value();
370 GraphVertex subCategoryV = getCategoryVertex.left().value();
372 TitanOperationStatus createEdge = titanDao.createEdge(nodeTypeVertex, subCategoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
373 if (createEdge != TitanOperationStatus.OK) {
374 log.trace("Failed to associate resource {} to category {} with id {}", nodeType.getUniqueId(), subcategoryName, subCategoryV.getUniqueId());
375 return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
377 return StorageOperationStatus.OK;
380 protected Either<GraphVertex, StorageOperationStatus> getResourceCategoryVertex(String elementId, String subcategoryName, String categoryName) {
381 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
382 if (category.isRight()) {
383 log.trace("Failed to fetch category {} for resource {} error {}", categoryName, elementId, category.right().value());
384 return Either.right(category.right().value());
386 GraphVertex categoryV = category.left().value();
388 if (subcategoryName != null) {
389 Either<GraphVertex, StorageOperationStatus> subCategory = categoryOperation.getSubCategoryForCategory(categoryV, subcategoryName);
390 if (subCategory.isRight()) {
391 log.trace("Failed to fetch subcategory {} of category for resource {} error {}", subcategoryName, categoryName, elementId, subCategory.right().value());
392 return Either.right(subCategory.right().value());
395 GraphVertex subCategoryV = subCategory.left().value();
396 return Either.left(subCategoryV);
398 return Either.left(categoryV);
401 private StorageOperationStatus associateArtifactsToResource(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
402 Map<String, ArtifactDataDefinition> artifacts = toscaElement.getArtifacts();
403 Either<GraphVertex, StorageOperationStatus> status;
404 if (artifacts != null) {
405 artifacts.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
406 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
407 a.setUniqueId(uniqueId);
409 status = associateElementToData(nodeTypeVertex, VertexTypeEnum.ARTIFACTS, EdgeLabelEnum.ARTIFACTS, artifacts);
410 if (status.isRight()) {
411 return status.right().value();
414 Map<String, ArtifactDataDefinition> toscaArtifacts = toscaElement.getToscaArtifacts();
415 if (toscaArtifacts != null) {
416 toscaArtifacts.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
417 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
418 a.setUniqueId(uniqueId);
420 status = associateElementToData(nodeTypeVertex, VertexTypeEnum.TOSCA_ARTIFACTS, EdgeLabelEnum.TOSCA_ARTIFACTS, toscaArtifacts);
421 if (status.isRight()) {
422 return status.right().value();
425 Map<String, ArtifactDataDefinition> deploymentArtifacts = toscaElement.getDeploymentArtifacts();
426 if (deploymentArtifacts != null) {
427 deploymentArtifacts.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
428 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
429 a.setUniqueId(uniqueId);
431 status = associateElementToData(nodeTypeVertex, VertexTypeEnum.DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS, deploymentArtifacts);
432 if (status.isRight()) {
433 return status.right().value();
436 return StorageOperationStatus.OK;
439 protected TitanOperationStatus disassociateAndDeleteCommonElements(GraphVertex toscaElementVertex) {
440 TitanOperationStatus status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.ARTIFACTS);
441 if (status != TitanOperationStatus.OK) {
442 log.debug("Failed to disaccociate artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
445 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.TOSCA_ARTIFACTS);
446 if (status != TitanOperationStatus.OK) {
447 log.debug("Failed to disaccociate tosca artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
450 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS);
451 if (status != TitanOperationStatus.OK) {
452 log.debug("Failed to deployment artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
455 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.PROPERTIES);
456 if (status != TitanOperationStatus.OK) {
457 log.debug("Failed to disaccociate properties for {} error {}", toscaElementVertex.getUniqueId(), status);
460 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.ATTRIBUTES);
461 if (status != TitanOperationStatus.OK) {
462 log.debug("Failed to disaccociate attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
465 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.ADDITIONAL_INFORMATION);
466 if (status != TitanOperationStatus.OK) {
467 log.debug("Failed to disaccociate additional information for {} error {}", toscaElementVertex.getUniqueId(), status);
470 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES);
471 if (status != TitanOperationStatus.OK) {
472 log.debug("Failed to disaccociate capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
475 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.REQUIREMENTS);
476 if (status != TitanOperationStatus.OK) {
477 log.debug("Failed to disaccociate requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
480 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
481 if (status != TitanOperationStatus.OK) {
482 log.debug("Failed to disaccociate requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
485 return TitanOperationStatus.OK;
488 protected StorageOperationStatus assosiateCommonForToscaElement(GraphVertex nodeTypeVertex, ToscaElement toscaElement, List<GraphVertex> derivedResources) {
490 StorageOperationStatus associateUsers = assosiateToUsers(nodeTypeVertex, toscaElement);
491 if (associateUsers != StorageOperationStatus.OK) {
492 return associateUsers;
494 StorageOperationStatus associateArtifacts = associateArtifactsToResource(nodeTypeVertex, toscaElement);
495 if (associateArtifacts != StorageOperationStatus.OK) {
496 return associateArtifacts;
498 StorageOperationStatus associateProperties = associatePropertiesToResource(nodeTypeVertex, toscaElement, derivedResources);
499 if (associateProperties != StorageOperationStatus.OK) {
500 return associateProperties;
502 StorageOperationStatus associateAdditionaInfo = associateAdditionalInfoToResource(nodeTypeVertex, toscaElement);
503 if (associateAdditionaInfo != StorageOperationStatus.OK) {
504 return associateAdditionaInfo;
506 if (needConnectToCatalog(toscaElement)) {
507 StorageOperationStatus associateToCatalog = associateToCatalogRoot(nodeTypeVertex);
508 if (associateToCatalog != StorageOperationStatus.OK) {
509 return associateToCatalog;
512 return StorageOperationStatus.OK;
515 private boolean needConnectToCatalog(ToscaElement toscaElement) {
516 Boolean isAbstract = (Boolean) toscaElement.getMetadataValue(JsonPresentationFields.IS_ABSTRACT);
517 if (isAbstract != null && isAbstract) {
520 return toscaElement.isHighestVersion();
523 private StorageOperationStatus associateToCatalogRoot(GraphVertex nodeTypeVertex) {
524 Either<GraphVertex, TitanOperationStatus> catalog = titanDao.getVertexByLabel(VertexTypeEnum.CATALOG_ROOT);
525 if (catalog.isRight()) {
526 log.debug("Failed to fetch catalog vertex. error {}", catalog.right().value());
527 return DaoStatusConverter.convertTitanStatusToStorageStatus(catalog.right().value());
529 TitanOperationStatus createEdge = titanDao.createEdge(catalog.left().value(), nodeTypeVertex, EdgeLabelEnum.CATALOG_ELEMENT, null);
531 return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
534 protected StorageOperationStatus associatePropertiesToResource(GraphVertex nodeTypeVertex, ToscaElement nodeType, List<GraphVertex> derivedResources) {
535 // Note : currently only one derived supported!!!!
536 Either<Map<String, PropertyDataDefinition>, StorageOperationStatus> dataFromDerived = getDataFromDerived(derivedResources, EdgeLabelEnum.PROPERTIES);
537 if (dataFromDerived.isRight()) {
538 return dataFromDerived.right().value();
540 Map<String, PropertyDataDefinition> propertiesAll = dataFromDerived.left().value();
542 Map<String, PropertyDataDefinition> properties = nodeType.getProperties();
544 if (properties != null) {
545 properties.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
546 String uid = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId(), p.getName());
550 Either<Map<String, PropertyDataDefinition>, String> eitherMerged = ToscaDataDefinition.mergeDataMaps(propertiesAll, properties);
551 if (eitherMerged.isRight()) {
552 // TODO re-factor error handling - moving BL to operation resulted in loss of info about the invalid property
553 log.debug("property {} cannot be overriden", eitherMerged.right().value());
554 return StorageOperationStatus.INVALID_PROPERTY;
557 if (!propertiesAll.isEmpty()) {
558 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.PROPERTIES, EdgeLabelEnum.PROPERTIES, propertiesAll);
559 if (assosiateElementToData.isRight()) {
560 return assosiateElementToData.right().value();
563 return StorageOperationStatus.OK;
566 private StorageOperationStatus associateAdditionalInfoToResource(GraphVertex nodeTypeVertex, ToscaElement nodeType) {
567 Map<String, AdditionalInfoParameterDataDefinition> additionalInformation = nodeType.getAdditionalInformation();
568 if (additionalInformation != null) {
569 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, additionalInformation);
570 if (assosiateElementToData.isRight()) {
571 return assosiateElementToData.right().value();
574 return StorageOperationStatus.OK;
577 protected <T extends ToscaDataDefinition> Either<Map<String, T>, StorageOperationStatus> getDataFromDerived(List<GraphVertex> derivedResources, EdgeLabelEnum edge) {
578 Map<String, T> propertiesAll = new HashMap<>();
580 if (derivedResources != null && !derivedResources.isEmpty()) {
581 for (GraphVertex derived : derivedResources) {
582 Either<List<GraphVertex>, TitanOperationStatus> derivedProperties = titanDao.getChildrenVertecies(derived, edge, JsonParseFlagEnum.ParseJson);
583 if (derivedProperties.isRight()) {
584 if (derivedProperties.right().value() != TitanOperationStatus.NOT_FOUND) {
585 log.debug("Failed to get properties for derived from {} error {}", derived.getUniqueId(), derivedProperties.right().value());
586 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(derivedProperties.right().value()));
591 List<GraphVertex> propList = derivedProperties.left().value();
592 for (GraphVertex propV : propList) {
593 Map<String, T> propertiesFromDerived = (Map<String, T>) propV.getJson();
594 if (propertiesFromDerived != null) {
595 propertiesFromDerived.entrySet().forEach(x -> x.getValue().setOwnerIdIfEmpty(derived.getUniqueId()));
596 propertiesAll.putAll(propertiesFromDerived);
601 return Either.left(propertiesAll);
604 protected TitanOperationStatus setArtifactsFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
605 Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.ARTIFACTS);
606 if (result.isLeft()) {
607 toscaElement.setArtifacts(result.left().value());
609 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
610 return result.right().value();
613 result = getDataFromGraph(componentV, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS);
614 if (result.isLeft()) {
615 toscaElement.setDeploymentArtifacts(result.left().value());
617 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
618 return result.right().value();
621 result = getDataFromGraph(componentV, EdgeLabelEnum.TOSCA_ARTIFACTS);
622 if (result.isLeft()) {
623 toscaElement.setToscaArtifacts(result.left().value());
625 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
626 return result.right().value();
629 return TitanOperationStatus.OK;
632 protected TitanOperationStatus setAllVersions(GraphVertex componentV, ToscaElement toscaElement) {
633 Map<String, String> allVersion = new HashMap<>();
635 allVersion.put((String) componentV.getMetadataProperty(GraphPropertyEnum.VERSION), componentV.getUniqueId());
636 ArrayList<GraphVertex> allChildrenAndParants = new ArrayList<>();
637 Either<GraphVertex, TitanOperationStatus> childResourceRes = titanDao.getChildVertex(componentV, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
638 while (childResourceRes.isLeft()) {
639 GraphVertex child = childResourceRes.left().value();
640 allChildrenAndParants.add(child);
641 childResourceRes = titanDao.getChildVertex(child, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
643 TitanOperationStatus operationStatus = childResourceRes.right().value();
645 if (operationStatus != TitanOperationStatus.NOT_FOUND) {
646 return operationStatus;
648 Either<GraphVertex, TitanOperationStatus> parentResourceRes = titanDao.getParentVertex(componentV, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
649 while (parentResourceRes.isLeft()) {
650 GraphVertex parent = parentResourceRes.left().value();
651 allChildrenAndParants.add(parent);
652 parentResourceRes = titanDao.getParentVertex(parent, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
654 operationStatus = parentResourceRes.right().value();
655 if (operationStatus != TitanOperationStatus.NOT_FOUND) {
656 return operationStatus;
658 allChildrenAndParants.stream().filter(vertex -> {
659 Boolean isDeleted = (Boolean) vertex.getMetadataProperty(GraphPropertyEnum.IS_DELETED);
660 return (isDeleted == null || !isDeleted);
661 }).forEach(vertex -> allVersion.put((String) vertex.getMetadataProperty(GraphPropertyEnum.VERSION), vertex.getUniqueId()));
663 toscaElement.setAllVersions(allVersion);
664 return TitanOperationStatus.OK;
669 protected <T extends ToscaElement> Either<List<T>, StorageOperationStatus> getFollowedComponent(String userId, Set<LifecycleStateEnum> lifecycleStates, Set<LifecycleStateEnum> lastStateStates, ComponentTypeEnum neededType) {
671 Either<List<T>, StorageOperationStatus> result = null;
673 Map<GraphPropertyEnum, Object> props = null;
675 if (userId != null) {
676 props = new EnumMap<>(GraphPropertyEnum.class);
677 // for Designer retrieve specific user
678 props.put(GraphPropertyEnum.USERID, userId);
680 // in case of user id == null -> get all users by label
681 // for Tester and Admin retrieve all users
682 Either<List<GraphVertex>, TitanOperationStatus> usersByCriteria = titanDao.getByCriteria(VertexTypeEnum.USER, props, JsonParseFlagEnum.NoParse);
683 if (usersByCriteria.isRight()) {
684 log.debug("Failed to fetch users by criteria {} error {}", props, usersByCriteria.right().value());
685 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(usersByCriteria.right().value()));
687 List<GraphVertex> users = usersByCriteria.left().value();
689 List<T> components = new ArrayList<>();
690 List<T> componentsPerUser;
691 for (GraphVertex userV : users) {
693 HashSet<String> ids = new HashSet<>();
694 Either<List<GraphVertex>, TitanOperationStatus> childrenVertecies = titanDao.getChildrenVertecies(userV, EdgeLabelEnum.STATE, JsonParseFlagEnum.NoParse);
695 if (childrenVertecies.isRight() && childrenVertecies.right().value() != TitanOperationStatus.NOT_FOUND) {
696 log.debug("Failed to fetch children vertices for user {} by edge {} error {}", userV.getMetadataProperty(GraphPropertyEnum.USERID), EdgeLabelEnum.STATE, childrenVertecies.right().value());
697 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(childrenVertecies.right().value()));
700 // get all resource with current state
701 if (childrenVertecies.isLeft()) {
702 componentsPerUser = fetchComponents(lifecycleStates, childrenVertecies.left().value(), neededType, EdgeLabelEnum.STATE);
704 if (componentsPerUser != null) {
705 for (T comp : componentsPerUser) {
706 ids.add(comp.getUniqueId());
707 components.add(comp);
711 if (lastStateStates != null && !lastStateStates.isEmpty()) {
712 // get all resource with last state
713 childrenVertecies = titanDao.getChildrenVertecies(userV, EdgeLabelEnum.LAST_STATE, JsonParseFlagEnum.NoParse);
714 if (childrenVertecies.isRight() && childrenVertecies.right().value() != TitanOperationStatus.NOT_FOUND) {
715 log.debug("Failed to fetch children vertices for user {} by edge {} error {}", userV.getMetadataProperty(GraphPropertyEnum.USERID), EdgeLabelEnum.LAST_STATE, childrenVertecies.right().value());
716 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(childrenVertecies.right().value()));
718 if (childrenVertecies.isLeft()) {
720 componentsPerUser = fetchComponents(lastStateStates, childrenVertecies.left().value(), neededType, EdgeLabelEnum.LAST_STATE);
721 if (componentsPerUser != null) {
722 for (T comp : componentsPerUser) {
725 if (ids.contains(comp.getUniqueId())) {
729 components.add(comp);
739 result = Either.left(components);
744 private <T extends ToscaElement> List<T> fetchComponents(Set<LifecycleStateEnum> lifecycleStates, List<GraphVertex> vertices, ComponentTypeEnum neededType, EdgeLabelEnum edgelabel) {
745 List<T> components = new ArrayList<>();
746 for (GraphVertex node : vertices) {
748 Iterator<Edge> edges = node.getVertex().edges(Direction.IN, edgelabel.name());
749 while (edges.hasNext()) {
750 Edge edge = edges.next();
751 String stateStr = (String) titanDao.getProperty(edge, EdgePropertyEnum.STATE);
753 LifecycleStateEnum nodeState = LifecycleStateEnum.findState(stateStr);
754 if (nodeState == null) {
755 log.debug("no supported STATE {} for element {}", stateStr, node.getUniqueId());
758 if (lifecycleStates != null && lifecycleStates.contains(nodeState)) {
760 Boolean isDeleted = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_DELETED);
761 Boolean isArchived = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_ARCHIVED);
762 if (isDeleted != null && isDeleted || isArchived != null && isArchived) {
763 log.trace("Deleted/Archived element {}, discard", node.getUniqueId());
767 Boolean isHighest = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION);
770 ComponentTypeEnum componentType = node.getType();
771 // get only latest versions
773 if (componentType == null) {
774 log.debug("No supported type {} for vertex {}", componentType, node.getUniqueId());
777 if (neededType == componentType) {
778 switch (componentType) {
781 handleNode(components, node, componentType);
784 Boolean isAbtract = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_ABSTRACT);
785 if (isAbtract == null || !isAbtract) {
786 handleNode(components, node, componentType);
790 log.debug("not supported node type {}", componentType);
801 protected <T extends ToscaElement> void handleNode(List<T> components, GraphVertex vertexComponent, ComponentTypeEnum nodeType) {
803 Either<T, StorageOperationStatus> component = getLightComponent(vertexComponent, nodeType, new ComponentParametersView(true));
804 if (component.isRight()) {
805 log.debug("Failed to get component for id = {} error : {} skip resource", vertexComponent.getUniqueId(), component.right().value());
807 components.add(component.left().value());
811 protected <T extends ToscaElement> Either<T, StorageOperationStatus> getLightComponent(String componentUid, ComponentTypeEnum nodeType, ComponentParametersView parametersFilter) {
812 Either<GraphVertex, TitanOperationStatus> getVertexRes = titanDao.getVertexById(componentUid);
813 if (getVertexRes.isRight()) {
814 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexRes.right().value()));
816 return getLightComponent(getVertexRes.left().value(), nodeType, parametersFilter);
819 protected <T extends ToscaElement> Either<T, StorageOperationStatus> getLightComponent(GraphVertex vertexComponent, ComponentTypeEnum nodeType, ComponentParametersView parametersFilter) {
821 log.trace("Starting to build light component of type {}, id {}", nodeType, vertexComponent.getUniqueId());
823 titanDao.parseVertexProperties(vertexComponent, JsonParseFlagEnum.ParseMetadata);
825 T toscaElement = convertToComponent(vertexComponent);
827 TitanOperationStatus status = setCreatorFromGraph(vertexComponent, toscaElement);
828 if (status != TitanOperationStatus.OK) {
829 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
832 status = setLastModifierFromGraph(vertexComponent, toscaElement);
833 if (status != TitanOperationStatus.OK) {
834 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
836 status = setCategoriesFromGraph(vertexComponent, toscaElement);
837 if (status != TitanOperationStatus.OK) {
838 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
840 if (!parametersFilter.isIgnoreAllVersions()) {
841 status = setAllVersions(vertexComponent, toscaElement);
842 if (status != TitanOperationStatus.OK) {
843 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
846 if (!parametersFilter.isIgnoreCapabilities()) {
847 status = setCapabilitiesFromGraph(vertexComponent, toscaElement);
848 if (status != TitanOperationStatus.OK) {
849 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
852 if (!parametersFilter.isIgnoreRequirements()) {
853 status = setRequirementsFromGraph(vertexComponent, toscaElement);
854 if (status != TitanOperationStatus.OK) {
855 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
858 log.debug("Ended to build light component of type {}, id {}", nodeType, vertexComponent.getUniqueId());
859 return Either.left(toscaElement);
862 @SuppressWarnings("unchecked")
863 protected <T extends ToscaElement> T convertToComponent(GraphVertex componentV) {
864 ToscaElement toscaElement = null;
865 VertexTypeEnum label = componentV.getLabel();
868 toscaElement = new NodeType();
870 case TOPOLOGY_TEMPLATE:
871 toscaElement = new TopologyTemplate();
874 log.debug("Not supported tosca type {}", label);
878 Map<String, Object> jsonMetada = componentV.getMetadataJson();
879 if (toscaElement != null) {
880 toscaElement.setMetadata(jsonMetada);
882 return (T) toscaElement;
885 protected TitanOperationStatus setResourceCategoryFromGraphV(Vertex vertex, CatalogComponent catalogComponent) {
887 Either<Vertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(vertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
888 if (childVertex.isRight()) {
889 log.debug(FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR, EdgeLabelEnum.CATEGORY, catalogComponent.getUniqueId(), childVertex.right().value());
890 return childVertex.right().value();
892 Vertex subCategoryV = childVertex.left().value();
893 catalogComponent.setSubCategoryNormalizedName((String) subCategoryV.property(JsonPresentationFields.NORMALIZED_NAME.getPresentation()).value());
894 Either<Vertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
895 Vertex categoryV = parentVertex.left().value();
896 catalogComponent.setCategoryNormalizedName((String) categoryV.property(JsonPresentationFields.NORMALIZED_NAME.getPresentation()).value());
898 return TitanOperationStatus.OK;
901 protected TitanOperationStatus setServiceCategoryFromGraphV(Vertex vertex, CatalogComponent catalogComponent) {
902 Either<Vertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(vertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
903 if (childVertex.isRight()) {
904 log.debug(FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR, EdgeLabelEnum.CATEGORY, catalogComponent.getUniqueId(), childVertex.right().value());
905 return childVertex.right().value();
907 Vertex categoryV = childVertex.left().value();
908 catalogComponent.setCategoryNormalizedName((String) categoryV.property(JsonPresentationFields.NORMALIZED_NAME.getPresentation()).value());
910 return TitanOperationStatus.OK;
913 protected TitanOperationStatus setResourceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
914 List<CategoryDefinition> categories = new ArrayList<>();
915 SubCategoryDefinition subcategory;
917 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
918 if (childVertex.isRight()) {
919 log.debug(FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR, EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
920 return childVertex.right().value();
922 GraphVertex subCategoryV = childVertex.left().value();
923 Map<GraphPropertyEnum, Object> metadataProperties = subCategoryV.getMetadataProperties();
924 subcategory = new SubCategoryDefinition();
925 subcategory.setUniqueId(subCategoryV.getUniqueId());
926 subcategory.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
927 subcategory.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
929 Type listTypeSubcat = new TypeToken<List<String>>() {
931 List<String> iconsfromJsonSubcat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS), listTypeSubcat);
932 subcategory.setIcons(iconsfromJsonSubcat);
934 Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
935 if (parentVertex.isRight()) {
936 log.debug("failed to fetch {} for category with id {}, error {}", EdgeLabelEnum.SUB_CATEGORY, subCategoryV.getUniqueId(), parentVertex.right().value());
937 return childVertex.right().value();
939 GraphVertex categoryV = parentVertex.left().value();
940 metadataProperties = categoryV.getMetadataProperties();
942 CategoryDefinition category = new CategoryDefinition();
943 category.setUniqueId(categoryV.getUniqueId());
944 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
945 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
947 Type listTypeCat = new TypeToken<List<String>>() {
949 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS), listTypeCat);
950 category.setIcons(iconsfromJsonCat);
952 category.addSubCategory(subcategory);
953 categories.add(category);
954 toscaElement.setCategories(categories);
956 return TitanOperationStatus.OK;
959 public <T extends ToscaElement> Either<T, StorageOperationStatus> updateToscaElement(T toscaElementToUpdate, GraphVertex elementV, ComponentParametersView filterResult) {
960 Either<T, StorageOperationStatus> result = null;
962 log.debug("In updateToscaElement. received component uid = {}", (toscaElementToUpdate == null ? null : toscaElementToUpdate.getUniqueId()));
963 if (toscaElementToUpdate == null) {
964 log.error("Service object is null");
965 result = Either.right(StorageOperationStatus.BAD_REQUEST);
969 String modifierUserId = toscaElementToUpdate.getLastUpdaterUserId();
970 if (modifierUserId == null || modifierUserId.isEmpty()) {
971 log.error("UserId is missing in the request.");
972 result = Either.right(StorageOperationStatus.BAD_REQUEST);
975 Either<GraphVertex, TitanOperationStatus> findUser = findUserVertex(modifierUserId);
977 if (findUser.isRight()) {
978 TitanOperationStatus status = findUser.right().value();
979 log.error(CANNOT_FIND_USER_IN_THE_GRAPH_STATUS_IS, modifierUserId, status);
983 GraphVertex modifierV = findUser.left().value();
984 String toscaElementId = toscaElementToUpdate.getUniqueId();
986 Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(elementV, EdgeLabelEnum.LAST_MODIFIER, JsonParseFlagEnum.NoParse);
987 if (parentVertex.isRight()) {
988 log.debug("Failed to fetch last modifier for tosca element with id {} error {}", toscaElementId, parentVertex.right().value());
989 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(parentVertex.right().value()));
991 GraphVertex userV = parentVertex.left().value();
992 String currentModifier = (String) userV.getMetadataProperty(GraphPropertyEnum.USERID);
994 String prevSystemName = (String) elementV.getMetadataProperty(GraphPropertyEnum.SYSTEM_NAME);
996 if (currentModifier.equals(modifierUserId)) {
997 log.debug("Graph LAST MODIFIER edge should not be changed since the modifier is the same as the last modifier.");
999 log.debug("Going to update the last modifier user of the resource from {} to {}", currentModifier, modifierUserId);
1000 StorageOperationStatus status = moveLastModifierEdge(elementV, modifierV);
1001 log.debug("Finish to update the last modifier user of the resource from {} to {}. status is {}", currentModifier, modifierUserId, status);
1002 if (status != StorageOperationStatus.OK) {
1003 result = Either.right(status);
1008 final long currentTimeMillis = System.currentTimeMillis();
1009 log.debug("Going to update the last Update Date of the resource from {} to {}", elementV.getJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE), currentTimeMillis);
1010 elementV.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, currentTimeMillis);
1012 StorageOperationStatus checkCategories = validateCategories(toscaElementToUpdate, elementV);
1013 if (checkCategories != StorageOperationStatus.OK) {
1014 result = Either.right(checkCategories);
1018 // update all data on vertex
1019 fillToscaElementVertexData(elementV, toscaElementToUpdate, JsonParseFlagEnum.ParseMetadata);
1021 Either<GraphVertex, TitanOperationStatus> updateElement = titanDao.updateVertex(elementV);
1023 if (updateElement.isRight()) {
1024 log.error("Failed to update resource {}. status is {}", toscaElementId, updateElement.right().value());
1025 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateElement.right().value()));
1028 GraphVertex updateElementV = updateElement.left().value();
1030 // DE230195 in case resource name changed update TOSCA artifacts
1031 // file names accordingly
1032 String newSystemName = (String) updateElementV.getMetadataProperty(GraphPropertyEnum.SYSTEM_NAME);
1033 if (newSystemName != null && !newSystemName.equals(prevSystemName)) {
1034 Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> resultToscaArt = getDataFromGraph(updateElementV, EdgeLabelEnum.TOSCA_ARTIFACTS);
1035 if (resultToscaArt.isRight()) {
1036 log.debug("Failed to get tosca artifact from graph for tosca element {} error {}", toscaElementId, resultToscaArt.right().value());
1037 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resultToscaArt.right().value()));
1040 Map<String, ArtifactDataDefinition> toscaArtifacts = resultToscaArt.left().value();
1041 if (toscaArtifacts != null) {
1042 for (Entry<String, ArtifactDataDefinition> artifact : toscaArtifacts.entrySet()) {
1043 generateNewToscaFileName(toscaElementToUpdate.getComponentType().getValue().toLowerCase(), newSystemName, artifact.getValue());
1045 // TODO call to new Artifact operation in order to update list of artifacts
1050 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.RESOURCE) {
1051 StorageOperationStatus resultDerived = updateDerived(toscaElementToUpdate, updateElementV);
1052 if (resultDerived != StorageOperationStatus.OK) {
1053 log.debug("Failed to update from derived data for element {} error {}", toscaElementId, resultDerived);
1054 return Either.right(resultDerived);
1058 Either<T, StorageOperationStatus> updatedResource = getToscaElement(updateElementV, filterResult);
1059 if (updatedResource.isRight()) {
1060 log.error("Failed to fetch tosca element {} after update , error {}", toscaElementId, updatedResource.right().value());
1061 result = Either.right(StorageOperationStatus.BAD_REQUEST);
1065 T updatedResourceValue = updatedResource.left().value();
1066 result = Either.left(updatedResourceValue);
1071 protected StorageOperationStatus moveLastModifierEdge(GraphVertex elementV, GraphVertex modifierV) {
1072 return DaoStatusConverter.convertTitanStatusToStorageStatus(titanDao.moveEdge(elementV, modifierV, EdgeLabelEnum.LAST_MODIFIER, Direction.IN));
1075 protected StorageOperationStatus moveCategoryEdge(GraphVertex elementV, GraphVertex categoryV) {
1076 return DaoStatusConverter.convertTitanStatusToStorageStatus(titanDao.moveEdge(elementV, categoryV, EdgeLabelEnum.CATEGORY, Direction.OUT));
1079 private void generateNewToscaFileName(String componentType, String componentName, ArtifactDataDefinition artifactInfo) {
1080 Map<String, Object> getConfig = (Map<String, Object>) ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts().entrySet().stream().filter(p -> p.getKey().equalsIgnoreCase(artifactInfo.getArtifactLabel()))
1081 .findAny().get().getValue();
1082 artifactInfo.setArtifactName(componentType + "-" + componentName + getConfig.get("artifactName"));
1085 protected <T extends ToscaElement> StorageOperationStatus validateResourceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1086 StorageOperationStatus status = StorageOperationStatus.OK;
1087 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1088 CategoryDefinition newCategory = newCategoryList.get(0);
1090 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1091 if (childVertex.isRight()) {
1092 log.debug(FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR, EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1093 return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
1095 GraphVertex subCategoryV = childVertex.left().value();
1096 Map<GraphPropertyEnum, Object> metadataProperties = subCategoryV.getMetadataProperties();
1097 String subCategoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1099 Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
1100 if (parentVertex.isRight()) {
1101 log.debug("failed to fetch {} for category with id {}, error {}", EdgeLabelEnum.SUB_CATEGORY, subCategoryV.getUniqueId(), parentVertex.right().value());
1102 return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
1104 GraphVertex categoryV = parentVertex.left().value();
1105 metadataProperties = categoryV.getMetadataProperties();
1106 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1108 boolean categoryWasChanged = false;
1110 String newCategoryName = newCategory.getName();
1111 SubCategoryDefinition newSubcategory = newCategory.getSubcategories().get(0);
1112 String newSubCategoryName = newSubcategory.getName();
1113 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1114 // the category was changed
1115 categoryWasChanged = true;
1117 // the sub-category was changed
1118 if (newSubCategoryName != null && !newSubCategoryName.equals(subCategoryNameCurrent)) {
1119 log.debug("Going to update the category of the resource from {} to {}", categoryNameCurrent, newCategory);
1120 categoryWasChanged = true;
1123 if (categoryWasChanged) {
1124 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = getResourceCategoryVertex(elementV.getUniqueId(), newSubCategoryName, newCategoryName);
1126 if (getCategoryVertex.isRight()) {
1127 return getCategoryVertex.right().value();
1129 GraphVertex newCategoryV = getCategoryVertex.left().value();
1130 status = moveCategoryEdge(elementV, newCategoryV);
1131 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1136 public <T extends ToscaElement> Either<List<T>, StorageOperationStatus> getElementCatalogData(ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes, boolean isHighestVersions) {
1137 Either<List<GraphVertex>, TitanOperationStatus> listOfComponents;
1138 if (isHighestVersions) {
1139 listOfComponents = getListOfHighestComponents(componentType, excludeTypes, JsonParseFlagEnum.NoParse);
1141 listOfComponents = getListOfHighestAndAllCertifiedComponents(componentType, excludeTypes);
1144 if (listOfComponents.isRight() && listOfComponents.right().value() != TitanOperationStatus.NOT_FOUND) {
1145 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(listOfComponents.right().value()));
1147 List<T> result = new ArrayList<>();
1148 if (listOfComponents.isLeft()) {
1149 List<GraphVertex> highestAndAllCertified = listOfComponents.left().value();
1150 if (highestAndAllCertified != null && !highestAndAllCertified.isEmpty()) {
1151 for (GraphVertex vertexComponent : highestAndAllCertified) {
1152 Either<T, StorageOperationStatus> component = getLightComponent(vertexComponent, componentType, new ComponentParametersView(true));
1153 if (component.isRight()) {
1154 log.debug("Failed to fetch light element for {} error {}", vertexComponent.getUniqueId(), component.right().value());
1155 return Either.right(component.right().value());
1157 result.add(component.left().value());
1162 return Either.left(result);
1165 public Either<List<CatalogComponent>, StorageOperationStatus> getElementCatalogData(boolean isCatalog, List<ResourceTypeEnum> excludeTypes) {
1166 StopWatch stopWatch = new StopWatch();
1169 Map<String, CatalogComponent> existInCatalog = new HashMap<>();
1170 Either<Iterator<Vertex>, TitanOperationStatus> verticesEither = titanDao.getCatalogOrArchiveVerticies(isCatalog);
1171 if (verticesEither.isRight()) {
1172 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(verticesEither.right().value()));
1174 Iterator<Vertex> vertices = verticesEither.left().value();
1175 while (vertices.hasNext()) {
1176 handleCatalogComponent(existInCatalog, vertices.next(), excludeTypes);
1179 String timeToFetchElements = stopWatch.prettyPrint();
1180 log.info("time to fetch all catalog elements: {}", timeToFetchElements);
1181 return Either.left(existInCatalog.values().stream().collect(Collectors.toList()));
1184 private void handleCatalogComponent(Map<String, CatalogComponent> existInCatalog, Vertex vertex, List<ResourceTypeEnum> excludeTypes) {
1185 VertexProperty<Object> property = vertex.property(GraphPropertiesDictionary.METADATA.getProperty());
1186 String json = (String) property.value();
1187 Map<String, Object> metadatObj = JsonParserUtils.toMap(json);
1189 String uniqueId = (String) metadatObj.get(JsonPresentationFields.UNIQUE_ID.getPresentation());
1190 Boolean isDeleted = (Boolean) metadatObj.get(JsonPresentationFields.IS_DELETED.getPresentation());
1193 if (isAddToCatalog(excludeTypes, metadatObj) && (existInCatalog.get(uniqueId) == null && (isDeleted == null || !isDeleted.booleanValue()))) {
1194 CatalogComponent catalogComponent = new CatalogComponent();
1195 catalogComponent.setUniqueId(uniqueId);
1197 catalogComponent.setComponentType(ComponentTypeEnum.valueOf((String) metadatObj.get(JsonPresentationFields.COMPONENT_TYPE.getPresentation())));
1198 catalogComponent.setVersion((String) metadatObj.get(JsonPresentationFields.VERSION.getPresentation()));
1199 catalogComponent.setName((String) metadatObj.get(JsonPresentationFields.NAME.getPresentation()));
1200 catalogComponent.setIcon((String) metadatObj.get(JsonPresentationFields.ICON.getPresentation()));
1201 catalogComponent.setLifecycleState((String) metadatObj.get(JsonPresentationFields.LIFECYCLE_STATE.getPresentation()));
1202 catalogComponent.setLastUpdateDate((Long) metadatObj.get(JsonPresentationFields.LAST_UPDATE_DATE.getPresentation()));
1203 catalogComponent.setDistributionStatus((String) metadatObj.get(JsonPresentationFields.DISTRIBUTION_STATUS.getPresentation()));
1204 Object resourceType = metadatObj.get(JsonPresentationFields.RESOURCE_TYPE.getPresentation());
1205 if (resourceType != null) {
1206 catalogComponent.setResourceType((String) resourceType);
1209 if (catalogComponent.getComponentType() == ComponentTypeEnum.SERVICE) {
1210 setServiceCategoryFromGraphV(vertex, catalogComponent);
1213 setResourceCategoryFromGraphV(vertex, catalogComponent);
1215 List<String> tags = (List<String>) metadatObj.get(JsonPresentationFields.TAGS.getPresentation());
1217 catalogComponent.setTags(tags);
1219 existInCatalog.put(uniqueId, catalogComponent);
1223 private boolean isAddToCatalog(List<ResourceTypeEnum> excludeTypes, Map<String, Object> metadatObj) {
1224 boolean isAddToCatalog = true;
1225 Object resourceTypeStr = metadatObj.get(JsonPresentationFields.RESOURCE_TYPE.getPresentation());
1226 if (resourceTypeStr != null) {
1227 ResourceTypeEnum resourceType = ResourceTypeEnum.getType((String) resourceTypeStr);
1228 if (!CollectionUtils.isEmpty(excludeTypes)) {
1229 Optional<ResourceTypeEnum> op = excludeTypes.stream().filter(rt -> rt == resourceType).findAny();
1231 isAddToCatalog = false;
1234 return isAddToCatalog;
1237 public Either<List<GraphVertex>, TitanOperationStatus> getListOfHighestComponents(ComponentTypeEnum
1238 componentType, List<ResourceTypeEnum> excludeTypes, JsonParseFlagEnum parseFlag) {
1239 Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
1240 Map<GraphPropertyEnum, Object> propertiesHasNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
1241 propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
1242 propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
1244 if (componentType == ComponentTypeEnum.RESOURCE) {
1245 propertiesToMatch.put(GraphPropertyEnum.IS_ABSTRACT, false);
1246 propertiesHasNotToMatch.put(GraphPropertyEnum.RESOURCE_TYPE, excludeTypes);
1248 propertiesHasNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
1249 propertiesHasNotToMatch.put(GraphPropertyEnum.IS_ARCHIVED, true); //US382674, US382683
1251 return titanDao.getByCriteria(null, propertiesToMatch, propertiesHasNotToMatch, parseFlag);
1254 // highest + (certified && !highest)
1255 public Either<List<GraphVertex>, TitanOperationStatus> getListOfHighestAndAllCertifiedComponents
1256 (ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes) {
1257 long startFetchAllStates = System.currentTimeMillis();
1258 Either<List<GraphVertex>, TitanOperationStatus> highestNodes = getListOfHighestComponents(componentType, excludeTypes, JsonParseFlagEnum.ParseMetadata);
1260 Map<GraphPropertyEnum, Object> propertiesToMatchCertified = new EnumMap<>(GraphPropertyEnum.class);
1261 Map<GraphPropertyEnum, Object> propertiesHasNotToMatchCertified = new EnumMap<>(GraphPropertyEnum.class);
1262 propertiesToMatchCertified.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
1263 propertiesToMatchCertified.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
1264 if (componentType == ComponentTypeEnum.RESOURCE) {
1265 propertiesToMatchCertified.put(GraphPropertyEnum.IS_ABSTRACT, false);
1266 propertiesHasNotToMatchCertified.put(GraphPropertyEnum.RESOURCE_TYPE, excludeTypes);
1269 propertiesHasNotToMatchCertified.put(GraphPropertyEnum.IS_DELETED, true);
1270 propertiesHasNotToMatchCertified.put(GraphPropertyEnum.IS_ARCHIVED, true); //US382674, US382683
1271 propertiesHasNotToMatchCertified.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
1273 Either<List<GraphVertex>, TitanOperationStatus> certifiedNotHighestNodes = titanDao.getByCriteria(null, propertiesToMatchCertified, propertiesHasNotToMatchCertified, JsonParseFlagEnum.ParseMetadata);
1274 if (certifiedNotHighestNodes.isRight() && certifiedNotHighestNodes.right().value() != TitanOperationStatus.NOT_FOUND) {
1275 return Either.right(certifiedNotHighestNodes.right().value());
1278 long endFetchAllStates = System.currentTimeMillis();
1280 List<GraphVertex> allNodes = new ArrayList<>();
1282 if (certifiedNotHighestNodes.isLeft()) {
1283 allNodes.addAll(certifiedNotHighestNodes.left().value());
1285 if (highestNodes.isLeft()) {
1286 allNodes.addAll(highestNodes.left().value());
1289 log.debug("Fetch catalog {}s all states from graph took {} ms", componentType, endFetchAllStates - startFetchAllStates);
1290 return Either.left(allNodes);
1293 protected Either<List<GraphVertex>, StorageOperationStatus> getAllComponentsMarkedForDeletion(ComponentTypeEnum
1296 // get all components marked for delete
1297 Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
1298 props.put(GraphPropertyEnum.IS_DELETED, true);
1299 props.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
1301 Either<List<GraphVertex>, TitanOperationStatus> componentsToDelete = titanDao.getByCriteria(null, props, JsonParseFlagEnum.NoParse);
1303 if (componentsToDelete.isRight()) {
1304 TitanOperationStatus error = componentsToDelete.right().value();
1305 if (error.equals(TitanOperationStatus.NOT_FOUND)) {
1306 log.trace("no components to delete");
1307 return Either.left(new ArrayList<>());
1309 log.info("failed to find components to delete. error : {}", error.name());
1310 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(error));
1313 return Either.left(componentsToDelete.left().value());
1316 protected TitanOperationStatus setAdditionalInformationFromGraph(GraphVertex componentV, ToscaElement
1318 Either<Map<String, AdditionalInfoParameterDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.ADDITIONAL_INFORMATION);
1319 if (result.isLeft()) {
1320 toscaElement.setAdditionalInformation(result.left().value());
1322 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1323 return result.right().value();
1326 return TitanOperationStatus.OK;
1329 // --------------------------------------------
1330 public abstract <T extends
1331 ToscaElement> Either<T, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView);
1333 public abstract <T extends
1334 ToscaElement> Either<T, StorageOperationStatus> getToscaElement(GraphVertex toscaElementVertex, ComponentParametersView componentParametersView);
1336 public abstract <T extends
1337 ToscaElement> Either<T, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex);
1339 public abstract <T extends
1340 ToscaElement> Either<T, StorageOperationStatus> createToscaElement(ToscaElement toscaElement);
1342 protected abstract <T extends ToscaElement> TitanOperationStatus
1343 setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement);
1345 protected abstract <T extends ToscaElement> TitanOperationStatus
1346 setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement);
1348 protected abstract <T extends ToscaElement> TitanOperationStatus
1349 setRequirementsFromGraph(GraphVertex componentV, T toscaElement);
1351 protected abstract <T extends ToscaElement> StorageOperationStatus
1352 validateCategories(T toscaElementToUpdate, GraphVertex elementV);
1354 protected abstract <T extends ToscaElement> StorageOperationStatus
1355 updateDerived(T toscaElementToUpdate, GraphVertex updateElementV);
1357 public abstract <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T
1358 toscaElementToUpdate, JsonParseFlagEnum flag);