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.stream.Collectors;
 
  29 import org.apache.commons.collections.MapUtils;
 
  30 import org.apache.tinkerpop.gremlin.structure.Direction;
 
  31 import org.apache.tinkerpop.gremlin.structure.Edge;
 
  32 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
 
  33 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
 
  34 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
 
  35 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
 
  36 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
 
  37 import org.openecomp.sdc.be.datatypes.category.MetadataKeyDataDefinition;
 
  38 import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
 
  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.MapDataDefinition;
 
  55 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
 
  56 import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
 
  57 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
 
  58 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
 
  59 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
 
  60 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
 
  61 import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
 
  62 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
 
  63 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
 
  64 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
 
  65 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
 
  66 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
 
  67 import org.openecomp.sdc.be.model.Component;
 
  68 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
 
  69 import org.openecomp.sdc.be.model.ComponentParametersView;
 
  70 import org.openecomp.sdc.be.model.DistributionStatusEnum;
 
  71 import org.openecomp.sdc.be.model.GroupDefinition;
 
  72 import org.openecomp.sdc.be.model.PolicyDefinition;
 
  73 import org.openecomp.sdc.be.model.User;
 
  74 import org.openecomp.sdc.be.model.category.CategoryDefinition;
 
  75 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
 
  76 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
 
  77 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
 
  78 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.CapabilityRequirementNameResolver;
 
  79 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
 
  80 import org.openecomp.sdc.be.model.operations.StorageException;
 
  81 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
 
  82 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
 
  83 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
 
  84 import org.openecomp.sdc.common.api.Constants;
 
  85 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
 
  86 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
 
  87 import org.openecomp.sdc.common.log.wrappers.Logger;
 
  88 import org.openecomp.sdc.common.util.ValidationUtils;
 
  89 import org.springframework.beans.factory.annotation.Autowired;
 
  92 @org.springframework.stereotype.Component("topology-template-operation")
 
  93 public class TopologyTemplateOperation extends ToscaElementOperation {
 
  95     private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
 
  98     private ArchiveOperation archiveOperation;
 
 100     public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
 
 101         topologyTemplate.generateUUID();
 
 103         topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
 
 104         String resourceUniqueId = topologyTemplate.getUniqueId();
 
 105         if (resourceUniqueId == null) {
 
 106             resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
 
 107             topologyTemplate.setUniqueId(resourceUniqueId);
 
 110         GraphVertex topologyTemplateVertex = new GraphVertex();
 
 111         topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
 
 113         Either<GraphVertex, JanusGraphOperationStatus> createdVertex = janusGraphDao.createVertex(topologyTemplateVertex);
 
 114         if (createdVertex.isRight()) {
 
 115             JanusGraphOperationStatus status = createdVertex.right().value();
 
 116             log.debug( "Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
 
 117             return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 120         StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate);
 
 121         if (assosiateCommon != StorageOperationStatus.OK) {
 
 122             return Either.right(assosiateCommon);
 
 125         StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
 
 126         if (associateCategory != StorageOperationStatus.OK) {
 
 127             return Either.right(associateCategory);
 
 130         StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
 
 131         if (associateInputs != StorageOperationStatus.OK) {
 
 132             return Either.right(associateInputs);
 
 134         StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
 
 135         if (associateGroups != StorageOperationStatus.OK) {
 
 136             return Either.right(associateGroups);
 
 138         StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
 
 139         if (associatePolicies != StorageOperationStatus.OK) {
 
 140             return Either.right(associatePolicies);
 
 142         StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
 
 143         if (associateInstAttr != StorageOperationStatus.OK) {
 
 144             return Either.right(associateInstAttr);
 
 146         StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
 
 147         if (associateInstProperties != StorageOperationStatus.OK) {
 
 148             return Either.right(associateInstProperties);
 
 150         StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
 
 151         if (associateInstProperties != StorageOperationStatus.OK) {
 
 152             return Either.right(associateInstInputs);
 
 154         StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
 
 155         if (associateInstGroups != StorageOperationStatus.OK) {
 
 156             return Either.right(associateInstInputs);
 
 159         StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
 
 160         if (associateRequirements != StorageOperationStatus.OK) {
 
 161             return Either.right(associateRequirements);
 
 164         StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
 
 165         if (associateCapabilities != StorageOperationStatus.OK) {
 
 166             return Either.right(associateCapabilities);
 
 169         StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
 
 170         if (associateArtifacts != StorageOperationStatus.OK) {
 
 171             return Either.right(associateArtifacts);
 
 174         StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
 
 175         if (addAdditionalInformation != StorageOperationStatus.OK) {
 
 176             return Either.right(addAdditionalInformation);
 
 178         StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
 
 179         if (associateCapProperties != StorageOperationStatus.OK) {
 
 180             return Either.right(associateCapProperties);
 
 183         StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
 
 184         if (associateInterfaces != StorageOperationStatus.OK) {
 
 185             return Either.right(associateInterfaces);
 
 188         StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
 
 189         if (associateCapProperties != StorageOperationStatus.OK) {
 
 190             return Either.right(associatePathProperties);
 
 192         return Either.left(topologyTemplate);
 
 195     private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 196         return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
 
 199     private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex,    Map<String, PolicyDataDefinition> policies) {
 
 200         if (policies != null && !policies.isEmpty()) {
 
 201             policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
 
 202                 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
 
 205             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
 
 206             if (assosiateElementToData.isRight()) {
 
 207                 return assosiateElementToData.right().value();
 
 210         return StorageOperationStatus.OK;
 
 213     private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
 
 214         Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
 
 215         return associateForwardingPathToComponent(topologyTemplateVertex,forwardingPaths);
 
 218     private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
 
 219         Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate
 
 220                 .getCalculatedCapabilitiesProperties();
 
 221         if (MapUtils.isNotEmpty(calculatedCapProperties)) {
 
 222             Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData
 
 223                     (topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
 
 224                             EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
 
 225             if (associateElementToData.isRight()) {
 
 226                 return associateElementToData.right().value();
 
 230         Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties();
 
 231         if (MapUtils.isNotEmpty(capabilitiesProperties)) {
 
 232             Either<GraphVertex, StorageOperationStatus> associateElementToData =
 
 233                     associateElementToData(topologyTemplateVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES,
 
 234                             EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties);
 
 235             if (associateElementToData.isRight()) {
 
 236                 return associateElementToData.right().value();
 
 239         return StorageOperationStatus.OK;
 
 242     private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 243         Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
 
 244         if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
 
 245             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
 
 246             if (assosiateElementToData.isRight()) {
 
 247                 return assosiateElementToData.right().value();
 
 250         Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
 
 251         if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
 
 252             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
 
 253             if (assosiateElementToData.isRight()) {
 
 254                 return assosiateElementToData.right().value();
 
 257         Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
 
 258         if(MapUtils.isNotEmpty(capabilities)) {
 
 259             Either<GraphVertex, StorageOperationStatus> associateElementToData =
 
 260                     associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
 
 261                             EdgeLabelEnum.CAPABILITIES, capabilities);
 
 262             if (associateElementToData.isRight()) {
 
 263                 return associateElementToData.right().value();
 
 266         return StorageOperationStatus.OK;
 
 270     private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 271         Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
 
 272         if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
 
 273             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
 
 274             if (assosiateElementToData.isRight()) {
 
 275                 return assosiateElementToData.right().value();
 
 278         Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
 
 279         if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
 
 280             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
 
 281             if (assosiateElementToData.isRight()) {
 
 282                 return assosiateElementToData.right().value();
 
 285         Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
 
 286         if(MapUtils.isNotEmpty(requirements)) {
 
 287             Either<GraphVertex, StorageOperationStatus> associateElementToData =
 
 288                     associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
 
 289                             EdgeLabelEnum.REQUIREMENTS, requirements);
 
 290             if (associateElementToData.isRight()) {
 
 291                 return associateElementToData.right().value();
 
 294         return StorageOperationStatus.OK;
 
 297     private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 298         Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
 
 300         if (addInformation != null && !addInformation.isEmpty()) {
 
 301             addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
 
 302                 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
 
 303                 a.setUniqueId(uniqueId);
 
 305             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
 
 306             if (assosiateElementToData.isRight()) {
 
 307                 return assosiateElementToData.right().value();
 
 310         Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
 
 312         if (instArtifacts != null && !instArtifacts.isEmpty()) {
 
 313             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
 
 314             if (assosiateElementToData.isRight()) {
 
 315                 return assosiateElementToData.right().value();
 
 318         Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
 
 320         if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
 
 321             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
 
 322             if (assosiateElementToData.isRight()) {
 
 323                 return assosiateElementToData.right().value();
 
 326         Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
 
 327         if(MapUtils.isNotEmpty(requirements)) {
 
 328             Either<GraphVertex, StorageOperationStatus> associateElementToData =
 
 329                     associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
 
 330                             EdgeLabelEnum.REQUIREMENTS, requirements);
 
 331             if (associateElementToData.isRight()) {
 
 332                 return associateElementToData.right().value();
 
 335         return StorageOperationStatus.OK;
 
 338     private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 340         Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
 
 342         if (addInformation != null && !addInformation.isEmpty()) {
 
 343             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
 
 344             if (assosiateElementToData.isRight()) {
 
 345                 return assosiateElementToData.right().value();
 
 348         return StorageOperationStatus.OK;
 
 351     public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 352         Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
 
 353         return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
 
 356     public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 357         Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
 
 358         return associateInstInputsToComponent(nodeTypeVertex, instProps);
 
 361     public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 362         Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
 
 363         return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
 
 367     public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
 
 368         if (instProps != null && !instProps.isEmpty()) {
 
 369             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
 
 370             if (assosiateElementToData.isRight()) {
 
 371                 return assosiateElementToData.right().value();
 
 374         return StorageOperationStatus.OK;
 
 377     public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
 
 378         if (instInputs != null && !instInputs.isEmpty()) {
 
 379             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
 
 380             if (assosiateElementToData.isRight()) {
 
 381                 return assosiateElementToData.right().value();
 
 384         return StorageOperationStatus.OK;
 
 387     public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
 
 388         if (instGroups != null && !instGroups.isEmpty()) {
 
 389             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
 
 390             if (assosiateElementToData.isRight()) {
 
 391                 return assosiateElementToData.right().value();
 
 394         return StorageOperationStatus.OK;
 
 398     public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
 
 400         if (instInputs != null && !instInputs.isEmpty()) {
 
 401             instInputs.entrySet().forEach(i -> {
 
 402                 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
 
 403                 List<String> pathKeys = new ArrayList<>();
 
 404                 pathKeys.add(i.getKey());
 
 406                 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
 
 407                 if (status != StorageOperationStatus.OK) {
 
 413         return StorageOperationStatus.OK;
 
 416     public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
 
 418         if (instInputs != null && !instInputs.isEmpty()) {
 
 419             instInputs.entrySet().forEach(i -> {
 
 420                 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
 
 421                 if (status != StorageOperationStatus.OK) {
 
 427         return StorageOperationStatus.OK;
 
 430     public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
 
 431         return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
 
 434     public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
 
 435         return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
 
 438     private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
 
 439         if (instProps != null && !instProps.isEmpty()) {
 
 440             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
 
 441             if (assosiateElementToData.isRight()) {
 
 442                 return assosiateElementToData.right().value();
 
 445         return StorageOperationStatus.OK;
 
 448     public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabilityDataDefinition> calcCapabilty, Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
 
 449         if (!MapUtils.isEmpty(calcRequirements)) {
 
 450             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
 
 451             if (assosiateElementToData.isRight()) {
 
 452                 return assosiateElementToData.right().value();
 
 454             Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
 
 455             assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
 
 456             if (assosiateElementToData.isRight()) {
 
 457                 return assosiateElementToData.right().value();
 
 460         if (!MapUtils.isEmpty(calcCapabilty)) {
 
 461             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES ,EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
 
 462             if (assosiateElementToData.isRight()) {
 
 463                 return assosiateElementToData.right().value();
 
 465             Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
 
 466             assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
 
 467             if (assosiateElementToData.isRight()) {
 
 468                 return assosiateElementToData.right().value();
 
 471         if (!MapUtils.isEmpty(calculatedCapabilitiesProperties)){
 
 472             return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
 
 473                     EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
 
 475                     .on(v -> StorageOperationStatus.OK);
 
 477         return StorageOperationStatus.OK;
 
 480     private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap){
 
 481         return janusGraphDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
 
 482                 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
 
 483                         status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
 
 486     private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(JanusGraphOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
 
 487         if (status == JanusGraphOperationStatus.NOT_FOUND) {
 
 488             return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
 
 490         return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 493     private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
 
 494         Optional<StorageOperationStatus> error = dataMap.entrySet()
 
 496                 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
 
 497                 .filter(s -> s != StorageOperationStatus.OK)
 
 499         if(error.isPresent()){
 
 500             return Either.right(error.get());
 
 502         return Either.left(dataVertex);
 
 505     private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 506         Map<String, MapAttributesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
 
 507         return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
 
 510     public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
 
 511         if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
 
 512             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
 
 513             if (assosiateElementToData.isRight()) {
 
 514                 return assosiateElementToData.right().value();
 
 517         return StorageOperationStatus.OK;
 
 520     public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapAttributesDataDefinition> instAttr) {
 
 521         if (instAttr != null && !instAttr.isEmpty()) {
 
 522             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
 
 523             if (assosiateElementToData.isRight()) {
 
 524                 return assosiateElementToData.right().value();
 
 527         return StorageOperationStatus.OK;
 
 530     public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
 
 532         if (groups != null && !groups.isEmpty()) {
 
 533             groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
 
 534                 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
 
 537             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
 
 538             if (assosiateElementToData.isRight()) {
 
 539                 return assosiateElementToData.right().value();
 
 542         return StorageOperationStatus.OK;
 
 545     private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 546         return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
 
 549     public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 550         Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
 
 551         return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
 
 554     public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
 
 555         if (inputs != null && !inputs.isEmpty()) {
 
 556             inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
 
 558             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
 
 559             if (assosiateElementToData.isRight()) {
 
 560                 return assosiateElementToData.right().value();
 
 563         return StorageOperationStatus.OK;
 
 566     private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
 
 567         nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
 
 568         fillCommonMetadata(nodeTypeVertex, topologyTemplate);
 
 569         if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
 
 570             nodeTypeVertex.setJson(topologyTemplate.getCompositions());
 
 572         nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
 
 573         nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
 
 575         return nodeTypeVertex;
 
 579     private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 580         if (topologyTemplate.getResourceType() == null) {
 
 582             return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
 
 585             return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
 
 589     private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
 
 590         String categoryName = topologyTemplate.getCategories().get(0).getName();
 
 591         Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
 
 592         if (category.isRight()) {
 
 593             log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
 
 594             return StorageOperationStatus.CATEGORY_NOT_FOUND;
 
 596         GraphVertex categoryV = category.left().value();
 
 597         JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
 
 598         if (createEdge != JanusGraphOperationStatus.OK) {
 
 599             log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
 
 600             return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge);
 
 602         return StorageOperationStatus.OK;
 
 606     public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
 
 607         JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
 
 609         Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag);
 
 610         if (componentByLabelAndId.isRight()) {
 
 611             return Either.right(componentByLabelAndId.right().value());
 
 613         GraphVertex componentV = componentByLabelAndId.left().value();
 
 615         return getToscaElement(componentV, componentParametersView);
 
 618     // -------------------------------------------------------------
 
 620     public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
 
 621         TopologyTemplate toscaElement;
 
 623         toscaElement = convertToTopologyTemplate(componentV);
 
 624         JanusGraphOperationStatus status;
 
 625         if (!componentParametersView.isIgnoreUsers()) {
 
 626             status = setCreatorFromGraph(componentV, toscaElement);
 
 627             if (status != JanusGraphOperationStatus.OK) {
 
 628                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 631             status = setLastModifierFromGraph(componentV, toscaElement);
 
 632             if (status != JanusGraphOperationStatus.OK) {
 
 633                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 636         if (!componentParametersView.isIgnoreCategories()) {
 
 637             status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
 
 638             if (status != JanusGraphOperationStatus.OK) {
 
 639                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 643         if (!componentParametersView.isIgnoreArtifacts()) {
 
 644             JanusGraphOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
 
 645             if (storageStatus != JanusGraphOperationStatus.OK) {
 
 646                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
 
 649         if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
 
 650             status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
 
 651             if (status != JanusGraphOperationStatus.OK) {
 
 652                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 655         if (!componentParametersView.isIgnoreComponentInstancesAttributes()) {
 
 656             status = setComponentInstancesAttributesFromGraph(componentV, toscaElement);
 
 657             if (status != JanusGraphOperationStatus.OK) {
 
 658                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 661         if (!componentParametersView.isIgnoreCapabilities()) {
 
 662             status = setCapabilitiesFromGraph(componentV, toscaElement);
 
 663             if (status != JanusGraphOperationStatus.OK) {
 
 664                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 667         if (!componentParametersView.isIgnoreRequirements()) {
 
 668             status = setRequirementsFromGraph(componentV, toscaElement);
 
 669             if (status != JanusGraphOperationStatus.OK) {
 
 670                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 673         if (!componentParametersView.isIgnoreAllVersions()) {
 
 674             status = setAllVersions(componentV, toscaElement);
 
 675             if (status != JanusGraphOperationStatus.OK) {
 
 676                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 679         if (!componentParametersView.isIgnoreAdditionalInformation()) {
 
 680             status = setAdditionalInformationFromGraph(componentV, toscaElement);
 
 681             if (status != JanusGraphOperationStatus.OK) {
 
 682                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 686         if (!componentParametersView.isIgnoreGroups()) {
 
 687             status = setGroupsFromGraph(componentV, toscaElement);
 
 688             if (status != JanusGraphOperationStatus.OK) {
 
 689                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 693         if (!componentParametersView.isIgnorePolicies()) {
 
 694             status = setPoliciesFromGraph(componentV, toscaElement);
 
 695             if (status != JanusGraphOperationStatus.OK) {
 
 696                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 700         if (!componentParametersView.isIgnoreComponentInstances()) {
 
 701             status = setInstGroupsFromGraph(componentV, toscaElement);
 
 703             //Mark all CIs that has archived origins
 
 704             archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
 
 706             if (status != JanusGraphOperationStatus.OK) {
 
 707                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 711         if (!componentParametersView.isIgnoreInputs()) {
 
 712             status = setInputsFromGraph(componentV, toscaElement);
 
 713             if (status != JanusGraphOperationStatus.OK) {
 
 714                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 719         if (!componentParametersView.isIgnoreOutputs()) {
 
 720             final JanusGraphOperationStatus storageStatus = setOutputsFromGraph(componentV, toscaElement);
 
 721             if (storageStatus != JanusGraphOperationStatus.OK) {
 
 722                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
 
 726         if (!componentParametersView.isIgnoreProperties()) {
 
 727             status = setPropertiesFromGraph(componentV, toscaElement);
 
 728             if (status != JanusGraphOperationStatus.OK) {
 
 729                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 734         if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
 
 735             status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
 
 736             if (status != JanusGraphOperationStatus.OK) {
 
 737                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 742         if (!componentParametersView.isIgnoreCapabiltyProperties()) {
 
 743             status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
 
 744             if (status != JanusGraphOperationStatus.OK) {
 
 745                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 750         if (!componentParametersView.isIgnoreServicePath()) {
 
 751             status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
 
 752             if (status != JanusGraphOperationStatus.OK) {
 
 753                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 758         if (!componentParametersView.isIgnoreNodeFilter()) {
 
 759             status = setNodeFilterComponentFromGraph(componentV, toscaElement);
 
 760             if (status != JanusGraphOperationStatus.OK) {
 
 761                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 766         if (!componentParametersView.isIgnoreSubstitutionFilter()) {
 
 767             status = setSubstitutionFilterComponentFromGraph(componentV, toscaElement);
 
 768             if (status != JanusGraphOperationStatus.OK) {
 
 769                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
 774         if (!componentParametersView.isIgnoreInterfaces()) {
 
 775             JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
 
 776             if (storageStatus != JanusGraphOperationStatus.OK) {
 
 777                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
 
 782         if (!componentParametersView.isIgnoreInterfaces()) {
 
 783             JanusGraphOperationStatus storageStatus = setInterfcesFromGraph(componentV, toscaElement);
 
 784             if (storageStatus != JanusGraphOperationStatus.OK) {
 
 785                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
 
 790         if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
 
 791             JanusGraphOperationStatus storageStatus =
 
 792                     setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
 
 793             if (storageStatus != JanusGraphOperationStatus.OK) {
 
 794                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
 
 798         if (!componentParametersView.isIgnoreDataType()) {
 
 799             JanusGraphOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
 
 800             if (storageStatus != JanusGraphOperationStatus.OK) {
 
 801                 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
 
 805         return Either.left(toscaElement);
 
 808     private JanusGraphOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
 
 809         Either<Map<String, DataTypeDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
 
 810         if (result.isLeft()) {
 
 811             toscaElement.setDataTypes(result.left().value());
 
 813             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 814                 return result.right().value();
 
 817         return JanusGraphOperationStatus.OK;
 
 820     private JanusGraphOperationStatus setInterfcesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 821         Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
 
 822         if (result.isLeft()) {
 
 823             topologyTemplate.setInterfaces(result.left().value());
 
 825             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 826                 return result.right().value();
 
 829         return JanusGraphOperationStatus.OK;
 
 832     private JanusGraphOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
 
 833         Either<Map<String, PolicyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
 
 834         if (result.isLeft()) {
 
 835             toscaElement.setPolicies(result.left().value());
 
 837             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 838                 return result.right().value();
 
 841         return JanusGraphOperationStatus.OK;
 
 844     private JanusGraphOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 845         Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
 
 846         if (result.isLeft()) {
 
 847             topologyTemplate.setInterfaces(result.left().value());
 
 849             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 850                 return result.right().value();
 
 853         return JanusGraphOperationStatus.OK;
 
 857     private JanusGraphOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV,
 
 858                                                                           TopologyTemplate topologyTemplate) {
 
 859         Either<Map<String, MapInterfaceDataDefinition>, JanusGraphOperationStatus> result =
 
 860                 getDataFromGraph(componentV, EdgeLabelEnum.INST_INTERFACES);
 
 861         if (result.isLeft()) {
 
 862             result.left().value().entrySet().forEach(entry -> topologyTemplate
 
 863                     .addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
 
 865             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 866                 return result.right().value();
 
 869         return JanusGraphOperationStatus.OK;
 
 872     private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
 
 873         Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
 
 874         if (interfaceMap != null && !interfaceMap.isEmpty()) {
 
 875             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
 
 876             if (assosiateElementToData.isRight()) {
 
 877                 return assosiateElementToData.right().value();
 
 880         return StorageOperationStatus.OK;
 
 883     private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 884         Either<Map<String, ForwardingPathDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
 
 885         if (result.isLeft()) {
 
 886             topologyTemplate.setForwardingPaths(result.left().value());
 
 888             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 889                 return result.right().value();
 
 892         return JanusGraphOperationStatus.OK;
 
 896     private JanusGraphOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 897         Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
 
 898         if (result.isLeft()) {
 
 899             topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
 
 901             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 902                 return result.right().value();
 
 905         Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> capPropResult =
 
 906                 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
 
 907         if (capPropResult.isLeft()) {
 
 908             topologyTemplate.setCapabilitiesProperties(capPropResult.left().value());
 
 910             if (capPropResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 911                 return capPropResult.right().value();
 
 915         return JanusGraphOperationStatus.OK;
 
 918     private JanusGraphOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
 
 919         Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
 
 920         if (result.isLeft()) {
 
 921             toscaElement.setProperties(result.left().value());
 
 923             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 924                 return result.right().value();
 
 927         return JanusGraphOperationStatus.OK;
 
 930     private JanusGraphOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 931         Either<Map<String, MapGroupsDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
 
 932         if (result.isLeft()) {
 
 933             topologyTemplate.setInstGroups(result.left().value());
 
 935             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 936                 return result.right().value();
 
 939         return JanusGraphOperationStatus.OK;
 
 942     private JanusGraphOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 943         Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
 
 944         if (result.isLeft()) {
 
 945             topologyTemplate.setInstProperties(result.left().value());
 
 947             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 948                 return result.right().value();
 
 951         return JanusGraphOperationStatus.OK;
 
 954     private JanusGraphOperationStatus setComponentInstancesAttributesFromGraph(final GraphVertex componentV,
 
 955                                                                                final TopologyTemplate topologyTemplate) {
 
 956         final Either<Map<String, MapAttributesDataDefinition>, JanusGraphOperationStatus> result =
 
 957             getDataFromGraph(componentV, EdgeLabelEnum.INST_ATTRIBUTES);
 
 958         if (result.isLeft()) {
 
 959             topologyTemplate.setInstAttributes(result.left().value());
 
 960         } else if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 961             return result.right().value();
 
 963         return JanusGraphOperationStatus.OK;
 
 966     private JanusGraphOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
 
 967         Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
 
 968         if (result.isLeft()) {
 
 969             topologyTemplate.setInstInputs(result.left().value());
 
 971             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 972                 return result.right().value();
 
 975         return JanusGraphOperationStatus.OK;
 
 978     private JanusGraphOperationStatus setNodeFilterComponentFromGraph(final GraphVertex componentV,
 
 979                                                                       final TopologyTemplate topologyTemplate) {
 
 981         final Either<Map<String, CINodeFilterDataDefinition>, JanusGraphOperationStatus> result =
 
 982             getDataFromGraph(componentV, EdgeLabelEnum.NODE_FILTER_TEMPLATE);
 
 983         if (result.isLeft()) {
 
 984             topologyTemplate.setNodeFilterComponents(result.left().value());
 
 986             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
 987                 return result.right().value();
 
 990         return JanusGraphOperationStatus.OK;
 
 993     private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV,
 
 994                                                                               final TopologyTemplate topologyTemplate) {
 
 996         final Either<Map<String, SubstitutionFilterDataDefinition>, JanusGraphOperationStatus> result =
 
 997             getDataFromGraph(componentV, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE);
 
 998         if (result.isLeft()) {
 
 999             topologyTemplate.setSubstitutionFilterDataDefinitionMap(result.left().value());
 
1001             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1002                 return result.right().value();
 
1005         return JanusGraphOperationStatus.OK;
 
1010     protected <T extends ToscaElement> JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
 
1011         Either<Map<String, MapListRequirementDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
 
1012         if (result.isLeft()) {
 
1013             ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
 
1015             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1016                 return result.right().value();
 
1019         result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
 
1020         if (result.isLeft()) {
 
1021             ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
 
1023             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1024                 return result.right().value();
 
1027         Either<Map<String, ListRequirementDataDefinition>, JanusGraphOperationStatus> requirementResult =
 
1028                 getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS);
 
1029         if (requirementResult.isLeft()) {
 
1030             toscaElement.setRequirements(requirementResult.left().value());
 
1032             if (requirementResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1033                 return requirementResult.right().value();
 
1036         return JanusGraphOperationStatus.OK;
 
1040     protected <T extends ToscaElement> JanusGraphOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
 
1041         Either<Map<String, MapListCapabilityDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
 
1042         if (result.isLeft()) {
 
1043             ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
 
1045             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1046                 return result.right().value();
 
1049         result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
 
1050         if (result.isLeft()) {
 
1051             ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
 
1053             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1054                 return result.right().value();
 
1057         Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
 
1058                 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
 
1059         if (capabilitiesResult.isLeft()) {
 
1060             toscaElement.setCapabilities(capabilitiesResult.left().value());
 
1062             if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1063                 return capabilitiesResult.right().value();
 
1066         return JanusGraphOperationStatus.OK;
 
1069     private JanusGraphOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
 
1070         JanusGraphOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
 
1071         if (storageStatus != JanusGraphOperationStatus.OK) {
 
1072             return storageStatus;
 
1074         Either<Map<String, ArtifactDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
 
1075         if (result.isLeft()) {
 
1076             toscaElement.setServiceApiArtifacts(result.left().value());
 
1078             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1079                 return result.right().value();
 
1082         Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
 
1083         if (resultInstArt.isLeft()) {
 
1084             toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
 
1086             if (resultInstArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1087                 return resultInstArt.right().value();
 
1090         Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
 
1091         if (instanceArt.isLeft()) {
 
1092             toscaElement.setInstanceArtifacts(instanceArt.left().value());
 
1094             if (instanceArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1095                 return instanceArt.right().value();
 
1098         return JanusGraphOperationStatus.OK;
 
1101     private JanusGraphOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
 
1102         Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
 
1103         if (result.isLeft()) {
 
1104             toscaElement.setInputs(result.left().value());
 
1106             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1107                 return result.right().value();
 
1110         Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
 
1111                 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
 
1112         if (capabilitiesResult.isLeft()) {
 
1113             toscaElement.setCapabilities(capabilitiesResult.left().value());
 
1115             if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1116                 return capabilitiesResult.right().value();
 
1119         return JanusGraphOperationStatus.OK;
 
1122     private JanusGraphOperationStatus setOutputsFromGraph(final GraphVertex componentV,
 
1123                                                           final TopologyTemplate toscaElement) {
 
1124         final Either<Map<String, AttributeDataDefinition>, JanusGraphOperationStatus> result =
 
1125             getDataFromGraph(componentV, EdgeLabelEnum.OUTPUTS);
 
1126         if (result.isLeft()) {
 
1127             toscaElement.setOutputs(result.left().value());
 
1129             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1130                 return result.right().value();
 
1133         return JanusGraphOperationStatus.OK;
 
1136     private JanusGraphOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
 
1137         Either<Map<String, GroupDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
 
1138         if (result.isLeft()) {
 
1139             toscaElement.setGroups(result.left().value());
 
1141             if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
 
1142                 return result.right().value();
 
1145         return JanusGraphOperationStatus.OK;
 
1148     private JanusGraphOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
 
1149         List<CategoryDefinition> categories = new ArrayList<>();
 
1151         switch (componentV.getType()) {
 
1153             return setResourceCategoryFromGraph(componentV, toscaElement);
 
1155             return setServiceCategoryFromGraph(componentV, toscaElement, categories);
 
1158             log.debug("Not supported component type {} ", componentV.getType());
 
1161         return JanusGraphOperationStatus.OK;
 
1164     private JanusGraphOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
 
1165         Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
 
1166         if (childVertex.isRight()) {
 
1167             log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
 
1168             return childVertex.right().value();
 
1170         GraphVertex categoryV = childVertex.left().value();
 
1171         Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
 
1172         CategoryDefinition category = new CategoryDefinition();
 
1173         category.setUniqueId(categoryV.getUniqueId());
 
1174         category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
 
1175         category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
 
1176         final Boolean useServiceSubstitutionForNestedServices = (Boolean)metadataProperties.get(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES);
 
1177         category.setUseServiceSubstitutionForNestedServices(useServiceSubstitutionForNestedServices == null ? false : useServiceSubstitutionForNestedServices);
 
1179         Type listTypeCat = new TypeToken<List<String>>() {}.getType();
 
1180         List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
 
1181         category.setIcons(iconsfromJsonCat);
 
1183         final Type metadataKeysTypeCat = new TypeToken<List<MetadataKeyDataDefinition>>() {}.getType();
 
1184         final List<MetadataKeyDataDefinition> metadataKeysfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.METADATA_KEYS), metadataKeysTypeCat);
 
1185         category.setMetadataKeys(metadataKeysfromJsonCat);
 
1187         categories.add(category);
 
1188         toscaElement.setCategories(categories);
 
1190         return JanusGraphOperationStatus.OK;
 
1193     @SuppressWarnings("unchecked")
 
1194     private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
 
1196         TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
 
1198         Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
 
1199         topologyTemplate.setCompositions(json);
 
1201         return topologyTemplate;
 
1205     public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
 
1206         Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
 
1207         if (nodeType.isRight()) {
 
1208             log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
 
1211         JanusGraphOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
 
1212         if (status != JanusGraphOperationStatus.OK) {
 
1213             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1215         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
 
1216         if (status != JanusGraphOperationStatus.OK) {
 
1217             log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1218             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1220         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
 
1221         if (status != JanusGraphOperationStatus.OK) {
 
1222             log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1223             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1226         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
 
1227         if (status != JanusGraphOperationStatus.OK) {
 
1228             log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1229             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1232         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
 
1233         if (status != JanusGraphOperationStatus.OK) {
 
1234             log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1235             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1237         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
 
1238         if (status != JanusGraphOperationStatus.OK) {
 
1239             log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1240             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1242         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
 
1243         if (status != JanusGraphOperationStatus.OK) {
 
1244             log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1245             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1247         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
 
1248         if (status != JanusGraphOperationStatus.OK) {
 
1249             log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1250             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1252         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
 
1253         if (status != JanusGraphOperationStatus.OK) {
 
1254             log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1255             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1257         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
 
1258         if (status != JanusGraphOperationStatus.OK) {
 
1259             log.debug("Failed to disassociate capabilities properties for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1260             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1262         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
 
1263         if (status != JanusGraphOperationStatus.OK) {
 
1264             log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1265             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1267         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
 
1268         if (status != JanusGraphOperationStatus.OK) {
 
1269             log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1270             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1272         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
 
1273         if (status != JanusGraphOperationStatus.OK) {
 
1274             log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1275             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1277         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
 
1278         if (status != JanusGraphOperationStatus.OK) {
 
1279             log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1280             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1282         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
 
1283         if (status != JanusGraphOperationStatus.OK) {
 
1284             log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1285             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1287         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
 
1288         if (status != JanusGraphOperationStatus.OK) {
 
1289             log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1290             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1292         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
 
1293         if (status != JanusGraphOperationStatus.OK) {
 
1294             log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1295             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1297         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
 
1298         if (status != JanusGraphOperationStatus.OK) {
 
1299             log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1300             Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1302         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
 
1303         if (status != JanusGraphOperationStatus.OK) {
 
1304             log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1305             return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1307         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
 
1308         if (status != JanusGraphOperationStatus.OK) {
 
1309             log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1310             return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1313         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
 
1314                 EdgeLabelEnum.REQUIREMENTS);
 
1315         if (status != JanusGraphOperationStatus.OK) {
 
1316             log.debug("Failed to disassociate requirements for {} error {}",
 
1317                     toscaElementVertex.getUniqueId(), status);
 
1318             return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1320         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
 
1321                 EdgeLabelEnum.CAPABILITIES);
 
1322         if (status != JanusGraphOperationStatus.OK) {
 
1323             log.debug("Failed to disassociate capabilities for {} error {}",
 
1324                     toscaElementVertex.getUniqueId(), status);
 
1325             return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1327         status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
 
1328         if (status != JanusGraphOperationStatus.OK) {
 
1329             log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
 
1330             return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1332         toscaElementVertex.getVertex().remove();
 
1333         log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
 
1338     @SuppressWarnings("unchecked")
 
1340     public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
 
1341         return createTopologyTemplate((TopologyTemplate) toscaElement);
 
1345     protected <T extends ToscaElement> JanusGraphOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
 
1346         return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
 
1350     protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
 
1351         // Product isn't supported now!!
 
1352         // TODO add for Product
 
1353         if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
 
1354             return validateServiceCategory(toscaElementToUpdate, elementV);
 
1357             return validateResourceCategory(toscaElementToUpdate, elementV);
 
1362     protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
 
1363         // not relevant now for topology template
 
1364         return StorageOperationStatus.OK;
 
1368     public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
 
1369         fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
 
1372     private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
 
1373         StorageOperationStatus status = StorageOperationStatus.OK;
 
1374         List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
 
1375         CategoryDefinition newCategory = newCategoryList.get(0);
 
1377         Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
 
1378         if (childVertex.isRight()) {
 
1379             log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
 
1380             return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childVertex.right().value());
 
1383         GraphVertex categoryV = childVertex.left().value();
 
1384         Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
 
1385         String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
 
1387         String newCategoryName = newCategory.getName();
 
1388         if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
 
1389             // the category was changed
 
1390             Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
 
1392             if (getCategoryVertex.isRight()) {
 
1393                 return getCategoryVertex.right().value();
 
1395             GraphVertex newCategoryV = getCategoryVertex.left().value();
 
1396             status = moveCategoryEdge(elementV, newCategoryV);
 
1397             log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
 
1402     public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
 
1404         Either<GraphVertex, StorageOperationStatus> result = null;
 
1405         String userId = user.getUserId();
 
1406         Either<GraphVertex, JanusGraphOperationStatus> getRes = findUserVertex(userId);
 
1407         GraphVertex userVertex = null;
 
1408         GraphVertex serviceVertex = null;
 
1409         if (getRes.isRight()) {
 
1410             JanusGraphOperationStatus status = getRes.right().value();
 
1411             CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
 
1412             result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1414         if (result == null) {
 
1415             userVertex = getRes.left().value();
 
1416             getRes = janusGraphDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
 
1417             if (getRes.isRight()) {
 
1418                 JanusGraphOperationStatus status = getRes.right().value();
 
1419                 log.debug( "Cannot find service {} in the graph. status is {}", uniqueId, status);
 
1420                 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1423         if (result == null) {
 
1424             serviceVertex = getRes.left().value();
 
1425             Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
 
1426             if (edgeIterator.hasNext()) {
 
1427                 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
 
1428                 edgeIterator.next().remove();
 
1431         if (result == null) {
 
1432             JanusGraphOperationStatus status = janusGraphDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
 
1433             if (status != JanusGraphOperationStatus.OK) {
 
1434                 log.debug( "Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
 
1435                 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
 
1438         if (result == null) {
 
1439             serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
 
1440             long lastUpdateDate = System.currentTimeMillis();
 
1441             serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
 
1442             Either<GraphVertex, JanusGraphOperationStatus> updateRes = janusGraphDao.updateVertex(serviceVertex);
 
1443             if (updateRes.isRight()) {
 
1444                 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateRes.right().value()));
 
1447         if (result == null) {
 
1448             result = Either.left(serviceVertex);
 
1453      * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
 
1454      * @param componentId
 
1456      * @param capabilityName
 
1457      * @param capabilityType
 
1461     public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
 
1463         Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
 
1464         Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
 
1465         Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
 
1466         if (componentByLabelAndId.isRight()) {
 
1467             result = Either.right(componentByLabelAndId.right().value());
 
1469         if(componentByLabelAndId.isLeft()){
 
1470             Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
 
1471             if (getDataRes.isRight()) {
 
1472                 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getDataRes.right().value()));
 
1474                 mapPropertiesDataDefinition = getDataRes.left().value();
 
1477         if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){
 
1478             result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
 
1483     public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) {
 
1484         return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
 
1487     public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent,
 
1488                                                                     String componentInstanceId,
 
1489                                                                     MapInterfaceDataDefinition instanceInterfaces) {
 
1490         if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
 
1491             return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(),
 
1492                     EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId);
 
1494         return StorageOperationStatus.OK;
 
1498     private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
 
1499         return  MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
 
1500                 instanceId != null &&
 
1501                 mapPropertiesDataDefinition.get(instanceId) != null &&
 
1502                 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
 
1505     private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
 
1506         List<ComponentInstanceProperty> capPropsList = null;
 
1507         for(Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()){
 
1508             if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
 
1509                 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
 
1510                 if (capMap != null && !capMap.isEmpty()) {
 
1511                     capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
 
1516         if(capPropsList == null){
 
1517             capPropsList = new ArrayList<>();
 
1519         return capPropsList;
 
1522     private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
 
1523         if (capProp != null) {
 
1524             String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM );
 
1525             if (path.length < 4) {
 
1526                 log.debug("wrong key format for capabilty, key {}", capProp);
 
1529             return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
 
1534     public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
 
1535         fillPolicyDefinition(componentV, policyDefinition, counter);
 
1536         return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
 
1539     public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
 
1540         return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
 
1543     public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
 
1544         return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
 
1547     public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
 
1548         return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
 
1551     public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
 
1552         return  deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
 
1555     public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
 
1556         return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.CI_INVARIANT_NAME);
 
1559     private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
 
1560         String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
 
1561         policyDefinition.setName(policyName);
 
1562         policyDefinition.setInvariantName(policyName);
 
1563         policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
 
1564         policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
 
1565         policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
 
1566         policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
 
1569     public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
 
1570         String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
 
1571         String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
 
1572         return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
 
1575     void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
 
1576         if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
 
1577             GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
 
1579                     .on(this::throwStorageException);
 
1580             if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
 
1581                 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
 
1583             if(MapUtils.isNotEmpty(toscaElement.getGroups())){
 
1584                 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
 
1586             topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES,  toscaElement.getCalculatedCapabilities());
 
1587             topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS,  toscaElement.getCalculatedRequirements());
 
1588             topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,  toscaElement.getCalculatedCapabilitiesProperties());
 
1592     public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
 
1593         if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
 
1594             GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
 
1596                     .on(this::throwStorageException);
 
1597             if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
 
1598                 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
 
1600             if(MapUtils.isNotEmpty(toscaElement.getGroups())){
 
1601                 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
 
1603             topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES,  toscaElement.getCalculatedCapabilities());
 
1604             topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS,  toscaElement.getCalculatedRequirements());
 
1605             topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,  toscaElement.getCalculatedCapabilitiesProperties());
 
1609     private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
 
1610         log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
 
1611         ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
 
1612         Either<ToscaElement, StorageOperationStatus> getOriginRes;
 
1613         if(elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE){
 
1614             getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
 
1617             getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
 
1619         if(getOriginRes.isRight()){
 
1620             log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
 
1621             throw new StorageException(getOriginRes.right().value());
 
1623         return getOriginRes.left().value();
 
1626     private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
 
1627         log.debug("#detectToscaType - type: {}", originType);
 
1628         if(originType == OriginTypeEnum.VFC
 
1629                 || originType == OriginTypeEnum.CP
 
1630                 || originType == OriginTypeEnum.VL
 
1631                 || originType == OriginTypeEnum.Configuration
 
1632                 || originType == OriginTypeEnum.VFCMT){
 
1633             return ToscaElementTypeEnum.NODE_TYPE;
 
1635             return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
 
1639     private ComponentParametersView getFilter() {
 
1640         ComponentParametersView filter = new ComponentParametersView();
 
1641         filter.setIgnoreCapabilities(false);
 
1642         filter.setIgnoreCapabiltyProperties(false);
 
1643         filter.setIgnoreRequirements(false);
 
1646     public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) {
 
1647         GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
 
1648                 .left().on(this::throwStorageException);
 
1649         updateCapOwnerId(toscaElement, componentId);
 
1650         updateReqOwnerId(toscaElement, componentId);
 
1651         updatePropertiesOwnerId(toscaElement, componentId);
 
1652         topologyTemplateOperation
 
1654                 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES,
 
1655                         VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
 
1656         topologyTemplateOperation
 
1657                 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS,
 
1658                         VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
 
1659         topologyTemplateOperation
 
1660                 .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES,
 
1661                         VertexTypeEnum.PROPERTIES, toscaElement.getProperties());
 
1664     private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
 
1665         if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
 
1666             toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
 
1667                     .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
 
1671     private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
 
1672         if(MapUtils.isNotEmpty(toscaElement.getRequirements())) {
 
1673             toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
 
1674                     .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));
 
1678     private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) {
 
1679         Map<String, PropertyDataDefinition> properties = toscaElement.getProperties();
 
1680         if(MapUtils.isNotEmpty(properties)) {
 
1681             properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId));