9c7f108a05b21eb26000319198fc7bf0dbf336a3
[sdc.git] /
1 package org.openecomp.sdc.be.model.jsontitan.operations;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.EnumMap;
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Map;
9 import java.util.Map.Entry;
10 import java.util.Optional;
11 import java.util.Set;
12 import java.util.stream.Collectors;
13
14 import org.apache.commons.collections.CollectionUtils;
15 import org.apache.commons.lang3.StringUtils;
16 import org.apache.commons.lang3.tuple.ImmutablePair;
17 import org.apache.commons.lang3.tuple.Pair;
18 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
19 import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
20 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
21 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
22 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
23 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
24 import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
25 import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
26 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
27 import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
28 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
29 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
30 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
31 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
32 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
33 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
34 import org.openecomp.sdc.be.datatypes.elements.MapAttributesDataDefinition;
35 import org.openecomp.sdc.be.datatypes.elements.MapCapabiltyProperty;
36 import org.openecomp.sdc.be.datatypes.elements.MapListCapabiltyDataDefinition;
37 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
38 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
39 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
40 import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
41 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
42 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
43 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
44 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
45 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
46 import org.openecomp.sdc.be.model.ArtifactDefinition;
47 import org.openecomp.sdc.be.model.AttributeDefinition;
48 import org.openecomp.sdc.be.model.CapabilityDefinition;
49 import org.openecomp.sdc.be.model.Component;
50 import org.openecomp.sdc.be.model.ComponentInstance;
51 import org.openecomp.sdc.be.model.ComponentInstanceInput;
52 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
53 import org.openecomp.sdc.be.model.ComponentParametersView;
54 import org.openecomp.sdc.be.model.DistributionStatusEnum;
55 import org.openecomp.sdc.be.model.GroupDefinition;
56 import org.openecomp.sdc.be.model.GroupInstance;
57 import org.openecomp.sdc.be.model.InputDefinition;
58 import org.openecomp.sdc.be.model.LifecycleStateEnum;
59 import org.openecomp.sdc.be.model.PropertyDefinition;
60 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
61 import org.openecomp.sdc.be.model.RequirementDefinition;
62 import org.openecomp.sdc.be.model.Resource;
63 import org.openecomp.sdc.be.model.Service;
64 import org.openecomp.sdc.be.model.User;
65 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
66 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
67 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
68 import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
69 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
70 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
71 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
72 import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
73 import org.openecomp.sdc.be.utils.CommonBeUtils;
74 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
75 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
76 import org.openecomp.sdc.common.util.ValidationUtils;
77 import org.slf4j.Logger;
78 import org.slf4j.LoggerFactory;
79 import org.springframework.beans.factory.annotation.Autowired;
80
81 import fj.data.Either;
82
83 @org.springframework.stereotype.Component("tosca-operation-facade")
84 public class ToscaOperationFacade {
85         @Autowired
86         private NodeTypeOperation nodeTypeOperation;
87         @Autowired
88         private TopologyTemplateOperation topologyTemplateOperation;
89         @Autowired
90         private NodeTemplateOperation nodeTemplateOperation;
91         @Autowired
92         private GroupsOperation groupsOperation;
93         @Autowired
94         private TitanDao titanDao;
95
96         private static Logger log = LoggerFactory.getLogger(ToscaOperationFacade.class.getName());
97
98         public <T extends Component> Either<T, StorageOperationStatus> getToscaElement(String componentId) {
99
100                 return getToscaElement(componentId, JsonParseFlagEnum.ParseAll);
101
102         }
103         public <T extends Component> Either<T, StorageOperationStatus> getToscaFullElement(String componentId) {
104                 ComponentParametersView filters = new ComponentParametersView();
105                 filters.setIgnoreCapabiltyProperties(false);
106                 
107                 return getToscaElement(componentId, filters);
108         }
109         public <T extends Component> Either<T, StorageOperationStatus> getToscaElement(String componentId, ComponentParametersView filters) {
110
111                 Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, filters.detectParseFlag());
112                 if (getVertexEither.isRight()) {
113                         log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
114                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
115
116                 }
117                 return getToscaElementByOperation(getVertexEither.left().value(), filters);
118         }
119
120         public <T extends Component> Either<T, StorageOperationStatus> getToscaElement(String componentId, JsonParseFlagEnum parseFlag) {
121
122                 Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, parseFlag);
123                 if (getVertexEither.isRight()) {
124                         log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
125                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
126
127                 }
128                 return getToscaElementByOperation(getVertexEither.left().value());
129         }
130
131         public <T extends Component> Either<T, StorageOperationStatus> getToscaElement(GraphVertex componentVertex) {
132                 return getToscaElementByOperation(componentVertex);
133         }
134
135         public Either<Boolean, StorageOperationStatus> validateComponentExists(String componentId) {
136
137                 Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
138                 if (getVertexEither.isRight()) {
139                         TitanOperationStatus status = getVertexEither.right().value();
140                         if (status == TitanOperationStatus.NOT_FOUND) {
141                                 return Either.left(false);
142                         } else {
143                                 log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
144                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
145                         }
146                 }
147                 return Either.left(true);
148         }
149
150         public <T extends Component> Either<T, StorageOperationStatus> findLastCertifiedToscaElementByUUID(T component) {
151                 Map<GraphPropertyEnum, Object> props = new HashMap<>();
152                 props.put(GraphPropertyEnum.UUID, component.getUUID());
153                 props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
154                 props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
155
156                 Either<List<GraphVertex>, TitanOperationStatus> getVertexEither = titanDao.getByCriteria(ModelConverter.getVertexType(component), props);
157                 if (getVertexEither.isRight()) {
158                         log.debug("Couldn't fetch component with and unique id {}, error: {}", component.getUniqueId(), getVertexEither.right().value());
159                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
160
161                 }
162                 return getToscaElementByOperation(getVertexEither.left().value().get(0));
163         }
164
165         private <T extends Component> Either<T, StorageOperationStatus> getToscaElementByOperation(GraphVertex componentV) {
166                 return getToscaElementByOperation(componentV, new ComponentParametersView());
167         }
168
169         private <T extends Component> Either<T, StorageOperationStatus> getToscaElementByOperation(GraphVertex componentV, ComponentParametersView filters) {
170                 VertexTypeEnum label = componentV.getLabel();
171
172                 ToscaElementOperation toscaOperation = getToscaElementOperation(componentV);
173                 Either<ToscaElement, StorageOperationStatus> toscaElement;
174                 String componentId = componentV.getUniqueId();
175                 if (toscaOperation != null) {
176                         log.debug("Need to fetch tosca element for id {}", componentId);
177                         toscaElement = toscaOperation.getToscaElement(componentV, filters);
178                 } else {
179                         log.debug("not supported tosca type {} for id {}", label, componentId);
180                         toscaElement = Either.right(StorageOperationStatus.BAD_REQUEST);
181                 }
182                 if (toscaElement.isRight()) {
183                         return Either.right(toscaElement.right().value());
184                 }
185                 return Either.left(ModelConverter.convertFromToscaElement(toscaElement.left().value()));
186         }
187
188         private ToscaElementOperation getToscaElementOperation(GraphVertex componentV) {
189                 VertexTypeEnum label = componentV.getLabel();
190                 switch (label) {
191                 case NODE_TYPE:
192                         return nodeTypeOperation;
193                 case TOPOLOGY_TEMPLATE:
194                         return topologyTemplateOperation;
195                 default:
196                         return null;
197                 }
198         }
199
200         /**
201          * 
202          * @param resource
203          * @return
204          */
205         public <T extends Component> Either<T, StorageOperationStatus> createToscaComponent(T resource) {
206                 ToscaElement toscaElement = ModelConverter.convertToToscaElement(resource);
207
208                 ToscaElementOperation toscaElementOperation = getToscaElementOperation(toscaElement);
209                 Either<ToscaElement, StorageOperationStatus> createToscaElement = toscaElementOperation.createToscaElement(toscaElement);
210                 if (createToscaElement.isLeft()) {
211                         log.debug("Component created successfully!!!");
212                         T dataModel = ModelConverter.convertFromToscaElement(createToscaElement.left().value());
213                         return Either.left(dataModel);
214                 }
215                 return Either.right(createToscaElement.right().value());
216         }
217
218         /**
219          * 
220          * @param componentToDelete
221          * @return
222          */
223         public StorageOperationStatus markComponentToDelete(Component componentToDelete) {
224
225                 if ((componentToDelete.getIsDeleted() != null) && componentToDelete.getIsDeleted() && !componentToDelete.isHighestVersion()) {
226                         // component already marked for delete
227                         return StorageOperationStatus.OK;
228                 } else {
229
230                         Either<GraphVertex, TitanOperationStatus> getResponse = titanDao.getVertexById(componentToDelete.getUniqueId(), JsonParseFlagEnum.ParseAll);
231                         if (getResponse.isRight()) {
232                                 log.debug("Couldn't fetch component with and unique id {}, error: {}", componentToDelete.getUniqueId(), getResponse.right().value());
233                                 return DaoStatusConverter.convertTitanStatusToStorageStatus(getResponse.right().value());
234
235                         }
236                         GraphVertex componentV = getResponse.left().value();
237
238                         // same operation for node type and topology template operations
239                         Either<GraphVertex, StorageOperationStatus> result = nodeTypeOperation.markComponentToDelete(componentV);
240                         if (result.isRight()) {
241                                 return result.right().value();
242                         }
243                         return StorageOperationStatus.OK;
244                 }
245         }
246
247         /**
248          * 
249          * @param componentId
250          * @return
251          */
252         public <T extends Component> Either<T, StorageOperationStatus> deleteToscaComponent(String componentId) {
253
254                 Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll);
255                 if (getVertexEither.isRight()) {
256                         log.debug("Couldn't fetch component vertex with and unique id {}, error: {}", componentId, getVertexEither.right().value());
257                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
258
259                 }
260                 Either<ToscaElement, StorageOperationStatus> deleteElement = deleteToscaElement(getVertexEither.left().value());
261                 if (deleteElement.isRight()) {
262                         log.debug("Failed to delete component with and unique id {}, error: {}", componentId, deleteElement.right().value());
263                         return Either.right(deleteElement.right().value());
264                 }
265                 T dataModel = ModelConverter.convertFromToscaElement(deleteElement.left().value());
266
267                 return Either.left(dataModel);
268         }
269
270         private Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex componentV) {
271                 VertexTypeEnum label = componentV.getLabel();
272                 Either<ToscaElement, StorageOperationStatus> toscaElement;
273                 Object componentId = componentV.getUniqueId();
274                 switch (label) {
275                 case NODE_TYPE:
276                         log.debug("Need to fetch node type for id {}", componentId);
277                         toscaElement = nodeTypeOperation.deleteToscaElement(componentV);
278                         break;
279                 case TOPOLOGY_TEMPLATE:
280                         log.debug("Need to fetch topology template for id {}", componentId);
281                         toscaElement = topologyTemplateOperation.deleteToscaElement(componentV);
282                         break;
283                 default:
284                         log.debug("not supported tosca type {} for id {}", label, componentId);
285                         toscaElement = Either.right(StorageOperationStatus.BAD_REQUEST);
286                         break;
287                 }
288                 return toscaElement;
289         }
290
291         private ToscaElementOperation getToscaElementOperation(ToscaElement toscaElement) {
292
293                 ComponentTypeEnum componentType = toscaElement.getComponentType();
294                 switch (componentType) {
295                 case RESOURCE:
296                         ResourceTypeEnum resourceType = toscaElement.getResourceType();
297                         if (resourceType == ResourceTypeEnum.VF) {
298                                 return topologyTemplateOperation;
299                         } else {
300                                 return nodeTypeOperation;
301                         }
302                 case SERVICE:
303                 case PRODUCT:
304                         return topologyTemplateOperation;
305                 default:
306                         break;
307                 }
308                 return null;
309         }
310
311         private ToscaElementOperation getToscaElementOperation(Component component) {
312
313                 switch (component.getComponentType()) {
314                 case RESOURCE:
315                         ResourceTypeEnum resourceType = ((Resource) component).getResourceType();
316                         if (resourceType != null && resourceType == ResourceTypeEnum.VF) {
317                                 return topologyTemplateOperation;
318                         } else {
319                                 return nodeTypeOperation;
320                         }
321                 case SERVICE:
322                 case PRODUCT:
323                         return topologyTemplateOperation;
324                 default:
325                         break;
326                 }
327                 return null;
328         }
329
330         public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName) {
331                 return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
332
333         }
334
335         public <T extends Component> Either<T, StorageOperationStatus> getLatestByName(String resourceName) {
336                 return getLatestByName(GraphPropertyEnum.NAME, resourceName);
337
338         }
339
340         public Either<Integer, StorageOperationStatus> validateCsarUuidUniqueness(String csarUUID) {
341                 Either<List<ToscaElement>, StorageOperationStatus> byCsar = null;
342
343                 Map<GraphPropertyEnum, Object> properties = new HashMap<GraphPropertyEnum, Object>();
344                 properties.put(GraphPropertyEnum.CSAR_UUID, csarUUID);
345
346                 Either<List<GraphVertex>, TitanOperationStatus> resources = titanDao.getByCriteria(null, properties, JsonParseFlagEnum.ParseMetadata);
347
348                 if (resources.isRight()) {
349                         if (resources.right().value() == TitanOperationStatus.NOT_FOUND) {
350                                 return Either.left(new Integer(0));
351                         } else {
352                                 log.debug("failed to get resources from graph with property name: {}", csarUUID);
353                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resources.right().value()));
354                         }
355                 }
356
357                 List<GraphVertex> resourceList = (resources.isLeft() ? resources.left().value() : null);
358
359                 return Either.left(new Integer(resourceList.size()));
360
361         }
362
363         public <T extends Component> Either<List<T>, StorageOperationStatus> getFollowed(String userId, Set<LifecycleStateEnum> lifecycleStates, Set<LifecycleStateEnum> lastStateStates, ComponentTypeEnum componentType) {
364                 Either<List<ToscaElement>, StorageOperationStatus> followedResources;
365                 if (componentType == ComponentTypeEnum.RESOURCE) {
366                         followedResources = nodeTypeOperation.getFollowedComponent(userId, lifecycleStates, lastStateStates, componentType);
367                 } else {
368                         followedResources = topologyTemplateOperation.getFollowedComponent(userId, lifecycleStates, lastStateStates, componentType);
369                 }
370
371                 List<T> components = new ArrayList<>();
372                 if (followedResources.isRight() && followedResources.right().value() != StorageOperationStatus.NOT_FOUND) {
373                         return Either.right(followedResources.right().value());
374                 }
375                 if (followedResources.isLeft()) {
376                         List<ToscaElement> toscaElements = followedResources.left().value();
377                         toscaElements.forEach(te -> {
378                                 T component = ModelConverter.convertFromToscaElement(te);
379                                 components.add(component);
380                         });
381                 }
382                 return Either.left(components);
383         }
384
385         public Either<Resource, StorageOperationStatus> getLatestCertifiedNodeTypeByToscaResourceName(String toscaResourceName) {
386
387                 return getLatestCertifiedByToscaResourceName(toscaResourceName, VertexTypeEnum.NODE_TYPE, JsonParseFlagEnum.ParseMetadata);
388         }
389
390         public Either<Resource, StorageOperationStatus> getLatestCertifiedByToscaResourceName(String toscaResourceName, VertexTypeEnum vertexType, JsonParseFlagEnum parseFlag) {
391
392                 Either<Resource, StorageOperationStatus> result = null;
393                 Map<GraphPropertyEnum, Object> props = new HashMap<GraphPropertyEnum, Object>();
394                 props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
395                 props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
396                 props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
397                 Either<List<GraphVertex>, TitanOperationStatus> getLatestRes = titanDao.getByCriteria(vertexType, props, parseFlag);
398
399                 if (getLatestRes.isRight()) {
400                         TitanOperationStatus status = getLatestRes.right().value();
401                         CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch {} with name {}. status={} ", vertexType, toscaResourceName, status);
402                         result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
403                 }
404                 if (result == null) {
405                         List<GraphVertex> resources = getLatestRes.left().value();
406                         double version = 0.0;
407                         GraphVertex highestResource = null;
408                         for (GraphVertex resource : resources) {
409                                 double resourceVersion = Double.parseDouble((String) resource.getJsonMetadataField(JsonPresentationFields.VERSION));
410                                 if (resourceVersion > version) {
411                                         version = resourceVersion;
412                                         highestResource = resource;
413                                 }
414                         }
415                         result = getToscaElement(highestResource.getUniqueId());
416                 }
417                 return result;
418         }
419
420         public Either<Boolean, StorageOperationStatus> validateToscaResourceNameExists(String templateName) {
421                 Either<Boolean, StorageOperationStatus> validateUniquenessRes = validateToscaResourceNameUniqueness(templateName);
422                 if (validateUniquenessRes.isLeft()) {
423                         return Either.left(!validateUniquenessRes.left().value());
424                 }
425                 return validateUniquenessRes;
426         }
427
428         public Either<RequirementCapabilityRelDef, StorageOperationStatus> dissociateResourceInstances(String componentId, RequirementCapabilityRelDef requirementDef) {
429                 return nodeTemplateOperation.dissociateResourceInstances(componentId, requirementDef);
430
431         }
432
433         public StorageOperationStatus associateResourceInstances(String componentId, List<RequirementCapabilityRelDef> relations) {
434                 Either<List<RequirementCapabilityRelDef>, StorageOperationStatus> status = nodeTemplateOperation.associateResourceInstances(componentId, relations);
435                 if (status.isRight()) {
436                         return status.right().value();
437                 }
438                 return StorageOperationStatus.OK;
439         }
440
441         protected Either<Boolean, StorageOperationStatus> validateToscaResourceNameUniqueness(String name) {
442
443                 Map<GraphPropertyEnum, Object> properties = new HashMap<GraphPropertyEnum, Object>();
444                 properties.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, name);
445
446                 Either<List<GraphVertex>, TitanOperationStatus> resources = titanDao.getByCriteria(null, properties, JsonParseFlagEnum.ParseMetadata);
447
448                 if (resources.isRight() && resources.right().value() != TitanOperationStatus.NOT_FOUND) {
449                         log.debug("failed to get resources from graph with property name: {}", name);
450                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resources.right().value()));
451                 }
452                 List<GraphVertex> resourceList = (resources.isLeft() ? resources.left().value() : null);
453                 if (resourceList != null && resourceList.size() > 0) {
454                         if (log.isDebugEnabled()) {
455                                 StringBuilder builder = new StringBuilder();
456                                 for (GraphVertex resourceData : resourceList) {
457                                         builder.append(resourceData.getUniqueId() + "|");
458                                 }
459                                 log.debug("resources  with property name:{} exists in graph. found {}", name, builder.toString());
460                         }
461                         return Either.left(false);
462                 } else {
463                         log.debug("resources  with property name:{} does not exists in graph", name);
464                         return Either.left(true);
465                 }
466
467         }
468
469         /**
470          * 
471          * @param newComponent
472          * @param oldComponent
473          * @return
474          */
475         public <T extends Component> Either<T, StorageOperationStatus> overrideComponent(T newComponent, T oldComponent) {
476
477                 // TODO
478                 // newComponent.setInterfaces(oldComponent.getInterfaces);
479                 newComponent.setArtifacts(oldComponent.getArtifacts());
480                 newComponent.setDeploymentArtifacts(oldComponent.getDeploymentArtifacts());
481                 newComponent.setGroups(oldComponent.getGroups());
482                 newComponent.setInputs(null);
483                 newComponent.setLastUpdateDate(null);
484                 newComponent.setHighestVersion(true);
485
486                 Either<GraphVertex, TitanOperationStatus> componentVEither = titanDao.getVertexById(oldComponent.getUniqueId(), JsonParseFlagEnum.NoParse);
487                 if (componentVEither.isRight()) {
488                         log.debug("Falied to fetch component {} error {}", oldComponent.getUniqueId(), componentVEither.right().value());
489                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(componentVEither.right().value()));
490                 }
491                 GraphVertex componentv = componentVEither.left().value();
492                 Either<GraphVertex, TitanOperationStatus> parentVertexEither = titanDao.getParentVertex(componentv, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
493                 if (parentVertexEither.isRight() && parentVertexEither.right().value() != TitanOperationStatus.NOT_FOUND) {
494                         log.debug("Falied to fetch parent version for component {} error {}", oldComponent.getUniqueId(), parentVertexEither.right().value());
495                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(parentVertexEither.right().value()));
496                 }
497
498                 Either<ToscaElement, StorageOperationStatus> deleteToscaComponent = deleteToscaElement(componentv);
499                 if (deleteToscaComponent.isRight()) {
500                         log.debug("Falied to remove old component {} error {}", oldComponent.getUniqueId(), deleteToscaComponent.right().value());
501                         return Either.right(deleteToscaComponent.right().value());
502                 }
503                 Either<T, StorageOperationStatus> createToscaComponent = createToscaComponent(newComponent);
504                 if (createToscaComponent.isRight()) {
505                         log.debug("Falied to create tosca element component {} error {}", newComponent.getUniqueId(), createToscaComponent.right().value());
506                         return Either.right(createToscaComponent.right().value());
507                 }
508                 T newElement = createToscaComponent.left().value();
509                 Either<GraphVertex, TitanOperationStatus> newVersionEither = titanDao.getVertexById(newElement.getUniqueId(), JsonParseFlagEnum.NoParse);
510                 if (newVersionEither.isRight()) {
511                         log.debug("Falied to fetch new tosca element component {} error {}", newComponent.getUniqueId(), newVersionEither.right().value());
512                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(newVersionEither.right().value()));
513                 }
514                 if (parentVertexEither.isLeft()) {
515                         GraphVertex previousVersionV = parentVertexEither.left().value();
516                         TitanOperationStatus createEdge = titanDao.createEdge(previousVersionV, newVersionEither.left().value(), EdgeLabelEnum.VERSION, null);
517                         if (createEdge != TitanOperationStatus.OK) {
518                                 log.debug("Falied to associate to previous version {} new version {} error {}", previousVersionV.getUniqueId(), newVersionEither.right().value(), createEdge);
519                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge));
520                         }
521                 }
522                 return Either.left(newElement);
523         }
524
525         /**
526          * 
527          * @param componentToUpdate
528          * @return
529          */
530         public <T extends Component> Either<T, StorageOperationStatus> updateToscaElement(T componentToUpdate) {
531                 return updateToscaElement(componentToUpdate, new ComponentParametersView());
532         }
533
534         /**
535          * 
536          * @param componentToUpdate
537          * @param type
538          * @param filterResult
539          * @return
540          */
541         public <T extends Component> Either<T, StorageOperationStatus> updateToscaElement(T componentToUpdate, ComponentParametersView filterResult) {
542                 String componentId = componentToUpdate.getUniqueId();
543                 Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll);
544                 if (getVertexEither.isRight()) {
545                         log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
546                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
547                 }
548                 GraphVertex elementV = getVertexEither.left().value();
549                 ToscaElementOperation toscaElementOperation = getToscaElementOperation(elementV);
550
551                 ToscaElement toscaElementToUpdate = ModelConverter.convertToToscaElement(componentToUpdate);
552                 Either<ToscaElement, StorageOperationStatus> updateToscaElement = toscaElementOperation.updateToscaElement(toscaElementToUpdate, elementV, filterResult);
553                 if (updateToscaElement.isRight()) {
554                         log.debug("Failed to update tosca element {} error {}", componentId, updateToscaElement.right().value());
555                         return Either.right(updateToscaElement.right().value());
556                 }
557                 return Either.left(ModelConverter.convertFromToscaElement(updateToscaElement.left().value()));
558         }
559
560         private <T extends Component> Either<T, StorageOperationStatus> getLatestByName(GraphPropertyEnum property, String nodeName) {
561                 Either<T, StorageOperationStatus> result;
562
563                 Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
564                 Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
565
566                 propertiesToMatch.put(property, nodeName);
567                 propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
568
569                 propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
570
571                 Either<List<GraphVertex>, TitanOperationStatus> highestResources = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseMetadata);
572                 if (highestResources.isRight()) {
573                         TitanOperationStatus status = highestResources.right().value();
574                         log.debug("failed to find resource with name {}. status={} ", nodeName, status);
575                         result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
576                         return result;
577                 }
578
579                 List<GraphVertex> resources = highestResources.left().value();
580                 double version = 0.0;
581                 GraphVertex highestResource = null;
582                 for (GraphVertex vertex : resources) {
583                         Object versionObj = vertex.getMetadataProperty(GraphPropertyEnum.VERSION);
584                         double resourceVersion = Double.valueOf((String) versionObj);
585                         if (resourceVersion > version) {
586                                 version = resourceVersion;
587                                 highestResource = vertex;
588                         }
589                 }
590                 return getToscaElementByOperation(highestResource);
591         }
592
593         public <T extends Component> Either<List<T>, StorageOperationStatus> getBySystemName(ComponentTypeEnum componentType, String systemName) {
594
595                 Either<List<T>, StorageOperationStatus> result = null;
596                 Either<T, StorageOperationStatus> getComponentRes;
597                 List<T> components = new ArrayList<>();
598                 List<GraphVertex> componentVertices;
599                 Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
600                 Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
601
602                 propertiesToMatch.put(GraphPropertyEnum.SYSTEM_NAME, systemName);
603                 if (componentType != null)
604                         propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
605
606                 propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
607
608                 Either<List<GraphVertex>, TitanOperationStatus> getComponentsRes = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
609                 if (getComponentsRes.isRight()) {
610                         TitanOperationStatus status = getComponentsRes.right().value();
611                         log.debug("Failed to fetch the component with system name {}. Status is {} ", systemName, status);
612                         result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
613                 }
614                 if (result == null) {
615                         componentVertices = getComponentsRes.left().value();
616                         for (GraphVertex componentVertex : componentVertices) {
617                                 getComponentRes = getToscaElementByOperation(componentVertex);
618                                 if (getComponentRes.isRight()) {
619                                         log.debug("Failed to get the component {}. Status is {} ", componentVertex.getJsonMetadataField(JsonPresentationFields.NAME), getComponentRes.right().value());
620                                         result = Either.right(getComponentRes.right().value());
621                                         break;
622                                 }
623                                 T componentBySystemName = getComponentRes.left().value();
624                                 log.debug("Found component, id: {}", componentBySystemName.getUniqueId());
625                                 components.add(componentBySystemName);
626                         }
627                 }
628                 if (result == null) {
629                         result = Either.left(components);
630                 }
631                 return result;
632         }
633
634         public <T extends Component> Either<T, StorageOperationStatus> getComponentByNameAndVersion(ComponentTypeEnum componentType, String name, String version) {
635                 return getComponentByNameAndVersion(componentType, name, version, JsonParseFlagEnum.ParseAll);
636         }
637
638         public <T extends Component> Either<T, StorageOperationStatus> getComponentByNameAndVersion(ComponentTypeEnum componentType, String name, String version, JsonParseFlagEnum parseFlag) {
639                 Either<T, StorageOperationStatus> result;
640
641                 Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
642                 Map<GraphPropertyEnum, Object> hasNotProperties = new EnumMap<>(GraphPropertyEnum.class);
643
644                 hasProperties.put(GraphPropertyEnum.NAME, name);
645                 hasProperties.put(GraphPropertyEnum.VERSION, version);
646                 hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true);
647                 if (componentType != null) {
648                         hasProperties.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
649                 }
650                 Either<List<GraphVertex>, TitanOperationStatus> getResourceRes = titanDao.getByCriteria(null, hasProperties, hasNotProperties, parseFlag);
651                 if (getResourceRes.isRight()) {
652                         TitanOperationStatus status = getResourceRes.right().value();
653                         log.debug("failed to find resource with name {}, version {}. Status is {} ", name, version, status);
654                         result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
655                         return result;
656                 }
657                 return getToscaElementByOperation(getResourceRes.left().value().get(0));
658         }
659
660         public <T extends Component> Either<List<T>, StorageOperationStatus> getCatalogComponents(ComponentTypeEnum componentType) {
661                 List<T> components = new ArrayList<>();
662                 Either<List<ToscaElement>, StorageOperationStatus> catalogDataResult;
663                 List<ToscaElement> toscaElements;
664                 switch (componentType) {
665                 case RESOURCE:
666                         catalogDataResult = nodeTypeOperation.getElementCatalogData(ComponentTypeEnum.RESOURCE ,ToscaElementTypeEnum.NodeType);
667                         if (catalogDataResult.isRight()) {
668                                 return Either.right(catalogDataResult.right().value());
669                         }
670                         toscaElements = catalogDataResult.left().value();
671                         Either<List<ToscaElement>, StorageOperationStatus> resourceCatalogData = topologyTemplateOperation.getElementCatalogData(ComponentTypeEnum.RESOURCE ,ToscaElementTypeEnum.TopologyTemplate);
672                         if (resourceCatalogData.isRight()) {
673                                 return Either.right(resourceCatalogData.right().value());
674                         }
675                         toscaElements.addAll(resourceCatalogData.left().value());
676                         break;
677                 case SERVICE:
678                         catalogDataResult = topologyTemplateOperation.getElementCatalogData(ComponentTypeEnum.SERVICE , ToscaElementTypeEnum.TopologyTemplate);
679                         if (catalogDataResult.isRight()) {
680                                 return Either.right(catalogDataResult.right().value());
681                         }
682                         toscaElements = catalogDataResult.left().value();
683                         break;
684                 default:
685                         log.debug("Not supported component type {}", componentType);
686                         return Either.right(StorageOperationStatus.BAD_REQUEST);
687                 }
688                 toscaElements.forEach(te -> {
689                         T component = ModelConverter.convertFromToscaElement(te);
690                         components.add(component);
691                 });
692                 return Either.left(components);
693         }
694
695         public Either<List<String>, StorageOperationStatus> deleteMarkedElements(ComponentTypeEnum componentType) {
696                 Either<List<GraphVertex>, StorageOperationStatus> allComponentsMarkedForDeletion;
697                 List<String> deleted = new ArrayList<>();
698                 switch (componentType) {
699                 case RESOURCE:
700                         allComponentsMarkedForDeletion = nodeTypeOperation.getAllComponentsMarkedForDeletion(componentType);
701                         break;
702                 case SERVICE:
703                 case PRODUCT:
704                         allComponentsMarkedForDeletion = topologyTemplateOperation.getAllComponentsMarkedForDeletion(componentType);
705                         break;
706                 default:
707                         log.debug("Not supported component type {}", componentType);
708                         return Either.right(StorageOperationStatus.BAD_REQUEST);
709                 }
710                 if (allComponentsMarkedForDeletion.isRight()) {
711                         return Either.right(allComponentsMarkedForDeletion.right().value());
712                 }
713                 List<GraphVertex> allMarked = allComponentsMarkedForDeletion.left().value();
714
715                 Either<List<GraphVertex>, TitanOperationStatus> allNotDeletedElements = topologyTemplateOperation.getAllNotDeletedElements();
716                 if (allNotDeletedElements.isRight()) {
717                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(allNotDeletedElements.right().value()));
718                 }
719                 List<GraphVertex> allNonMarked = allNotDeletedElements.left().value();
720                 for (GraphVertex elementV : allMarked) {
721                         if (topologyTemplateOperation.isInUse(elementV, allNonMarked) == false) {
722                                 Either<ToscaElement, StorageOperationStatus> deleteToscaElement = deleteToscaElement(elementV);
723                                 if (deleteToscaElement.isRight()) {
724                                         log.debug("Failed to delete marked element {} error {}", elementV.getUniqueId(), deleteToscaElement.right().value());
725                                 }
726                         } else {
727                                 deleted.add(elementV.getUniqueId());
728                                 log.debug("Marked element {} in use. don't delete it", elementV.getUniqueId());
729                         }
730                 }
731                 return Either.left(deleted);
732         }
733
734         public Either<List<String>, StorageOperationStatus> getAllComponentsMarkedForDeletion(ComponentTypeEnum componentType) {
735                 Either<List<GraphVertex>, StorageOperationStatus> allComponentsMarkedForDeletion;
736                 switch (componentType) {
737                 case RESOURCE:
738                         allComponentsMarkedForDeletion = nodeTypeOperation.getAllComponentsMarkedForDeletion(componentType);
739                         break;
740                 case SERVICE:
741                 case PRODUCT:
742                         allComponentsMarkedForDeletion = topologyTemplateOperation.getAllComponentsMarkedForDeletion(componentType);
743                         break;
744                 default:
745                         log.debug("Not supported component type {}", componentType);
746                         return Either.right(StorageOperationStatus.BAD_REQUEST);
747                 }
748                 if (allComponentsMarkedForDeletion.isRight()) {
749                         return Either.right(allComponentsMarkedForDeletion.right().value());
750                 }
751                 return Either.left(allComponentsMarkedForDeletion.left().value().stream().map(v -> v.getUniqueId()).collect(Collectors.toList()));
752         }
753
754         public Either<Boolean, StorageOperationStatus> isComponentInUse(String componentId) {
755                 Either<Boolean, StorageOperationStatus> result;
756                 Either<List<GraphVertex>, TitanOperationStatus> allNotDeletedElements = topologyTemplateOperation.getAllNotDeletedElements();
757                 if (allNotDeletedElements.isRight()) {
758                         result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(allNotDeletedElements.right().value()));
759                 } else {
760                         result = Either.left(topologyTemplateOperation.isInUse(componentId, allNotDeletedElements.left().value()));
761                 }
762                 return result;
763         }
764
765         public Either<ImmutablePair<Component, String>, StorageOperationStatus> addComponentInstanceToTopologyTemplate(Component containerComponent, Component origComponent, ComponentInstance componentInstance, boolean allowDeleted, User user) {
766
767                 Either<ImmutablePair<Component, String>, StorageOperationStatus> result = null;
768                 Either<ToscaElement, StorageOperationStatus> updateContainerComponentRes = null;
769                 componentInstance.setIcon(origComponent.getIcon());
770                 Either<ImmutablePair<TopologyTemplate, String>, StorageOperationStatus> addResult = nodeTemplateOperation.addComponentInstanceToTopologyTemplate(ModelConverter.convertToToscaElement(containerComponent),
771                                 ModelConverter.convertToToscaElement(origComponent), getNextComponentInstanceCounter(containerComponent, origComponent.getName()), componentInstance, allowDeleted, user);
772
773                 if (addResult.isRight()) {
774                         CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the component instance {} to container component {}. ", componentInstance.getName(), containerComponent.getName());
775                         result = Either.right(addResult.right().value());
776                 }
777                 if (result == null) {
778                         updateContainerComponentRes = topologyTemplateOperation.getToscaElement(containerComponent.getUniqueId());
779                         if (updateContainerComponentRes.isRight()) {
780                                 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch updated topology template {} with updated component instance {}. ", containerComponent.getName(), componentInstance.getName());
781                                 result = Either.right(updateContainerComponentRes.right().value());
782                         }
783                 }
784                 if (result == null) {
785                         Component updatedComponent = ModelConverter.convertFromToscaElement(updateContainerComponentRes.left().value());
786                         String createdInstanceId = addResult.left().value().getRight();
787                         CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "The component instance {} has been added to container component {}. ", createdInstanceId, updatedComponent.getName());
788                         result = Either.left(new ImmutablePair<>(updatedComponent, createdInstanceId));
789                 }
790                 return result;
791         }
792
793         public StorageOperationStatus associateComponentInstancesToComponent(Component containerComponent, Map<ComponentInstance, Resource> resourcesInstancesMap, boolean allowDeleted) {
794
795                 StorageOperationStatus result = null;
796                 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Going to add component instances to component {}", containerComponent.getUniqueId());
797
798                 Either<GraphVertex, TitanOperationStatus> metadataVertex = titanDao.getVertexById(containerComponent.getUniqueId(), JsonParseFlagEnum.ParseAll);
799                 if (metadataVertex.isRight()) {
800                         TitanOperationStatus status = metadataVertex.right().value();
801                         if (status == TitanOperationStatus.NOT_FOUND) {
802                                 status = TitanOperationStatus.INVALID_ID;
803                         }
804                         result = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
805                 }
806                 if (result == null) {
807                         result = nodeTemplateOperation.associateComponentInstancesToComponent(containerComponent, resourcesInstancesMap, metadataVertex.left().value(), allowDeleted);
808                 }
809                 return result;
810         }
811
812         public Either<ImmutablePair<Component, String>, StorageOperationStatus> updateComponentInstanceMetadataOfTopologyTemplate(Component containerComponent, Component origComponent, ComponentInstance componentInstance) {
813
814                 Either<ImmutablePair<Component, String>, StorageOperationStatus> result = null;
815
816                 CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "Going to update the metadata of the component instance {} belonging to container component {}. ", componentInstance.getName(), containerComponent.getName());
817                 componentInstance.setIcon(origComponent.getIcon());
818                 Either<ImmutablePair<TopologyTemplate, String>, StorageOperationStatus> updateResult = nodeTemplateOperation.updateComponentInstanceMetadataOfTopologyTemplate(ModelConverter.convertToToscaElement(containerComponent),
819                                 ModelConverter.convertToToscaElement(origComponent), componentInstance);
820                 if (updateResult.isRight()) {
821                         CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the metadata of the component instance {} belonging to container component {}. ", componentInstance.getName(), containerComponent.getName());
822                         result = Either.right(updateResult.right().value());
823                 }
824                 if (result == null) {
825                         Component updatedComponent = ModelConverter.convertFromToscaElement(updateResult.left().value().getLeft());
826                         String createdInstanceId = updateResult.left().value().getRight();
827                         CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "The metadata of the component instance {} has been updated to container component {}. ", createdInstanceId, updatedComponent.getName());
828                         result = Either.left(new ImmutablePair<>(updatedComponent, createdInstanceId));
829                 }
830                 return result;
831         }
832
833         public Either<Component, StorageOperationStatus> updateComponentInstanceMetadataOfTopologyTemplate(Component containerComponent) {
834
835                 Either<Component, StorageOperationStatus> result = null;
836
837                 CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "Going to update the metadata  belonging to container component {}. ", containerComponent.getName());
838
839                 Either<TopologyTemplate, StorageOperationStatus> updateResult = nodeTemplateOperation.updateComponentInstanceMetadataOfTopologyTemplate(ModelConverter.convertToToscaElement(containerComponent));
840                 if (updateResult.isRight()) {
841                         CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the metadata  belonging to container component {}. ", containerComponent.getName());
842                         result = Either.right(updateResult.right().value());
843                 }
844                 if (result == null) {
845                         Component updatedComponent = ModelConverter.convertFromToscaElement(updateResult.left().value());
846                         CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "The metadata has been updated to container component {}. ", updatedComponent.getName());
847                         result = Either.left(updatedComponent);
848                 }
849                 return result;
850         }
851
852         public Either<ImmutablePair<Component, String>, StorageOperationStatus> deleteComponentInstanceFromTopologyTemplate(Component containerComponent, String resourceInstanceId) {
853
854                 Either<ImmutablePair<Component, String>, StorageOperationStatus> result = null;
855
856                 CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "Going to delete the component instance {} belonging to container component {}. ", resourceInstanceId, containerComponent.getName());
857
858                 Either<ImmutablePair<TopologyTemplate, String>, StorageOperationStatus> updateResult = nodeTemplateOperation.deleteComponentInstanceFromTopologyTemplate(ModelConverter.convertToToscaElement(containerComponent), resourceInstanceId);
859                 if (updateResult.isRight()) {
860                         CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to delete the component instance {} belonging to container component {}. ", resourceInstanceId, containerComponent.getName());
861                         result = Either.right(updateResult.right().value());
862                 }
863                 if (result == null) {
864                         Component updatedComponent = ModelConverter.convertFromToscaElement(updateResult.left().value().getLeft());
865                         String deletedInstanceId = updateResult.left().value().getRight();
866                         CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "The component instance {} has been deleted from container component {}. ", deletedInstanceId, updatedComponent.getName());
867                         result = Either.left(new ImmutablePair<>(updatedComponent, deletedInstanceId));
868                 }
869                 return result;
870         }
871
872         private String getNextComponentInstanceCounter(Component containerComponent, String originResourceName) {
873
874                 Integer nextCounter = 0;
875
876                 if (CollectionUtils.isNotEmpty(containerComponent.getComponentInstances())) {
877
878                         String normalizedName = ValidationUtils.normalizeComponentInstanceName(originResourceName);
879                         Integer maxCounterFromNames = getMaxCounterFromNames(containerComponent, normalizedName);
880                         Integer maxCounterFromIds = getMaxCounterFromIds(containerComponent, normalizedName);
881
882                         if (maxCounterFromNames == null && maxCounterFromIds != null) {
883                                 nextCounter = maxCounterFromIds + 1;
884                         } else if (maxCounterFromIds == null && maxCounterFromNames != null) {
885                                 nextCounter = maxCounterFromNames + 1;
886                         } else if (maxCounterFromIds != null && maxCounterFromNames != null) {
887                                 nextCounter = maxCounterFromNames > maxCounterFromIds ? maxCounterFromNames + 1 : maxCounterFromIds + 1;
888                         }
889                 }
890                 return nextCounter.toString();
891         }
892
893         private Integer getMaxCounterFromNames(Component containerComponent, String normalizedName) {
894
895                 Integer maxCounter = 0;
896                 List<String> countersStr = containerComponent.getComponentInstances().stream().filter(ci -> ci.getNormalizedName() != null && ci.getNormalizedName().startsWith(normalizedName)).map(ci -> ci.getNormalizedName().split(normalizedName)[1])
897                                 .collect(Collectors.toList());
898
899                 if (CollectionUtils.isEmpty(countersStr)) {
900                         return null;
901                 }
902                 Integer currCounter = null;
903                 for (String counter : countersStr) {
904                         if (StringUtils.isEmpty(counter)) {
905                                 continue;
906                         }
907                         try {
908                                 currCounter = Integer.parseInt(counter);
909                         } catch (Exception e) {
910                                 continue;
911                         }
912                         maxCounter = maxCounter < currCounter ? currCounter : maxCounter;
913                 }
914                 if (currCounter == null) {
915                         return null;
916                 }
917                 return maxCounter;
918         }
919
920         private Integer getMaxCounterFromIds(Component containerComponent, String normalizedName) {
921
922                 Integer maxCounter = 0;
923                 List<String> countersStr = containerComponent.getComponentInstances().stream().filter(ci -> ci.getUniqueId() != null && ci.getUniqueId().contains(normalizedName)).map(ci -> ci.getUniqueId().split(normalizedName)[1])
924                                 .collect(Collectors.toList());
925
926                 if (CollectionUtils.isEmpty(countersStr)) {
927                         return null;
928                 }
929                 Integer currCounter = null;
930                 for (String counter : countersStr) {
931                         if (StringUtils.isEmpty(counter)) {
932                                 continue;
933                         }
934                         try {
935                                 currCounter = Integer.parseInt(counter);
936                         } catch (Exception e) {
937                                 continue;
938                         }
939                         maxCounter = maxCounter < currCounter ? currCounter : maxCounter;
940                 }
941                 if (currCounter == null) {
942                         return null;
943                 }
944                 return maxCounter;
945         }
946
947         public Either<RequirementCapabilityRelDef, StorageOperationStatus> associateResourceInstances(String componentId, RequirementCapabilityRelDef requirementDef) {
948                 return nodeTemplateOperation.associateResourceInstances(componentId, requirementDef);
949
950         }
951
952         public Either<List<InputDefinition>, StorageOperationStatus> createAndAssociateInputs(Map<String, InputDefinition> inputs, String componentId) {
953
954                 Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
955                 if (getVertexEither.isRight()) {
956                         log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
957                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
958
959                 }
960
961                 GraphVertex vertex = getVertexEither.left().value();
962                 Map<String, PropertyDataDefinition> inputsMap = inputs.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new PropertyDataDefinition(e.getValue())));
963
964                 StorageOperationStatus status = topologyTemplateOperation.associateInputsToComponent(vertex, inputsMap, componentId);
965
966                 if (StorageOperationStatus.OK == status) {
967                         log.debug("Component created successfully!!!");
968                         List<InputDefinition> inputsResList = null;
969                         if (inputsMap != null && !inputsMap.isEmpty()) {
970                                 inputsResList = inputsMap.values().stream().map(i -> new InputDefinition(i)).collect(Collectors.toList());
971                         }
972                         return Either.left(inputsResList);
973                 }
974                 return Either.right(status);
975
976         }
977
978         public Either<List<InputDefinition>, StorageOperationStatus> addInputsToComponent(Map<String, InputDefinition> inputs, String componentId) {
979
980                 Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
981                 if (getVertexEither.isRight()) {
982                         log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
983                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
984
985                 }
986
987                 GraphVertex vertex = getVertexEither.left().value();
988                 Map<String, PropertyDataDefinition> inputsMap = inputs.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new PropertyDataDefinition(e.getValue())));
989
990                 StorageOperationStatus status = topologyTemplateOperation.addToscaDataToToscaElement(vertex, EdgeLabelEnum.INPUTS, VertexTypeEnum.INPUTS, inputsMap, JsonPresentationFields.NAME);
991
992                 if (StorageOperationStatus.OK == status) {
993                         log.debug("Component created successfully!!!");
994                         List<InputDefinition> inputsResList = null;
995                         if (inputsMap != null && !inputsMap.isEmpty()) {
996                                 inputsResList = inputsMap.values().stream().map(i -> new InputDefinition(i)).collect(Collectors.toList());
997                         }
998                         return Either.left(inputsResList);
999                 }
1000                 return Either.right(status);
1001
1002         }
1003
1004         public Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> associateComponentInstancePropertiesToComponent(Map<String, List<ComponentInstanceProperty>> instProperties, String componentId) {
1005
1006                 Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
1007                 if (getVertexEither.isRight()) {
1008                         log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
1009                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
1010
1011                 }
1012
1013                 GraphVertex vertex = getVertexEither.left().value();
1014                 Map<String, MapPropertiesDataDefinition> instPropsMap = new HashMap<>();
1015                 if (instProperties != null) {
1016
1017                         MapPropertiesDataDefinition propertiesMap;
1018                         for (Entry<String, List<ComponentInstanceProperty>> entry : instProperties.entrySet()) {
1019                                 propertiesMap = new MapPropertiesDataDefinition();
1020
1021                                 propertiesMap.setMapToscaDataDefinition(entry.getValue().stream().map(e -> new PropertyDataDefinition(e)).collect(Collectors.toMap(e -> e.getName(), e -> e)));
1022
1023                                 instPropsMap.put(entry.getKey(), propertiesMap);
1024                         }
1025                 }
1026
1027                 StorageOperationStatus status = topologyTemplateOperation.associateInstPropertiesToComponent(vertex, instPropsMap);
1028
1029                 if (StorageOperationStatus.OK == status) {
1030                         log.debug("Component created successfully!!!");
1031                         return Either.left(instProperties);
1032                 }
1033                 return Either.right(status);
1034
1035         }
1036
1037         public Either<Map<String, List<ComponentInstanceInput>>, StorageOperationStatus> addComponentInstanceInputsToComponent(Map<String, List<ComponentInstanceInput>> instProperties, String componentId) {
1038
1039                 Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
1040                 if (getVertexEither.isRight()) {
1041                         log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
1042                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
1043
1044                 }
1045
1046                 GraphVertex vertex = getVertexEither.left().value();
1047                 Map<String, MapPropertiesDataDefinition> instPropsMap = new HashMap<>();
1048                 if (instProperties != null) {
1049
1050                         MapPropertiesDataDefinition propertiesMap;
1051                         for (Entry<String, List<ComponentInstanceInput>> entry : instProperties.entrySet()) {
1052                                 propertiesMap = new MapPropertiesDataDefinition();
1053
1054                                 propertiesMap.setMapToscaDataDefinition(entry.getValue().stream().map(e -> new PropertyDataDefinition(e)).collect(Collectors.toMap(e -> e.getName(), e -> e)));
1055
1056                                 instPropsMap.put(entry.getKey(), propertiesMap);
1057                         }
1058                 }
1059
1060                 StorageOperationStatus status = topologyTemplateOperation.addInstInputsToComponent(vertex, instPropsMap);
1061
1062                 if (StorageOperationStatus.OK == status) {
1063                         log.debug("Component created successfully!!!");
1064                         return Either.left(instProperties);
1065                 }
1066                 return Either.right(status);
1067
1068         }
1069
1070         public StorageOperationStatus deleteComponentInstanceInputsToComponent(Map<String, List<ComponentInstanceInput>> instProperties, String componentId) {
1071
1072                 Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
1073                 if (getVertexEither.isRight()) {
1074                         log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
1075                         return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
1076
1077                 }
1078
1079                 GraphVertex vertex = getVertexEither.left().value();
1080                 Map<String, MapPropertiesDataDefinition> instPropsMap = new HashMap<>();
1081                 if (instProperties != null) {
1082
1083                         MapPropertiesDataDefinition propertiesMap;
1084                         for (Entry<String, List<ComponentInstanceInput>> entry : instProperties.entrySet()) {
1085                                 propertiesMap = new MapPropertiesDataDefinition();
1086
1087                                 propertiesMap.setMapToscaDataDefinition(entry.getValue().stream().map(e -> new PropertyDataDefinition(e)).collect(Collectors.toMap(e -> e.getName(), e -> e)));
1088
1089                                 instPropsMap.put(entry.getKey(), propertiesMap);
1090                         }
1091                 }
1092
1093                 return topologyTemplateOperation.deleteInstInputsToComponent(vertex, instPropsMap);
1094
1095         }
1096
1097         public Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> addComponentInstancePropertiesToComponent(Component containerComponent, Map<String, List<ComponentInstanceProperty>> instProperties, String componentId) {
1098
1099                 StorageOperationStatus status = StorageOperationStatus.OK;
1100                 if (instProperties != null) {
1101
1102                         for (Entry<String, List<ComponentInstanceProperty>> entry : instProperties.entrySet()) {
1103                                 List<ComponentInstanceProperty> props = entry.getValue();
1104                                 String componentInstanseId = entry.getKey();
1105                                 List<ComponentInstanceProperty> instanceProperties = containerComponent.getComponentInstancesProperties().get(componentInstanseId);
1106                                 if (props != null && !props.isEmpty()) {
1107                                         for (ComponentInstanceProperty property : props) {
1108                                                 Optional<ComponentInstanceProperty> instanceProperty = instanceProperties.stream().filter(p -> p.getUniqueId().equals(property.getUniqueId())).findAny();
1109                                                 if (instanceProperty.isPresent()) {
1110                                                         status = updateComponentInstanceProperty(containerComponent, componentInstanseId, property);
1111                                                 } else {
1112                                                         status = addComponentInstanceProperty(containerComponent, componentInstanseId, property);
1113                                                 }
1114
1115                                         }
1116                                 }
1117                         }
1118                 }
1119
1120                 return Either.left(instProperties);
1121
1122         }
1123
1124         public StorageOperationStatus associateArtifactToInstances(Map<String, Map<String, ArtifactDefinition>> instArtifacts, String componentId, User user) {
1125
1126                 Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
1127                 if (getVertexEither.isRight()) {
1128                         log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
1129                         return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
1130
1131                 }
1132
1133                 GraphVertex vertex = getVertexEither.left().value();
1134                 Map<String, MapArtifactDataDefinition> instArtMap = new HashMap<>();
1135                 if (instArtifacts != null) {
1136
1137                         MapArtifactDataDefinition artifactsMap;
1138                         for (Entry<String, Map<String, ArtifactDefinition>> entry : instArtifacts.entrySet()) {
1139                                 Map<String, ArtifactDefinition> artList = entry.getValue();
1140                                 Map<String, ArtifactDataDefinition> artifacts = artList.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ArtifactDataDefinition(e.getValue())));
1141                                 artifactsMap = nodeTemplateOperation.prepareInstDeploymentArtifactPerInstance(artifacts, entry.getKey(), user, NodeTemplateOperation.HEAT_VF_ENV_NAME);
1142
1143                                 instArtMap.put(entry.getKey(), artifactsMap);
1144                         }
1145                 }
1146
1147                 return topologyTemplateOperation.associateInstArtifactToComponent(vertex, instArtMap);
1148
1149         }
1150
1151         public StorageOperationStatus associateInstAttributeToComponentToInstances(Map<String, List<AttributeDefinition>> instArttributes, String componentId) {
1152
1153                 Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
1154                 if (getVertexEither.isRight()) {
1155                         log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
1156                         return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
1157
1158                 }
1159
1160                 GraphVertex vertex = getVertexEither.left().value();
1161                 Map<String, MapAttributesDataDefinition> instAttr = new HashMap<>();
1162                 if (instArttributes != null) {
1163
1164                         MapAttributesDataDefinition attributesMap;
1165                         for (Entry<String, List<AttributeDefinition>> entry : instArttributes.entrySet()) {
1166                                 attributesMap = new MapAttributesDataDefinition();
1167                                 attributesMap.setMapToscaDataDefinition(entry.getValue().stream().map(e -> new AttributeDataDefinition(e)).collect(Collectors.toMap(e -> e.getName(), e -> e)));
1168                                 instAttr.put(entry.getKey(), attributesMap);
1169                         }
1170                 }
1171
1172                 return topologyTemplateOperation.associateInstAttributeToComponent(vertex, instAttr);
1173
1174         }
1175
1176         public StorageOperationStatus associateCalculatedCapReq(Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties, Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instReg, String componentId) {
1177                 Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
1178                 if (getVertexEither.isRight()) {
1179                         log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
1180                         return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
1181
1182                 }
1183
1184                 GraphVertex vertex = getVertexEither.left().value();
1185
1186                 Map<String, MapListRequirementDataDefinition> calcRequirements = new HashMap<>();
1187                 
1188                 Map<String, MapListCapabiltyDataDefinition> calcCapabilty = new HashMap<>();
1189                 Map<String, MapCapabiltyProperty> calculatedCapabilitiesProperties = new HashMap<>();;
1190                 if (instCapabilties != null) {
1191                         for (Entry<ComponentInstance, Map<String, List<CapabilityDefinition>>> entry : instCapabilties.entrySet()) {
1192
1193                                 Map<String, List<CapabilityDefinition>> caps = entry.getValue();
1194                                 Map<String, ListCapabilityDataDefinition> mapToscaDataDefinition = new HashMap<>();
1195                                 for (Entry<String, List<CapabilityDefinition>> instCapability : caps.entrySet()) {
1196                                         mapToscaDataDefinition.put(instCapability.getKey(), new ListCapabilityDataDefinition(instCapability.getValue().stream().map(iCap -> new CapabilityDataDefinition(iCap)).collect(Collectors.toList())));
1197                                 }
1198
1199                                 ComponentInstanceDataDefinition componentInstance = new ComponentInstanceDataDefinition(entry.getKey());
1200                                 MapListCapabiltyDataDefinition capMap = nodeTemplateOperation.prepareCalculatedCapabiltyForNodeType(mapToscaDataDefinition, componentInstance);
1201
1202                                 MapCapabiltyProperty mapCapabiltyProperty = ModelConverter.convertToMapOfMapCapabiltyProperties(caps, componentInstance.getUniqueId(), true);
1203                                 
1204                                 calcCapabilty.put(entry.getKey().getUniqueId(), capMap);
1205                                 calculatedCapabilitiesProperties.put(entry.getKey().getUniqueId(), mapCapabiltyProperty);
1206                         }
1207                 }
1208
1209                 if (instReg != null) {
1210                         for (Entry<ComponentInstance, Map<String, List<RequirementDefinition>>> entry : instReg.entrySet()) {
1211
1212                                 Map<String, List<RequirementDefinition>> req = entry.getValue();
1213                                 Map<String, ListRequirementDataDefinition> mapToscaDataDefinition = new HashMap<>();
1214                                 for (Entry<String, List<RequirementDefinition>> instReq : req.entrySet()) {
1215                                         mapToscaDataDefinition.put(instReq.getKey(), new ListRequirementDataDefinition(instReq.getValue().stream().map(iCap -> new RequirementDataDefinition(iCap)).collect(Collectors.toList())));
1216                                 }
1217
1218                                 MapListRequirementDataDefinition capMap = nodeTemplateOperation.prepareCalculatedRequirementForNodeType(mapToscaDataDefinition, new ComponentInstanceDataDefinition(entry.getKey()));
1219
1220                                 calcRequirements.put(entry.getKey().getUniqueId(), capMap);
1221                         }
1222                 }
1223
1224                 StorageOperationStatus status = topologyTemplateOperation.associateCalcCapReqToComponent(vertex, calcRequirements, calcCapabilty, calculatedCapabilitiesProperties);
1225
1226                 return status;
1227         }
1228
1229         private Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractToscaElementsMetadataOnly(boolean isAbstract, Boolean isHighest, ComponentTypeEnum componentTypeEnum, String internalComponentType,
1230                         VertexTypeEnum vertexType) {
1231
1232                 Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class);
1233                 Map<GraphPropertyEnum, Object> hasNotProps = new EnumMap<>(GraphPropertyEnum.class);
1234
1235                 fillPropsMap(hasProps, hasNotProps, internalComponentType, componentTypeEnum, isAbstract, vertexType);
1236
1237                 Either<List<GraphVertex>, TitanOperationStatus> getRes = titanDao.getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata);
1238                 if (getRes.isRight()) {
1239                         if (getRes.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
1240                                 return Either.left(new ArrayList<>());
1241                         } else {
1242                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
1243                         }
1244                 } else {
1245                          List<Component> nonAbstractLatestComponents = new ArrayList<>();
1246                          ComponentParametersView params = new ComponentParametersView(true);
1247                          params.setIgnoreAllVersions(false);
1248                          for (GraphVertex vertexComponent : getRes.left().value()) {
1249                 Either<ToscaElement, StorageOperationStatus> componentRes = topologyTemplateOperation.getLightComponent(vertexComponent, componentTypeEnum, params);
1250                 if (componentRes.isRight()) {
1251                     log.debug("Failed to fetch ligth element for {} error {}", vertexComponent.getUniqueId(), componentRes.right().value());
1252                     return Either.right(componentRes.right().value());
1253                 } else {
1254                     Component component = ModelConverter.convertFromToscaElement(componentRes.left().value());
1255                 
1256                 nonAbstractLatestComponents.add(component);
1257                 }
1258                 }
1259
1260                         return Either.left(nonAbstractLatestComponents);
1261                 }
1262         }
1263
1264         public Either<ComponentMetadataData, StorageOperationStatus> getLatestComponentMetadataByUuid(String componentUuid, JsonParseFlagEnum parseFlag) {
1265
1266                 Either<ComponentMetadataData, StorageOperationStatus> result;
1267
1268                 Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
1269
1270                 hasProperties.put(GraphPropertyEnum.UUID, componentUuid);
1271                 hasProperties.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
1272
1273                 Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
1274                 propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
1275
1276                 Either<List<GraphVertex>, TitanOperationStatus> getRes = titanDao.getByCriteria(null, hasProperties, propertiesNotToMatch, parseFlag);
1277                 if (getRes.isRight()) {
1278                         result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
1279                 } else {
1280                         List<ComponentMetadataData> latestVersionList = getRes.left().value().stream().map(ModelConverter::convertToComponentMetadata).collect(Collectors.toList());
1281                         ComponentMetadataData latestVersion = latestVersionList.size() == 1 ? latestVersionList.get(0)
1282                                         : latestVersionList.stream().max((c1, c2) -> Double.compare(Double.parseDouble(c1.getMetadataDataDefinition().getVersion()), Double.parseDouble(c2.getMetadataDataDefinition().getVersion()))).get();
1283                         result = Either.left(latestVersion);
1284                 }
1285                 return result;
1286         }
1287
1288         public Either<ComponentMetadataData, StorageOperationStatus> getComponentMetadata(String componentId) {
1289
1290                 Either<ComponentMetadataData, StorageOperationStatus> result;
1291                 Either<GraphVertex, TitanOperationStatus> getRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseMetadata);
1292                 if (getRes.isRight()) {
1293                         result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
1294                 } else {
1295                         ComponentMetadataData componentMetadata = ModelConverter.convertToComponentMetadata(getRes.left().value());
1296                         result = Either.left(componentMetadata);
1297                 }
1298                 return result;
1299         }
1300
1301         private Map<String, ComponentMetadataData> findLatestVersion(List<ComponentMetadataData> resourceDataList) {
1302                 Map<Pair<String, String>, ComponentMetadataData> latestVersionMap = new HashMap<Pair<String, String>, ComponentMetadataData>();
1303                 for (ComponentMetadataData resourceData : resourceDataList) {
1304                         ComponentMetadataData latestVersionData = resourceData;
1305
1306                         ComponentMetadataDataDefinition metadataDataDefinition = resourceData.getMetadataDataDefinition();
1307                         Pair<String, String> pair = createKeyPair(latestVersionData);
1308                         if (latestVersionMap.containsKey(pair)) {
1309                                 latestVersionData = latestVersionMap.get(pair);
1310                                 String currentVersion = latestVersionData.getMetadataDataDefinition().getVersion();
1311                                 String newVersion = metadataDataDefinition.getVersion();
1312                                 if (CommonBeUtils.compareAsdcComponentVersions(newVersion, currentVersion)) {
1313                                         latestVersionData = resourceData;
1314                                 }
1315                         }
1316                         if (log.isDebugEnabled())
1317                                 log.debug("last certified version of resource = {}  version is {}", latestVersionData.getMetadataDataDefinition().getName(), latestVersionData.getMetadataDataDefinition().getVersion());
1318
1319                         latestVersionMap.put(pair, latestVersionData);
1320                 }
1321
1322                 Map<String, ComponentMetadataData> resVersionMap = new HashMap<String, ComponentMetadataData>();
1323                 for (ComponentMetadataData resourceData : latestVersionMap.values()) {
1324                         ComponentMetadataData latestVersionData = resourceData;
1325                         ComponentMetadataDataDefinition metadataDataDefinition = resourceData.getMetadataDataDefinition();
1326                         if (resVersionMap.containsKey(metadataDataDefinition.getUUID())) {
1327                                 latestVersionData = resVersionMap.get(metadataDataDefinition.getUUID());
1328                                 String currentVersion = latestVersionData.getMetadataDataDefinition().getVersion();
1329                                 String newVersion = metadataDataDefinition.getVersion();
1330                                 if (CommonBeUtils.compareAsdcComponentVersions(newVersion, currentVersion)) {
1331                                         latestVersionData = resourceData;
1332                                 }
1333                         }
1334                         if (log.isDebugEnabled())
1335                                 log.debug("last uuid version of resource = {}  version is {}", latestVersionData.getMetadataDataDefinition().getName(), latestVersionData.getMetadataDataDefinition().getVersion());
1336                         resVersionMap.put(latestVersionData.getMetadataDataDefinition().getUUID(), latestVersionData);
1337                 }
1338
1339                 return resVersionMap;
1340         }
1341
1342         private Pair<String, String> createKeyPair(ComponentMetadataData metadataData) {
1343                 Pair<String, String> pair;
1344                 NodeTypeEnum label = NodeTypeEnum.getByName(metadataData.getLabel());
1345                 switch (label) {
1346                 case Resource:
1347                         pair = new ImmutablePair<>(metadataData.getMetadataDataDefinition().getName(), ((ResourceMetadataDataDefinition) metadataData.getMetadataDataDefinition()).getResourceType().name());
1348                         break;
1349                 default:
1350                         pair = new ImmutablePair<>(metadataData.getMetadataDataDefinition().getName(), metadataData.getLabel());
1351                         break;
1352                 }
1353
1354                 return pair;
1355         }
1356
1357         public Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractComponents(boolean isAbstract, Boolean isHighest, ComponentTypeEnum componentTypeEnum, String internalComponentType, List<String> componentUids) {
1358
1359                 Either<List<Component>, StorageOperationStatus> result = null;
1360                 List<Component> components = new ArrayList<>();
1361                 if (componentUids == null) {
1362                         Either<List<String>, StorageOperationStatus> componentUidsRes = getComponentUids(isAbstract, isHighest, componentTypeEnum, internalComponentType, componentUids);
1363                         if (componentUidsRes.isRight()) {
1364                                 result = Either.right(componentUidsRes.right().value());
1365                         } else {
1366                                 componentUids = componentUidsRes.left().value();
1367                         }
1368                 }
1369                 if (!componentUids.isEmpty()) {
1370                         for (String componentUid : componentUids) {
1371                                 ComponentParametersView componentParametersView = buildComponentViewForNotAbstract();
1372                                 if (internalComponentType != null && "vl".equalsIgnoreCase(internalComponentType)) {
1373                                         componentParametersView.setIgnoreCapabilities(false);
1374                                         componentParametersView.setIgnoreRequirements(false);
1375                                 }
1376                                 Either<ToscaElement, StorageOperationStatus> getToscaElementRes = nodeTemplateOperation.getToscaElementOperation(componentTypeEnum).getLightComponent(componentUid, componentTypeEnum, componentParametersView);
1377                                 if (getToscaElementRes.isRight()) {
1378                                         if (log.isDebugEnabled())
1379                                                 log.debug("Failed to fetch resource for error is {}", getToscaElementRes.right().value());
1380                                         result = Either.right(getToscaElementRes.right().value());
1381                                         break;
1382                                 }
1383                                 Component component = ModelConverter.convertFromToscaElement(getToscaElementRes.left().value());
1384                                 component.setContactId(null);
1385                                 component.setCreationDate(null);
1386                                 component.setCreatorUserId(null);
1387                                 component.setCreatorFullName(null);
1388                                 component.setLastUpdateDate(null);
1389                                 component.setLastUpdaterUserId(null);
1390                                 component.setLastUpdaterFullName(null);
1391                                 component.setNormalizedName(null);
1392                                 components.add(component);
1393                         }
1394                 }
1395                 if (result == null) {
1396                         result = Either.left(components);
1397                 }
1398                 return result;
1399         }
1400
1401         private Either<List<String>, StorageOperationStatus> getComponentUids(boolean isAbstract, Boolean isHighest, ComponentTypeEnum componentTypeEnum, String internalComponentType, List<String> componentUids) {
1402
1403                 Either<List<String>, StorageOperationStatus> result = null;
1404                 Either<List<Component>, StorageOperationStatus> getToscaElementsRes = getLatestVersionNotAbstractMetadataOnly(isAbstract, isHighest, componentTypeEnum, internalComponentType);
1405                 if (getToscaElementsRes.isRight()) {
1406                         result = Either.right(getToscaElementsRes.right().value());
1407                 } else {
1408                         List<Component> collection = getToscaElementsRes.left().value();
1409                         if (collection == null) {
1410                                 componentUids = new ArrayList<>();
1411                         } else {
1412                                 componentUids = collection.stream().map(p -> p.getUniqueId()).collect(Collectors.toList());
1413                         }
1414                 }
1415                 if (result == null) {
1416                         result = Either.left(componentUids);
1417                 }
1418                 return result;
1419         }
1420
1421         private ComponentParametersView buildComponentViewForNotAbstract() {
1422                 ComponentParametersView componentParametersView = new ComponentParametersView();
1423                 componentParametersView.disableAll();
1424                 componentParametersView.setIgnoreCategories(false);
1425                 componentParametersView.setIgnoreAllVersions(false);
1426                 return componentParametersView;
1427         }
1428
1429         public Either<Boolean, StorageOperationStatus> validateComponentNameExists(String name, ResourceTypeEnum resourceType, ComponentTypeEnum componentType) {
1430                 Either<Boolean, StorageOperationStatus> result = validateComponentNameUniqueness(name, resourceType, componentType);
1431                 if (result.isLeft()) {
1432                         result = Either.left(!result.left().value());
1433                 }
1434                 return result;
1435         }
1436
1437         public Either<Boolean, StorageOperationStatus> validateComponentNameUniqueness(String name, ResourceTypeEnum resourceType, ComponentTypeEnum componentType) {
1438                 VertexTypeEnum vertexType = getVertexTypeByComponentAndResourceTypeEnum(resourceType, componentType);
1439                 String normalizedName = ValidationUtils.normaliseComponentName(name);
1440                 Map<GraphPropertyEnum, Object> properties = new EnumMap<>(GraphPropertyEnum.class);
1441                 properties.put(GraphPropertyEnum.NORMALIZED_NAME, normalizedName);
1442                 properties.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
1443
1444                 Either<List<GraphVertex>, TitanOperationStatus> vertexEither = titanDao.getByCriteria(vertexType, properties, JsonParseFlagEnum.NoParse);
1445                 if (vertexEither.isRight() && vertexEither.right().value() != TitanOperationStatus.NOT_FOUND) {
1446                         log.debug("failed to get vertex from graph with property normalizedName: {}", normalizedName);
1447                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(vertexEither.right().value()));
1448                 }
1449                 List<GraphVertex> vertexList = vertexEither.isLeft() ? vertexEither.left().value() : null;
1450                 if (vertexList != null && !vertexList.isEmpty()) {
1451                         return Either.left(false);
1452                 } else {
1453                         return Either.left(true);
1454                 }
1455         }
1456
1457         // UI query parameter is either VFC/CP/VL(for yaml upload/update) or VF (for CSAR upload/user composed VF)
1458         // TODO implementation of topology template VFCs may require updating this method - depending on UI implementation
1459         private VertexTypeEnum getVertexTypeByComponentAndResourceTypeEnum(ResourceTypeEnum resourceType, ComponentTypeEnum componentType) {
1460                 VertexTypeEnum vertexType = VertexTypeEnum.TOPOLOGY_TEMPLATE;
1461                 if (ComponentTypeEnum.RESOURCE == componentType && ResourceTypeEnum.VF != resourceType) {
1462                         vertexType = VertexTypeEnum.NODE_TYPE;
1463                 }
1464                 return vertexType;
1465         }
1466
1467         private void fillNodeTypePropsMap(Map<GraphPropertyEnum, Object> hasProps, Map<GraphPropertyEnum, Object> hasNotProps, String internalComponentType) {
1468                 switch (internalComponentType.toLowerCase()) {
1469                 case "vf":
1470                         hasNotProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF.name());
1471                         hasNotProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VFCMT.name());
1472                         break;
1473                 case "service":
1474                         hasNotProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VFC.name());
1475                         hasNotProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VFCMT.name());
1476                         break;
1477                 case "vl":
1478                         hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VL.name());
1479                         break;
1480                 default:
1481                         break;
1482                 }
1483         }
1484
1485         private void fillTopologyTemplatePropsMap(Map<GraphPropertyEnum, Object> hasProps, ComponentTypeEnum componentTypeEnum) {
1486                 switch (componentTypeEnum) {
1487                 case RESOURCE:
1488                         hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
1489                         break;
1490                 case SERVICE:
1491                         hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
1492                         break;
1493                 default:
1494                         break;
1495                 }
1496         }
1497
1498         private void fillPropsMap(Map<GraphPropertyEnum, Object> hasProps, Map<GraphPropertyEnum, Object> hasNotProps, String internalComponentType, ComponentTypeEnum componentTypeEnum, boolean isAbstract, VertexTypeEnum internalVertexType) {
1499                 hasNotProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
1500
1501                 hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
1502                 if (VertexTypeEnum.NODE_TYPE == internalVertexType) {
1503                         hasProps.put(GraphPropertyEnum.IS_ABSTRACT, isAbstract);
1504                         if (internalComponentType != null) {
1505                                 fillNodeTypePropsMap(hasProps, hasNotProps, internalComponentType);
1506                         }
1507                 } else {
1508                         fillTopologyTemplatePropsMap(hasProps, componentTypeEnum);
1509                 }
1510         }
1511
1512         private List<VertexTypeEnum> getInternalVertexTypes(ComponentTypeEnum componentTypeEnum, String internalComponentType) {
1513                 List<VertexTypeEnum> internalVertexTypes = new ArrayList<>();
1514                 if (ComponentTypeEnum.RESOURCE == componentTypeEnum) {
1515                         internalVertexTypes.add(VertexTypeEnum.NODE_TYPE);
1516                 }
1517                 if (ComponentTypeEnum.SERVICE == componentTypeEnum || "service".equalsIgnoreCase(internalComponentType)) {
1518                         internalVertexTypes.add(VertexTypeEnum.TOPOLOGY_TEMPLATE);
1519                 }
1520                 return internalVertexTypes;
1521         }
1522
1523         public Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractMetadataOnly(boolean isAbstract, Boolean isHighest, ComponentTypeEnum componentTypeEnum, String internalComponentType) {
1524                 List<VertexTypeEnum> internalVertexTypes = getInternalVertexTypes(componentTypeEnum, internalComponentType);
1525                 List<Component> result = new ArrayList<>();
1526                 for (VertexTypeEnum vertexType : internalVertexTypes) {
1527                         Either<List<Component>, StorageOperationStatus> listByVertexType = getLatestVersionNotAbstractToscaElementsMetadataOnly(isAbstract, isHighest, componentTypeEnum, internalComponentType, vertexType);
1528                         if (listByVertexType.isRight()) {
1529                                 return listByVertexType;
1530                         }
1531                         result.addAll(listByVertexType.left().value());
1532                 }
1533                 return Either.left(result);
1534
1535         }
1536         
1537         public Either<List<Component>, StorageOperationStatus> getLatestComponentListByUuid(String componentUuid) {
1538                 Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
1539                 propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
1540                 return getComponentListByUuid(componentUuid, propertiesToMatch);
1541         }
1542         
1543         public Either<List<Component>, StorageOperationStatus> getComponentListByUuid(String componentUuid, Map<GraphPropertyEnum, Object> additionalPropertiesToMatch) {
1544                 
1545                 Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
1546                 
1547                 if(additionalPropertiesToMatch != null){
1548                         propertiesToMatch.putAll(additionalPropertiesToMatch);
1549                 }
1550                 
1551                 propertiesToMatch.put(GraphPropertyEnum.UUID, componentUuid);
1552
1553                 Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
1554                 propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
1555
1556                 Either<List<GraphVertex>, TitanOperationStatus> vertexEither = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
1557
1558                 if (vertexEither.isRight()) {
1559                         log.debug("Couldn't fetch metadata for component with type {} and uuid {}, error: {}", componentUuid, vertexEither.right().value());
1560                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(vertexEither.right().value()));
1561                 }
1562                 List<GraphVertex> vertexList = vertexEither.isLeft() ? vertexEither.left().value() : null;
1563
1564                 if (vertexList == null || vertexList.isEmpty()) {
1565                         log.debug("Component with uuid {} was not found", componentUuid);
1566                         return Either.right(StorageOperationStatus.NOT_FOUND);
1567                 }
1568
1569                 List<Component> latestComponents = new ArrayList<Component>();
1570                 for (GraphVertex vertex : vertexList) {
1571                         latestComponents.add(getToscaElementByOperation(vertex).left().value());
1572                 }
1573
1574                 return Either.left(latestComponents);
1575         }
1576
1577         public Either<Component, StorageOperationStatus> getLatestComponentByUuid(String componentUuid) {
1578
1579                 Either<List<Component>, StorageOperationStatus> latestVersionListEither = getLatestComponentListByUuid(componentUuid);
1580
1581                 if (latestVersionListEither.isRight()) {
1582                         return Either.right(latestVersionListEither.right().value());
1583                 }
1584
1585                 List<Component> latestVersionList = latestVersionListEither.left().value();
1586
1587                 if (latestVersionList.isEmpty()) {
1588                         return Either.right(StorageOperationStatus.NOT_FOUND);
1589                 }
1590                 Component component = latestVersionList.size() == 1 ? latestVersionList.get(0) : latestVersionList.stream().max((c1, c2) -> Double.compare(Double.parseDouble(c1.getVersion()), Double.parseDouble(c2.getVersion()))).get();
1591
1592                 return Either.left(component);
1593         }
1594
1595         public Either<List<Resource>, StorageOperationStatus> getAllCertifiedResources(boolean isAbstract, Boolean isHighest) {
1596
1597                 List<Resource> resources = new ArrayList<>();
1598                 Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
1599                 Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
1600
1601                 propertiesToMatch.put(GraphPropertyEnum.IS_ABSTRACT, isAbstract);
1602                 if (isHighest != null) {
1603                         propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, isHighest.booleanValue());
1604                 }
1605                 propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
1606                 propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
1607                 propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
1608
1609                 Either<List<GraphVertex>, TitanOperationStatus> getResourcesRes = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
1610
1611                 if (getResourcesRes.isRight()) {
1612                         log.debug("Failed to fetch all certified resources. Status is {}", getResourcesRes.right().value());
1613                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getResourcesRes.right().value()));
1614                 }
1615                 List<GraphVertex> resourceVerticies = getResourcesRes.left().value();
1616                 for (GraphVertex resourceV : resourceVerticies) {
1617                         Either<Resource, StorageOperationStatus> getResourceRes = getToscaElement(resourceV);
1618                         if (getResourceRes.isRight()) {
1619                                 return Either.right(getResourceRes.right().value());
1620                         }
1621                         resources.add(getResourceRes.left().value());
1622                 }
1623                 return Either.left(resources);
1624         }
1625
1626         public <T extends Component> Either<T, StorageOperationStatus> getLatestByNameAndVersion(String name, String version, JsonParseFlagEnum parseFlag) {
1627                 Either<T, StorageOperationStatus> result;
1628
1629                 Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
1630                 Map<GraphPropertyEnum, Object> hasNotProperties = new EnumMap<>(GraphPropertyEnum.class);
1631
1632                 hasProperties.put(GraphPropertyEnum.NAME, name);
1633                 hasProperties.put(GraphPropertyEnum.VERSION, version);
1634                 hasProperties.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
1635
1636                 hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true);
1637
1638                 Either<List<GraphVertex>, TitanOperationStatus> getResourceRes = titanDao.getByCriteria(null, hasProperties, hasNotProperties, parseFlag);
1639                 if (getResourceRes.isRight()) {
1640                         TitanOperationStatus status = getResourceRes.right().value();
1641                         log.debug("failed to find resource with name {}, version {}. Status is {} ", name, version, status);
1642                         result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1643                         return result;
1644                 }
1645                 return getToscaElementByOperation(getResourceRes.left().value().get(0));
1646         }
1647
1648         public Either<Resource, StorageOperationStatus> getLatestComponentByCsarOrName(ComponentTypeEnum componentType, String csarUUID, String systemName) {
1649                 return getLatestComponentByCsarOrName(componentType, csarUUID, systemName, false, JsonParseFlagEnum.ParseAll);
1650         }
1651
1652         public Either<Resource, StorageOperationStatus> getLatestComponentByCsarOrName(ComponentTypeEnum componentType, String csarUUID, String systemName, boolean allowDeleted, JsonParseFlagEnum parseFlag) {
1653                 Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
1654                 props.put(GraphPropertyEnum.CSAR_UUID, csarUUID);
1655                 props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
1656                 if (componentType != null) {
1657                         props.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
1658                 }
1659                 Map<GraphPropertyEnum, Object> propsHasNot = new EnumMap<>(GraphPropertyEnum.class);
1660                 propsHasNot.put(GraphPropertyEnum.IS_DELETED, true);
1661
1662                 GraphVertex resourceMetadataData = null;
1663                 List<GraphVertex> resourceMetadataDataList = null;
1664                 Either<List<GraphVertex>, TitanOperationStatus> byCsar = titanDao.getByCriteria(null, props, propsHasNot, JsonParseFlagEnum.ParseMetadata);
1665                 if (byCsar.isRight()) {
1666                         if (TitanOperationStatus.NOT_FOUND == byCsar.right().value()) {
1667                                 // Fix Defect DE256036
1668                                 if (StringUtils.isEmpty(systemName)) {
1669                                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(TitanOperationStatus.NOT_FOUND));
1670                                 }
1671
1672                                 props.clear();
1673                                 props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
1674                                 props.put(GraphPropertyEnum.SYSTEM_NAME, systemName);
1675                                 Either<List<GraphVertex>, TitanOperationStatus> bySystemname = titanDao.getByCriteria(null, props, JsonParseFlagEnum.ParseMetadata);
1676                                 if (bySystemname.isRight()) {
1677                                         log.debug("getLatestResourceByCsarOrName - Failed to find by system name {}  error {} ", systemName, bySystemname.right().value());
1678                                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(bySystemname.right().value()));
1679                                 }
1680                                 if (bySystemname.left().value().size() > 2) {
1681                                         log.debug("getLatestResourceByCsarOrName - getByCriteria(by system name) must return only 2 latest version, but was returned - {}", bySystemname.left().value().size());
1682                                         return Either.right(StorageOperationStatus.GENERAL_ERROR);
1683                                 }
1684                                 resourceMetadataDataList = bySystemname.left().value();
1685                                 if (resourceMetadataDataList.size() == 1) {
1686                                         resourceMetadataData = resourceMetadataDataList.get(0);
1687                                 } else {
1688                                         for (GraphVertex curResource : resourceMetadataDataList) {
1689                                                 if (!((String) curResource.getJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE)).equals("CERTIFIED")) {
1690                                                         resourceMetadataData = curResource;
1691                                                         break;
1692                                                 }
1693                                         }
1694                                 }
1695                                 if (resourceMetadataData == null) {
1696                                         log.debug("getLatestResourceByCsarOrName - getByCriteria(by system name) returned 2 latest CERTIFIED versions");
1697                                         return Either.right(StorageOperationStatus.GENERAL_ERROR);
1698                                 }
1699                                 if (resourceMetadataData.getJsonMetadataField(JsonPresentationFields.CSAR_UUID) != null && !((String) resourceMetadataData.getJsonMetadataField(JsonPresentationFields.CSAR_UUID)).equals(csarUUID)) {
1700                                         log.debug("getLatestResourceByCsarOrName - same system name {} but different csarUUID. exist {} and new {} ", systemName, resourceMetadataData.getJsonMetadataField(JsonPresentationFields.CSAR_UUID), csarUUID);
1701                                         // correct error will be returned from create flow. with all
1702                                         // correct audit records!!!!!
1703                                         return Either.right(StorageOperationStatus.NOT_FOUND);
1704                                 }
1705                                 Either<Resource, StorageOperationStatus> resource = getToscaElement((String) resourceMetadataData.getUniqueId());
1706                                 return resource;
1707                         }
1708                 } else {
1709                         resourceMetadataDataList = byCsar.left().value();
1710                         if (resourceMetadataDataList.size() > 2) {
1711                                 log.debug("getLatestResourceByCsarOrName - getByCriteria(by csar) must return only 2 latest version, but was returned - {}", byCsar.left().value().size());
1712                                 return Either.right(StorageOperationStatus.GENERAL_ERROR);
1713                         }
1714                         if (resourceMetadataDataList.size() == 1) {
1715                                 resourceMetadataData = resourceMetadataDataList.get(0);
1716                         } else {
1717                                 for (GraphVertex curResource : resourceMetadataDataList) {
1718                                         if (!((String) curResource.getJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE)).equals("CERTIFIED")) {
1719                                                 resourceMetadataData = curResource;
1720                                                 break;
1721                                         }
1722                                 }
1723                         }
1724                         if (resourceMetadataData == null) {
1725                                 log.debug("getLatestResourceByCsarOrName - getByCriteria(by csar) returned 2 latest CERTIFIED versions");
1726                                 return Either.right(StorageOperationStatus.GENERAL_ERROR);
1727                         }
1728                         Either<Resource, StorageOperationStatus> resource = getToscaElement((String) resourceMetadataData.getJsonMetadataField(JsonPresentationFields.UNIQUE_ID), parseFlag);
1729                         return resource;
1730                 }
1731                 return null;
1732         }
1733
1734         public Either<Boolean, StorageOperationStatus> validateToscaResourceNameExtends(String templateNameCurrent, String templateNameExtends) {
1735
1736                 String currentTemplateNameChecked = templateNameExtends;
1737
1738                 while (currentTemplateNameChecked != null && !currentTemplateNameChecked.equalsIgnoreCase(templateNameCurrent)) {
1739                         Either<Resource, StorageOperationStatus> latestByToscaResourceName = getLatestByToscaResourceName(currentTemplateNameChecked);
1740
1741                         if (latestByToscaResourceName.isRight()) {
1742                                 return latestByToscaResourceName.right().value() == StorageOperationStatus.NOT_FOUND ? Either.left(false) : Either.right(latestByToscaResourceName.right().value());
1743                         }
1744
1745                         Resource value = latestByToscaResourceName.left().value();
1746
1747                         if (value.getDerivedFrom() != null) {
1748                                 currentTemplateNameChecked = value.getDerivedFrom().get(0);
1749                         } else {
1750                                 currentTemplateNameChecked = null;
1751                         }
1752                 }
1753
1754                 return (currentTemplateNameChecked != null && currentTemplateNameChecked.equalsIgnoreCase(templateNameCurrent)) ? Either.left(true) : Either.left(false);
1755         }
1756
1757         public Either<List<Component>, StorageOperationStatus> fetchByResourceType(String resourceType) {
1758
1759                 Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
1760                 props.put(GraphPropertyEnum.RESOURCE_TYPE, resourceType);
1761                 props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
1762                 Either<List<GraphVertex>, TitanOperationStatus> resourcesByTypeEither = titanDao.getByCriteria(null, props);
1763
1764                 if (resourcesByTypeEither.isRight()) {
1765                         return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resourcesByTypeEither.right().value()));
1766                 }
1767
1768                 List<GraphVertex> vertexList = resourcesByTypeEither.left().value();
1769                 List<Component> components = new ArrayList<>();
1770
1771                 for (GraphVertex vertex : vertexList) {
1772                         components.add(getToscaElementByOperation(vertex).left().value());
1773                 }
1774
1775                 return Either.left(components);
1776
1777         }
1778
1779         public void commit() {
1780                 titanDao.commit();
1781         }
1782
1783         public Either<Service, StorageOperationStatus> updateDistributionStatus(Service service, User user, DistributionStatusEnum distributionStatus) {
1784                         Either<GraphVertex, StorageOperationStatus> updateDistributionStatus = topologyTemplateOperation.updateDistributionStatus(service.getUniqueId(), user, distributionStatus);
1785                         if ( updateDistributionStatus.isRight() ){
1786                                 return Either.right(updateDistributionStatus.right().value());
1787                         }
1788                         GraphVertex serviceV = updateDistributionStatus.left().value();
1789                         service.setDistributionStatus(distributionStatus);
1790                         service.setLastUpdateDate((Long) serviceV.getJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE));
1791                         return Either.left(service);
1792         }
1793
1794         public Either<ComponentMetadataData, StorageOperationStatus> updateComponentLastUpdateDateOnGraph(Component component, Long modificationTime) {
1795
1796                 Either<ComponentMetadataData, StorageOperationStatus> result = null;
1797                 GraphVertex serviceVertex;
1798                 Either<GraphVertex, TitanOperationStatus> updateRes = null;
1799                 Either<GraphVertex, TitanOperationStatus> getRes = titanDao.getVertexById(component.getUniqueId(), JsonParseFlagEnum.ParseMetadata);
1800                 if (getRes.isRight()) {
1801                         TitanOperationStatus status = getRes.right().value();
1802                         log.error("Failed to fetch component {}. status is {}", component.getUniqueId(), status);
1803                         result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1804                 }
1805                 if (result == null) {
1806                         serviceVertex = getRes.left().value();
1807                         long lastUpdateDate = System.currentTimeMillis();
1808                         serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1809                         component.setLastUpdateDate(lastUpdateDate);
1810                         updateRes = titanDao.updateVertex(serviceVertex);
1811                         if (updateRes.isRight()) {
1812                                 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateRes.right().value()));
1813                         }
1814                 }
1815                 if (result == null) {
1816                         result = Either.left(ModelConverter.convertToComponentMetadata(updateRes.left().value()));
1817                 }
1818                 return result;
1819         }
1820
1821         public TitanDao getTitanDao() {
1822                 return titanDao;
1823         }
1824         
1825         public Either<List<Service>, StorageOperationStatus> getCertifiedServicesWithDistStatus(Set<DistributionStatusEnum> distStatus) {
1826                 Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
1827                 propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
1828                 
1829                 return getServicesWithDistStatus(distStatus, propertiesToMatch);
1830         }
1831         
1832         public Either<List<Service>, StorageOperationStatus> getServicesWithDistStatus(Set<DistributionStatusEnum> distStatus, Map<GraphPropertyEnum, Object> additionalPropertiesToMatch) {
1833
1834                 List<Service> servicesAll = new ArrayList<>();
1835
1836                 Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
1837                 Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
1838                 
1839                 if(additionalPropertiesToMatch != null && !additionalPropertiesToMatch.isEmpty()) {
1840                         propertiesToMatch.putAll(additionalPropertiesToMatch);
1841                 }
1842                 
1843                 propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
1844
1845                 propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
1846
1847                 if (distStatus != null && !distStatus.isEmpty()) {
1848                         for (DistributionStatusEnum state : distStatus) {
1849                                 propertiesToMatch.put(GraphPropertyEnum.DISTRIBUTION_STATUS, state.name());
1850                                 Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria = fetchServicesByCriteria(servicesAll, propertiesToMatch, propertiesNotToMatch);
1851                                 if ( fetchServicesByCriteria.isRight() ){
1852                                         return fetchServicesByCriteria;
1853                                 }
1854                                 else{
1855                                         servicesAll = fetchServicesByCriteria.left().value();
1856                                 }
1857                         }
1858                         return Either.left(servicesAll);
1859                 } else {
1860                         return fetchServicesByCriteria(servicesAll, propertiesToMatch, propertiesNotToMatch);
1861                 }
1862         }
1863
1864         private Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria(List<Service> servicesAll, Map<GraphPropertyEnum, Object> propertiesToMatch, Map<GraphPropertyEnum, Object> propertiesNotToMatch) {
1865                 Either<List<GraphVertex>, TitanOperationStatus> getRes = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
1866                 if (getRes.isRight()) {
1867                         if (getRes.right().value() != TitanOperationStatus.NOT_FOUND) {
1868                                 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch certified services by match properties {} not match properties {} . Status is {}. ", propertiesToMatch, propertiesNotToMatch, getRes.right().value());
1869                                 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
1870                         }
1871                 } else {
1872                         for (GraphVertex vertex : getRes.left().value()) {
1873                                 Either<Component, StorageOperationStatus> getServiceRes = getToscaElementByOperation(vertex);
1874                                 if (getServiceRes.isRight()) {
1875                                         CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch certified service {}. Status is {}. ", vertex.getJsonMetadataField(JsonPresentationFields.NAME), getServiceRes.right().value());
1876                                         return Either.right(getServiceRes.right().value());
1877                                 } else {
1878                                         servicesAll.add((Service) getToscaElementByOperation(vertex).left().value());
1879                                 }
1880                         }
1881                 }
1882                 return Either.left(servicesAll);
1883         }
1884
1885         public void rollback() {
1886                 titanDao.rollback();
1887         }
1888
1889         public StorageOperationStatus addDeploymentArtifactsToInstance(String componentId, ComponentInstance componentInstance, Map<String, ArtifactDefinition> finalDeploymentArtifacts) {
1890                 Map<String, ArtifactDataDefinition> instDeplArtifacts = finalDeploymentArtifacts.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ArtifactDataDefinition(e.getValue())));
1891
1892                 return nodeTemplateOperation.addDeploymentArtifactsToInstance(componentId, componentInstance.getUniqueId(), instDeplArtifacts);
1893         }
1894
1895         public StorageOperationStatus generateCustomizationUUIDOnInstance(String componentId, String instanceId) {
1896                 return nodeTemplateOperation.generateCustomizationUUIDOnInstance(componentId, instanceId);
1897         }
1898
1899         public StorageOperationStatus generateCustomizationUUIDOnInstanceGroup(String componentId, String instanceId, List<String> groupInstances) {
1900                 return nodeTemplateOperation.generateCustomizationUUIDOnInstanceGroup(componentId, instanceId, groupInstances);
1901         }
1902
1903         public Either<PropertyDefinition, StorageOperationStatus> addPropertyToResource(String propertyName, PropertyDefinition newPropertyDefinition, Resource resource) {
1904
1905                 Either<PropertyDefinition, StorageOperationStatus> result = null;
1906                 Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
1907                 newPropertyDefinition.setName(propertyName);
1908                 newPropertyDefinition.setParentUniqueId(resource.getUniqueId());
1909                 StorageOperationStatus status = getToscaElementOperation(resource).addToscaDataToToscaElement(resource.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, newPropertyDefinition, JsonPresentationFields.NAME);
1910                 if (status != StorageOperationStatus.OK) {
1911                         CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the resource {}. Status is {}. ", propertyName, resource.getName(), status);
1912                         result = Either.right(status);
1913                 }
1914                 if (result == null) {
1915                         ComponentParametersView filter = new ComponentParametersView(true);
1916                         filter.setIgnoreProperties(false);
1917                         getUpdatedComponentRes = getToscaElement(resource.getUniqueId(), filter);
1918                         if (getUpdatedComponentRes.isRight()) {
1919                                 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", resource.getUniqueId(), getUpdatedComponentRes.right().value());
1920                                 result = Either.right(status);
1921                         }
1922                 }
1923                 if (result == null) {
1924                         PropertyDefinition newProperty = null;
1925                         List<PropertyDefinition> properties = ((Resource) getUpdatedComponentRes.left().value()).getProperties();
1926                         if (CollectionUtils.isNotEmpty(properties)) {
1927                                 Optional<PropertyDefinition> newPropertyOptional = properties.stream().filter(p -> p.getName().equals(propertyName)).findAny();
1928                                 if (newPropertyOptional.isPresent()) {
1929                                         newProperty = newPropertyOptional.get();
1930                                 }
1931                         }
1932                         if (newProperty == null) {
1933                                 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the resource {}. Status is {}. ", propertyName, resource.getUniqueId(), StorageOperationStatus.NOT_FOUND);
1934                                 result = Either.right(StorageOperationStatus.NOT_FOUND);
1935                         } else {
1936                                 result = Either.left(newProperty);
1937                         }
1938                 }
1939                 return result;
1940         }
1941
1942         public StorageOperationStatus deletePropertyOfResource(Resource resource, String propertyName) {
1943                 return getToscaElementOperation(resource).deleteToscaDataElement(resource.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, propertyName, JsonPresentationFields.NAME);
1944         }
1945         
1946         public StorageOperationStatus deleteAttributeOfResource(Component component, String attributeName) {
1947                 return getToscaElementOperation(component).deleteToscaDataElement(component.getUniqueId(), EdgeLabelEnum.ATTRIBUTES, VertexTypeEnum.ATTRIBUTES, attributeName, JsonPresentationFields.NAME);
1948         }
1949
1950         public StorageOperationStatus deleteInputOfResource(Component resource, String inputName) {
1951                 return getToscaElementOperation(resource).deleteToscaDataElement(resource.getUniqueId(), EdgeLabelEnum.INPUTS, VertexTypeEnum.INPUTS, inputName, JsonPresentationFields.NAME);
1952         }
1953
1954         public Either<PropertyDefinition, StorageOperationStatus> updatePropertyOfResource(Resource resource, PropertyDefinition newPropertyDefinition) {
1955
1956                 Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
1957                 Either<PropertyDefinition, StorageOperationStatus> result = null;
1958                 StorageOperationStatus status = getToscaElementOperation(resource).updateToscaDataOfToscaElement(resource.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, newPropertyDefinition, JsonPresentationFields.NAME);
1959                 if (status != StorageOperationStatus.OK) {
1960                         CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the resource {}. Status is {}. ", newPropertyDefinition.getName(), resource.getName(), status);
1961                         result = Either.right(status);
1962                 }
1963                 if (result == null) {
1964                         ComponentParametersView filter = new ComponentParametersView(true);
1965                         filter.setIgnoreProperties(false);
1966                         getUpdatedComponentRes = getToscaElement(resource.getUniqueId(), filter);
1967                         if (getUpdatedComponentRes.isRight()) {
1968                                 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", resource.getUniqueId(), getUpdatedComponentRes.right().value());
1969                                 result = Either.right(status);
1970                         }
1971                 }
1972                 if (result == null) {
1973                         Optional<PropertyDefinition> newProperty = ((Resource) getUpdatedComponentRes.left().value()).getProperties().stream().filter(p -> p.getName().equals(newPropertyDefinition.getName())).findAny();
1974                         if (newProperty.isPresent()) {
1975                                 result = Either.left(newProperty.get());
1976                         } else {
1977                                 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the resource {}. Status is {}. ", newPropertyDefinition.getName(), resource.getUniqueId(), StorageOperationStatus.NOT_FOUND);
1978                                 result = Either.right(StorageOperationStatus.NOT_FOUND);
1979                         }
1980                 }
1981                 return result;
1982         }
1983         
1984         public Either<AttributeDefinition, StorageOperationStatus> addAttributeOfResource(Component component, AttributeDefinition newAttributeDef) {
1985
1986                 Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
1987                 Either<AttributeDefinition, StorageOperationStatus> result = null;
1988                 if(newAttributeDef.getUniqueId() == null || newAttributeDef.getUniqueId().isEmpty()){
1989                         String attUniqueId = UniqueIdBuilder.buildAttributeUid(component.getUniqueId(), newAttributeDef.getName());
1990                         newAttributeDef.setUniqueId(attUniqueId);
1991                 }
1992                 
1993                 StorageOperationStatus status = getToscaElementOperation(component).addToscaDataToToscaElement(component.getUniqueId(), EdgeLabelEnum.ATTRIBUTES, VertexTypeEnum.ATTRIBUTES, newAttributeDef, JsonPresentationFields.NAME);
1994                 if (status != StorageOperationStatus.OK) {
1995                         CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the resource {}. Status is {}. ", newAttributeDef.getName(), component.getName(), status);
1996                         result = Either.right(status);
1997                 }
1998                 if (result == null) {
1999                         ComponentParametersView filter = new ComponentParametersView(true);
2000                         filter.setIgnoreAttributesFrom(false);
2001                         getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter);
2002                         if (getUpdatedComponentRes.isRight()) {
2003                                 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value());
2004                                 result = Either.right(status);
2005                         }
2006                 }
2007                 if (result == null) {
2008                         Optional<AttributeDefinition> newAttribute = ((Resource) getUpdatedComponentRes.left().value()).getAttributes().stream().filter(p -> p.getName().equals(newAttributeDef.getName())).findAny();
2009                         if (newAttribute.isPresent()) {
2010                                 result = Either.left(newAttribute.get());
2011                         } else {
2012                                 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the resource {}. Status is {}. ", newAttributeDef.getName(), component.getUniqueId(), StorageOperationStatus.NOT_FOUND);
2013                                 result = Either.right(StorageOperationStatus.NOT_FOUND);
2014                         }
2015                 }
2016                 return result;
2017         }
2018         
2019         public Either<AttributeDefinition, StorageOperationStatus> updateAttributeOfResource(Component component, AttributeDefinition newAttributeDef) {
2020
2021                 Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
2022                 Either<AttributeDefinition, StorageOperationStatus> result = null;
2023                 StorageOperationStatus status = getToscaElementOperation(component).updateToscaDataOfToscaElement(component.getUniqueId(), EdgeLabelEnum.ATTRIBUTES, VertexTypeEnum.ATTRIBUTES, newAttributeDef, JsonPresentationFields.NAME);
2024                 if (status != StorageOperationStatus.OK) {
2025                         CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the resource {}. Status is {}. ", newAttributeDef.getName(), component.getName(), status);
2026                         result = Either.right(status);
2027                 }
2028                 if (result == null) {
2029                         ComponentParametersView filter = new ComponentParametersView(true);
2030                         filter.setIgnoreAttributesFrom(false);
2031                         getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter);
2032                         if (getUpdatedComponentRes.isRight()) {
2033                                 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value());
2034                                 result = Either.right(status);
2035                         }
2036                 }
2037                 if (result == null) {
2038                         Optional<AttributeDefinition> newProperty = ((Resource) getUpdatedComponentRes.left().value()).getAttributes().stream().filter(p -> p.getName().equals(newAttributeDef.getName())).findAny();
2039                         if (newProperty.isPresent()) {
2040                                 result = Either.left(newProperty.get());
2041                         } else {
2042                                 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the resource {}. Status is {}. ", newAttributeDef.getName(), component.getUniqueId(), StorageOperationStatus.NOT_FOUND);
2043                                 result = Either.right(StorageOperationStatus.NOT_FOUND);
2044                         }
2045                 }
2046                 return result;
2047         }
2048         
2049         public Either<InputDefinition, StorageOperationStatus> updateInputOfComponent(Component component, InputDefinition newInputDefinition) {
2050
2051                 Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
2052                 Either<InputDefinition, StorageOperationStatus> result = null;
2053                 StorageOperationStatus status = getToscaElementOperation(component).updateToscaDataOfToscaElement(component.getUniqueId(), EdgeLabelEnum.INPUTS, VertexTypeEnum.INPUTS, newInputDefinition, JsonPresentationFields.NAME);
2054                 if (status != StorageOperationStatus.OK) {
2055                         CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the input {} to the component {}. Status is {}. ", newInputDefinition.getName(), component.getName(), status);
2056                         result = Either.right(status);
2057                 }
2058                 if (result == null) {
2059                         ComponentParametersView filter = new ComponentParametersView(true);
2060                         filter.setIgnoreInputs(false);
2061                         getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter);
2062                         if (getUpdatedComponentRes.isRight()) {
2063                                 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value());
2064                                 result = Either.right(status);
2065                         }
2066                 }
2067                 if (result == null) {
2068                         Optional<InputDefinition> updatedInput = getUpdatedComponentRes.left().value().getInputs().stream().filter(p -> p.getName().equals(newInputDefinition.getName())).findAny();
2069                         if (updatedInput.isPresent()) {
2070                                 result = Either.left(updatedInput.get());
2071                         } else {
2072                                 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently updated inputs {} on the resource {}. Status is {}. ", newInputDefinition.getName(), component.getUniqueId(), StorageOperationStatus.NOT_FOUND);
2073                                 result = Either.right(StorageOperationStatus.NOT_FOUND);
2074                         }
2075                 }
2076                 return result;
2077         }
2078
2079         public StorageOperationStatus addGroupInstancesToComponentInstance(Component containerComponent, ComponentInstance componentInstance, List<GroupDefinition> groups, Map<String, List<ArtifactDefinition>> groupInstancesArtifacts) {
2080                 return nodeTemplateOperation.addGroupInstancesToComponentInstance(containerComponent, componentInstance, groups, groupInstancesArtifacts);
2081         }
2082
2083         public Either<List<GroupDefinition>, StorageOperationStatus> updateGroupsOnComponent(Component component, ComponentTypeEnum componentType, List<GroupDataDefinition> updatedGroups) {
2084                 return groupsOperation.updateGroups(component, componentType, updatedGroups);
2085         }
2086
2087         public Either<List<GroupInstance>, StorageOperationStatus> updateGroupInstancesOnComponent(Component component, ComponentTypeEnum componentType, String instanceId, List<GroupInstance> updatedGroupInstances) {
2088                 return groupsOperation.updateGroupInstances(component, componentType, instanceId, updatedGroupInstances);
2089         }
2090
2091         public StorageOperationStatus addGroupInstancesToComponentInstance(Component containerComponent, ComponentInstance componentInstance, List<GroupInstance> groupInstances) {
2092                 return nodeTemplateOperation.addGroupInstancesToComponentInstance(containerComponent, componentInstance, groupInstances);
2093         }
2094
2095         public StorageOperationStatus addDeploymentArtifactsToComponentInstance(Component containerComponent, ComponentInstance componentInstance, Map<String, ArtifactDefinition> deploymentArtifacts) {
2096                 return nodeTemplateOperation.addDeploymentArtifactsToComponentInstance(containerComponent, componentInstance, deploymentArtifacts);
2097         }
2098
2099         public StorageOperationStatus updateComponentInstanceProperty(Component containerComponent, String componentInstanceId, ComponentInstanceProperty property) {
2100                 return nodeTemplateOperation.updateComponentInstanceProperty(containerComponent, componentInstanceId, property);
2101         }
2102
2103         public StorageOperationStatus addComponentInstanceProperty(Component containerComponent, String componentInstanceId, ComponentInstanceProperty property) {
2104                 return nodeTemplateOperation.addComponentInstanceProperty(containerComponent, componentInstanceId, property);
2105         }
2106         
2107         public StorageOperationStatus updateComponentInstanceInput(Component containerComponent, String componentInstanceId, ComponentInstanceInput property) {
2108                 return nodeTemplateOperation.updateComponentInstanceInput(containerComponent, componentInstanceId, property);
2109         }
2110
2111         public StorageOperationStatus addComponentInstanceInput(Component containerComponent, String componentInstanceId, ComponentInstanceInput property) {
2112                 return nodeTemplateOperation.addComponentInstanceInput(containerComponent, componentInstanceId, property);
2113         }
2114
2115         public void setNodeTypeOperation(NodeTypeOperation nodeTypeOperation) {
2116                 this.nodeTypeOperation = nodeTypeOperation;
2117         }
2118
2119         public void setTopologyTemplateOperation(TopologyTemplateOperation topologyTemplateOperation) {
2120                 this.topologyTemplateOperation = topologyTemplateOperation;
2121         }
2122
2123 }