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