summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuli Shlosberg <ys9693@att.com>2019-02-11 10:42:44 +0200
committerOren Kleks <orenkle@amdocs.com>2019-02-13 08:43:03 +0000
commitd72aaa18d4dbfb8017dce566d9c41ccc00985528 (patch)
treeeb2c905f3df2d8638b6e3810ed20310d04b0d46f
parent4cedea9f7bc216df6e4ece4386b5a7b5a536671f (diff)
Bug Fix - error 500
bug desc- Can't checkin service that has service with EXT VL inside - error 500 Change-Id: I711d70b153e6370dffba2130a1aedd7cab28a065 Issue-ID: SDC-2073 Signed-off-by: Yuli Shlosberg <ys9693@att.com>
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java386
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/CapabilityRequirementNameResolver.java394
2 files changed, 519 insertions, 261 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
index 26fe1e262d..fab64988d4 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,7 +23,6 @@ package org.openecomp.sdc.be.model.jsontitan.operations;
import com.google.gson.reflect.TypeToken;
import fj.data.Either;
import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.StringUtils;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
@@ -32,24 +31,22 @@ import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.*;
-import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
-import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
+import org.openecomp.sdc.be.model.jsontitan.utils.CapabilityRequirementNameResolver;
import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
-import org.openecomp.sdc.be.model.utils.ComponentUtilities;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
@@ -66,6 +63,7 @@ import java.util.stream.Collectors;
public class TopologyTemplateOperation extends ToscaElementOperation {
private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
+ private Set<OriginTypeEnum> nodeTypeSet = new HashSet<>(Arrays.asList(OriginTypeEnum.VFC, OriginTypeEnum.CP, OriginTypeEnum.VL, OriginTypeEnum.Configuration, OriginTypeEnum.VFCMT));
@Autowired
private ArchiveOperation archiveOperation;
@@ -88,7 +86,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
Either<GraphVertex, TitanOperationStatus> createdVertex = titanDao.createVertex(topologyTemplateVertex);
if (createdVertex.isRight()) {
TitanOperationStatus status = createdVertex.right().value();
- log.debug( "Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
+ log.debug("Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
return result;
}
@@ -171,13 +169,6 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
result = Either.right(associateCapProperties);
return result;
}
-
- StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
- if (associateInterfaces != StorageOperationStatus.OK) {
- result = Either.right(associateInterfaces);
- return result;
- }
-
StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
if (associateCapProperties != StorageOperationStatus.OK) {
result = Either.right(associatePathProperties);
@@ -193,7 +184,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
}
- private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
+ private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
if (policies != null && !policies.isEmpty()) {
policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
@@ -209,11 +200,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
- return associateForwardingPathToComponent(topologyTemplateVertex,forwardingPaths);
+ return associateForwardingPathToComponent(topologyTemplateVertex, forwardingPaths);
}
private StorageOperationStatus associateNodeFilterToResource(GraphVertex topologyTemplateVertex,
- TopologyTemplate topologyTemplate) {
+ TopologyTemplate topologyTemplate) {
Map<String, CINodeFilterDataDefinition> nodeFilters =
topologyTemplate.getNodeFilterComponents();
return associateNodeFiltersToComponent(topologyTemplateVertex, nodeFilters);
@@ -422,7 +413,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
}
if (calcCapabilty != null && !calcCapabilty.isEmpty()) {
- Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES ,EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
+ Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
if (assosiateElementToData.isRight()) {
return assosiateElementToData.right().value();
}
@@ -432,7 +423,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return assosiateElementToData.right().value();
}
}
- if ( calculatedCapabilitiesProperties != null && !calculatedCapabilitiesProperties.isEmpty() ){
+ if (calculatedCapabilitiesProperties != null && !calculatedCapabilitiesProperties.isEmpty()) {
return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
.right()
@@ -441,14 +432,14 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return StorageOperationStatus.OK;
}
- private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap){
+ private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
return titanDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
.either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
}
-
+
private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(TitanOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
- if(status == TitanOperationStatus.NOT_FOUND){
+ if (status == TitanOperationStatus.NOT_FOUND) {
return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
}
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
@@ -460,7 +451,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
.map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
.filter(s -> s != StorageOperationStatus.OK)
.findFirst();
- if(error.isPresent()){
+ if (error.isPresent()) {
return Either.right(error.get());
}
return Either.left(dataVertex);
@@ -713,40 +704,9 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
}
- if (!componentParametersView.isIgnoreInterfaces()) {
- TitanOperationStatus storageStatus = setInterfcesFromGraph(componentV, toscaElement);
- if (storageStatus != TitanOperationStatus.OK) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
-
- }
- }
-
return Either.left(toscaElement);
}
- private TitanOperationStatus setInterfcesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
- Either<Map<String, InterfaceDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
- if (result.isLeft()) {
- topologyTemplate.setInterfaces(result.left().value());
- } else {
- if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
- return result.right().value();
- }
- }
- return TitanOperationStatus.OK;
- }
-
- private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
- Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
- if (interfaceMap != null && !interfaceMap.isEmpty()) {
- Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
- if (assosiateElementToData.isRight()) {
- return assosiateElementToData.right().value();
- }
- }
- return StorageOperationStatus.OK;
- }
-
private TitanOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
Either<Map<String, PolicyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
if (result.isLeft()) {
@@ -760,11 +720,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex,
- Map<String, CINodeFilterDataDefinition> filterMaps) {
+ Map<String, CINodeFilterDataDefinition> filterMaps) {
if (filterMaps != null && !filterMaps.isEmpty()) {
Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData
- (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
- EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
+ (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
+ EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
if (assosiateElementToData.isRight()) {
return assosiateElementToData.right().value();
}
@@ -846,7 +806,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
private TitanOperationStatus setNodeFilterComponentFromGraph(GraphVertex componentV,
- TopologyTemplate topologyTemplate) {
+ TopologyTemplate topologyTemplate) {
Either<Map<String, CINodeFilterDataDefinition>, TitanOperationStatus> result =
getDataFromGraph(componentV,
EdgeLabelEnum.NODE_FILTER_TEMPLATE);
@@ -962,14 +922,14 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
List<CategoryDefinition> categories = new ArrayList<>();
switch (componentV.getType()) {
- case RESOURCE:
- return setResourceCategoryFromGraph(componentV, toscaElement);
- case SERVICE:
- return setServiceCategoryFromGraph(componentV, toscaElement, categories);
+ case RESOURCE:
+ return setResourceCategoryFromGraph(componentV, toscaElement);
+ case SERVICE:
+ return setServiceCategoryFromGraph(componentV, toscaElement, categories);
- default:
- log.debug("Not supported component type {} ", componentV.getType());
- break;
+ default:
+ log.debug("Not supported component type {} ", componentV.getType());
+ break;
}
return TitanOperationStatus.OK;
}
@@ -987,7 +947,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
- Type listTypeCat = new TypeToken<List<String>>() {}.getType();
+ Type listTypeCat = new TypeToken<List<String>>() {
+ }.getType();
List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
category.setIcons(iconsfromJsonCat);
categories.add(category);
@@ -1016,96 +977,92 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
TitanOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
if (status != TitanOperationStatus.OK) {
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
if (status != TitanOperationStatus.OK) {
log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
- if (status != TitanOperationStatus.OK) {
- log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
- if (status != TitanOperationStatus.OK) {
- log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
+ titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
toscaElementVertex.getVertex().remove();
log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
@@ -1193,7 +1150,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
getRes = titanDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
if (getRes.isRight()) {
TitanOperationStatus status = getRes.right().value();
- log.debug( "Cannot find service {} in the graph. status is {}", uniqueId, status);
+ log.debug("Cannot find service {} in the graph. status is {}", uniqueId, status);
result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
@@ -1208,7 +1165,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
if (result == null) {
TitanOperationStatus status = titanDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
if (status != TitanOperationStatus.OK) {
- log.debug( "Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
+ log.debug("Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
@@ -1226,8 +1183,10 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
return result;
}
+
/**
* Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
+ *
* @param componentId
* @param instanceId
* @param capabilityName
@@ -1243,7 +1202,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
if (componentByLabelAndId.isRight()) {
result = Either.right(componentByLabelAndId.right().value());
}
- if(componentByLabelAndId.isLeft()){
+ if (componentByLabelAndId.isLeft()) {
Either<Map<String, MapCapabilityProperty>, TitanOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
if (getDataRes.isRight()) {
result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getDataRes.right().value()));
@@ -1251,7 +1210,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
mapPropertiesDataDefinition = getDataRes.left().value();
}
}
- if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){
+ if (isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)) {
result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
}
return result;
@@ -1263,14 +1222,14 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
- return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
+ return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
mapPropertiesDataDefinition.get(instanceId) != null &&
MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
}
private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
List<ComponentInstanceProperty> capPropsList = null;
- for(Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()){
+ for (Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()) {
if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
if (capMap != null && !capMap.isEmpty()) {
@@ -1279,7 +1238,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
}
}
- if(capPropsList == null){
+ if (capPropsList == null) {
capPropsList = new ArrayList<>();
}
return capPropsList;
@@ -1287,7 +1246,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
if (capProp != null) {
- String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM );
+ String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM);
if (path.length < 4) {
log.debug("wrong key format for capabilty, key {}", capProp);
return false;
@@ -1315,194 +1274,99 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
- return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
- }
-
- public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
- return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.NAME);
- }
-
- private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
- String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
- policyDefinition.setName(policyName);
- policyDefinition.setInvariantName(policyName);
- policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
- policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
- policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
- policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
- }
-
- public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
+ return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
+ }
+
+ public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
+ return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.NAME);
+ }
+
+ private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
+ String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
+ policyDefinition.setName(policyName);
+ policyDefinition.setInvariantName(policyName);
+ policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
+ policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
+ policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
+ policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
+ }
+
+ public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
- String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
- return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
- }
+ String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
+ return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
+ }
void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
- if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
+ if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
.left()
.on(this::throwStorageException);
- if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
- toscaElement.getComponentInstances().values().forEach(i -> revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId()));
+ if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
+ toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
}
- if(MapUtils.isNotEmpty(toscaElement.getGroups())){
- toscaElement.getGroups().values().forEach(g -> revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId()));
+ if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
+ toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
}
- topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
- topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
- topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
+ topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
+ topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
+ topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
}
}
public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
- if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
+ if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
.left()
.on(this::throwStorageException);
- if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
- toscaElement.getComponentInstances().values().forEach(i -> updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName()));
- }
- if(MapUtils.isNotEmpty(toscaElement.getGroups())){
- toscaElement.getGroups().values().forEach(g -> updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName()));
- }
- topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
- topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
- topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
- }
- }
-
- private void updateNamesOfCalculatedCapabilitiesRequirements(TopologyTemplate toscaElement, String ownerId, String ownerName) {
- updateCalculatedCapabilitiesNames(toscaElement, ownerId, ownerName);
- updateCalculatedRequirementsNames(toscaElement, ownerId, ownerName);
- updateCalculatedCapabilitiesPropertiesKeys(toscaElement, ownerId);
- }
-
- private void updateCalculatedCapabilitiesPropertiesKeys(TopologyTemplate toscaElement, String ownerId) {
- if(toscaElement.getCalculatedCapabilitiesProperties() != null && toscaElement.getCalculatedCapabilitiesProperties().containsKey(ownerId)){
- MapCapabilityProperty newProps = new MapCapabilityProperty();
- toscaElement.getCalculatedCapabilitiesProperties().get(ownerId)
- .getMapToscaDataDefinition()
- .forEach((k, v)-> updateAndAddCalculatedCapabilitiesProperties(k, v, toscaElement.getCalculatedCapabilities().get(ownerId), newProps));
- if(MapUtils.isNotEmpty(newProps.getMapToscaDataDefinition())) {
- toscaElement.getCalculatedCapabilitiesProperties().put(ownerId, newProps);
- }
- }
- }
-
- private void updateCalculatedRequirementsNames(TopologyTemplate toscaElement, String ownerId, String ownerName) {
- if(toscaElement.getCalculatedRequirements() != null && toscaElement.getCalculatedRequirements().containsKey(ownerId)){
- String prefix = ownerName + ".";
- toscaElement.getCalculatedRequirements().get(ownerId)
- .getMapToscaDataDefinition().values().stream()
- .flatMap(l -> l.getListToscaDataDefinition().stream())
- .forEach(r -> {
- if(ComponentUtilities.isNotUpdatedCapReqName(prefix, r.getName(), r.getPreviousName())) {
- if(StringUtils.isNotEmpty(r.getPreviousName())){
- r.setParentName(r.getPreviousName());
- }
- r.setPreviousName(r.getName());
- }
- r.setName(prefix + r.getPreviousName());
- });
- }
- }
-
- private void updateCalculatedCapabilitiesNames(TopologyTemplate toscaElement, String ownerId, String ownerName) {
- if(toscaElement.getCalculatedCapabilities() != null && toscaElement.getCalculatedCapabilities().containsKey(ownerId)){
- String prefix = ownerName + ".";
- toscaElement.getCalculatedCapabilities().get(ownerId)
- .getMapToscaDataDefinition().values().stream()
- .flatMap(l -> l.getListToscaDataDefinition().stream())
- .forEach(c -> {
- if(ComponentUtilities.isNotUpdatedCapReqName(prefix, c.getName(), c.getPreviousName())) {
- if(StringUtils.isNotEmpty(c.getPreviousName())){
- c.setParentName(c.getPreviousName());
- }
- c.setPreviousName(c.getName());
- }
- c.setName(prefix + c.getPreviousName());
- });
- }
- }
-
- private void updateAndAddCalculatedCapabilitiesProperties(String stringKey, MapPropertiesDataDefinition properties, MapListCapabilityDataDefinition calculatedCapabilities, MapCapabilityProperty newProps) {
- String[] key = stringKey.split(ModelConverter.CAP_PROP_DELIM);
- String capType = key[key.length - 2];
- String capName = key[key.length - 1];
- Optional<CapabilityDataDefinition> foundCapOpt = calculatedCapabilities.getMapToscaDataDefinition().get(capType)
- .getListToscaDataDefinition().stream()
- .filter(c -> c.getPreviousName().equals(capName))
- .findFirst();
- if(foundCapOpt.isPresent()){
- key[key.length - 1] = foundCapOpt.get().getName();
- newProps.put(buildCaLCapPropKey(key),properties);
- }
- }
-
- private void revertNamesOfCalculatedCapabilitiesRequirements(TopologyTemplate toscaElement, String ownerId) {
- revertCalculatedCapabilitiesPropertiesKeys(toscaElement, ownerId);
- revertCalculatedCapabilitiesNames(toscaElement, ownerId);
- revertCalculatedRequirementsNames(toscaElement, ownerId);
- }
-
- private void revertCalculatedCapabilitiesPropertiesKeys(TopologyTemplate toscaElement, String ownerId) {
- if(toscaElement.getCalculatedCapabilitiesProperties() != null && toscaElement.getCalculatedCapabilitiesProperties().containsKey(ownerId)){
- MapCapabilityProperty newProps = new MapCapabilityProperty();
- toscaElement.getCalculatedCapabilitiesProperties().get(ownerId)
- .getMapToscaDataDefinition()
- .forEach((k,v) -> revertAndAddCalculatedCapabilitiesProperties(k, v, toscaElement.getCalculatedCapabilities().get(ownerId), newProps));
- if(MapUtils.isNotEmpty(newProps.getMapToscaDataDefinition())) {
- toscaElement.getCalculatedCapabilitiesProperties().put(ownerId, newProps);
+ if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
+ toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
+ }
+ if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
+ toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
}
+ topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
+ topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
+ topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
}
}
- private void revertCalculatedRequirementsNames(TopologyTemplate toscaElement, String ownerId) {
- if(toscaElement.getCalculatedRequirements() != null && toscaElement.getCalculatedRequirements().containsKey(ownerId)){
- toscaElement.getCalculatedRequirements().get(ownerId)
- .getMapToscaDataDefinition().values().stream()
- .flatMap(l -> l.getListToscaDataDefinition().stream())
- .forEach(r -> {r.setName(r.getPreviousName());r.setPreviousName(r.getParentName());});
- }
+ private GraphVertex throwStorageException(TitanOperationStatus status) {
+ throw new StorageException(status);
}
- private void revertCalculatedCapabilitiesNames(TopologyTemplate toscaElement, String ownerId) {
- if(toscaElement.getCalculatedCapabilities() != null && toscaElement.getCalculatedCapabilities().containsKey(ownerId)){
- toscaElement.getCalculatedCapabilities().get(ownerId)
- .getMapToscaDataDefinition().values().stream()
- .flatMap(l -> l.getListToscaDataDefinition().stream())
- .forEach(c -> {c.setName(c.getPreviousName());c.setPreviousName(c.getParentName());});
- }
- }
+ private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
+ log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
+ ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
+ Either<ToscaElement, StorageOperationStatus> getOriginRes;
+ if (elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE) {
+ getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
- private void revertAndAddCalculatedCapabilitiesProperties(String stringKey, MapPropertiesDataDefinition properties, MapListCapabilityDataDefinition calculatedCapabilities, MapCapabilityProperty newProps) {
- String[] key = stringKey.split(ModelConverter.CAP_PROP_DELIM);
- String capType = key[key.length - 2];
- String capName = key[key.length - 1];
- Optional<CapabilityDataDefinition> foundCapOpt = calculatedCapabilities.getMapToscaDataDefinition().get(capType)
- .getListToscaDataDefinition().stream()
- .filter(c -> c.getName().equals(capName) && StringUtils.isNotEmpty(c.getPreviousName()))
- .findFirst();
- if(foundCapOpt.isPresent()){
- key[key.length - 1] = foundCapOpt.get().getPreviousName();
+ } else {
+ getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
+ }
+ if (getOriginRes.isRight()) {
+ log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
+ throw new StorageException(getOriginRes.right().value());
}
- newProps.put(buildCaLCapPropKey(key), properties);
+ return getOriginRes.left().value();
}
- private String buildCaLCapPropKey(String[] keyArray) {
- StringBuilder key = new StringBuilder();
- for(int i = 0; i< keyArray.length; ++i){
- key.append(keyArray[i]);
- if(i < keyArray.length - 1){
- key.append(ModelConverter.CAP_PROP_DELIM);
- }
+ private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
+ log.debug("#detectToscaType - type: {}", originType);
+ if (nodeTypeSet.contains(originType)){
+ return ToscaElementTypeEnum.NODE_TYPE;
+ } else {
+ return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
}
- return key.toString();
}
- private GraphVertex throwStorageException(TitanOperationStatus status) {
- throw new StorageException(status);
+ private ComponentParametersView getFilter() {
+ ComponentParametersView filter = new ComponentParametersView();
+ filter.setIgnoreCapabilities(false);
+ filter.setIgnoreCapabiltyProperties(false);
+ filter.setIgnoreRequirements(false);
+ return filter;
}
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/CapabilityRequirementNameResolver.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/CapabilityRequirementNameResolver.java
new file mode 100644
index 0000000000..6bdce99d95
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/CapabilityRequirementNameResolver.java
@@ -0,0 +1,394 @@
+package org.openecomp.sdc.be.model.jsontitan.utils;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.datatypes.elements.*;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
+import org.openecomp.sdc.be.model.utils.ComponentUtilities;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
+import static org.apache.commons.lang3.StringUtils.isBlank;
+
+public class CapabilityRequirementNameResolver {
+
+ private static final Logger log = Logger.getLogger(CapabilityRequirementNameResolver.class);
+ private static final String PATH_DELIMITER = ".";
+
+ private CapabilityRequirementNameResolver() {
+ }
+
+ public static void updateNamesOfCalculatedCapabilitiesRequirements(TopologyTemplate toscaElement, String ownerId, String ownerName, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ Map<String, ToscaElement> componentCacheToRepair = new HashMap<>();
+ log.debug("#updateNamesOfCalculatedCapabilitiesRequirements");
+ updateCalculatedCapabilitiesNames(componentCacheToRepair, toscaElement, ownerId, ownerName, originGetter);
+ updateCalculatedRequirementsNames(componentCacheToRepair, toscaElement, ownerId, ownerName, originGetter);
+ updateCalculatedCapabilitiesPropertiesKeys(toscaElement, ownerId);
+ }
+
+ private static void updateCalculatedCapabilitiesPropertiesKeys(TopologyTemplate toscaElement, String ownerId) {
+ if (calCapPropertiesExist(toscaElement, ownerId)) {
+ MapCapabilityProperty newProps = new MapCapabilityProperty();
+ toscaElement.getCalculatedCapabilitiesProperties().get(ownerId)
+ .getMapToscaDataDefinition()
+ .forEach((k, v) -> updateAndAddCalculatedCapabilitiesProperties(k, v, toscaElement.getCalculatedCapabilities().get(ownerId), newProps));
+ if (MapUtils.isNotEmpty(newProps.getMapToscaDataDefinition())) {
+ toscaElement.getCalculatedCapabilitiesProperties().put(ownerId, newProps);
+ }
+ }
+ }
+
+ private static boolean calCapPropertiesExist(TopologyTemplate toscaElement, String ownerId) {
+ return toscaElement.getCalculatedCapabilitiesProperties() != null
+ && toscaElement.getCalculatedCapabilitiesProperties().get(ownerId) != null
+ && MapUtils.isNotEmpty(toscaElement.getCalculatedCapabilitiesProperties().get(ownerId).getMapToscaDataDefinition())
+ && capabilitiesExist(toscaElement, ownerId);
+ }
+
+ private static void updateCalculatedRequirementsNames(Map<String, ToscaElement> componentCacheToRepair, TopologyTemplate toscaElement, String ownerId, String ownerName, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ if (requirementsExist(toscaElement, ownerId)) {
+ String prefix = ownerName + PATH_DELIMITER;
+ repairReqNames(componentCacheToRepair, toscaElement, ownerId, originGetter);
+ toscaElement.getCalculatedRequirements().get(ownerId)
+ .getMapToscaDataDefinition().values().stream()
+ .flatMap(l -> l.getListToscaDataDefinition().stream())
+ .forEach(r -> {
+ if (isRequiredToRepair(r.getName())) {
+ BeEcompErrorManager.getInstance()
+ .logBeComponentMissingError("The empty name of the requirement was found. Id: " + r.getUniqueId() + ", ownerId: " + ownerId + ", ownerName: " + ownerName,
+ toscaElement.getComponentType().getValue(), toscaElement.getName());
+ }
+ if (ComponentUtilities.isNotUpdatedCapReqName(prefix, r.getName(), r.getPreviousName())) {
+ if (StringUtils.isNotEmpty(r.getPreviousName())) {
+ r.setParentName(r.getPreviousName());
+ }
+ r.setPreviousName(r.getName());
+ }
+ r.setName(prefix + r.getPreviousName());
+ });
+ }
+ }
+
+ private static boolean requirementsExist(TopologyTemplate toscaElement, String ownerId) {
+ return toscaElement.getCalculatedRequirements() != null
+ && toscaElement.getCalculatedRequirements().get(ownerId) != null
+ && MapUtils.isNotEmpty(toscaElement.getCalculatedRequirements().get(ownerId).getMapToscaDataDefinition());
+ }
+
+ private static void updateCalculatedCapabilitiesNames(Map<String, ToscaElement> componentCacheToRepair, TopologyTemplate toscaElement, String ownerId, String ownerName, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ if (capabilitiesExist(toscaElement, ownerId)) {
+ String prefix = ownerName + PATH_DELIMITER;
+ repairCapNames(componentCacheToRepair, toscaElement, ownerId, originGetter);
+ toscaElement.getCalculatedCapabilities().get(ownerId)
+ .getMapToscaDataDefinition().values().stream()
+ .flatMap(l -> l.getListToscaDataDefinition().stream())
+ .forEach(c -> {
+ if (isRequiredToRepair(c.getName())) {
+ BeEcompErrorManager.getInstance()
+ .logBeComponentMissingError("The empty name of the capability was found. Id: " + c.getUniqueId() + ", ownerId: " + ownerId + ", ownerName: " + ownerName,
+ toscaElement.getComponentType().getValue(), toscaElement.getName());
+ }
+ if (ComponentUtilities.isNotUpdatedCapReqName(prefix, c.getName(), c.getPreviousName())) {
+ if (StringUtils.isNotEmpty(c.getPreviousName())) {
+ c.setParentName(c.getPreviousName());
+ }
+ c.setPreviousName(c.getName());
+ }
+ c.setName(prefix + c.getPreviousName());
+ });
+ }
+ }
+
+ private static boolean capabilitiesExist(TopologyTemplate toscaElement, String ownerId) {
+ return toscaElement.getCalculatedCapabilities() != null
+ && toscaElement.getCalculatedCapabilities().get(ownerId) != null
+ && MapUtils.isNotEmpty(toscaElement.getCalculatedCapabilities().get(ownerId).getMapToscaDataDefinition());
+ }
+
+ private static void repairCapNames(Map<String, ToscaElement> componentCacheToRepair, TopologyTemplate toscaElement, String ownerId, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ log.debug("#repairCapNames");
+ boolean emptyNameFound = toscaElement.getCalculatedCapabilities() != null
+ && toscaElement.getCalculatedCapabilities().get(ownerId) != null
+ && toscaElement.getCalculatedCapabilities().get(ownerId).getMapToscaDataDefinition() != null
+ && toscaElement.getCalculatedCapabilities().get(ownerId).getMapToscaDataDefinition().values()
+ .stream()
+ .filter(Objects::nonNull)
+ .flatMap(l -> l.getListToscaDataDefinition().stream())
+ .filter(Objects::nonNull)
+ .anyMatch(c -> isRequiredToRepair(c.getName()));
+
+ ComponentInstanceDataDefinition instance = toscaElement.getComponentInstances() != null ?
+ toscaElement.getComponentInstances().get(ownerId) : null;
+ if (instance != null && emptyNameFound) {
+ log.debug("#repairCapNames - Going to repair the name of the capability for the owner {}. ", ownerId);
+ toscaElement.getCalculatedCapabilities().get(ownerId)
+ .getMapToscaDataDefinition().values()
+ .stream()
+ .flatMap(l -> l.getListToscaDataDefinition().stream())
+ .forEach(c -> repairCapName(componentCacheToRepair, instance, c, originGetter));
+ }
+ }
+
+ private static void repairReqNames(Map<String, ToscaElement> componentCacheToRepair, TopologyTemplate toscaElement, String ownerId, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ log.debug("#repairReqNames");
+ boolean emptyNameFound = toscaElement.getCalculatedRequirements() != null
+ && toscaElement.getCalculatedRequirements().get(ownerId) != null
+ && toscaElement.getCalculatedRequirements().get(ownerId).getMapToscaDataDefinition() != null
+ && toscaElement.getCalculatedRequirements().get(ownerId).getMapToscaDataDefinition().values()
+ .stream()
+ .filter(Objects::nonNull)
+ .flatMap(l -> l.getListToscaDataDefinition().stream())
+ .filter(Objects::nonNull)
+ .anyMatch(r -> isRequiredToRepair(r.getName()));
+
+ ComponentInstanceDataDefinition instance = toscaElement.getComponentInstances() != null ?
+ toscaElement.getComponentInstances().get(ownerId) : null;
+ if (instance != null && emptyNameFound) {
+ log.debug("#repairReqNames - Going to repair the name of the requirement for the owner {}. ", ownerId);
+ toscaElement.getCalculatedRequirements().get(ownerId)
+ .getMapToscaDataDefinition().values()
+ .stream()
+ .flatMap(l -> l.getListToscaDataDefinition().stream())
+ .forEach(r -> repairReqName(componentCacheToRepair, instance, r, originGetter));
+ }
+ }
+
+ private static void repairCapName(Map<String, ToscaElement> componentCacheToRepair, ComponentInstanceDataDefinition instance, CapabilityDataDefinition capability, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ if (isRequiredToRepair(capability.getName())) {
+ log.debug("#repairTopologyTemplateCapName - Going to build the name for the capability: ", capability.getUniqueId());
+ buildSetCapName(componentCacheToRepair, capability, instance, originGetter);
+ }
+ }
+
+ private static boolean isRequiredToRepair(String name) {
+ boolean isRequiredToRepair = StringUtils.isEmpty(name) || name.endsWith(".null") || name.contains(".null.");
+ if (isRequiredToRepair) {
+ log.debug("#isRequiredToRepair - The name {} should be repaired. ", name);
+ } else {
+ log.debug("#isRequiredToRepair - The name {} should not be repaired. ", name);
+ }
+ return isRequiredToRepair;
+ }
+
+ private static void repairReqName(Map<String, ToscaElement> componentCacheToRepair, ComponentInstanceDataDefinition instance, RequirementDataDefinition requirement, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ if (isRequiredToRepair(requirement.getName())) {
+ log.debug("#repairTopologyTemplateCapName - Going to build the name for the requirement: ", requirement.getUniqueId());
+ buildSetReqName(componentCacheToRepair, requirement, instance, originGetter);
+ }
+ }
+
+ private static void updateAndAddCalculatedCapabilitiesProperties(String stringKey, MapPropertiesDataDefinition properties, MapListCapabilityDataDefinition calculatedCapabilities, MapCapabilityProperty newProps) {
+ String[] key = stringKey.split(ModelConverter.CAP_PROP_DELIM);
+ String capType = key[key.length - 2];
+ String capName = key[key.length - 1];
+ Optional<CapabilityDataDefinition> foundCapOpt = calculatedCapabilities.getMapToscaDataDefinition().get(capType)
+ .getListToscaDataDefinition().stream()
+ .filter(c -> StringUtils.isNotEmpty(c.getPreviousName()) && c.getPreviousName().equals(capName))
+ .findFirst();
+ foundCapOpt.ifPresent(capabilityDataDefinition -> key[key.length - 1] = capabilityDataDefinition.getName());
+ newProps.put(buildCaLCapPropKey(key), properties);
+ }
+
+ public static void revertNamesOfCalculatedCapabilitiesRequirements(TopologyTemplate toscaElement, String ownerId, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ Map<String, ToscaElement> componentCacheToRepair = new HashMap<>();
+ log.debug("#revertNamesOfCalculatedCapabilitiesRequirements");
+ revertCalculatedCapabilitiesPropertiesKeys(componentCacheToRepair, toscaElement, ownerId, originGetter);
+ revertCalculatedCapabilitiesNames(toscaElement, ownerId);
+ revertCalculatedRequirementsNames(componentCacheToRepair, toscaElement, ownerId, originGetter);
+ }
+
+ private static void revertCalculatedCapabilitiesPropertiesKeys(Map<String, ToscaElement> componentCacheToRepair, TopologyTemplate toscaElement, String ownerId, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ repairCapNames(componentCacheToRepair, toscaElement, ownerId, originGetter);
+ if (calCapPropertiesExist(toscaElement, ownerId)) {
+ MapCapabilityProperty newProps = new MapCapabilityProperty();
+ toscaElement.getCalculatedCapabilitiesProperties().get(ownerId)
+ .getMapToscaDataDefinition()
+ .forEach((k, v) -> revertAndAddCalculatedCapabilitiesProperties(k, v, toscaElement.getCalculatedCapabilities().get(ownerId), newProps));
+ if (MapUtils.isNotEmpty(newProps.getMapToscaDataDefinition())) {
+ toscaElement.getCalculatedCapabilitiesProperties().put(ownerId, newProps);
+ }
+ }
+ }
+
+ private static void revertCalculatedRequirementsNames(Map<String, ToscaElement> componentCacheToRepair, TopologyTemplate toscaElement, String ownerId, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ repairReqNames(componentCacheToRepair, toscaElement, ownerId, originGetter);
+ if (requirementsExist(toscaElement, ownerId)) {
+ toscaElement.getCalculatedRequirements().get(ownerId)
+ .getMapToscaDataDefinition().values().stream()
+ .flatMap(l -> l.getListToscaDataDefinition().stream())
+ .forEach(CapabilityRequirementNameResolver::revertReqNames);
+ }
+ }
+
+ private static void revertReqNames(RequirementDataDefinition requirement) {
+ if (StringUtils.isNotEmpty(requirement.getPreviousName())) {
+ requirement.setName(requirement.getPreviousName());
+ requirement.setPreviousName(requirement.getParentName());
+ }
+ }
+
+ private static void revertCalculatedCapabilitiesNames(TopologyTemplate toscaElement, String ownerId) {
+ if (capabilitiesExist(toscaElement, ownerId)) {
+ toscaElement.getCalculatedCapabilities().get(ownerId)
+ .getMapToscaDataDefinition().values().stream()
+ .flatMap(l -> l.getListToscaDataDefinition().stream())
+ .forEach(CapabilityRequirementNameResolver::revertCapNames);
+ }
+ }
+
+ private static void revertCapNames(CapabilityDataDefinition capability) {
+ if (StringUtils.isNotEmpty(capability.getPreviousName())) {
+ capability.setName(capability.getPreviousName());
+ capability.setPreviousName(capability.getParentName());
+ }
+ }
+
+ private static void revertAndAddCalculatedCapabilitiesProperties(String stringKey, MapPropertiesDataDefinition properties, MapListCapabilityDataDefinition calculatedCapabilities, MapCapabilityProperty newProps) {
+ String[] key = stringKey.split(ModelConverter.CAP_PROP_DELIM);
+ String capType = key[key.length - 2];
+ String capName = key[key.length - 1];
+ Optional<CapabilityDataDefinition> foundCapOpt = calculatedCapabilities.getMapToscaDataDefinition().get(capType)
+ .getListToscaDataDefinition().stream()
+ .filter(c -> c.getName().equals(capName) && StringUtils.isNotEmpty(c.getPreviousName()))
+ .findFirst();
+ foundCapOpt.ifPresent(capabilityDataDefinition -> key[key.length - 1] = capabilityDataDefinition.getPreviousName());
+ newProps.put(buildCaLCapPropKey(key), properties);
+ }
+
+ private static String buildCaLCapPropKey(String[] keyArray) {
+ StringBuilder key = new StringBuilder();
+ for (int i = 0; i < keyArray.length; ++i) {
+ key.append(keyArray[i]);
+ if (i < keyArray.length - 1) {
+ key.append(ModelConverter.CAP_PROP_DELIM);
+ }
+ }
+ return key.toString();
+ }
+
+ private static void buildSetCapName(Map<String, ToscaElement> componentsCache, CapabilityDataDefinition capability, ComponentInstanceDataDefinition instance, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ List<String> reducedPath = capability.getOwnerId() != null ? getReducedPathByOwner(capability.getPath(), capability.getOwnerId()) : getReducedPath(capability.getPath());
+ log.debug("reducedPath for ownerId {}, reducedPath {} ", capability.getOwnerId(), reducedPath);
+ reducedPath.remove(reducedPath.size() - 1);
+ ToscaElement originComponent = getOriginComponent(componentsCache, instance, originGetter);
+ String name = isRequiredToRepair(capability.getParentName()) ?
+ extractNameFromUniqueId(capability.getUniqueId()) : capability.getParentName();
+ StringBuilder repairedName = buildSubstitutedName(componentsCache, originComponent, reducedPath, originGetter);
+ log.debug("#buildSetCapName - The name for the capability was built: {}", repairedName);
+
+ capability.setName(repairedName.append(name).toString());
+ if (isRequiredToRepair(capability.getPreviousName())) {
+ capability.setPreviousName(capability.getName().substring(capability.getName().indexOf(PATH_DELIMITER) + 1));
+ }
+ if (isRequiredToRepair(capability.getParentName())) {
+ capability.setParentName(name);
+ }
+ }
+
+ private static void buildSetReqName(Map<String, ToscaElement> componentsCache, RequirementDataDefinition requirement, ComponentInstanceDataDefinition instance, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ List<String> reducedPath = requirement.getOwnerId() != null ? getReducedPathByOwner(requirement.getPath(), requirement.getOwnerId()) : getReducedPath(requirement.getPath());
+ log.debug("reducedPath for ownerId {}, reducedPath {} ", requirement.getOwnerId(), reducedPath);
+ reducedPath.remove(reducedPath.size() - 1);
+ ToscaElement originComponent = getOriginComponent(componentsCache, instance, originGetter);
+ String name = isRequiredToRepair(requirement.getParentName()) ?
+ extractNameFromUniqueId(requirement.getUniqueId()) : requirement.getParentName();
+
+ StringBuilder repairedName = buildSubstitutedName(componentsCache, originComponent, reducedPath, originGetter);
+ log.debug("#buildSetReqName - The name for the capability was built: ", repairedName);
+ requirement.setName(repairedName.append(name).toString());
+ if (isRequiredToRepair(requirement.getPreviousName())) {
+ requirement.setPreviousName(requirement.getName().substring(requirement.getName().indexOf(PATH_DELIMITER) + 1));
+ }
+ if (isRequiredToRepair(requirement.getParentName())) {
+ requirement.setParentName(name);
+ }
+ }
+
+ private static String extractNameFromUniqueId(String uniqueId) {
+ String[] uid = uniqueId.split("\\.");
+ return uid[uid.length - 1];
+ }
+
+ private static StringBuilder buildSubstitutedName(Map<String, ToscaElement> componentsCache, ToscaElement originComponent, List<String> path, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ StringBuilder substitutedName = new StringBuilder();
+ log.debug("#buildSubstitutedName");
+ if (isNotEmpty(path) && isTopologyTemplateNotCvfc(originComponent)) {
+ log.debug("#buildSubstitutedName");
+ List<String> reducedPath = getReducedPath(path);
+ Collections.reverse(reducedPath);
+ appendNameRecursively(componentsCache, originComponent, reducedPath.iterator(), substitutedName, originGetter);
+ }
+ return substitutedName;
+ }
+
+ private static boolean isTopologyTemplateNotCvfc(ToscaElement originComponent) {
+ return originComponent.getToscaType() == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE && originComponent.getResourceType() != ResourceTypeEnum.CVFC;
+ }
+
+ private static ToscaElement getOriginComponent(Map<String, ToscaElement> componentsCache, ComponentInstanceDataDefinition instance, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ if (componentsCache.containsKey(getActualComponentUid(instance))) {
+ return componentsCache.get(getActualComponentUid(instance));
+ }
+ ToscaElement origin = originGetter.apply(instance);
+ componentsCache.put(origin.getUniqueId(), origin);
+ return origin;
+ }
+
+ public static String getActualComponentUid(ComponentInstanceDataDefinition instance) {
+ return instance.getIsProxy() ? instance.getSourceModelUid() : instance.getComponentUid();
+ }
+
+ private static List<String> getReducedPath(List<String> path) {
+ return path.stream().distinct().collect(Collectors.toList());
+ }
+
+ private static void appendNameRecursively(Map<String, ToscaElement> componentsCache, ToscaElement originComponent, Iterator<String> instanceIdIter, StringBuilder substitutedName, Function<ComponentInstanceDataDefinition, ToscaElement> originGetter) {
+ log.debug("#appendNameRecursively");
+ if (isTopologyTemplateNotCvfc(originComponent)
+ && MapUtils.isNotEmpty(((TopologyTemplate) originComponent).getComponentInstances()) && instanceIdIter.hasNext()) {
+
+ String ownerId = instanceIdIter.next();
+ Optional<ComponentInstanceDataDefinition> instanceOpt = ((TopologyTemplate) originComponent).getComponentInstances().values().stream().filter(i -> i.getUniqueId().equals(ownerId)).findFirst();
+ if (instanceOpt.isPresent()) {
+ substitutedName.append(instanceOpt.get().getNormalizedName()).append(PATH_DELIMITER);
+ ToscaElement getOriginRes = getOriginComponent(componentsCache, instanceOpt.get(), originGetter);
+ appendNameRecursively(componentsCache, getOriginRes, instanceIdIter, substitutedName, originGetter);
+ } else if (MapUtils.isNotEmpty(((TopologyTemplate) originComponent).getGroups())) {
+ Optional<GroupDataDefinition> groupOpt = ((TopologyTemplate) originComponent).getGroups().values().stream().filter(g -> g.getUniqueId().equals(ownerId)).findFirst();
+ groupOpt.ifPresent(groupDataDefinition -> substitutedName.append(groupDataDefinition.getName()).append(PATH_DELIMITER));
+ } else {
+ log.debug("Failed to find an capability owner with uniqueId {} on a component with uniqueId {}", ownerId, originComponent.getUniqueId());
+ }
+ }
+ }
+
+ private static List<String> getReducedPathByOwner(List<String> path, String ownerId) {
+ log.debug("ownerId {}, path {} ", ownerId, path);
+ if (CollectionUtils.isEmpty(path)) {
+ log.debug("cannot perform reduce by owner, path to component is empty");
+ return path;
+ }
+ if (isBlank(ownerId)) {
+ log.debug("cannot perform reduce by owner, component owner is empty");
+ return path;
+ }
+ //reduce by owner
+ Map map = path.stream().collect(Collectors.toMap(it -> dropLast(it, PATH_DELIMITER), Function.identity(), (a, b) -> a.endsWith(ownerId) ? a : b));
+ //reduce list&duplicates and preserve order
+ return path.stream().distinct().filter(it -> map.values().contains(it)).collect(Collectors.toList());
+ }
+
+ private static String dropLast(String path, String delimiter) {
+ if (isBlank(path) || isBlank(delimiter)) {
+ return path;
+ }
+ return path.substring(0, path.lastIndexOf(delimiter));
+ }
+}