[SDC-29] rebase continue work to align source
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / jsontitan / operations / BaseOperation.java
1 package org.openecomp.sdc.be.model.jsontitan.operations;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.Iterator;
6 import java.util.List;
7 import java.util.Map;
8 import java.util.UUID;
9 import java.util.stream.Collectors;
10
11 import org.apache.commons.collections.CollectionUtils;
12 import org.apache.commons.collections.MapUtils;
13 import org.apache.commons.lang.StringUtils;
14 import org.apache.commons.lang3.tuple.ImmutablePair;
15 import org.apache.commons.lang3.tuple.Pair;
16 import org.apache.tinkerpop.gremlin.structure.Direction;
17 import org.apache.tinkerpop.gremlin.structure.Edge;
18 import org.apache.tinkerpop.gremlin.structure.Vertex;
19 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
20 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
21 import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
22 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
23 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
24 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
25 import org.openecomp.sdc.be.dao.jsongraph.utils.IdBuilderUtils;
26 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
27 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
28 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
29 import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
30 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
31 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
32 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
33 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
34 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
35 import org.openecomp.sdc.be.model.ComponentInstance;
36 import org.openecomp.sdc.be.model.GroupDefinition;
37 import org.openecomp.sdc.be.model.User;
38 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
39 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
40 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
41 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
42 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
43 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
44 import org.openecomp.sdc.common.util.ValidationUtils;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47 import org.springframework.beans.factory.annotation.Autowired;
48
49 import com.thinkaurelius.titan.core.TitanVertex;
50
51 import fj.data.Either;
52
53 /**
54  * public abstract class BaseOperation provides base operation functionality and common fields
55  *
56  */
57 public abstract class BaseOperation {
58
59         private static Logger logger = LoggerFactory.getLogger(BaseOperation.class.getName());
60
61         public static final String VF_MODULE = "org.openecomp.groups.VfModule";
62
63         @Autowired
64         protected TitanDao titanDao;
65
66         @Autowired
67         protected NodeTypeOperation nodeTypeOperation;
68
69         @Autowired
70         protected TopologyTemplateOperation topologyTemplateOperation;
71
72         /**
73          * Returns reference to appropriate toscaTemplateOperation
74          * 
75          * @param componentType
76          * @return
77          */
78         public ToscaElementOperation getToscaElementOperation(ComponentTypeEnum componentType) {
79                 ToscaElementOperation operation;
80                 switch (componentType) {
81                 case SERVICE:
82                 case RESOURCE:
83                         operation = topologyTemplateOperation;
84                         break;
85                 default:
86                         operation = nodeTypeOperation;
87                         break;
88                 }
89                 return operation;
90         }
91
92         /**
93          * Returns reference to appropriate toscaTemplateOperation
94          * 
95          * @param toscaElementType
96          * @return
97          */
98         public ToscaElementOperation getToscaElementOperation(ToscaElementTypeEnum toscaElementType) {
99                 ToscaElementOperation operation;
100                 switch (toscaElementType) {
101                 case TopologyTemplate:
102                         operation = topologyTemplateOperation;
103                         break;
104                 case NodeType:
105                         operation = nodeTypeOperation;
106                         break;
107                 default:
108                         operation = null;
109                         break;
110                 }
111                 return operation;
112         }
113
114         /**
115          * Returns reference to appropriate toscaTemplateOperation
116          * 
117          * @param toscaElementType
118          * @return
119          */
120         public ToscaElementOperation getToscaElementOperation(VertexTypeEnum toscaElementType) {
121                 ToscaElementOperation operation;
122                 switch (toscaElementType) {
123                 case TOPOLOGY_TEMPLATE:
124                         operation = topologyTemplateOperation;
125                         break;
126                 case NODE_TYPE:
127                         operation = nodeTypeOperation;
128                         break;
129                 default:
130                         operation = null;
131                         break;
132                 }
133                 return operation;
134         }
135         /**
136          * Converts received vertex to User object
137          * 
138          * @param ownerV
139          * @return
140          */
141         public User convertToUser(Vertex ownerV) {
142                 User owner = new User();
143                 owner.setUserId((String) ownerV.property(GraphPropertyEnum.USERID.getProperty()).value());
144                 VertexProperty<Object> property = ownerV.property(GraphPropertyEnum.ROLE.getProperty());
145                 if(property != null && property.isPresent() ){
146                         owner.setRole((String) property.value());
147                 }
148                 
149                 property = ownerV.property(GraphPropertyEnum.FIRST_NAME.getProperty()); 
150                 if(property != null && property.isPresent() ){
151                         owner.setFirstName((String) ownerV.property(GraphPropertyEnum.FIRST_NAME.getProperty()).value());
152                 }
153                 
154                 property = ownerV.property(GraphPropertyEnum.LAST_NAME.getProperty());
155                 if( property != null && property.isPresent() ){
156                         owner.setLastName((String) ownerV.property(GraphPropertyEnum.LAST_NAME.getProperty()).value());
157                 }
158                 
159                 property = ownerV.property(GraphPropertyEnum.EMAIL.getProperty());
160                 if( property != null && property.isPresent() ){
161                         owner.setEmail((String) ownerV.property(GraphPropertyEnum.EMAIL.getProperty()).value());
162                 }
163                 
164                 property = ownerV.property(GraphPropertyEnum.LAST_LOGIN_TIME.getProperty());
165                 if( property != null && property.isPresent() ){
166                         owner.setLastLoginTime((Long) ownerV.property(GraphPropertyEnum.LAST_LOGIN_TIME.getProperty()).value());
167                 }
168                 return owner;
169         }
170
171         protected <T extends ToscaDataDefinition> Either<Map<String, T>, TitanOperationStatus> getDataFromGraph(GraphVertex componentV, EdgeLabelEnum edgelabel) {
172                 Either<Pair<GraphVertex, Map<String, T>>, TitanOperationStatus> dataVertex = getDataAndVertexFromGraph(componentV, edgelabel);
173                 if (dataVertex.isRight()) {
174                         return Either.right(dataVertex.right().value());
175                 }
176                 Map<String, T> properties = dataVertex.left().value().getRight();
177                 return Either.left(properties);
178         }
179
180         @SuppressWarnings("unchecked")
181         protected <T extends ToscaDataDefinition> Either<Pair<GraphVertex, Map<String, T>>, TitanOperationStatus> getDataAndVertexFromGraph(GraphVertex componentV, EdgeLabelEnum edgelabel) {
182                 Either<GraphVertex, TitanOperationStatus> dataVertex = getDataVertex(componentV, edgelabel);
183                 if (dataVertex.isRight()) {
184                         return Either.right(dataVertex.right().value());
185                 }
186                 GraphVertex propV = dataVertex.left().value();
187                 Map<String, T> properties = (Map<String, T>) propV.getJson();
188                 Pair<GraphVertex, Map<String, T>> pair = new ImmutablePair<GraphVertex, Map<String, T>>(propV, properties);
189                 return Either.left(pair);
190         }
191
192         protected <T extends ToscaDataDefinition> Either<GraphVertex, TitanOperationStatus> getDataVertex(GraphVertex componentV, EdgeLabelEnum edgelabel) {
193                 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(componentV, edgelabel, JsonParseFlagEnum.ParseJson);
194                 if (childVertex.isRight()) {
195                         if (childVertex.right().value() != TitanOperationStatus.NOT_FOUND) {
196                                 logger.debug("failed to fetch {} for tosca element with id {}, error {}", edgelabel, componentV.getUniqueId(), childVertex.right().value());
197                         }
198                         return Either.right(childVertex.right().value());
199                 }
200                 GraphVertex propV = childVertex.left().value();
201                 return Either.left(propV);
202         }
203
204         /**
205          * Returns tosca data belonging to tosca element specified by uid according received label
206          * 
207          * @param toscaElementUid
208          * @param edgelabel
209          * @return
210          */
211         public <T extends ToscaDataDefinition> Either<Map<String, T>, TitanOperationStatus> getDataFromGraph(String toscaElementUid, EdgeLabelEnum edgelabel) {
212
213                 Either<Map<String, T>, TitanOperationStatus> result = null;
214                 Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
215
216                 getToscaElementRes = titanDao.getVertexById(toscaElementUid, JsonParseFlagEnum.NoParse);
217                 if (getToscaElementRes.isRight()) {
218                         TitanOperationStatus status = getToscaElementRes.right().value();
219                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get tosca element {} upon getting tosca data from graph. Status is {}. ", toscaElementUid, status);
220                         result = Either.right(status);
221                 }
222                 if (result == null) {
223                         result = getDataFromGraph(getToscaElementRes.left().value(), edgelabel);
224                 }
225                 return result;
226         }
227
228         public Either<GraphVertex, TitanOperationStatus> findUserVertex(String userId) {
229                 return titanDao.getVertexByPropertyAndLabel(GraphPropertyEnum.USERID, userId, VertexTypeEnum.USER, JsonParseFlagEnum.NoParse);
230         }
231
232         /**
233          * 
234          * @param elemementId
235          * @param label
236          * @return
237          */
238         public Either<Boolean, StorageOperationStatus> isCloneNeeded(String elemementId, EdgeLabelEnum label) {
239                 Either<GraphVertex, TitanOperationStatus> vertexById = titanDao.getVertexById(elemementId);
240                 if (vertexById.isRight()) {
241                         logger.debug("Failed to fetch element by id {} error {}", elemementId, vertexById.right().value());
242                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(vertexById.right().value()));
243                 }
244                 GraphVertex toscaElementVertex = vertexById.left().value();
245                 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(toscaElementVertex, label, JsonParseFlagEnum.NoParse);
246                 if (childVertex.isRight()) {
247                         if (childVertex.right().value() != TitanOperationStatus.NOT_FOUND) {
248                                 logger.debug("failed to fetch {} for tosca element with id {}, error {}", label, toscaElementVertex.getUniqueId(), childVertex.right().value());
249                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value()));
250                         }
251                         return Either.left(Boolean.FALSE);
252                 }
253                 GraphVertex dataVertex = childVertex.left().value();
254                 Iterator<Edge> edges = dataVertex.getVertex().edges(Direction.IN, label.name());
255                 int edgeCount = 0;
256                 while (edges.hasNext()) {
257                         edges.next();
258                         ++edgeCount;
259                 }
260                 if (edgeCount > 1) {
261                         return Either.left(Boolean.TRUE);
262                 } else {
263                         return Either.left(Boolean.FALSE);
264                 }
265         }
266
267         protected Either<GraphVertex, TitanOperationStatus> updateOrCopyOnUpdate(GraphVertex dataVertex, GraphVertex toscaElementVertex, EdgeLabelEnum label) {
268                 Iterator<Edge> edges = dataVertex.getVertex().edges(Direction.IN, label.name());
269                 int edgeCount = 0;
270                 Edge edgeToRemove = null;
271                 while (edges.hasNext()) {
272                         Edge edge = edges.next();
273                         ++edgeCount;
274                         Vertex outVertex = edge.outVertex();
275                         String outId = (String) titanDao.getProperty((TitanVertex) outVertex, GraphPropertyEnum.UNIQUE_ID.getProperty());
276                         if (toscaElementVertex.getUniqueId().equals(outId)) {
277                                 edgeToRemove = edge;
278                         }
279                 }
280                 if (edgeToRemove == null) {
281                         logger.debug("No edges {} from vertex {} to vertex {}", label, toscaElementVertex.getUniqueId(), dataVertex.getUniqueId());
282                         return Either.right(TitanOperationStatus.GENERAL_ERROR);
283                 }
284                 switch (edgeCount) {
285                 case 0:
286                         // error
287                         logger.debug("No edges {} to vertex {}", label, dataVertex.getUniqueId());
288                         return Either.right(TitanOperationStatus.GENERAL_ERROR);
289                 case 1:
290                         // update
291                         logger.trace("Only one edge {} to vertex {}. Update vertex", label, dataVertex.getUniqueId());
292                         return titanDao.updateVertex(dataVertex);
293                 default:
294                         // copy on update
295                         logger.trace("More than one edge {} to vertex {}. Need to clone vertex", label, dataVertex.getUniqueId());
296                         return cloneDataVertex(dataVertex, toscaElementVertex, label, edgeToRemove);
297                 }
298         }
299
300         private Either<GraphVertex, TitanOperationStatus> cloneDataVertex(GraphVertex dataVertex, GraphVertex toscaElementVertex, EdgeLabelEnum label, Edge edgeToRemove) {
301                 GraphVertex newDataVertex = new GraphVertex(dataVertex.getLabel());
302                 String id = IdBuilderUtils.generateChildId(toscaElementVertex.getUniqueId(), dataVertex.getLabel());
303                 newDataVertex.setUniqueId(id);
304                 newDataVertex.cloneData(dataVertex);
305
306                 Either<GraphVertex, TitanOperationStatus> createVertex = titanDao.createVertex(newDataVertex);
307                 if (createVertex.isRight()) {
308                         logger.debug("Failed to clone data vertex for {} error {}", dataVertex.getUniqueId(), createVertex.right().value());
309                         return createVertex;
310                 }
311                 newDataVertex = createVertex.left().value();
312                 TitanOperationStatus createEdge = titanDao.createEdge(toscaElementVertex, newDataVertex, label, titanDao.getEdgeProperties(edgeToRemove));
313                 if (createEdge != TitanOperationStatus.OK) {
314                         logger.debug("Failed to associate vertex {} to vertex {}, error {}", toscaElementVertex.getUniqueId(), newDataVertex.getUniqueId(), createEdge);
315                         return Either.right(createEdge);
316                 }
317                 edgeToRemove.remove();
318                 return Either.left(newDataVertex);
319         }
320
321         public Either<GraphVertex, StorageOperationStatus> assosiateElementToData(GraphVertex element, VertexTypeEnum vertexLabel, EdgeLabelEnum edgeLabel, Map<String, ? extends ToscaDataDefinition> data) {
322                 GraphVertex dataV = new GraphVertex(vertexLabel);
323                 String id = IdBuilderUtils.generateChildId(element.getUniqueId(), vertexLabel);
324                 dataV.setUniqueId(id);
325                 dataV.setJson(data);
326                 Either<GraphVertex, TitanOperationStatus> createVertex = titanDao.createVertex(dataV);
327                 if (createVertex.isRight()) {
328                         logger.trace("Failed to create {} vertex for type node {}", vertexLabel, element.getUniqueId());
329                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(createVertex.right().value()));
330                 }
331                 dataV = createVertex.left().value();
332                 TitanOperationStatus createEdgeStatus = titanDao.createEdge(element.getVertex(), dataV.getVertex(), edgeLabel, new HashMap<>());
333                 if (createEdgeStatus != TitanOperationStatus.OK) {
334                         logger.trace("Failed to create {} vertex for type node {}", vertexLabel, element.getUniqueId());
335                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(createEdgeStatus));
336                 }
337                 return Either.left(dataV);
338         }
339
340         /**
341          * Adds tosca data element to tosca element according received labels
342          * 
343          * @param toscaElement
344          * @param edgeLabel
345          * @param vertexLabel
346          * @param toscaData
347          * @param mapKeyField
348          * @return
349          */
350         public <T extends ToscaDataDefinition> StorageOperationStatus addToscaDataToToscaElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, T toscaData, JsonPresentationFields mapKeyField) {
351
352                 List<T> toscaDataList = new ArrayList<>();
353                 toscaDataList.add(toscaData);
354                 return addToscaDataToToscaElement(toscaElement, edgeLabel, vertexLabel, toscaDataList, mapKeyField);
355         }
356
357         /**
358          * Adds tosca data deep element to tosca element according received labels
359          * 
360          * @param toscaElement
361          * @param edgeLabel
362          * @param vertexLabel
363          * @param toscaData
364          * @param pathKeys
365          * @param mapKeyField
366          * @return
367          */
368         public <T extends ToscaDataDefinition> StorageOperationStatus addToscaDataDeepElementToToscaElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, T toscaData, List<String> pathKeys,
369                         JsonPresentationFields mapKeyField) {
370
371                 List<T> toscaDataList = new ArrayList<>();
372                 toscaDataList.add(toscaData);
373                 return addToscaDataDeepElementsToToscaElement(toscaElement, edgeLabel, vertexLabel, toscaDataList, pathKeys, mapKeyField);
374         }
375
376         /**
377          * Converts recieved map of tosca data deep elements to list and adds it to tosca element according received labels
378          * 
379          * @param toscaElement
380          * @param edgeLabel
381          * @param vertexLabel
382          * @param toscaDataMap
383          * @param pathKeys
384          * @param mapKeyField
385          * @return
386          */
387         public <T extends ToscaDataDefinition> StorageOperationStatus addToscaDataDeepElementsToToscaElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, Map<String, T> toscaDataMap, List<String> pathKeys,
388                         JsonPresentationFields mapKeyField) {
389
390                 if (toscaDataMap != null) {
391                         return addToscaDataDeepElementsToToscaElement(toscaElement, edgeLabel, vertexLabel, toscaDataMap.values().stream().collect(Collectors.toList()), pathKeys, mapKeyField);
392                 }
393                 return StorageOperationStatus.OK;
394         }
395
396         /**
397          * Adds list of tosca data deep elements to tosca element according received labels
398          * 
399          * @param toscaElement
400          * @param edgeLabel
401          * @param vertexLabel
402          * @param toscaDataList
403          * @param pathKeys
404          * @param mapKeyField
405          * @return
406          */
407         public <T extends ToscaDataDefinition> StorageOperationStatus addToscaDataDeepElementsToToscaElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<T> toscaDataList, List<String> pathKeys,
408                         JsonPresentationFields mapKeyField) {
409
410                 return updateOrAddToscaDataDeepElement(toscaElement, edgeLabel, vertexLabel, toscaDataList, pathKeys, mapKeyField, false);
411         }
412
413         /**
414          * Updates list of tosca data elements of tosca element according received labels
415          * 
416          * @param toscaElement
417          * @param edgeLabel
418          * @param vertexLabel
419          * @param toscaData
420          * @param mapKeyField
421          * @return
422          */
423         public <T extends ToscaDataDefinition> StorageOperationStatus updateToscaDataOfToscaElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, T toscaData, JsonPresentationFields mapKeyField) {
424                 List<T> toscaDataList = new ArrayList<>();
425                 toscaDataList.add(toscaData);
426                 return updateToscaDataOfToscaElement(toscaElement, edgeLabel, vertexLabel, toscaDataList, mapKeyField);
427         }
428
429         /**
430          * Updates tosca data deep element of tosca element according received labels
431          * 
432          * @param toscaElement
433          * @param edgeLabel
434          * @param vertexLabel
435          * @param toscaData
436          * @param pathKeys
437          * @param mapKeyField
438          * @return
439          */
440         public <T extends ToscaDataDefinition> StorageOperationStatus updateToscaDataDeepElementOfToscaElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, T toscaData, List<String> pathKeys,
441                         JsonPresentationFields mapKeyField) {
442                 List<T> toscaDataList = new ArrayList<>();
443                 toscaDataList.add(toscaData);
444                 return updateToscaDataDeepElementsOfToscaElement(toscaElement, edgeLabel, vertexLabel, toscaDataList, pathKeys, mapKeyField);
445         }
446
447         /**
448          * Updates tosca data deep elements of tosca element according received labels
449          * 
450          * @param toscaElement
451          * @param edgeLabel
452          * @param vertexLabel
453          * @param toscaDataList
454          * @param pathKeys
455          * @param mapKeyField
456          * @return
457          */
458         public <T extends ToscaDataDefinition> StorageOperationStatus updateToscaDataDeepElementsOfToscaElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<T> toscaDataList, List<String> pathKeys,
459                         JsonPresentationFields mapKeyField) {
460
461                 return updateOrAddToscaDataDeepElement(toscaElement, edgeLabel, vertexLabel, toscaDataList, pathKeys, mapKeyField, true);
462         }
463
464         /**
465          * Adds tosca data element to tosca element with specified uid according received labels
466          * 
467          * @param toscaElementUid
468          * @param toscaData
469          * @param edgeLabel
470          * @param vertexLabel
471          * @param mapKeyField
472          * @return
473          */
474         public <T extends ToscaDataDefinition> StorageOperationStatus addToscaDataToToscaElement(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, T toscaData, JsonPresentationFields mapKeyField) {
475
476                 List<T> toscaDataList = new ArrayList<>();
477                 toscaDataList.add(toscaData);
478                 return addToscaDataToToscaElement(toscaElementUid, edgeLabel, vertexLabel, toscaDataList, mapKeyField);
479         }
480
481         /**
482          * Adds tosca data deep element to tosca element with specified uid according received labels
483          * 
484          * @param toscaElementUid
485          * @param edgeLabel
486          * @param vertexLabel
487          * @param toscaData
488          * @param pathKeys
489          * @param mapKeyField
490          * @return
491          */
492         public <T extends ToscaDataDefinition> StorageOperationStatus addToscaDataDeepElementToToscaElement(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, T toscaData, List<String> pathKeys,
493                         JsonPresentationFields mapKeyField) {
494
495                 List<T> toscaDataList = new ArrayList<>();
496                 toscaDataList.add(toscaData);
497                 return addToscaDataDeepElementsToToscaElement(toscaElementUid, edgeLabel, vertexLabel, toscaDataList, pathKeys, mapKeyField);
498         }
499
500         public <T extends ToscaDataDefinition> StorageOperationStatus updateToscaDataDeepElementOfToscaElement(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, T toscaData, List<String> pathKeys,
501                         JsonPresentationFields mapKeyField) {
502
503                 List<T> toscaDataList = new ArrayList<>();
504                 toscaDataList.add(toscaData);
505                 return updateToscaDataDeepElementsOfToscaElement(toscaElementUid, edgeLabel, vertexLabel, toscaDataList, pathKeys, mapKeyField);
506         }
507
508         public <T extends ToscaDataDefinition> StorageOperationStatus updateToscaDataDeepElementsOfToscaElement(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<T> toscaDataList, List<String> pathKeys,
509                         JsonPresentationFields mapKeyField) {
510
511                 StorageOperationStatus statusRes = null;
512                 Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
513
514                 getToscaElementRes = titanDao.getVertexById(toscaElementUid, JsonParseFlagEnum.NoParse);
515                 if (getToscaElementRes.isRight()) {
516                         TitanOperationStatus status = getToscaElementRes.right().value();
517                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get tosca element {} upon adding the properties. Status is {}. ", toscaElementUid, status);
518                         statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
519                 }
520                 if (statusRes == null && CollectionUtils.isNotEmpty(toscaDataList)) {
521                         statusRes = updateToscaDataDeepElementsOfToscaElement(getToscaElementRes.left().value(), edgeLabel, vertexLabel, toscaDataList, pathKeys, mapKeyField);
522                 }
523                 if (statusRes == null) {
524                         statusRes = StorageOperationStatus.OK;
525                 }
526                 return statusRes;
527         }
528
529         /**
530          * Adds list of tosca data deep elements to tosca element with specified uid according received labels
531          * 
532          * @param toscaElementUid
533          * @param edgeLabel
534          * @param vertexLabel
535          * @param toscaDataList
536          * @param pathKeys
537          * @param mapKeyField
538          * @return
539          */
540         public <T extends ToscaDataDefinition> StorageOperationStatus addToscaDataDeepElementsToToscaElement(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<T> toscaDataList, List<String> pathKeys,
541                         JsonPresentationFields mapKeyField) {
542
543                 StorageOperationStatus statusRes = null;
544                 Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
545
546                 getToscaElementRes = titanDao.getVertexById(toscaElementUid, JsonParseFlagEnum.NoParse);
547                 if (getToscaElementRes.isRight()) {
548                         TitanOperationStatus status = getToscaElementRes.right().value();
549                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get tosca element {} upon adding the properties. Status is {}. ", toscaElementUid, status);
550                         statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
551                 }
552                 if (statusRes == null && CollectionUtils.isNotEmpty(toscaDataList)) {
553                         statusRes = addToscaDataDeepElementsToToscaElement(getToscaElementRes.left().value(), edgeLabel, vertexLabel, toscaDataList, pathKeys, mapKeyField);
554                 }
555                 if (statusRes == null) {
556                         statusRes = StorageOperationStatus.OK;
557                 }
558                 return statusRes;
559         }
560
561         public <T extends ToscaDataDefinition> StorageOperationStatus deleteToscaDataDeepElementsBlockToToscaElement(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, String key) {
562
563                 StorageOperationStatus statusRes = null;
564                 Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
565
566                 getToscaElementRes = titanDao.getVertexById(toscaElementUid, JsonParseFlagEnum.NoParse);
567                 if (getToscaElementRes.isRight()) {
568                         TitanOperationStatus status = getToscaElementRes.right().value();
569                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get tosca element {} upon adding the properties. Status is {}. ", toscaElementUid, status);
570                         statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
571                 }
572                 if (statusRes == null) {
573                         statusRes = deleteToscaDataDeepElementsBlockToToscaElement(getToscaElementRes.left().value(), edgeLabel, vertexLabel, key);
574                 }
575                 if (statusRes == null) {
576                         statusRes = StorageOperationStatus.OK;
577                 }
578                 return statusRes;
579         }
580
581         public <T extends ToscaDataDefinition> StorageOperationStatus deleteToscaDataDeepElementsBlockToToscaElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, String key) {
582
583                 StorageOperationStatus result = null;
584                 GraphVertex toscaDataVertex = null;
585                 Either<GraphVertex, TitanOperationStatus> toscaDataVertexRes = titanDao.getChildVertex(toscaElement, edgeLabel, JsonParseFlagEnum.ParseJson);
586                 if (toscaDataVertexRes.isRight()) {
587                         TitanOperationStatus status = toscaDataVertexRes.right().value();
588                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get child vertex of the tosca element {} by label {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, status);
589                         result = DaoStatusConverter.convertTitanStatusToStorageStatus(toscaDataVertexRes.right().value());
590                 }
591                 if (result == null) {
592                         toscaDataVertex = toscaDataVertexRes.left().value();
593                         result = deleteDeepElementsBlock(toscaDataVertex, key);
594                 }
595                 if (result == null) {
596                         Either<GraphVertex, TitanOperationStatus> updateOrCopyRes = updateOrCopyOnUpdate(toscaDataVertex, toscaElement, edgeLabel);
597                         if (updateOrCopyRes.isRight()) {
598                                 TitanOperationStatus status = updateOrCopyRes.right().value();
599                                 CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to delete tosca data block {} from the tosca element {}. Status is {}. ", edgeLabel, toscaElement.getUniqueId(), status);
600                                 result = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
601                         }
602                 }
603                 if (result == null) {
604                         result = StorageOperationStatus.OK;
605                 }
606                 return result;
607         }
608
609         @SuppressWarnings("rawtypes")
610         public <T extends ToscaDataDefinition> StorageOperationStatus addToscaDataDeepElementsBlockToToscaElement(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, MapDataDefinition toscaDataMap, String key) {
611
612                 StorageOperationStatus statusRes = null;
613                 Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
614
615                 getToscaElementRes = titanDao.getVertexById(toscaElementUid, JsonParseFlagEnum.NoParse);
616                 if (getToscaElementRes.isRight()) {
617                         TitanOperationStatus status = getToscaElementRes.right().value();
618                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get tosca element {} upon adding the properties. Status is {}. ", toscaElementUid, status);
619                         statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
620                 }
621                 if (statusRes == null && toscaDataMap != null) {
622                         statusRes = addToscaDataDeepElementsBlockToToscaElement(getToscaElementRes.left().value(), edgeLabel, vertexLabel, toscaDataMap, key);
623                 }
624                 if (statusRes == null) {
625                         statusRes = StorageOperationStatus.OK;
626                 }
627                 return statusRes;
628         }
629
630         @SuppressWarnings("rawtypes")
631         public <T extends ToscaDataDefinition> StorageOperationStatus addToscaDataDeepElementsBlockToToscaElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, MapDataDefinition toscaDataMap, String key) {
632
633                 StorageOperationStatus result = null;
634                 GraphVertex toscaDataVertex = null;
635                 Either<GraphVertex, TitanOperationStatus> toscaDataVertexRes = titanDao.getChildVertex(toscaElement, edgeLabel, JsonParseFlagEnum.ParseJson);
636                 if (toscaDataVertexRes.isRight() && toscaDataVertexRes.right().value() != TitanOperationStatus.NOT_FOUND) {
637                         TitanOperationStatus status = toscaDataVertexRes.right().value();
638                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get child vertex of the tosca element {} by label {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, status);
639                         result = DaoStatusConverter.convertTitanStatusToStorageStatus(toscaDataVertexRes.right().value());
640                 }
641                 if (result == null) {
642                         if (toscaDataVertexRes.isLeft()) {
643                                 toscaDataVertex = toscaDataVertexRes.left().value();
644                                 result = addDeepElementsBlock(toscaDataVertex, toscaDataMap, key);
645                         }
646                 }
647                 if (result == null) {
648                         if (toscaDataVertex != null) {
649                                 Either<GraphVertex, TitanOperationStatus> updateOrCopyRes = updateOrCopyOnUpdate(toscaDataVertex, toscaElement, edgeLabel);
650                                 if (updateOrCopyRes.isRight()) {
651                                         TitanOperationStatus status = updateOrCopyRes.right().value();
652                                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to add tosca data {} to the tosca element {}. Status is {}. ", edgeLabel, toscaElement.getUniqueId(), status);
653                                         result = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
654                                 }
655                         } else {
656                                 Map<String, MapDataDefinition> data = new HashMap<>();
657                                 data.put(key, toscaDataMap);
658                                 Either<GraphVertex, StorageOperationStatus> createRes = assosiateElementToData(toscaElement, vertexLabel, edgeLabel, data);
659                                 if (createRes.isRight()) {
660                                         StorageOperationStatus status = createRes.right().value();
661                                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to assosiate tosca data {} of the tosca element {}. Status is {}. ", edgeLabel, toscaElement.getUniqueId(), status);
662                                         result = status;
663                                 }
664                         }
665                 }
666                 if (result == null) {
667                         result = StorageOperationStatus.OK;
668                 }
669                 return result;
670         }
671
672         /**
673          * Updates tosca data element of tosca element by specified uid according received labels
674          * 
675          * @param toscaElementUid
676          * @param edgeLabel
677          * @param vertexLabel
678          * @param toscaData
679          * @param mapKeyField
680          * @return
681          */
682         public <T extends ToscaDataDefinition> StorageOperationStatus updateToscaDataOfToscaElement(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, T toscaData, JsonPresentationFields mapKeyField) {
683
684                 List<T> toscaDataList = new ArrayList<>();
685                 toscaDataList.add(toscaData);
686                 return updateToscaDataOfToscaElement(toscaElementUid, edgeLabel, vertexLabel, toscaDataList, mapKeyField);
687         }
688
689         /**
690          * Updates list of tosca data elements belonging to tosca element with specified uid according received labels
691          * 
692          * @param toscaElementUid
693          * @param edgeLabel
694          * @param vertexLabel
695          * @param toscaDataList
696          * @param mapKeyField
697          * @return
698          */
699         public <T extends ToscaDataDefinition> StorageOperationStatus updateToscaDataOfToscaElement(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<T> toscaDataList, JsonPresentationFields mapKeyField) {
700
701                 StorageOperationStatus statusRes = null;
702                 Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
703
704                 getToscaElementRes = titanDao.getVertexById(toscaElementUid, JsonParseFlagEnum.NoParse);
705                 if (getToscaElementRes.isRight()) {
706                         TitanOperationStatus status = getToscaElementRes.right().value();
707                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get tosca element {} upon adding the properties. Status is {}. ", toscaElementUid, status);
708                         statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
709                 }
710                 if (statusRes == null && CollectionUtils.isNotEmpty(toscaDataList)) {
711                         statusRes = updateToscaDataOfToscaElement(getToscaElementRes.left().value(), edgeLabel, vertexLabel, toscaDataList, mapKeyField);
712                 }
713                 if (statusRes == null) {
714                         statusRes = StorageOperationStatus.OK;
715                 }
716                 return statusRes;
717         }
718
719         /**
720          * Adds list of tosca data elements to tosca element with specified uid according received labels
721          * 
722          * @param toscaElementUid
723          * @param edgeLabel
724          * @param vertexLabel
725          * @param toscaDataList
726          * @param mapKeyField
727          * @return
728          */
729         public <T extends ToscaDataDefinition> StorageOperationStatus addToscaDataToToscaElement(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<T> toscaDataList, JsonPresentationFields mapKeyField) {
730
731                 StorageOperationStatus statusRes = null;
732                 Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
733
734                 getToscaElementRes = titanDao.getVertexById(toscaElementUid, JsonParseFlagEnum.NoParse);
735                 if (getToscaElementRes.isRight()) {
736                         TitanOperationStatus status = getToscaElementRes.right().value();
737                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get tosca element {} upon adding the properties. Status is {}. ", toscaElementUid, status);
738                         statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
739                 }
740                 if (statusRes == null && CollectionUtils.isNotEmpty(toscaDataList)) {
741                         statusRes = addToscaDataToToscaElement(getToscaElementRes.left().value(), edgeLabel, vertexLabel, toscaDataList, mapKeyField);
742                 }
743                 if (statusRes == null) {
744                         statusRes = StorageOperationStatus.OK;
745                 }
746                 return statusRes;
747         }
748
749         /**
750          * Converts recieved map of tosca data elements to list and adds it to tosca element according received labels
751          * 
752          * @param toscaElement
753          * @param edgeLabel
754          * @param vertexLabel
755          * @param toscaDataMap
756          * @param mapKeyField
757          * @return
758          */
759         public <T extends ToscaDataDefinition> StorageOperationStatus addToscaDataToToscaElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, Map<String, T> toscaDataMap, JsonPresentationFields mapKeyField) {
760
761                 return addToscaDataToToscaElement(toscaElement, edgeLabel, vertexLabel, toscaDataMap.values().stream().collect(Collectors.toList()), mapKeyField);
762         }
763
764         /**
765          * Adds list of tosca data elements to tosca element according received labels
766          * 
767          * @param toscaElement
768          * @param edgeLabel
769          * @param vertexLabel
770          * @param toscaDataList
771          * @param mapKeyField
772          * @return
773          */
774         public <T extends ToscaDataDefinition> StorageOperationStatus addToscaDataToToscaElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<T> toscaDataList, JsonPresentationFields mapKeyField) {
775
776                 return updateOrAddToscaData(toscaElement, edgeLabel, vertexLabel, toscaDataList, mapKeyField, false);
777         }
778
779         /**
780          * Updates list of tosca data elements belonging to tosca element according received labels
781          * 
782          * @param toscaElement
783          * @param edgeLabel
784          * @param vertexLabel
785          * @param toscaDataList
786          * @param mapKeyField
787          * @return
788          */
789         public <T extends ToscaDataDefinition> StorageOperationStatus updateToscaDataOfToscaElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<T> toscaDataList, JsonPresentationFields mapKeyField) {
790
791                 return updateOrAddToscaData(toscaElement, edgeLabel, vertexLabel, toscaDataList, mapKeyField, true);
792         }
793
794         @SuppressWarnings("unchecked")
795         private <T extends ToscaDataDefinition> StorageOperationStatus updateOrAddToscaData(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<T> toscaDataList, JsonPresentationFields mapKeyField, boolean isUpdate) {
796                 StorageOperationStatus result = null;
797                 GraphVertex toscaDataVertex = null;
798                 Map<String, T> existingToscaDataMap = null;
799                 Either<Map<String, T>, StorageOperationStatus> validateRes = null;
800                 Map<String, T> mergedToscaDataMap;
801                 Either<GraphVertex, TitanOperationStatus> toscaDataVertexRes = titanDao.getChildVertex(toscaElement, edgeLabel, JsonParseFlagEnum.ParseJson);
802                 if (toscaDataVertexRes.isRight() && toscaDataVertexRes.right().value() != TitanOperationStatus.NOT_FOUND) {
803                         TitanOperationStatus status = toscaDataVertexRes.right().value();
804                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get child vertex of the tosca element {} by label {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, status);
805                         result = DaoStatusConverter.convertTitanStatusToStorageStatus(toscaDataVertexRes.right().value());
806                 }
807                 if (result == null) {
808                         if (toscaDataVertexRes.isLeft()) {
809                                 toscaDataVertex = toscaDataVertexRes.left().value();
810                                 existingToscaDataMap = (Map<String, T>) toscaDataVertex.getJson();
811                         }
812
813                         validateRes = validateMergeToscaData(toscaElement, toscaDataList, mapKeyField, existingToscaDataMap, isUpdate);
814                         if (validateRes.isRight()) {
815                                 result = validateRes.right().value();
816                                 CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed validate tosca data upon adding to tosca element {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, result);
817                         }
818                 }
819                 if (result == null) {
820                         mergedToscaDataMap = validateRes.left().value();
821                         result = handleToscaData(toscaElement, vertexLabel, edgeLabel, toscaDataVertex, mergedToscaDataMap);
822                 }
823                 if (result == null) {
824                         result = StorageOperationStatus.OK;
825                 }
826                 return result;
827
828         }
829         
830         @SuppressWarnings("unchecked")
831         public <T extends ToscaDataDefinition> StorageOperationStatus updateFullToscaData(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, Map<String, T> toscaData) {
832                 StorageOperationStatus result = null;
833                 GraphVertex toscaDataVertex = null;
834                 Map<String, T> existingToscaDataMap = null;             
835                 
836                 Either<GraphVertex, TitanOperationStatus> toscaDataVertexRes = titanDao.getChildVertex(toscaElement, edgeLabel, JsonParseFlagEnum.ParseJson);
837                 if (toscaDataVertexRes.isRight() && toscaDataVertexRes.right().value() != TitanOperationStatus.NOT_FOUND) {
838                         TitanOperationStatus status = toscaDataVertexRes.right().value();
839                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get child vertex of the tosca element {} by label {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, status);
840                         result = DaoStatusConverter.convertTitanStatusToStorageStatus(toscaDataVertexRes.right().value());
841                 }
842                 if (result == null) {
843                         if (toscaDataVertexRes.isLeft()) {
844                                 toscaDataVertex = toscaDataVertexRes.left().value();
845                                 existingToscaDataMap = (Map<String, T>) toscaDataVertex.getJson();
846                         }
847
848                 
849                 }
850                 if (result == null) {
851                         
852                         result = handleToscaData(toscaElement, vertexLabel, edgeLabel, toscaDataVertex, toscaData);
853                 }
854                 if (result == null) {
855                         result = StorageOperationStatus.OK;
856                 }
857                 return result;
858
859         }
860
861         @SuppressWarnings({ "rawtypes", "unchecked" })
862         private <T, K extends ToscaDataDefinition> StorageOperationStatus updateOrAddToscaDataDeepElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<K> toscaDataList, List<String> pathKeys,
863                         JsonPresentationFields mapKeyField, boolean isUpdate) {
864
865                 StorageOperationStatus result = null;
866                 GraphVertex toscaDataVertex = null;
867                 Map<String, K> existingDeepElementsMap = null;
868                 Either<Map<String, K>, StorageOperationStatus> validateRes = null;
869                 Either<GraphVertex, TitanOperationStatus> toscaDataVertexRes = titanDao.getChildVertex(toscaElement, edgeLabel, JsonParseFlagEnum.ParseJson);
870                 if (toscaDataVertexRes.isRight() && toscaDataVertexRes.right().value() != TitanOperationStatus.NOT_FOUND) {
871                         TitanOperationStatus status = toscaDataVertexRes.right().value();
872                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get child vertex of the tosca element {} by label {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, status);
873                         result = DaoStatusConverter.convertTitanStatusToStorageStatus(toscaDataVertexRes.right().value());
874                 }
875                 if (result == null) {
876                         if (toscaDataVertexRes.isLeft()) {
877                                 toscaDataVertex = toscaDataVertexRes.left().value();
878                                 existingDeepElementsMap = getDeepElements(toscaDataVertex, pathKeys);
879                         }
880                         validateRes = validateMergeToscaData(toscaElement, toscaDataList, mapKeyField, existingDeepElementsMap, isUpdate);
881                         if (validateRes.isRight()) {
882                                 result = validateRes.right().value();
883                                 CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed validate tosca data upon adding to tosca element {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, result);
884                         }
885                 }
886                 if (result == null) {
887                         updateDeepElements(toscaDataVertex, validateRes.left().value(), pathKeys);
888                         Map<String, K> toscaDataToHandle;
889                         if(toscaDataVertex == null){
890                                 toscaDataToHandle = new HashMap<>();
891                                 Map<String, K> currMap = toscaDataToHandle;
892                                 for (int i = 1; i < pathKeys.size()-1; ++i) {
893                                         currMap.put(pathKeys.get(i), (K) new MapDataDefinition());
894                                         currMap = (Map<String, K>) ((MapDataDefinition) currMap).getMapToscaDataDefinition().get(pathKeys.get(i));
895                                 }
896                                 toscaDataToHandle.put(pathKeys.get(pathKeys.size()-1), (K) new MapDataDefinition(validateRes.left().value()));
897                                 
898                         } else {
899                                 toscaDataToHandle =  (Map<String, K>) toscaDataVertex.getJson();
900                         }
901                         result = handleToscaData(toscaElement, vertexLabel, edgeLabel, toscaDataVertex, toscaDataToHandle);
902                 }
903                 if (result == null) {
904                         result = StorageOperationStatus.OK;
905                 }
906                 return result;
907         }
908
909         @SuppressWarnings({ "rawtypes", "unchecked" })
910         private <T, K extends ToscaDataDefinition> void updateDeepElements(GraphVertex toscaDataVertex, Map<String, K> mergedDeepElementMap, List<String> pathKeys) {
911
912                 if (toscaDataVertex != null && MapUtils.isNotEmpty(mergedDeepElementMap)) {
913                         Map<String, MapDataDefinition> currMap = (Map<String, MapDataDefinition>) toscaDataVertex.getJson();
914                         if(!currMap.containsKey(pathKeys.get(0))){
915                                 currMap.put(pathKeys.get(0), new MapDataDefinition<>());
916                         }
917                         MapDataDefinition currDeepElement = currMap.get(pathKeys.get(0));
918
919                         for (int i = 1; i < pathKeys.size(); ++i) {
920                                 if(currDeepElement.findByKey(pathKeys.get(i)) == null){
921                                         currDeepElement.put(pathKeys.get(i), new MapDataDefinition<>());
922                                 }
923                                 currDeepElement = (MapDataDefinition) currDeepElement.findByKey(pathKeys.get(i));
924                         }
925                         if(currDeepElement != null){
926                                 for (Map.Entry<String, K> elementEntry : mergedDeepElementMap.entrySet()) {
927                                         currDeepElement.put(elementEntry.getKey(), elementEntry.getValue());
928                                 }
929                         }
930                 }
931         }
932
933         @SuppressWarnings({ "unchecked", "rawtypes" })
934         private <T, K extends ToscaDataDefinition> Map<String, K> getDeepElements(GraphVertex toscaDataVertex, List<String> pathKeys) {
935                 Map<String, K> result = null;
936                 Map<String, T> currMap = (Map<String, T>) toscaDataVertex.getJson();
937                 MapDataDefinition currDeepElement = (MapDataDefinition) currMap.get(pathKeys.get(0));
938                 for (int i = 1; i < pathKeys.size(); ++i) {
939                         currDeepElement = (MapDataDefinition) currDeepElement.findByKey(pathKeys.get(i));
940                 }
941                 if(currDeepElement != null){
942                         result = (Map<String, K>) currDeepElement.getMapToscaDataDefinition();
943                 }
944                 return result;
945         }
946
947         @SuppressWarnings("unchecked")
948         private <T extends ToscaDataDefinition> StorageOperationStatus addDeepElementsBlock(GraphVertex toscaDataVertex, T toscaDataBlock, String key) {
949
950                 StorageOperationStatus result = null;
951                 Map<String, T> currMap = (Map<String, T>) toscaDataVertex.getJson();
952                 if (currMap.containsKey(key)) {
953                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to add block of deep tosca data elements by label {}." + " The block element with the same key {} already exists. ", toscaDataVertex.getLabel(), key);
954                         result = StorageOperationStatus.ENTITY_ALREADY_EXISTS;
955                 }
956                 if (result == null) {
957                         currMap.put(key, toscaDataBlock);
958                 }
959                 return result;
960         }
961
962         @SuppressWarnings("unchecked")
963         private <T extends ToscaDataDefinition> StorageOperationStatus deleteDeepElementsBlock(GraphVertex toscaDataVertex, String key) {
964
965                 StorageOperationStatus result = null;
966                 Map<String, T> currMap = (Map<String, T>) toscaDataVertex.getJson();
967                 if (!currMap.containsKey(key)) {
968                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to delete block of deep tosca data elements by label {}." + " The block element with the same key {} doesn't exist. ", toscaDataVertex.getLabel(), key);
969                         result = StorageOperationStatus.NOT_FOUND;
970                 }
971                 if (result == null) {
972                         currMap.remove(key);
973                 }
974                 return null;
975         }
976
977         /**
978          * Removes tosca data vertex belonging to tosca element specified by uid according label
979          * 
980          * @param toscaElementUid
981          * @param edgeLabel
982          * @param vertexLabel
983          * @return
984          */
985         public StorageOperationStatus removeToscaData(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel) {
986
987                 StorageOperationStatus statusRes = StorageOperationStatus.OK;
988                 Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
989
990                 getToscaElementRes = titanDao.getVertexById(toscaElementUid, JsonParseFlagEnum.NoParse);
991                 if (getToscaElementRes.isRight()) {
992                         TitanOperationStatus status = getToscaElementRes.right().value();
993                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get tosca element {} upon adding the properties. Status is {}. ", toscaElementUid, status);
994                         statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
995                 }
996                 if (statusRes == StorageOperationStatus.OK) {
997                         statusRes = removeToscaDataVertex(getToscaElementRes.left().value(), edgeLabel, vertexLabel);
998                 }
999                 return statusRes;
1000         }
1001
1002         /**
1003          * Removes tosca data vertex belonging to tosca element according label
1004          * 
1005          * @param toscaElement
1006          * @param edgeLabel
1007          * @param vertexLabel
1008          * @return
1009          */
1010         public StorageOperationStatus removeToscaDataVertex(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel) {
1011                 StorageOperationStatus result = null;
1012                 GraphVertex toscaDataVertex = null;
1013                 Iterator<Edge> edges = null;
1014                 int edgeCounter = 0;
1015                 Edge edge = null;
1016                 Edge edgeToDelete = null;
1017                 Either<GraphVertex, TitanOperationStatus> toscaDataVertexRes = titanDao.getChildVertex(toscaElement, edgeLabel, JsonParseFlagEnum.ParseJson);
1018                 if (toscaDataVertexRes.isRight()) {
1019                         TitanOperationStatus status = toscaDataVertexRes.right().value();
1020                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed remove tosca data vertex of the tosca element {} by label {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, status);
1021                         result = DaoStatusConverter.convertTitanStatusToStorageStatus(toscaDataVertexRes.right().value());
1022                 }
1023                 if (result == null) {
1024                         toscaDataVertex = toscaDataVertexRes.left().value();
1025                         edges = toscaDataVertex.getVertex().edges(Direction.IN);
1026                         if (edges == null || !edges.hasNext()) {
1027                                 result = StorageOperationStatus.NOT_FOUND;
1028                                 CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed remove tosca data vertex of the tosca element {} by label {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, result);
1029                         }
1030                 }
1031                 if (result == null) {
1032                         while (edges.hasNext()) {
1033                                 ++edgeCounter;
1034                                 edge = edges.next();
1035                                 if (edge.outVertex().id().equals(toscaElement.getVertex().id())) {
1036                                         edgeToDelete = edge;
1037                                         break;
1038                                 }
1039                         }
1040                         if (edgeToDelete == null) {
1041                                 result = StorageOperationStatus.NOT_FOUND;
1042                                 CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed remove tosca data vertex of the tosca element {} by label {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, result);
1043                         }
1044                 }
1045                 if (result == null) {
1046                         if (edgeCounter > 1) {
1047                                 edgeToDelete.remove();
1048                         } else {
1049                                 toscaDataVertex.getVertex().remove();
1050                         }
1051                 }
1052                 if (result == null) {
1053                         result = StorageOperationStatus.OK;
1054                 }
1055                 return result;
1056         }
1057
1058         /**
1059          * Deletes tosca data elements belonging to tosca element specified by uid according label
1060          * 
1061          * @param toscaElementUid
1062          * @param edgeLabel
1063          * @param vertexLabel
1064          * @param uniqueKeys
1065          * @param mapKeyField
1066          * @return
1067          */
1068         public StorageOperationStatus deleteToscaDataElements(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<String> uniqueKeys, JsonPresentationFields mapKeyField) {
1069
1070                 StorageOperationStatus statusRes = StorageOperationStatus.OK;
1071                 Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
1072
1073                 getToscaElementRes = titanDao.getVertexById(toscaElementUid, JsonParseFlagEnum.NoParse);
1074                 if (getToscaElementRes.isRight()) {
1075                         TitanOperationStatus status = getToscaElementRes.right().value();
1076                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get tosca element {} upon adding the properties. Status is {}. ", toscaElementUid, status);
1077                         statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
1078                 }
1079                 if (statusRes == StorageOperationStatus.OK) {
1080                         statusRes = deleteToscaDataElements(getToscaElementRes.left().value(), edgeLabel, vertexLabel, uniqueKeys, mapKeyField);
1081                 }
1082                 return statusRes;
1083         }
1084
1085         /**
1086          * Deletes tosca data element belonging to tosca element specified by uid according label
1087          * 
1088          * @param toscaElementUid
1089          * @param edgeLabel
1090          * @param vertexLabel
1091          * @param uniqueKey
1092          * @param mapKeyField
1093          * @return
1094          */
1095         public StorageOperationStatus deleteToscaDataElement(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, String uniqueKey, JsonPresentationFields mapKeyField) {
1096
1097                 StorageOperationStatus statusRes = StorageOperationStatus.OK;
1098                 Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
1099
1100                 getToscaElementRes = titanDao.getVertexById(toscaElementUid, JsonParseFlagEnum.NoParse);
1101                 if (getToscaElementRes.isRight()) {
1102                         TitanOperationStatus status = getToscaElementRes.right().value();
1103                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get tosca element {} upon adding the properties. Status is {}. ", toscaElementUid, status);
1104                         statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
1105                 }
1106                 if (statusRes == StorageOperationStatus.OK) {
1107                         statusRes = deleteToscaDataElement(getToscaElementRes.left().value(), edgeLabel, vertexLabel, uniqueKey, mapKeyField);
1108                 }
1109                 return statusRes;
1110
1111         }
1112
1113         /**
1114          * Deletes tosca data deep element belonging to tosca element specified by uid according label
1115          * 
1116          * @param toscaElementUid
1117          * @param edgeLabel
1118          * @param vertexLabel
1119          * @param uniqueKey
1120          * @param pathKeys
1121          * @param mapKeyField
1122          * @return
1123          */
1124         public StorageOperationStatus deleteToscaDataDeepElement(String toscaElementUid, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, String uniqueKey, List<String> pathKeys, JsonPresentationFields mapKeyField) {
1125
1126                 StorageOperationStatus statusRes = StorageOperationStatus.OK;
1127                 Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
1128
1129                 getToscaElementRes = titanDao.getVertexById(toscaElementUid, JsonParseFlagEnum.NoParse);
1130                 if (getToscaElementRes.isRight()) {
1131                         TitanOperationStatus status = getToscaElementRes.right().value();
1132                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get tosca element {} upon adding the properties. Status is {}. ", toscaElementUid, status);
1133                         statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
1134                 }
1135                 if (statusRes == StorageOperationStatus.OK) {
1136                         statusRes = deleteToscaDataDeepElement(getToscaElementRes.left().value(), edgeLabel, vertexLabel, uniqueKey, pathKeys, mapKeyField);
1137                 }
1138                 return statusRes;
1139
1140         }
1141
1142         /**
1143          * Deletes tosca data deep element belonging to tosca element according label
1144          * 
1145          * @param toscaElement
1146          * @param edgeLabel
1147          * @param vertexLabel
1148          * @param uniqueKey
1149          * @param pathKeys
1150          * @param mapKeyField
1151          * @return
1152          */
1153         public StorageOperationStatus deleteToscaDataDeepElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, String uniqueKey, List<String> pathKeys, JsonPresentationFields mapKeyField) {
1154
1155                 List<String> uniqueKeys = new ArrayList<>();
1156                 uniqueKeys.add(uniqueKey);
1157                 return deleteToscaDataDeepElements(toscaElement, edgeLabel, vertexLabel, uniqueKeys, pathKeys, mapKeyField);
1158         }
1159
1160         public StorageOperationStatus deleteToscaDataDeepElements(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<String> uniqueKeys, List<String> pathKeys, JsonPresentationFields mapKeyField) {
1161
1162                 StorageOperationStatus result = null;
1163                 GraphVertex toscaDataVertex;
1164                 Map<String, ToscaDataDefinition> existingToscaDataMap = null;
1165                 Either<GraphVertex, TitanOperationStatus> toscaDataVertexRes = titanDao.getChildVertex(toscaElement, edgeLabel, JsonParseFlagEnum.ParseJson);
1166                 if (toscaDataVertexRes.isRight()) {
1167                         TitanOperationStatus status = toscaDataVertexRes.right().value();
1168                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get child vertex of the tosca element {} by label {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, status);
1169                         result = DaoStatusConverter.convertTitanStatusToStorageStatus(toscaDataVertexRes.right().value());
1170                 }
1171                 if (result == null) {
1172                         toscaDataVertex = toscaDataVertexRes.left().value();
1173                         existingToscaDataMap = (Map<String, ToscaDataDefinition>) getDeepElements(toscaDataVertexRes.left().value(), pathKeys);
1174                         for (String uniqueKey : uniqueKeys) {
1175                                 result = removeToscaDataElement(toscaElement, edgeLabel, uniqueKey, toscaDataVertex, existingToscaDataMap);
1176                                 if (result != StorageOperationStatus.OK) {
1177                                         break;
1178                                 }
1179                         }
1180                 }
1181                 if (result == null) {
1182                         result = StorageOperationStatus.OK;
1183                 }
1184                 return result;
1185         }
1186
1187         /**
1188          * Deletes tosca data element belonging to tosca element according label
1189          * 
1190          * @param toscaElement
1191          * @param edgeLabel
1192          * @param vertexLabel
1193          * @param uniqueKey
1194          * @param mapKeyField
1195          * @return
1196          */
1197         public StorageOperationStatus deleteToscaDataElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, String uniqueKey, JsonPresentationFields mapKeyField) {
1198
1199                 List<String> uniqueKeys = new ArrayList<>();
1200                 uniqueKeys.add(uniqueKey);
1201                 return deleteToscaDataElements(toscaElement, edgeLabel, vertexLabel, uniqueKeys, mapKeyField);
1202         }
1203
1204         @SuppressWarnings("unchecked")
1205         /**
1206          * Deletes tosca data elements belonging to tosca element according label
1207          * 
1208          * @param toscaElement
1209          * @param edgeLabel
1210          * @param vertexLabel
1211          * @param uniqueKeys
1212          * @param mapKeyField
1213          * @return
1214          */
1215         public StorageOperationStatus deleteToscaDataElements(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<String> uniqueKeys, JsonPresentationFields mapKeyField) {
1216
1217                 StorageOperationStatus result = null;
1218                 GraphVertex toscaDataVertex;
1219                 Map<String, ToscaDataDefinition> existingToscaDataMap = null;
1220                 Either<GraphVertex, TitanOperationStatus> toscaDataVertexRes = titanDao.getChildVertex(toscaElement, edgeLabel, JsonParseFlagEnum.ParseJson);
1221                 if (toscaDataVertexRes.isRight()) {
1222                         TitanOperationStatus status = toscaDataVertexRes.right().value();
1223                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get child vertex of the tosca element {} by label {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, status);
1224                         result = DaoStatusConverter.convertTitanStatusToStorageStatus(toscaDataVertexRes.right().value());
1225                 }
1226                 if (result == null) {
1227                         toscaDataVertex = toscaDataVertexRes.left().value();
1228                         existingToscaDataMap = (Map<String, ToscaDataDefinition>) toscaDataVertex.getJson();
1229                         for (String uniqueKey : uniqueKeys) {
1230                                 result = removeToscaDataElement(toscaElement, edgeLabel, uniqueKey, toscaDataVertex, existingToscaDataMap);
1231                                 if (result != StorageOperationStatus.OK) {
1232                                         break;
1233                                 }
1234                         }
1235                 }
1236                 if (result == null) {
1237                         result = StorageOperationStatus.OK;
1238                 }
1239                 return result;
1240         }
1241
1242         private <T extends ToscaDataDefinition> StorageOperationStatus removeToscaDataElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, String uniqueKey, GraphVertex toscaDataVertex, Map<String, T> existingToscaDataMap) {
1243
1244                 StorageOperationStatus result = StorageOperationStatus.OK;
1245                 if (!existingToscaDataMap.containsKey(uniqueKey)) {
1246                         result = StorageOperationStatus.NOT_FOUND;
1247                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to delete tosca data element of the tosca element {} by label {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, result);
1248                 } else {
1249                         existingToscaDataMap.remove(uniqueKey);
1250                         Either<GraphVertex, TitanOperationStatus> updateOrCopyRes = updateOrCopyOnUpdate(toscaDataVertex, toscaElement, edgeLabel);
1251                         if (updateOrCopyRes.isRight()) {
1252                                 result = DaoStatusConverter.convertTitanStatusToStorageStatus(updateOrCopyRes.right().value());
1253                                 CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to update tosca data {} of the tosca element {}. Status is {}. ", edgeLabel, toscaElement.getUniqueId(), result);
1254                         }
1255                 }
1256                 return result;
1257         }
1258
1259         protected <K extends ToscaDataDefinition> StorageOperationStatus handleToscaData(GraphVertex toscaElement, VertexTypeEnum vertexLabel, EdgeLabelEnum edgeLabel, GraphVertex toscaDataVertex, Map<String, K> mergedToscaDataMap) {
1260
1261                 StorageOperationStatus result = StorageOperationStatus.OK;
1262                 if (toscaDataVertex == null) {
1263
1264                         Either<GraphVertex, StorageOperationStatus> createRes = assosiateElementToData(toscaElement, vertexLabel, edgeLabel, mergedToscaDataMap);
1265                         if (createRes.isRight()) {
1266                                 StorageOperationStatus status = createRes.right().value();
1267                                 CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to assosiate tosca data {} of the tosca element {}. Status is {}. ", edgeLabel, toscaElement.getUniqueId(), status);
1268                                 result = status;
1269                         }
1270                 } else {
1271                         toscaDataVertex.setJson(mergedToscaDataMap);
1272                         Either<GraphVertex, TitanOperationStatus> updateOrCopyRes = updateOrCopyOnUpdate(toscaDataVertex, toscaElement, edgeLabel);
1273                         if (updateOrCopyRes.isRight()) {
1274                                 TitanOperationStatus status = updateOrCopyRes.right().value();
1275                                 CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to add tosca data {} to the tosca element {}. Status is {}. ", edgeLabel, toscaElement.getUniqueId(), status);
1276                                 result = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
1277                         }
1278                 }
1279                 return result;
1280         }
1281
1282         private <T extends ToscaDataDefinition> Either<Map<String, T>, StorageOperationStatus> validateMergeToscaData(GraphVertex toscaElement, List<T> toscaDataList, JsonPresentationFields mapKeyField, Map<String, T> existingToscaDataMap,
1283                         boolean isUpdate) {
1284
1285                 Map<String, T> mergedToscaDataMap = new HashMap<>();
1286                 StorageOperationStatus status;
1287                 Either<Map<String, T>, StorageOperationStatus> result = Either.left(mergedToscaDataMap);
1288                 if (MapUtils.isNotEmpty(existingToscaDataMap)) {
1289                         mergedToscaDataMap.putAll(existingToscaDataMap);
1290                 }
1291                 for (T toscaDataElement : toscaDataList) {
1292                         status = handleToscaDataElement(toscaElement, mapKeyField, mergedToscaDataMap, toscaDataElement, isUpdate);
1293                         if (status != StorageOperationStatus.OK) {
1294                                 result = Either.right(status);
1295                                 break;
1296                         }
1297                 }
1298                 return result;
1299         }
1300
1301         private <T extends ToscaDataDefinition> StorageOperationStatus handleToscaDataElement(GraphVertex toscaElement, JsonPresentationFields mapKeyField, Map<String, T> mergedToscaDataMap, T toscaDataElement, boolean isUpdate) {
1302
1303                 StorageOperationStatus status = StorageOperationStatus.OK;
1304                 String currKey = (String) toscaDataElement.getToscaPresentationValue(mapKeyField);
1305                 if (StringUtils.isEmpty(currKey)) {
1306                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to add tosca data to tosca element {}. The key is empty. ");
1307                         status = StorageOperationStatus.BAD_REQUEST;
1308                 } else if (!isUpdate && mergedToscaDataMap.containsKey(currKey)) {
1309                         CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to add tosca data to tosca element {}. The element with the same key {} already exists. ", toscaElement.getUniqueId(), currKey);
1310                         status = StorageOperationStatus.BAD_REQUEST;
1311                 }
1312                 mergedToscaDataMap.put(currKey, toscaDataElement);
1313                 return status;
1314         }
1315
1316 //      public StorageOperationStatus updateDataOnGraph(GraphVertex dataVertex) {
1317 //              Either<GraphVertex, TitanOperationStatus> updateVertex = titanDao.updateVertex(dataVertex);
1318 //              if (updateVertex.isRight()) {
1319 //                      return DaoStatusConverter.convertTitanStatusToStorageStatus(updateVertex.right().value());
1320 //              }
1321 //              return StorageOperationStatus.OK;
1322 //      }
1323         
1324         protected GroupInstanceDataDefinition buildGroupInstanceDataDefinition(GroupDataDefinition group, ComponentInstanceDataDefinition componentInstance) {
1325
1326                 String componentInstanceName = componentInstance.getName();
1327                 Long creationDate = System.currentTimeMillis();
1328                 GroupInstanceDataDefinition groupInstance = new GroupInstanceDataDefinition();
1329                 String groupUid = group.getUniqueId();
1330
1331                 groupInstance.setGroupUid(groupUid);
1332                 groupInstance.setType(group.getType());
1333                 groupInstance.setCustomizationUUID(generateCustomizationUUID());
1334                 groupInstance.setCreationTime(creationDate);
1335                 groupInstance.setModificationTime(creationDate);
1336                 groupInstance.setName(buildGroupInstanceName(componentInstanceName, group.getName()));
1337                 groupInstance.setGroupName(group.getName());
1338                 groupInstance.setNormalizedName(ValidationUtils.normalizeComponentInstanceName(groupInstance.getName()));
1339                 groupInstance.setUniqueId(UniqueIdBuilder.buildResourceInstanceUniuqeId(componentInstance.getUniqueId(), groupUid, groupInstance.getNormalizedName()));
1340                 groupInstance.setArtifacts(group.getArtifacts());
1341                 groupInstance.setArtifactsUuid(group.getArtifactsUuid());
1342                 groupInstance.setProperties(group.getProperties());
1343                 groupInstance.setInvariantUUID(group.getInvariantUUID());
1344                 groupInstance.setGroupUUID(group.getGroupUUID());
1345                 groupInstance.setVersion(group.getVersion());
1346
1347                 return groupInstance;
1348         }
1349         
1350         protected String buildGroupInstanceName(String instanceName, String groupName) {
1351                 int groupNameIndex = groupName.indexOf("..");
1352                 //turn group name from VFName..heatfile..module-n to VFiName..heatfile..module-n
1353                 return ValidationUtils.normaliseComponentName(instanceName) + groupName.substring(groupNameIndex);
1354         }
1355         
1356         protected String generateCustomizationUUID() {
1357                 return UUID.randomUUID().toString();
1358         }
1359
1360 }