2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 
   6  * ================================================================================
 
   7  * Licensed under the Apache License, Version 2.0 (the "License");
 
   8  * you may not use this file except in compliance with the License.
 
   9  * You may obtain a copy of the License at
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  13  * Unless required by applicable law or agreed to in writing, software
 
  14  * distributed under the License is distributed on an "AS IS" BASIS,
 
  15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  16  * See the License for the specific language governing permissions and
 
  17  * limitations under the License.
 
  18  * ============LICENSE_END=========================================================
 
  21 package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
 
  23 import com.google.gson.reflect.TypeToken;
 
  24 import fj.data.Either;
 
  25 import java.lang.reflect.Type;
 
  27 import java.util.Map.Entry;
 
  28 import java.util.function.BiFunction;
 
  29 import java.util.stream.Collectors;
 
  30 import org.apache.commons.collections.MapUtils;
 
  31 import org.apache.tinkerpop.gremlin.structure.Direction;
 
  32 import org.apache.tinkerpop.gremlin.structure.Edge;
 
  33 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
 
  34 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
 
  35 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
 
  36 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
 
  37 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
 
  38 import org.openecomp.sdc.be.datatypes.category.MetadataKeyDataDefinition;
 
  39 import org.openecomp.sdc.be.datatypes.elements.MapAttributesDataDefinition;
 
  40 import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
 
  41 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
 
  42 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
 
  43 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
 
  44 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
 
  45 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
 
  46 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
 
  47 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
 
  48 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
 
  49 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
 
  50 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
 
  51 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
 
  52 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
 
  53 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
 
  54 import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
 
  55 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
 
  56 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
 
  57 import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
 
  58 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
 
  59 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
 
  60 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
 
  61 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
 
  62 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
 
  63 import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
 
  64 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
 
  65 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
 
  66 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
 
  67 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
 
  68 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
 
  69 import org.openecomp.sdc.be.model.Component;
 
  70 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
 
  71 import org.openecomp.sdc.be.model.ComponentParametersView;
 
  72 import org.openecomp.sdc.be.model.DistributionStatusEnum;
 
  73 import org.openecomp.sdc.be.model.GroupDefinition;
 
  74 import org.openecomp.sdc.be.model.PolicyDefinition;
 
  75 import org.openecomp.sdc.be.model.User;
 
  76 import org.openecomp.sdc.be.model.category.CategoryDefinition;
 
  77 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
 
  78 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
 
  79 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
 
  80 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.CapabilityRequirementNameResolver;
 
  81 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
 
  82 import org.openecomp.sdc.be.model.operations.StorageException;
 
  83 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
 
  84 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
 
  85 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
 
  86 import org.openecomp.sdc.common.api.Constants;
 
  87 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
 
  88 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
 
  89 import org.openecomp.sdc.common.log.wrappers.Logger;
 
  90 import org.openecomp.sdc.common.util.ValidationUtils;
 
  91 import org.springframework.beans.factory.annotation.Autowired;
 
  94 @org.springframework.stereotype.Component("topology-template-operation")
 
  95 public class TopologyTemplateOperation extends ToscaElementOperation {
 
  97     private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
 
 100     private ArchiveOperation archiveOperation;
 
 102     public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
 
 103         topologyTemplate.generateUUID();
 
 105         topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
 
 106         String resourceUniqueId = topologyTemplate.getUniqueId();
 
 107         if (resourceUniqueId == null) {
 
 108             resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
 
 109             topologyTemplate.setUniqueId(resourceUniqueId);
 
 112         GraphVertex topologyTemplateVertex = new GraphVertex();
 
 113         topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
 
 115         Either<GraphVertex, JanusGraphOperationStatus> createdVertex = janusGraphDao.createVertex(topologyTemplateVertex);
 
 116         if (createdVertex.isRight()) {
 
 117             JanusGraphOperationStatus status = createdVertex.right().value();
 
 118             log.debug( "Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
 
 119             return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 122         StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate);
 
 123         if (assosiateCommon != StorageOperationStatus.OK) {
 
 124             return Either.right(assosiateCommon);
 
 127         StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
 
 128         if (associateCategory != StorageOperationStatus.OK) {
 
 129             return Either.right(associateCategory);
 
 132         StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
 
 133         if (associateInputs != StorageOperationStatus.OK) {
 
 134             return Either.right(associateInputs);
 
 136         StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
 
 137         if (associateGroups != StorageOperationStatus.OK) {
 
 138             return Either.right(associateGroups);
 
 140         StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
 
 141         if (associatePolicies != StorageOperationStatus.OK) {
 
 142             return Either.right(associatePolicies);
 
 144         StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
 
 145         if (associateInstAttr != StorageOperationStatus.OK) {
 
 146             return Either.right(associateInstAttr);
 
 148         StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
 
 149         if (associateInstProperties != StorageOperationStatus.OK) {
 
 150             return Either.right(associateInstProperties);
 
 152         StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
 
 153         if (associateInstProperties != StorageOperationStatus.OK) {
 
 154             return Either.right(associateInstInputs);
 
 156         StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
 
 157         if (associateInstGroups != StorageOperationStatus.OK) {
 
 158             return Either.right(associateInstInputs);
 
 161         StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
 
 162         if (associateRequirements != StorageOperationStatus.OK) {
 
 163             return Either.right(associateRequirements);
 
 166         StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
 
 167         if (associateCapabilities != StorageOperationStatus.OK) {
 
 168             return Either.right(associateCapabilities);
 
 171         StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
 
 172         if (associateArtifacts != StorageOperationStatus.OK) {
 
 173             return Either.right(associateArtifacts);
 
 176         StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
 
 177         if (addAdditionalInformation != StorageOperationStatus.OK) {
 
 178             return Either.right(addAdditionalInformation);
 
 180         StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
 
 181         if (associateCapProperties != StorageOperationStatus.OK) {
 
 182             return Either.right(associateCapProperties);
 
 185         StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
 
 186         if (associateInterfaces != StorageOperationStatus.OK) {
 
 187             return Either.right(associateInterfaces);
 
 190         StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
 
 191         if (associateCapProperties != StorageOperationStatus.OK) {
 
 192             return Either.right(associatePathProperties);
 
 194         return Either.left(topologyTemplate);
 
 197     private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 198         return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
 
 201     private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex,    Map<String, PolicyDataDefinition> policies) {
 
 202         if (policies != null && !policies.isEmpty()) {
 
 203             policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
 
 204                 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
 
 207             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
 
 208             if (assosiateElementToData.isRight()) {
 
 209                 return assosiateElementToData.right().value();
 
 212         return StorageOperationStatus.OK;
 
 215     private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
 
 216         Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
 
 217         return associateForwardingPathToComponent(topologyTemplateVertex,forwardingPaths);
 
 220     private StorageOperationStatus associateNodeFilterToResource(GraphVertex topologyTemplateVertex,
 
 221             TopologyTemplate topologyTemplate) {
 
 222         Map<String, CINodeFilterDataDefinition> nodeFilters =
 
 223                 topologyTemplate.getNodeFilterComponents();
 
 224         return associateNodeFiltersToComponent(topologyTemplateVertex, nodeFilters);
 
 227     private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
 
 228         Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate
 
 229                 .getCalculatedCapabilitiesProperties();
 
 230         if (MapUtils.isNotEmpty(calculatedCapProperties)) {
 
 231             Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData
 
 232                     (topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
 
 233                             EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
 
 234             if (associateElementToData.isRight()) {
 
 235                 return associateElementToData.right().value();
 
 239         Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties();
 
 240         if (MapUtils.isNotEmpty(capabilitiesProperties)) {
 
 241             Either<GraphVertex, StorageOperationStatus> associateElementToData =
 
 242                     associateElementToData(topologyTemplateVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES,
 
 243                             EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties);
 
 244             if (associateElementToData.isRight()) {
 
 245                 return associateElementToData.right().value();
 
 248         return StorageOperationStatus.OK;
 
 251     private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 252         Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
 
 253         if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
 
 254             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
 
 255             if (assosiateElementToData.isRight()) {
 
 256                 return assosiateElementToData.right().value();
 
 259         Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
 
 260         if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
 
 261             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
 
 262             if (assosiateElementToData.isRight()) {
 
 263                 return assosiateElementToData.right().value();
 
 266         Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
 
 267         if(MapUtils.isNotEmpty(capabilities)) {
 
 268             Either<GraphVertex, StorageOperationStatus> associateElementToData =
 
 269                     associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
 
 270                             EdgeLabelEnum.CAPABILITIES, capabilities);
 
 271             if (associateElementToData.isRight()) {
 
 272                 return associateElementToData.right().value();
 
 275         return StorageOperationStatus.OK;
 
 279     private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 280         Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
 
 281         if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
 
 282             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
 
 283             if (assosiateElementToData.isRight()) {
 
 284                 return assosiateElementToData.right().value();
 
 287         Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
 
 288         if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
 
 289             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
 
 290             if (assosiateElementToData.isRight()) {
 
 291                 return assosiateElementToData.right().value();
 
 294         Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
 
 295         if(MapUtils.isNotEmpty(requirements)) {
 
 296             Either<GraphVertex, StorageOperationStatus> associateElementToData =
 
 297                     associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
 
 298                             EdgeLabelEnum.REQUIREMENTS, requirements);
 
 299             if (associateElementToData.isRight()) {
 
 300                 return associateElementToData.right().value();
 
 303         return StorageOperationStatus.OK;
 
 306     private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 307         Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
 
 309         if (addInformation != null && !addInformation.isEmpty()) {
 
 310             addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
 
 311                 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
 
 312                 a.setUniqueId(uniqueId);
 
 314             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
 
 315             if (assosiateElementToData.isRight()) {
 
 316                 return assosiateElementToData.right().value();
 
 319         Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
 
 321         if (instArtifacts != null && !instArtifacts.isEmpty()) {
 
 322             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
 
 323             if (assosiateElementToData.isRight()) {
 
 324                 return assosiateElementToData.right().value();
 
 327         Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
 
 329         if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
 
 330             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
 
 331             if (assosiateElementToData.isRight()) {
 
 332                 return assosiateElementToData.right().value();
 
 335         Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
 
 336         if(MapUtils.isNotEmpty(requirements)) {
 
 337             Either<GraphVertex, StorageOperationStatus> associateElementToData =
 
 338                     associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
 
 339                             EdgeLabelEnum.REQUIREMENTS, requirements);
 
 340             if (associateElementToData.isRight()) {
 
 341                 return associateElementToData.right().value();
 
 344         return StorageOperationStatus.OK;
 
 347     private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 349         Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
 
 351         if (addInformation != null && !addInformation.isEmpty()) {
 
 352             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
 
 353             if (assosiateElementToData.isRight()) {
 
 354                 return assosiateElementToData.right().value();
 
 357         return StorageOperationStatus.OK;
 
 360     public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 361         Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
 
 362         return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
 
 365     public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 366         Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
 
 367         return associateInstInputsToComponent(nodeTypeVertex, instProps);
 
 370     public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 371         Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
 
 372         return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
 
 376     public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
 
 377         if (instProps != null && !instProps.isEmpty()) {
 
 378             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
 
 379             if (assosiateElementToData.isRight()) {
 
 380                 return assosiateElementToData.right().value();
 
 383         return StorageOperationStatus.OK;
 
 386     public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
 
 387         if (instInputs != null && !instInputs.isEmpty()) {
 
 388             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
 
 389             if (assosiateElementToData.isRight()) {
 
 390                 return assosiateElementToData.right().value();
 
 393         return StorageOperationStatus.OK;
 
 396     public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
 
 397         if (instGroups != null && !instGroups.isEmpty()) {
 
 398             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
 
 399             if (assosiateElementToData.isRight()) {
 
 400                 return assosiateElementToData.right().value();
 
 403         return StorageOperationStatus.OK;
 
 407     public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
 
 409         if (instInputs != null && !instInputs.isEmpty()) {
 
 410             instInputs.entrySet().forEach(i -> {
 
 411                 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
 
 412                 List<String> pathKeys = new ArrayList<>();
 
 413                 pathKeys.add(i.getKey());
 
 415                 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
 
 416                 if (status != StorageOperationStatus.OK) {
 
 422         return StorageOperationStatus.OK;
 
 425     public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
 
 427         if (instInputs != null && !instInputs.isEmpty()) {
 
 428             instInputs.entrySet().forEach(i -> {
 
 429                 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
 
 430                 if (status != StorageOperationStatus.OK) {
 
 436         return StorageOperationStatus.OK;
 
 439     public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
 
 440         return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
 
 443     public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
 
 444         return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
 
 447     private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
 
 448         if (instProps != null && !instProps.isEmpty()) {
 
 449             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
 
 450             if (assosiateElementToData.isRight()) {
 
 451                 return assosiateElementToData.right().value();
 
 454         return StorageOperationStatus.OK;
 
 457     public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabilityDataDefinition> calcCapabilty, Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
 
 458         if (!MapUtils.isEmpty(calcRequirements)) {
 
 459             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
 
 460             if (assosiateElementToData.isRight()) {
 
 461                 return assosiateElementToData.right().value();
 
 463             Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
 
 464             assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
 
 465             if (assosiateElementToData.isRight()) {
 
 466                 return assosiateElementToData.right().value();
 
 469         if (!MapUtils.isEmpty(calcCapabilty)) {
 
 470             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES ,EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
 
 471             if (assosiateElementToData.isRight()) {
 
 472                 return assosiateElementToData.right().value();
 
 474             Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
 
 475             assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
 
 476             if (assosiateElementToData.isRight()) {
 
 477                 return assosiateElementToData.right().value();
 
 480         if (!MapUtils.isEmpty(calculatedCapabilitiesProperties)){
 
 481             return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
 
 482                     EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
 
 484                     .on(v -> StorageOperationStatus.OK);
 
 486         return StorageOperationStatus.OK;
 
 489     private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap){
 
 490         return janusGraphDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
 
 491                 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
 
 492                         status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
 
 495     private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(JanusGraphOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
 
 496         if (status == JanusGraphOperationStatus.NOT_FOUND) {
 
 497             return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
 
 499         return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 502     private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
 
 503         Optional<StorageOperationStatus> error = dataMap.entrySet()
 
 505                 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
 
 506                 .filter(s -> s != StorageOperationStatus.OK)
 
 508         if(error.isPresent()){
 
 509             return Either.right(error.get());
 
 511         return Either.left(dataVertex);
 
 514     private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 515         Map<String, MapAttributesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
 
 516         return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
 
 519     public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
 
 520         if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
 
 521             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
 
 522             if (assosiateElementToData.isRight()) {
 
 523                 return assosiateElementToData.right().value();
 
 526         return StorageOperationStatus.OK;
 
 529     public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapAttributesDataDefinition> instAttr) {
 
 530         if (instAttr != null && !instAttr.isEmpty()) {
 
 531             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
 
 532             if (assosiateElementToData.isRight()) {
 
 533                 return assosiateElementToData.right().value();
 
 536         return StorageOperationStatus.OK;
 
 539     public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
 
 541         if (groups != null && !groups.isEmpty()) {
 
 542             groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
 
 543                 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
 
 546             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
 
 547             if (assosiateElementToData.isRight()) {
 
 548                 return assosiateElementToData.right().value();
 
 551         return StorageOperationStatus.OK;
 
 554     private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 555         return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
 
 558     public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 559         Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
 
 560         return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
 
 563     public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
 
 564         if (inputs != null && !inputs.isEmpty()) {
 
 565             inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
 
 567             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
 
 568             if (assosiateElementToData.isRight()) {
 
 569                 return assosiateElementToData.right().value();
 
 572         return StorageOperationStatus.OK;
 
 575     private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
 
 576         nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
 
 577         fillCommonMetadata(nodeTypeVertex, topologyTemplate);
 
 578         if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
 
 579             nodeTypeVertex.setJson(topologyTemplate.getCompositions());
 
 581         nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
 
 582         nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
 
 584         return nodeTypeVertex;
 
 588     private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 589         if (topologyTemplate.getResourceType() == null) {
 
 591             return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
 
 594             return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
 
 598     private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 599         String categoryName = topologyTemplate.getCategories().get(0).getName();
 
 600         Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
 
 601         if (category.isRight()) {
 
 602             log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
 
 603             return StorageOperationStatus.CATEGORY_NOT_FOUND;
 
 605         GraphVertex categoryV = category.left().value();
 
 606         JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
 
 607         if (createEdge != JanusGraphOperationStatus.OK) {
 
 608             log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
 
 609             return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge);
 
 611         return StorageOperationStatus.OK;
 
 615     public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
 
 616         JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
 
 618         Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag);
 
 619         if (componentByLabelAndId.isRight()) {
 
 620             return Either.right(componentByLabelAndId.right().value());
 
 622         GraphVertex componentV = componentByLabelAndId.left().value();
 
 624         return getToscaElement(componentV, componentParametersView);
 
 627     // -------------------------------------------------------------
 
 629     public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
 
 630         TopologyTemplate toscaElement;
 
 632         toscaElement = convertToTopologyTemplate(componentV);
 
 633         JanusGraphOperationStatus status;
 
 634         if (!componentParametersView.isIgnoreUsers()) {
 
 635             status = setCreatorFromGraph(componentV, toscaElement);
 
 636             if (status != JanusGraphOperationStatus.OK) {
 
 637                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 640             status = setLastModifierFromGraph(componentV, toscaElement);
 
 641             if (status != JanusGraphOperationStatus.OK) {
 
 642                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 645         if (!componentParametersView.isIgnoreCategories()) {
 
 646             status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
 
 647             if (status != JanusGraphOperationStatus.OK) {
 
 648                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 652         if (!componentParametersView.isIgnoreArtifacts()) {
 
 653             JanusGraphOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
 
 654             if (storageStatus != JanusGraphOperationStatus.OK) {
 
 655                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
 
 658         if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
 
 659             status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
 
 660             if (status != JanusGraphOperationStatus.OK) {
 
 661                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 664         if (!componentParametersView.isIgnoreCapabilities()) {
 
 665             status = setCapabilitiesFromGraph(componentV, toscaElement);
 
 666             if (status != JanusGraphOperationStatus.OK) {
 
 667                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 670         if (!componentParametersView.isIgnoreRequirements()) {
 
 671             status = setRequirementsFromGraph(componentV, toscaElement);
 
 672             if (status != JanusGraphOperationStatus.OK) {
 
 673                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 676         if (!componentParametersView.isIgnoreAllVersions()) {
 
 677             status = setAllVersions(componentV, toscaElement);
 
 678             if (status != JanusGraphOperationStatus.OK) {
 
 679                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 682         if (!componentParametersView.isIgnoreAdditionalInformation()) {
 
 683             status = setAdditionalInformationFromGraph(componentV, toscaElement);
 
 684             if (status != JanusGraphOperationStatus.OK) {
 
 685                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 689         if (!componentParametersView.isIgnoreGroups()) {
 
 690             status = setGroupsFromGraph(componentV, toscaElement);
 
 691             if (status != JanusGraphOperationStatus.OK) {
 
 692                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 696         if (!componentParametersView.isIgnorePolicies()) {
 
 697             status = setPoliciesFromGraph(componentV, toscaElement);
 
 698             if (status != JanusGraphOperationStatus.OK) {
 
 699                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 703         if (!componentParametersView.isIgnoreComponentInstances()) {
 
 704             status = setInstGroupsFromGraph(componentV, toscaElement);
 
 706             //Mark all CIs that has archived origins
 
 707             archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
 
 709             if (status != JanusGraphOperationStatus.OK) {
 
 710                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 714         if (!componentParametersView.isIgnoreInputs()) {
 
 715             status = setInputsFromGraph(componentV, toscaElement);
 
 716             if (status != JanusGraphOperationStatus.OK) {
 
 717                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 721         if (!componentParametersView.isIgnoreProperties()) {
 
 722             status = setPropertiesFromGraph(componentV, toscaElement);
 
 723             if (status != JanusGraphOperationStatus.OK) {
 
 724                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 729         if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
 
 730             status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
 
 731             if (status != JanusGraphOperationStatus.OK) {
 
 732                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 737         if (!componentParametersView.isIgnoreCapabiltyProperties()) {
 
 738             status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
 
 739             if (status != JanusGraphOperationStatus.OK) {
 
 740                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 745         if (!componentParametersView.isIgnoreForwardingPath()) {
 
 746             status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
 
 747             if (status != JanusGraphOperationStatus.OK) {
 
 748                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 753         if (!componentParametersView.isIgnoreNodeFilter()) {
 
 754             status = setNodeFilterComponentFromGraph(componentV, toscaElement);
 
 755             if (status != JanusGraphOperationStatus.OK) {
 
 756                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 761         if (!componentParametersView.isIgnoreSubstitutionFilter()) {
 
 762             status = setSubstitutionFilterComponentFromGraph(componentV, toscaElement);
 
 763             if (status != JanusGraphOperationStatus.OK) {
 
 764                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 769         if (!componentParametersView.isIgnoreInterfaces()) {
 
 770             JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
 
 771             if (storageStatus != JanusGraphOperationStatus.OK) {
 
 772                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
 
 777         if (!componentParametersView.isIgnoreInterfaces()) {
 
 778             JanusGraphOperationStatus storageStatus = setInterfcesFromGraph(componentV, toscaElement);
 
 779             if (storageStatus != JanusGraphOperationStatus.OK) {
 
 780                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
 
 785         if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
 
 786             JanusGraphOperationStatus storageStatus =
 
 787                     setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
 
 788             if (storageStatus != JanusGraphOperationStatus.OK) {
 
 789                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
 
 793         if (!componentParametersView.isIgnoreDataType()) {
 
 794             JanusGraphOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
 
 795             if (storageStatus != JanusGraphOperationStatus.OK) {
 
 796                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
 
 800         return Either.left(toscaElement);
 
 803     private JanusGraphOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
 
 804         Either<Map<String, DataTypeDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
 
 805         if (result.isLeft()) {
 
 806             toscaElement.setDataTypes(result.left().value());
 
 808             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 809                 return result.right().value();
 
 812         return JanusGraphOperationStatus.OK;
 
 815     private JanusGraphOperationStatus setInterfcesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 816         Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
 
 817         if (result.isLeft()) {
 
 818             topologyTemplate.setInterfaces(result.left().value());
 
 820             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 821                 return result.right().value();
 
 824         return JanusGraphOperationStatus.OK;
 
 827     private JanusGraphOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
 
 828         Either<Map<String, PolicyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
 
 829         if (result.isLeft()) {
 
 830             toscaElement.setPolicies(result.left().value());
 
 832             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 833                 return result.right().value();
 
 836         return JanusGraphOperationStatus.OK;
 
 839     private JanusGraphOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 840         Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
 
 841         if (result.isLeft()) {
 
 842             topologyTemplate.setInterfaces(result.left().value());
 
 844             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 845                 return result.right().value();
 
 848         return JanusGraphOperationStatus.OK;
 
 852     private JanusGraphOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV,
 
 853                                                                           TopologyTemplate topologyTemplate) {
 
 854         Either<Map<String, MapInterfaceDataDefinition>, JanusGraphOperationStatus> result =
 
 855                 getDataFromGraph(componentV, EdgeLabelEnum.INST_INTERFACES);
 
 856         if (result.isLeft()) {
 
 857             result.left().value().entrySet().forEach(entry -> topologyTemplate
 
 858                     .addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
 
 860             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 861                 return result.right().value();
 
 864         return JanusGraphOperationStatus.OK;
 
 867     private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
 
 868         Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
 
 869         if (interfaceMap != null && !interfaceMap.isEmpty()) {
 
 870             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
 
 871             if (assosiateElementToData.isRight()) {
 
 872                 return assosiateElementToData.right().value();
 
 875         return StorageOperationStatus.OK;
 
 878     public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex,
 
 879             Map<String, CINodeFilterDataDefinition> filterMaps) {
 
 880         if (filterMaps != null && !filterMaps.isEmpty()) {
 
 881             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData
 
 882                                                                                          (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
 
 883                                                                                                  EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
 
 884             if (assosiateElementToData.isRight()) {
 
 885                 return assosiateElementToData.right().value();
 
 888         return StorageOperationStatus.OK;
 
 891     private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 892         Either<Map<String, ForwardingPathDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
 
 893         if (result.isLeft()) {
 
 894             topologyTemplate.setForwardingPaths(result.left().value());
 
 896             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 897                 return result.right().value();
 
 900         return JanusGraphOperationStatus.OK;
 
 904     private JanusGraphOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 905         Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
 
 906         if (result.isLeft()) {
 
 907             topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
 
 909             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 910                 return result.right().value();
 
 913         Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> capPropResult =
 
 914                 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
 
 915         if (capPropResult.isLeft()) {
 
 916             topologyTemplate.setCapabilitiesProperties(capPropResult.left().value());
 
 918             if (capPropResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 919                 return capPropResult.right().value();
 
 923         return JanusGraphOperationStatus.OK;
 
 926     private JanusGraphOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
 
 927         Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
 
 928         if (result.isLeft()) {
 
 929             toscaElement.setProperties(result.left().value());
 
 931             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 932                 return result.right().value();
 
 935         return JanusGraphOperationStatus.OK;
 
 938     private JanusGraphOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 939         Either<Map<String, MapGroupsDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
 
 940         if (result.isLeft()) {
 
 941             topologyTemplate.setInstGroups(result.left().value());
 
 943             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 944                 return result.right().value();
 
 947         return JanusGraphOperationStatus.OK;
 
 950     private JanusGraphOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 951         Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
 
 952         if (result.isLeft()) {
 
 953             topologyTemplate.setInstProperties(result.left().value());
 
 955             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 956                 return result.right().value();
 
 959         return JanusGraphOperationStatus.OK;
 
 962     private JanusGraphOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 963         Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
 
 964         if (result.isLeft()) {
 
 965             topologyTemplate.setInstInputs(result.left().value());
 
 967             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 968                 return result.right().value();
 
 971         return JanusGraphOperationStatus.OK;
 
 974     private JanusGraphOperationStatus setNodeFilterComponentFromGraph(final GraphVertex componentV,
 
 975                                                                       final TopologyTemplate topologyTemplate) {
 
 977         final Either<Map<String, CINodeFilterDataDefinition>, JanusGraphOperationStatus> result =
 
 978             getDataFromGraph(componentV, EdgeLabelEnum.NODE_FILTER_TEMPLATE);
 
 979         if (result.isLeft()) {
 
 980             topologyTemplate.setNodeFilterComponents(result.left().value());
 
 982             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 983                 return result.right().value();
 
 986         return JanusGraphOperationStatus.OK;
 
 989     private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV,
 
 990                                                                               final TopologyTemplate topologyTemplate) {
 
 992         final Either<Map<String, SubstitutionFilterDataDefinition>, JanusGraphOperationStatus> result =
 
 993             getDataFromGraph(componentV, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE);
 
 994         if (result.isLeft()) {
 
 995             topologyTemplate.setSubstitutionFilterDataDefinitionMap(result.left().value());
 
 997             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 998                 return result.right().value();
 
1001         return JanusGraphOperationStatus.OK;
 
1006     protected <T extends ToscaElement> JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
 
1007         Either<Map<String, MapListRequirementDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
 
1008         if (result.isLeft()) {
 
1009             ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
 
1011             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1012                 return result.right().value();
 
1015         result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
 
1016         if (result.isLeft()) {
 
1017             ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
 
1019             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1020                 return result.right().value();
 
1023         Either<Map<String, ListRequirementDataDefinition>, JanusGraphOperationStatus> requirementResult =
 
1024                 getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS);
 
1025         if (requirementResult.isLeft()) {
 
1026             toscaElement.setRequirements(requirementResult.left().value());
 
1028             if (requirementResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1029                 return requirementResult.right().value();
 
1032         return JanusGraphOperationStatus.OK;
 
1036     protected <T extends ToscaElement> JanusGraphOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
 
1037         Either<Map<String, MapListCapabilityDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
 
1038         if (result.isLeft()) {
 
1039             ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
 
1041             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1042                 return result.right().value();
 
1045         result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
 
1046         if (result.isLeft()) {
 
1047             ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
 
1049             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1050                 return result.right().value();
 
1053         Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
 
1054                 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
 
1055         if (capabilitiesResult.isLeft()) {
 
1056             toscaElement.setCapabilities(capabilitiesResult.left().value());
 
1058             if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1059                 return capabilitiesResult.right().value();
 
1062         return JanusGraphOperationStatus.OK;
 
1065     private JanusGraphOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
 
1066         JanusGraphOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
 
1067         if (storageStatus != JanusGraphOperationStatus.OK) {
 
1068             return storageStatus;
 
1070         Either<Map<String, ArtifactDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
 
1071         if (result.isLeft()) {
 
1072             toscaElement.setServiceApiArtifacts(result.left().value());
 
1074             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1075                 return result.right().value();
 
1078         Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
 
1079         if (resultInstArt.isLeft()) {
 
1080             toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
 
1082             if (resultInstArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1083                 return resultInstArt.right().value();
 
1086         Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
 
1087         if (instanceArt.isLeft()) {
 
1088             toscaElement.setInstanceArtifacts(instanceArt.left().value());
 
1090             if (instanceArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1091                 return instanceArt.right().value();
 
1094         return JanusGraphOperationStatus.OK;
 
1097     private JanusGraphOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
 
1098         Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
 
1099         if (result.isLeft()) {
 
1100             toscaElement.setInputs(result.left().value());
 
1102             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1103                 return result.right().value();
 
1106         Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
 
1107                 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
 
1108         if (capabilitiesResult.isLeft()) {
 
1109             toscaElement.setCapabilities(capabilitiesResult.left().value());
 
1111             if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1112                 return capabilitiesResult.right().value();
 
1115         return JanusGraphOperationStatus.OK;
 
1118     private JanusGraphOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
 
1119         Either<Map<String, GroupDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
 
1120         if (result.isLeft()) {
 
1121             toscaElement.setGroups(result.left().value());
 
1123             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1124                 return result.right().value();
 
1127         return JanusGraphOperationStatus.OK;
 
1130     private JanusGraphOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
 
1131         List<CategoryDefinition> categories = new ArrayList<>();
 
1133         switch (componentV.getType()) {
 
1135             return setResourceCategoryFromGraph(componentV, toscaElement);
 
1137             return setServiceCategoryFromGraph(componentV, toscaElement, categories);
 
1140             log.debug("Not supported component type {} ", componentV.getType());
 
1143         return JanusGraphOperationStatus.OK;
 
1146     private JanusGraphOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
 
1147         Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
 
1148         if (childVertex.isRight()) {
 
1149             log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
 
1150             return childVertex.right().value();
 
1152         GraphVertex categoryV = childVertex.left().value();
 
1153         Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
 
1154         CategoryDefinition category = new CategoryDefinition();
 
1155         category.setUniqueId(categoryV.getUniqueId());
 
1156         category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
 
1157         category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
 
1158         final Boolean useServiceSubstitutionForNestedServices = (Boolean)metadataProperties.get(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES);
 
1159         category.setUseServiceSubstitutionForNestedServices(useServiceSubstitutionForNestedServices == null ? false : useServiceSubstitutionForNestedServices);
 
1161         Type listTypeCat = new TypeToken<List<String>>() {}.getType();
 
1162         List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
 
1163         category.setIcons(iconsfromJsonCat);
 
1165         final Type metadataKeysTypeCat = new TypeToken<List<MetadataKeyDataDefinition>>() {}.getType();
 
1166         final List<MetadataKeyDataDefinition> metadataKeysfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.METADATA_KEYS), metadataKeysTypeCat);
 
1167         category.setMetadataKeys(metadataKeysfromJsonCat);
 
1169         categories.add(category);
 
1170         toscaElement.setCategories(categories);
 
1172         return JanusGraphOperationStatus.OK;
 
1175     @SuppressWarnings("unchecked")
 
1176     private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
 
1178         TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
 
1180         Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
 
1181         topologyTemplate.setCompositions(json);
 
1183         return topologyTemplate;
 
1187     public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
 
1188         Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
 
1189         if (nodeType.isRight()) {
 
1190             log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
 
1193         JanusGraphOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
 
1194         if (status != JanusGraphOperationStatus.OK) {
 
1195             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1197         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
 
1198         if (status != JanusGraphOperationStatus.OK) {
 
1199             log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1200             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1202         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
 
1203         if (status != JanusGraphOperationStatus.OK) {
 
1204             log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1205             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1208         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
 
1209         if (status != JanusGraphOperationStatus.OK) {
 
1210             log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1211             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1214         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
 
1215         if (status != JanusGraphOperationStatus.OK) {
 
1216             log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1217             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1219         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
 
1220         if (status != JanusGraphOperationStatus.OK) {
 
1221             log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1222             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1224         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
 
1225         if (status != JanusGraphOperationStatus.OK) {
 
1226             log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1227             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1229         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
 
1230         if (status != JanusGraphOperationStatus.OK) {
 
1231             log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1232             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1234         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
 
1235         if (status != JanusGraphOperationStatus.OK) {
 
1236             log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1237             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1239         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
 
1240         if (status != JanusGraphOperationStatus.OK) {
 
1241             log.debug("Failed to disassociate capabilities properties for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1242             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1244         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
 
1245         if (status != JanusGraphOperationStatus.OK) {
 
1246             log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1247             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1249         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
 
1250         if (status != JanusGraphOperationStatus.OK) {
 
1251             log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1252             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1254         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
 
1255         if (status != JanusGraphOperationStatus.OK) {
 
1256             log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1257             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1259         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
 
1260         if (status != JanusGraphOperationStatus.OK) {
 
1261             log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1262             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1264         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
 
1265         if (status != JanusGraphOperationStatus.OK) {
 
1266             log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1267             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1269         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
 
1270         if (status != JanusGraphOperationStatus.OK) {
 
1271             log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1272             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1274         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
 
1275         if (status != JanusGraphOperationStatus.OK) {
 
1276             log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1277             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1279         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
 
1280         if (status != JanusGraphOperationStatus.OK) {
 
1281             log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1282             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1284         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
 
1285         if (status != JanusGraphOperationStatus.OK) {
 
1286             log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1287             return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1289         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
 
1290         if (status != JanusGraphOperationStatus.OK) {
 
1291             log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1292             return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1295         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
 
1296                 EdgeLabelEnum.REQUIREMENTS);
 
1297         if (status != JanusGraphOperationStatus.OK) {
 
1298             log.debug("Failed to disassociate requirements for {} error {}",
 
1299                     toscaElementVertex.getUniqueId(), status);
 
1300             return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1302         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
 
1303                 EdgeLabelEnum.CAPABILITIES);
 
1304         if (status != JanusGraphOperationStatus.OK) {
 
1305             log.debug("Failed to disassociate capabilities for {} error {}",
 
1306                     toscaElementVertex.getUniqueId(), status);
 
1307             return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1309         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
 
1310         if (status != JanusGraphOperationStatus.OK) {
 
1311             log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1312             return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1314         toscaElementVertex.getVertex().remove();
 
1315         log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
 
1320     @SuppressWarnings("unchecked")
 
1322     public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
 
1323         return createTopologyTemplate((TopologyTemplate) toscaElement);
 
1327     protected <T extends ToscaElement> JanusGraphOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
 
1328         return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
 
1332     protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
 
1333         // Product isn't supported now!!
 
1334         // TODO add for Product
 
1335         if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
 
1336             return validateServiceCategory(toscaElementToUpdate, elementV);
 
1339             return validateResourceCategory(toscaElementToUpdate, elementV);
 
1344     protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
 
1345         // not relevant now for topology template
 
1346         return StorageOperationStatus.OK;
 
1350     public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
 
1351         fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
 
1354     private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
 
1355         StorageOperationStatus status = StorageOperationStatus.OK;
 
1356         List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
 
1357         CategoryDefinition newCategory = newCategoryList.get(0);
 
1359         Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
 
1360         if (childVertex.isRight()) {
 
1361             log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
 
1362             return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childVertex.right().value());
 
1365         GraphVertex categoryV = childVertex.left().value();
 
1366         Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
 
1367         String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
 
1369         String newCategoryName = newCategory.getName();
 
1370         if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
 
1371             // the category was changed
 
1372             Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
 
1374             if (getCategoryVertex.isRight()) {
 
1375                 return getCategoryVertex.right().value();
 
1377             GraphVertex newCategoryV = getCategoryVertex.left().value();
 
1378             status = moveCategoryEdge(elementV, newCategoryV);
 
1379             log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
 
1384     public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
 
1386         Either<GraphVertex, StorageOperationStatus> result = null;
 
1387         String userId = user.getUserId();
 
1388         Either<GraphVertex, JanusGraphOperationStatus> getRes = findUserVertex(userId);
 
1389         GraphVertex userVertex = null;
 
1390         GraphVertex serviceVertex = null;
 
1391         if (getRes.isRight()) {
 
1392             JanusGraphOperationStatus status = getRes.right().value();
 
1393             CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
 
1394             result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1396         if (result == null) {
 
1397             userVertex = getRes.left().value();
 
1398             getRes = janusGraphDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
 
1399             if (getRes.isRight()) {
 
1400                 JanusGraphOperationStatus status = getRes.right().value();
 
1401                 log.debug( "Cannot find service {} in the graph. status is {}", uniqueId, status);
 
1402                 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1405         if (result == null) {
 
1406             serviceVertex = getRes.left().value();
 
1407             Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
 
1408             if (edgeIterator.hasNext()) {
 
1409                 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
 
1410                 edgeIterator.next().remove();
 
1413         if (result == null) {
 
1414             JanusGraphOperationStatus status = janusGraphDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
 
1415             if (status != JanusGraphOperationStatus.OK) {
 
1416                 log.debug( "Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
 
1417                 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1420         if (result == null) {
 
1421             serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
 
1422             long lastUpdateDate = System.currentTimeMillis();
 
1423             serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
 
1424             Either<GraphVertex, JanusGraphOperationStatus> updateRes = janusGraphDao.updateVertex(serviceVertex);
 
1425             if (updateRes.isRight()) {
 
1426                 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateRes.right().value()));
 
1429         if (result == null) {
 
1430             result = Either.left(serviceVertex);
 
1435      * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
 
1436      * @param componentId
 
1438      * @param capabilityName
 
1439      * @param capabilityType
 
1443     public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
 
1445         Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
 
1446         Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
 
1447         Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
 
1448         if (componentByLabelAndId.isRight()) {
 
1449             result = Either.right(componentByLabelAndId.right().value());
 
1451         if(componentByLabelAndId.isLeft()){
 
1452             Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
 
1453             if (getDataRes.isRight()) {
 
1454                 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getDataRes.right().value()));
 
1456                 mapPropertiesDataDefinition = getDataRes.left().value();
 
1459         if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){
 
1460             result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
 
1465     public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) {
 
1466         return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
 
1469     public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent,
 
1470                                                                     String componentInstanceId,
 
1471                                                                     MapInterfaceDataDefinition instanceInterfaces) {
 
1472         if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
 
1473             return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(),
 
1474                     EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId);
 
1476         return StorageOperationStatus.OK;
 
1480     private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
 
1481         return  MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
 
1482                 instanceId != null &&
 
1483                 mapPropertiesDataDefinition.get(instanceId) != null &&
 
1484                 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
 
1487     private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
 
1488         List<ComponentInstanceProperty> capPropsList = null;
 
1489         for(Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()){
 
1490             if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
 
1491                 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
 
1492                 if (capMap != null && !capMap.isEmpty()) {
 
1493                     capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
 
1498         if(capPropsList == null){
 
1499             capPropsList = new ArrayList<>();
 
1501         return capPropsList;
 
1504     private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
 
1505         if (capProp != null) {
 
1506             String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM );
 
1507             if (path.length < 4) {
 
1508                 log.debug("wrong key format for capabilty, key {}", capProp);
 
1511             return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
 
1516     public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
 
1517         fillPolicyDefinition(componentV, policyDefinition, counter);
 
1518         return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
 
1521     public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
 
1522         return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
 
1525     public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
 
1526         return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
 
1529     public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
 
1530         return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
 
1533     public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
 
1534         return  deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
 
1537     public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
 
1538         return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.CI_INVARIANT_NAME);
 
1541     private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
 
1542         String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
 
1543         policyDefinition.setName(policyName);
 
1544         policyDefinition.setInvariantName(policyName);
 
1545         policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
 
1546         policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
 
1547         policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
 
1548         policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
 
1551     public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
 
1552         String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
 
1553         String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
 
1554         return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
 
1557     void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
 
1558         if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
 
1559             GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
 
1561                     .on(this::throwStorageException);
 
1562             if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
 
1563                 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
 
1565             if(MapUtils.isNotEmpty(toscaElement.getGroups())){
 
1566                 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
 
1568             topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES,  toscaElement.getCalculatedCapabilities());
 
1569             topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS,  toscaElement.getCalculatedRequirements());
 
1570             topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,  toscaElement.getCalculatedCapabilitiesProperties());
 
1574     public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
 
1575         if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
 
1576             GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
 
1578                     .on(this::throwStorageException);
 
1579             if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
 
1580                 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
 
1582             if(MapUtils.isNotEmpty(toscaElement.getGroups())){
 
1583                 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
 
1585             topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES,  toscaElement.getCalculatedCapabilities());
 
1586             topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS,  toscaElement.getCalculatedRequirements());
 
1587             topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,  toscaElement.getCalculatedCapabilitiesProperties());
 
1591     private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
 
1592         log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
 
1593         ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
 
1594         Either<ToscaElement, StorageOperationStatus> getOriginRes;
 
1595         if(elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE){
 
1596             getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
 
1599             getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
 
1601         if(getOriginRes.isRight()){
 
1602             log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
 
1603             throw new StorageException(getOriginRes.right().value());
 
1605         return getOriginRes.left().value();
 
1608     private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
 
1609         log.debug("#detectToscaType - type: {}", originType);
 
1610         if(originType == OriginTypeEnum.VFC
 
1611                 || originType == OriginTypeEnum.CP
 
1612                 || originType == OriginTypeEnum.VL
 
1613                 || originType == OriginTypeEnum.Configuration
 
1614                 || originType == OriginTypeEnum.VFCMT){
 
1615             return ToscaElementTypeEnum.NODE_TYPE;
 
1617             return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
 
1621     private ComponentParametersView getFilter() {
 
1622         ComponentParametersView filter = new ComponentParametersView();
 
1623         filter.setIgnoreCapabilities(false);
 
1624         filter.setIgnoreCapabiltyProperties(false);
 
1625         filter.setIgnoreRequirements(false);
 
1628     public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) {
 
1629         GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
 
1630                 .left().on(this::throwStorageException);
 
1631         updateCapOwnerId(toscaElement, componentId);
 
1632         updateReqOwnerId(toscaElement, componentId);
 
1633         updatePropertiesOwnerId(toscaElement, componentId);
 
1634         topologyTemplateOperation
 
1636                 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES,
 
1637                         VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
 
1638         topologyTemplateOperation
 
1639                 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS,
 
1640                         VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
 
1641         topologyTemplateOperation
 
1642                 .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES,
 
1643                         VertexTypeEnum.PROPERTIES, toscaElement.getProperties());
 
1646     private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
 
1647         if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
 
1648             toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
 
1649                     .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
 
1653     private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
 
1654         if(MapUtils.isNotEmpty(toscaElement.getRequirements())) {
 
1655             toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
 
1656                     .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));
 
1660     private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) {
 
1661         Map<String, PropertyDataDefinition> properties = toscaElement.getProperties();
 
1662         if(MapUtils.isNotEmpty(properties)) {
 
1663             properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId));