Sync Integ to Master
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / jsontitan / operations / TopologyTemplateOperation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.model.jsontitan.operations;
22
23 import com.google.gson.reflect.TypeToken;
24 import fj.data.Either;
25 import org.apache.commons.collections.MapUtils;
26 import org.apache.tinkerpop.gremlin.structure.Direction;
27 import org.apache.tinkerpop.gremlin.structure.Edge;
28 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
29 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
30 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
31 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
32 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
33 import org.openecomp.sdc.be.datatypes.elements.*;
34 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
35 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
36 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
37 import org.openecomp.sdc.be.model.Component;
38 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
39 import org.openecomp.sdc.be.model.ComponentParametersView;
40 import org.openecomp.sdc.be.model.DistributionStatusEnum;
41 import org.openecomp.sdc.be.model.PolicyDefinition;
42 import org.openecomp.sdc.be.model.User;
43 import org.openecomp.sdc.be.model.category.CategoryDefinition;
44 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
45 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
46 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
47 import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum;
48 import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
49 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
50 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
51 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
52 import org.openecomp.sdc.common.api.Constants;
53 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
54 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
55 import org.slf4j.Logger;
56 import org.slf4j.LoggerFactory;
57
58 import java.lang.reflect.Type;
59 import java.util.ArrayList;
60 import java.util.HashMap;
61 import java.util.Iterator;
62 import java.util.List;
63 import java.util.Map;
64 import java.util.Map.Entry;
65 import java.util.stream.Collectors;
66
67 @org.springframework.stereotype.Component("topology-template-operation")
68 public class TopologyTemplateOperation extends ToscaElementOperation {
69
70         private static Logger log = LoggerFactory.getLogger(TopologyTemplateOperation.class.getName());
71
72         @Override
73         public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId) {
74                 return super.getToscaElement(uniqueId);
75         }
76
77         public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
78                 Either<TopologyTemplate, StorageOperationStatus> result = null;
79
80                 topologyTemplate.generateUUID();
81
82                 topologyTemplate = (TopologyTemplate) getResourceMetaDataFromResource(topologyTemplate);
83                 String resourceUniqueId = topologyTemplate.getUniqueId();
84                 if (resourceUniqueId == null) {
85                         resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
86                         topologyTemplate.setUniqueId(resourceUniqueId);
87                 }
88
89                 GraphVertex topologyTemplateVertex = new GraphVertex();
90                 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
91
92                 Either<GraphVertex, TitanOperationStatus> createdVertex = titanDao.createVertex(topologyTemplateVertex);
93                 if (createdVertex.isRight()) {
94                         TitanOperationStatus status = createdVertex.right().value();
95                         log.error("Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
96                         result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
97                         return result;
98                 }
99
100                 topologyTemplateVertex = createdVertex.left().value();
101
102                 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate, null);
103                 if (assosiateCommon != StorageOperationStatus.OK) {
104                         result = Either.right(assosiateCommon);
105                         return result;
106                 }
107
108                 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
109                 if (associateCategory != StorageOperationStatus.OK) {
110                         result = Either.right(associateCategory);
111                         return result;
112                 }
113
114                 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
115                 if (associateInputs != StorageOperationStatus.OK) {
116                         result = Either.right(associateInputs);
117                         return result;
118                 }
119                 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
120                 if (associateGroups != StorageOperationStatus.OK) {
121                         result = Either.right(associateGroups);
122                         return result;
123                 }
124                 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
125                 if (associatePolicies != StorageOperationStatus.OK) {
126                         result = Either.right(associatePolicies);
127                         return result;
128                 }
129                 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
130                 if (associateInstAttr != StorageOperationStatus.OK) {
131                         result = Either.right(associateInstAttr);
132                         return result;
133                 }
134                 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
135                 if (associateInstProperties != StorageOperationStatus.OK) {
136                         result = Either.right(associateInstProperties);
137                         return result;
138                 }
139                 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
140                 if (associateInstProperties != StorageOperationStatus.OK) {
141                         result = Either.right(associateInstInputs);
142                         return result;
143                 }
144                 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
145                 if (associateInstGroups != StorageOperationStatus.OK) {
146                         result = Either.right(associateInstInputs);
147                         return result;
148                 }
149                 
150                 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
151                 if (associateRequirements != StorageOperationStatus.OK) {
152                         result = Either.right(associateRequirements);
153                         return result;
154                 }
155
156                 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
157                 if (associateCapabilities != StorageOperationStatus.OK) {
158                         result = Either.right(associateCapabilities);
159                         return result;
160                 }
161
162                 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
163                 if (associateArtifacts != StorageOperationStatus.OK) {
164                         result = Either.right(associateArtifacts);
165                         return result;
166                 }
167
168                 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
169                 if (addAdditionalInformation != StorageOperationStatus.OK) {
170                         result = Either.right(addAdditionalInformation);
171                         return result;
172                 }
173                 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
174                 if (associateCapProperties != StorageOperationStatus.OK) {
175                         result = Either.right(associateCapProperties);
176                         return result;
177                 }
178                 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
179                 if (associateCapProperties != StorageOperationStatus.OK) {
180                         result = Either.right(associatePathProperties);
181                         return result;
182                 }
183
184
185                 return Either.left(topologyTemplate);
186
187         }
188
189         private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
190                 return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
191         }
192
193         private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
194                 if (policies != null && !policies.isEmpty()) {
195                         policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
196                                 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
197                                 p.setUniqueId(uid);
198                         });
199                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
200                         if (assosiateElementToData.isRight()) {
201                                 return assosiateElementToData.right().value();
202                         }
203                 }
204                 return StorageOperationStatus.OK;
205         }
206
207         private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
208                 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
209                 return associateForwardingPathToComponent(topologyTemplateVertex,forwardingPaths);
210         }
211
212         private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
213                 Map<String, MapCapabiltyProperty> calculatedCapProperties = topologyTemplate.getCalculatedCapabilitiesProperties();
214                 if (calculatedCapProperties != null && !calculatedCapProperties.isEmpty()) {
215                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
216                         if (assosiateElementToData.isRight()) {
217                                 return assosiateElementToData.right().value();
218                         }
219                 }
220                 return StorageOperationStatus.OK;
221         }
222
223         private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
224                 Map<String, MapListCapabiltyDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
225                 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
226                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
227                         if (assosiateElementToData.isRight()) {
228                                 return assosiateElementToData.right().value();
229                         }
230                 }
231                 Map<String, MapListCapabiltyDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
232                 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
233                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
234                         if (assosiateElementToData.isRight()) {
235                                 return assosiateElementToData.right().value();
236                         }
237                 }
238                 return StorageOperationStatus.OK;
239
240         }
241
242         private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
243                 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
244                 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
245                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
246                         if (assosiateElementToData.isRight()) {
247                                 return assosiateElementToData.right().value();
248                         }
249                 }
250                 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
251                 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
252                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
253                         if (assosiateElementToData.isRight()) {
254                                 return assosiateElementToData.right().value();
255                         }
256                 }
257                 return StorageOperationStatus.OK;
258         }
259
260         private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
261                 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
262
263                 if (addInformation != null && !addInformation.isEmpty()) {
264                         addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
265                                 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
266                                 a.setUniqueId(uniqueId);
267                         });
268                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
269                         if (assosiateElementToData.isRight()) {
270                                 return assosiateElementToData.right().value();
271                         }
272                 }
273                 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
274
275                 if (instArtifacts != null && !instArtifacts.isEmpty()) {
276                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
277                         if (assosiateElementToData.isRight()) {
278                                 return assosiateElementToData.right().value();
279                         }
280                 }
281                 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
282
283                 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
284                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
285                         if (assosiateElementToData.isRight()) {
286                                 return assosiateElementToData.right().value();
287                         }
288                 }
289                 return StorageOperationStatus.OK;
290         }
291
292         private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
293
294                 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
295
296                 if (addInformation != null && !addInformation.isEmpty()) {
297                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
298                         if (assosiateElementToData.isRight()) {
299                                 return assosiateElementToData.right().value();
300                         }
301                 }
302                 return StorageOperationStatus.OK;
303         }
304
305         public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
306                 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
307                 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
308         }
309
310         public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
311                 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
312                 return associateInstInputsToComponent(nodeTypeVertex, instProps);
313         }
314         
315         public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
316                 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
317                 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
318         }
319         
320
321         public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
322                 if (instProps != null && !instProps.isEmpty()) {
323                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
324                         if (assosiateElementToData.isRight()) {
325                                 return assosiateElementToData.right().value();
326                         }
327                 }
328                 return StorageOperationStatus.OK;
329         }
330
331         public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
332                 if (instInputs != null && !instInputs.isEmpty()) {
333                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
334                         if (assosiateElementToData.isRight()) {
335                                 return assosiateElementToData.right().value();
336                         }
337                 }
338                 return StorageOperationStatus.OK;
339         }
340         
341         public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
342                 if (instGroups != null && !instGroups.isEmpty()) {
343                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
344                         if (assosiateElementToData.isRight()) {
345                                 return assosiateElementToData.right().value();
346                         }
347                 }
348                 return StorageOperationStatus.OK;
349         }
350
351
352         public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
353
354                 if (instInputs != null && !instInputs.isEmpty()) {
355                         instInputs.entrySet().forEach(i -> {
356                                 List<String> uniqueKeys = new ArrayList<String>(i.getValue().getMapToscaDataDefinition().keySet());
357                                 List<String> pathKeys = new ArrayList<String>();
358                                 pathKeys.add(i.getKey());
359
360                                 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
361                                 if (status != StorageOperationStatus.OK) {
362                                         return;
363                                 }
364                         });
365                 }
366
367                 return StorageOperationStatus.OK;
368         }
369
370         public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
371
372                 if (instInputs != null && !instInputs.isEmpty()) {
373                         instInputs.entrySet().forEach(i -> {
374                                 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
375                                 if (status != StorageOperationStatus.OK) {
376                                         return;
377                                 }
378                         });
379                 }
380
381                 return StorageOperationStatus.OK;
382         }
383
384         public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
385                 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
386         }
387         
388         public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
389                 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
390         }
391
392         private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
393                 if (instProps != null && !instProps.isEmpty()) {
394                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
395                         if (assosiateElementToData.isRight()) {
396                                 return assosiateElementToData.right().value();
397                         }
398                 }
399                 return StorageOperationStatus.OK;
400         }
401
402         public StorageOperationStatus associateCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabiltyDataDefinition> calcCapabilty, Map<String, MapCapabiltyProperty> calculatedCapabilitiesProperties) {
403                 if (calcRequirements != null && !calcRequirements.isEmpty()) {
404                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
405                         if (assosiateElementToData.isRight()) {
406                                 return assosiateElementToData.right().value();
407                         }
408                         Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
409                         assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
410                         if (assosiateElementToData.isRight()) {
411                                 return assosiateElementToData.right().value();
412                         }
413                 }
414                 if (calcCapabilty != null && !calcCapabilty.isEmpty()) {
415                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
416                         if (assosiateElementToData.isRight()) {
417                                 return assosiateElementToData.right().value();
418                         }
419                         Map<String, MapListCapabiltyDataDefinition> fullFilled = new HashMap<>();
420                         assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
421                         if (assosiateElementToData.isRight()) {
422                                 return assosiateElementToData.right().value();
423                         }
424                 }
425                 if ( calculatedCapabilitiesProperties != null && !calculatedCapabilitiesProperties.isEmpty() ){
426                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties);
427                         if (assosiateElementToData.isRight()) {
428                                 return assosiateElementToData.right().value();
429                         }
430                 }
431                 return StorageOperationStatus.OK;
432         }
433
434         private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
435                 Map<String, MapPropertiesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
436                 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
437         }
438
439         public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
440                 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
441                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
442                         if (assosiateElementToData.isRight()) {
443                                 return assosiateElementToData.right().value();
444                         }
445                 }
446                 return StorageOperationStatus.OK;
447         }
448
449         public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instAttr) {
450                 if (instAttr != null && !instAttr.isEmpty()) {
451                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
452                         if (assosiateElementToData.isRight()) {
453                                 return assosiateElementToData.right().value();
454                         }
455                 }
456                 return StorageOperationStatus.OK;
457         }
458
459         public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
460
461                 if (groups != null && !groups.isEmpty()) {
462                         groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
463                                 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
464                                 p.setUniqueId(uid);
465                         });
466                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
467                         if (assosiateElementToData.isRight()) {
468                                 return assosiateElementToData.right().value();
469                         }
470                 }
471                 return StorageOperationStatus.OK;
472         }
473
474         private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
475                 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
476         }
477
478         public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
479                 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
480                 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
481         }
482
483         public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
484                 if (inputs != null && !inputs.isEmpty()) {
485                         inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
486
487                         Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
488                         if (assosiateElementToData.isRight()) {
489                                 return assosiateElementToData.right().value();
490                         }
491                 }
492                 return StorageOperationStatus.OK;
493         }
494
495         private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
496                 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
497                 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
498                 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
499                         nodeTypeVertex.setJson(topologyTemplate.getCompositions());
500                 }
501                 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
502                 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
503                 
504                 return nodeTypeVertex;
505
506         }
507
508         private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
509                 if (topologyTemplate.getResourceType() == null) {
510                         // service
511                         return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
512                 } else {
513                         // VF
514                         return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
515                 }
516         }
517
518         private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
519                 String categoryName = topologyTemplate.getCategories().get(0).getName();
520                 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
521                 if (category.isRight()) {
522                         log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
523                         return StorageOperationStatus.CATEGORY_NOT_FOUND;
524                 }
525                 GraphVertex categoryV = category.left().value();
526                 TitanOperationStatus createEdge = titanDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
527                 if (createEdge != TitanOperationStatus.OK) {
528                         log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
529                         return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
530                 }
531                 return StorageOperationStatus.OK;
532         }
533
534         @Override
535         public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
536                 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
537
538                 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TopologyTemplate, parseFlag);
539                 if (componentByLabelAndId.isRight()) {
540                         return Either.right(componentByLabelAndId.right().value());
541                 }
542                 GraphVertex componentV = componentByLabelAndId.left().value();
543
544                 return getToscaElement(componentV, componentParametersView);
545
546         }
547         // -------------------------------------------------------------
548
549         public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
550                 TopologyTemplate toscaElement;
551
552                 toscaElement = convertToTopologyTemplate(componentV);
553                 TitanOperationStatus status;
554                 if (!componentParametersView.isIgnoreUsers()) {
555                         status = setCreatorFromGraph(componentV, toscaElement);
556                         if (status != TitanOperationStatus.OK) {
557                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
558                         }
559
560                         status = setLastModifierFromGraph(componentV, toscaElement);
561                         if (status != TitanOperationStatus.OK) {
562                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
563                         }
564                 }
565                 if (!componentParametersView.isIgnoreCategories()) {
566                         status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
567                         if (status != TitanOperationStatus.OK) {
568                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
569
570                         }
571                 }
572                 if (!componentParametersView.isIgnoreArtifacts()) {
573                         TitanOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
574                         if (storageStatus != TitanOperationStatus.OK) {
575                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
576                         }
577                 }
578                 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
579                         status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
580                         if (status != TitanOperationStatus.OK) {
581                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
582                         }
583                 }
584                 if (!componentParametersView.isIgnoreCapabilities()) {
585                         status = setCapabilitiesFromGraph(componentV, toscaElement);
586                         if (status != TitanOperationStatus.OK) {
587                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
588                         }
589                 }
590                 if (!componentParametersView.isIgnoreRequirements()) {
591                         status = setRequirementsFromGraph(componentV, toscaElement);
592                         if (status != TitanOperationStatus.OK) {
593                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
594                         }
595                 }
596                 if (!componentParametersView.isIgnoreAllVersions()) {
597                         status = setAllVersions(componentV, toscaElement);
598                         if (status != TitanOperationStatus.OK) {
599                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
600                         }
601                 }
602                 if (!componentParametersView.isIgnoreAdditionalInformation()) {
603                         status = setAdditionalInformationFromGraph(componentV, toscaElement);
604                         if (status != TitanOperationStatus.OK) {
605                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
606                         }
607                 }
608
609                 if (!componentParametersView.isIgnoreGroups()) {
610                         status = setGroupsFromGraph(componentV, toscaElement);
611                         if (status != TitanOperationStatus.OK) {
612                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
613                         }
614
615                 }
616                 if (!componentParametersView.isIgnorePolicies()) {
617                         status = setPoliciesFromGraph(componentV, toscaElement);
618                         if (status != TitanOperationStatus.OK) {
619                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
620                         }
621
622                 }
623                 if (!componentParametersView.isIgnoreComponentInstances()) {
624                         status = setInstGroupsFromGraph(componentV, toscaElement);
625                         if (status != TitanOperationStatus.OK) {
626                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
627                         }
628
629                 }
630                 if (!componentParametersView.isIgnoreInputs()) {
631                         status = setInputsFromGraph(componentV, toscaElement);
632                         if (status != TitanOperationStatus.OK) {
633                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
634                         }
635
636                 }
637                 if (!componentParametersView.isIgnoreProperties()) {
638                         status = setPropertiesFromGraph(componentV, toscaElement);
639                         if (status != TitanOperationStatus.OK) {
640                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
641                         }
642
643                 }
644
645                 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
646                         status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
647                         if (status != TitanOperationStatus.OK) {
648                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
649
650                         }
651                 }
652
653                 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
654                         status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
655                         if (status != TitanOperationStatus.OK) {
656                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
657
658                         }
659                 }
660
661                 if (!componentParametersView.isIgnoreForwardingPath()) {
662                         status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
663                         if (status != TitanOperationStatus.OK) {
664                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
665
666                         }
667                 }
668                 return Either.left(toscaElement);
669         }
670
671         private TitanOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
672                 Either<Map<String, PolicyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
673                 if (result.isLeft()) {
674                         toscaElement.setPolicies(result.left().value());
675                 } else {
676                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
677                                 return result.right().value();
678                         }
679                 }
680                 return TitanOperationStatus.OK;
681         }
682
683         private TitanOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
684                 Either<Map<String, ForwardingPathDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
685                 if (result.isLeft()) {
686                         topologyTemplate.setForwardingPaths(result.left().value());
687                 } else {
688                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
689                                 return result.right().value();
690                         }
691                 }
692                 return TitanOperationStatus.OK;
693         }
694
695
696         private TitanOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
697                 Either<Map<String, MapCapabiltyProperty>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
698                 if (result.isLeft()) {
699                         topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
700                 } else {
701                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
702                                 return result.right().value();
703                         }
704                 }
705                 return TitanOperationStatus.OK;
706         }
707
708         private TitanOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
709                 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
710                 if (result.isLeft()) {
711                         toscaElement.setProperties(result.left().value());
712                 } else {
713                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
714                                 return result.right().value();
715                         }
716                 }
717                 return TitanOperationStatus.OK;
718         }
719
720         private TitanOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
721                 Either<Map<String, MapGroupsDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
722                 if (result.isLeft()) {
723                         topologyTemplate.setInstGroups(result.left().value());
724                 } else {
725                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
726                                 return result.right().value();
727                         }
728                 }
729                 return TitanOperationStatus.OK;
730         }
731
732         private TitanOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
733                 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
734                 if (result.isLeft()) {
735                         topologyTemplate.setInstProperties(result.left().value());
736                 } else {
737                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
738                                 return result.right().value();
739                         }
740                 }
741                 return TitanOperationStatus.OK;
742         }
743
744         private TitanOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
745                 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
746                 if (result.isLeft()) {
747                         topologyTemplate.setInstInputs(result.left().value());
748                 } else {
749                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
750                                 return result.right().value();
751                         }
752                 }
753                 return TitanOperationStatus.OK;
754         }
755
756         @Override
757         protected <T extends ToscaElement> TitanOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
758                 Either<Map<String, MapListRequirementDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
759                 if (result.isLeft()) {
760                         ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
761                 } else {
762                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
763                                 return result.right().value();
764                         }
765                 }
766                 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
767                 if (result.isLeft()) {
768                         ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
769                 } else {
770                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
771                                 return result.right().value();
772                         }
773                 }
774                 return TitanOperationStatus.OK;
775
776         }
777
778         protected <T extends ToscaElement> TitanOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
779                 Either<Map<String, MapListCapabiltyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
780                 if (result.isLeft()) {
781                         ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
782                 } else {
783                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
784                                 return result.right().value();
785                         }
786                 }
787                 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
788                 if (result.isLeft()) {
789                         ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
790                 } else {
791                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
792                                 return result.right().value();
793                         }
794                 }
795                 return TitanOperationStatus.OK;
796         }
797
798         private TitanOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
799                 TitanOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
800                 if (storageStatus != TitanOperationStatus.OK) {
801                         return storageStatus;
802                 }
803                 Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
804                 if (result.isLeft()) {
805                         toscaElement.setServiceApiArtifacts(result.left().value());
806                 } else {
807                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
808                                 return result.right().value();
809                         }
810                 }
811                 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
812                 if (resultInstArt.isLeft()) {
813                         toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
814                 } else {
815                         if (resultInstArt.right().value() != TitanOperationStatus.NOT_FOUND) {
816                                 return resultInstArt.right().value();
817                         }
818                 }
819                 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
820                 if (instanceArt.isLeft()) {
821                         toscaElement.setInstanceArtifacts(instanceArt.left().value());
822                 } else {
823                         if (instanceArt.right().value() != TitanOperationStatus.NOT_FOUND) {
824                                 return instanceArt.right().value();
825                         }
826                 }
827                 return TitanOperationStatus.OK;
828         }
829
830         private TitanOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
831                 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
832                 if (result.isLeft()) {
833                         toscaElement.setInputs(result.left().value());
834                 } else {
835                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
836                                 return result.right().value();
837                         }
838                 }
839                 return TitanOperationStatus.OK;
840         }
841
842         private TitanOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
843                 Either<Map<String, GroupDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
844                 if (result.isLeft()) {
845                         toscaElement.setGroups(result.left().value());
846                 } else {
847                         if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
848                                 return result.right().value();
849                         }
850                 }
851                 return TitanOperationStatus.OK;
852         }
853
854         private TitanOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
855                 List<CategoryDefinition> categories = new ArrayList<>();
856
857                 switch (componentV.getType()) {
858                 case RESOURCE:
859                         return setResourceCategoryFromGraph(componentV, toscaElement);
860                 case SERVICE:
861                         return setServiceCategoryFromGraph(componentV, toscaElement, categories);
862
863                 default:
864                         log.debug("Not supported component type {} ", componentV.getType());
865                         break;
866                 }
867                 return TitanOperationStatus.OK;
868         }
869
870         private TitanOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
871                 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
872                 if (childVertex.isRight()) {
873                         log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
874                         return childVertex.right().value();
875                 }
876                 GraphVertex categoryV = childVertex.left().value();
877                 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
878                 CategoryDefinition category = new CategoryDefinition();
879                 category.setUniqueId(categoryV.getUniqueId());
880                 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
881                 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
882
883                 Type listTypeCat = new TypeToken<List<String>>() {}.getType();
884                 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
885                 category.setIcons(iconsfromJsonCat);
886                 categories.add(category);
887                 toscaElement.setCategories(categories);
888
889                 return TitanOperationStatus.OK;
890         }
891
892         @SuppressWarnings("unchecked")
893         private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
894
895                 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
896
897                 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
898                 topologyTemplate.setCompositions(json);
899
900                 return topologyTemplate;
901         }
902
903         @Override
904         public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
905                 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
906                 if (nodeType.isRight()) {
907                         log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
908                         return nodeType;
909                 }
910                 TitanOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
911                 if (status != TitanOperationStatus.OK) {
912                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
913                 }
914                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
915                 if (status != TitanOperationStatus.OK) {
916                         log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
917                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
918                 }
919                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
920                 if (status != TitanOperationStatus.OK) {
921                         log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
922                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
923                 }
924
925                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
926                 if (status != TitanOperationStatus.OK) {
927                         log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
928                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
929                 }
930
931                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
932                 if (status != TitanOperationStatus.OK) {
933                         log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
934                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
935                 }
936                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
937                 if (status != TitanOperationStatus.OK) {
938                         log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
939                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
940                 }
941                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
942                 if (status != TitanOperationStatus.OK) {
943                         log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
944                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
945                 }
946                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
947                 if (status != TitanOperationStatus.OK) {
948                         log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
949                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
950                 }
951                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
952                 if (status != TitanOperationStatus.OK) {
953                         log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
954                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
955                 }
956                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
957                 if (status != TitanOperationStatus.OK) {
958                         log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
959                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
960                 }
961                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
962                 if (status != TitanOperationStatus.OK) {
963                         log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
964                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
965                 }
966                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
967                 if (status != TitanOperationStatus.OK) {
968                         log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
969                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
970                 }
971                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
972                 if (status != TitanOperationStatus.OK) {
973                         log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
974                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
975                 }
976                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
977                 if (status != TitanOperationStatus.OK) {
978                         log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
979                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
980                 }
981                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
982                 if (status != TitanOperationStatus.OK) {
983                         log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
984                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
985                 }
986                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
987                 if (status != TitanOperationStatus.OK) {
988                         log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
989                         Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
990                 }
991
992                 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
993                 toscaElementVertex.getVertex().remove();
994                 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
995
996                 return nodeType;
997         }
998
999         @SuppressWarnings("unchecked")
1000         @Override
1001         public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1002                 return createTopologyTemplate((TopologyTemplate) toscaElement);
1003         }
1004
1005         @Override
1006         protected <T extends ToscaElement> TitanOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1007                 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1008         }
1009
1010         @Override
1011         protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1012                 // Product isn't supported now!!
1013                 // TODO add for Product
1014                 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1015                         return validateServiceCategory(toscaElementToUpdate, elementV);
1016                 } else {
1017                         // Resource
1018                         return validateResourceCategory(toscaElementToUpdate, elementV);
1019                 }
1020         }
1021
1022         @Override
1023         protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1024                 // not relevant now for topology template
1025                 return StorageOperationStatus.OK;
1026         }
1027
1028         @Override
1029         public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1030                 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1031         }
1032
1033         private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1034                 StorageOperationStatus status = StorageOperationStatus.OK;
1035                 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1036                 CategoryDefinition newCategory = newCategoryList.get(0);
1037
1038                 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1039                 if (childVertex.isRight()) {
1040                         log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1041                         return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
1042                 }
1043
1044                 GraphVertex categoryV = childVertex.left().value();
1045                 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1046                 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1047
1048                 String newCategoryName = newCategory.getName();
1049                 if (newCategoryName != null && false == newCategoryName.equals(categoryNameCurrent)) {
1050                         // the category was changed
1051                         Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1052
1053                         if (getCategoryVertex.isRight()) {
1054                                 return getCategoryVertex.right().value();
1055                         }
1056                         GraphVertex newCategoryV = getCategoryVertex.left().value();
1057                         status = moveCategoryEdge(elementV, newCategoryV);
1058                         log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1059                 }
1060                 return status;
1061         }
1062
1063         public Either<List<GraphVertex>, TitanOperationStatus> getAllNotDeletedElements() {
1064                 Map<GraphPropertyEnum, Object> propsHasNot = new HashMap<>();
1065                 propsHasNot.put(GraphPropertyEnum.IS_DELETED, true);
1066
1067                 Either<List<GraphVertex>, TitanOperationStatus> byCriteria = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, null, propsHasNot, JsonParseFlagEnum.ParseJson);
1068                 if (byCriteria.isRight()) {
1069                         log.debug("Failed to fetch all non marked topology templates , propsHasNot {}, error {}", propsHasNot, byCriteria.right().value());
1070                         return Either.right(byCriteria.right().value());
1071                 }
1072                 return Either.left(byCriteria.left().value());
1073         }
1074
1075         @SuppressWarnings("unchecked")
1076         public boolean isInUse(GraphVertex elementV, List<GraphVertex> allNonDeleted) {
1077                 for (GraphVertex containerV : allNonDeleted) {
1078                         Map<String, CompositionDataDefinition> composition = (Map<String, CompositionDataDefinition>) containerV.getJson();
1079                         if (composition != null) {
1080                                 CompositionDataDefinition instances = composition.get(JsonConstantKeysEnum.COMPOSITION.getValue());
1081                                 if (instances != null && instances.getComponentInstances() != null && !instances.getComponentInstances().isEmpty()) {
1082                                         for (ComponentInstanceDataDefinition ci : instances.getComponentInstances().values()) {
1083                                                 if (ci.getComponentUid().equals(elementV.getUniqueId())) {
1084                                                         log.debug("The resource {} failed to delete cause in use as component instance UniqueID = {} in {} with UniqueID {}", elementV.getUniqueId(), ci.getUniqueId(), containerV.getType(), containerV.getUniqueId());
1085                                                         return true;
1086                                                 }
1087                                         }
1088
1089                                 }
1090                         }
1091                 }
1092
1093                 return false;
1094         }
1095
1096         @SuppressWarnings("unchecked")
1097         public boolean isInUse(String componentId, List<GraphVertex> allNonDeleted) {
1098                 for (GraphVertex containerV : allNonDeleted) {
1099                         Map<String, CompositionDataDefinition> composition = (Map<String, CompositionDataDefinition>) containerV.getJson();
1100                         if (composition != null) {
1101                                 CompositionDataDefinition instances = composition.get(JsonConstantKeysEnum.COMPOSITION.getValue());
1102                                 if (instances != null && instances.getComponentInstances() != null && !instances.getComponentInstances().isEmpty()) {
1103                                         for (ComponentInstanceDataDefinition ci : instances.getComponentInstances().values()) {
1104                                                 if (ci.getComponentUid().equals(componentId)) {
1105                                                         return true;
1106                                                 }
1107                                         }
1108
1109                                 }
1110                         }
1111                 }
1112
1113                 return false;
1114         }
1115
1116         public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1117
1118                 Either<GraphVertex, StorageOperationStatus> result = null;
1119                 String userId = user.getUserId();
1120                 Either<GraphVertex, TitanOperationStatus> getRes = findUserVertex(userId);
1121                 GraphVertex userVertex = null;
1122                 GraphVertex serviceVertex = null;
1123                 if (getRes.isRight()) {
1124                         TitanOperationStatus status = getRes.right().value();
1125                         CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1126                         result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1127                 }
1128                 if (result == null) {
1129                         userVertex = getRes.left().value();
1130                         getRes = titanDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1131                         if (getRes.isRight()) {
1132                                 TitanOperationStatus status = getRes.right().value();
1133                                 log.error("Cannot find service {} in the graph. status is {}", uniqueId, status);
1134                                 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1135                         }
1136                 }
1137                 if (result == null) {
1138                         serviceVertex = getRes.left().value();
1139                         Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1140                         if (edgeIterator.hasNext()) {
1141                                 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1142                                 edgeIterator.next().remove();
1143                         }
1144                 }
1145                 if (result == null) {
1146                         TitanOperationStatus status = titanDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1147                         if (status != TitanOperationStatus.OK) {
1148                                 log.error("Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1149                                 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1150                         }
1151                 }
1152                 if (result == null) {
1153                         serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1154                         long lastUpdateDate = System.currentTimeMillis();
1155                         serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1156                         Either<GraphVertex, TitanOperationStatus> updateRes = titanDao.updateVertex(serviceVertex);
1157                         if (updateRes.isRight()) {
1158                                 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateRes.right().value()));
1159                         }
1160                 }
1161                 if (result == null) {
1162                         result = Either.left(serviceVertex);
1163                 }
1164                 return result;
1165         }
1166         /**
1167          * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1168          * @param componentId
1169          * @param instanceId
1170          * @param capabilityName
1171          * @param capabilityType
1172          * @param ownerId 
1173          * @return
1174          */
1175         public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
1176
1177                 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1178                 Map<String, MapCapabiltyProperty> mapPropertiesDataDefinition = null;
1179                 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TopologyTemplate, JsonParseFlagEnum.NoParse);
1180                 if (componentByLabelAndId.isRight()) {
1181                         result = Either.right(componentByLabelAndId.right().value());
1182                 }
1183                 if(componentByLabelAndId.isLeft()){
1184                         Either<Map<String, MapCapabiltyProperty>, TitanOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1185                         if (getDataRes.isRight()) {
1186                                 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getDataRes.right().value()));
1187                         } else {
1188                                 mapPropertiesDataDefinition = getDataRes.left().value();
1189                         }
1190                 }
1191                 if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){
1192                         result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1193                 }
1194                 return result;
1195         }
1196
1197         public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabiltyProperty instanceProperties) {
1198                 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
1199         }
1200
1201
1202         private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabiltyProperty> mapPropertiesDataDefinition) {
1203                 return  MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
1204                                 mapPropertiesDataDefinition.get(instanceId) != null &&
1205                                 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1206         }
1207
1208         private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
1209                 List<ComponentInstanceProperty> capPropsList = null;
1210                 for(Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()){
1211                         if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1212                                 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1213                                 if (capMap != null && !capMap.isEmpty()) {
1214                                         capPropsList = capMap.values().stream().map(o -> new ComponentInstanceProperty(o)).collect(Collectors.toList());
1215                                         break;
1216                                 }
1217                         }
1218                 }
1219                 if(capPropsList == null){
1220                         capPropsList = new ArrayList<>();
1221                 }
1222                 return capPropsList;
1223         }
1224
1225         private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
1226                 if (capProp != null) {
1227                         String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM );
1228                         if (path.length < 4) {
1229                                 log.debug("wrong key format for capabilty, key {}", capProp);
1230                                 return false;
1231                         }
1232                         return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
1233                 }
1234                 return false;
1235         }
1236
1237         public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1238                 fillPolicyDefinition(componentV, policyDefinition, counter);
1239                 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1240         }
1241         
1242         public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1243                 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1244         }
1245
1246         public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1247                 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
1248         }
1249         
1250         public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1251                 return  deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1252         }
1253
1254         private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1255                 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
1256                 policyDefinition.setName(policyName);
1257                 policyDefinition.setInvariantName(policyName);
1258                 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1259                 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1260                 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1261                 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1262         }
1263         
1264         public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
1265                 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
1266                 return componentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
1267         }
1268
1269 }