From 778d5b0650f4a3b7c6760ee1d4d67cee653c8664 Mon Sep 17 00:00:00 2001 From: vasraz Date: Tue, 25 Jul 2023 16:59:52 +0100 Subject: [PATCH] Fix 'Unable to drag a VFC on to composition if an existing VFC instance has the same name'-bug Signed-off-by: Vasyl Razinkov Change-Id: I8140a2908fc0bfefa3724fdc9eb4697d8fb6490e Issue-ID: SDC-4583 --- .../operations/ToscaOperationFacade.java | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java index 0ed0a7b79d..d654f23fbb 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java @@ -22,6 +22,8 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.operations; import com.vdurmont.semver4j.Semver; import com.vdurmont.semver4j.Semver.SemverType; import fj.data.Either; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -785,7 +787,7 @@ public class ToscaOperationFacade { return updateToscaElement(componentToUpdate, new ComponentParametersView()); } - public Either updateToscaElement(T componentToUpdate, ComponentParametersView filterResult) { + private Either updateToscaElement(T componentToUpdate, ComponentParametersView filterResult) { String componentId = componentToUpdate.getUniqueId(); Either getVertexEither = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll); if (getVertexEither.isRight()) { @@ -1303,14 +1305,22 @@ public class ToscaOperationFacade { /** * @return max counter of component instance Id's, null if not found */ - private Integer getMaxCounterFromNamesAndIds(Component containerComponent, String normalizedName) { - List countersInNames = containerComponent.getComponentInstances().stream() + private Integer getMaxCounterFromNamesAndIds(final Component containerComponent, final String normalizedName) { + final Pattern COUNTER_PATTERN = Pattern.compile(normalizedName + "[\\s_:-]?\\d+$"); + final List countersInNames = containerComponent.getComponentInstances().stream() .filter(ci -> ci.getNormalizedName() != null && ci.getNormalizedName().startsWith(normalizedName)) - .map(ci -> ci.getNormalizedName().split(normalizedName)[1].replaceAll("\\D", "")).collect(Collectors.toList()); - List countersInIds = containerComponent.getComponentInstances().stream() + .filter(ci -> !ci.getNormalizedName().equals(normalizedName)) + .map(ComponentInstance::getNormalizedName) + .map(COUNTER_PATTERN::matcher).filter(Matcher::find).map(matcher -> matcher.group(0)) + .map(nn -> nn.replaceAll("\\D", "")) + .collect(Collectors.toList()); + final List countersInIds = containerComponent.getComponentInstances().stream() .filter(ci -> ci.getUniqueId() != null && ci.getUniqueId().contains(normalizedName)) - .map(ci -> ci.getUniqueId().split(normalizedName)[1].replaceAll("\\D", "")).collect(Collectors.toList()); - List namesAndIdsList = new ArrayList<>(countersInNames); + .map(ComponentInstance::getUniqueId) + .map(COUNTER_PATTERN::matcher).filter(Matcher::find).map(matcher -> matcher.group(0)) + .map(nn -> nn.replaceAll("\\D", "")) + .collect(Collectors.toList()); + final List namesAndIdsList = new ArrayList<>(countersInNames); namesAndIdsList.addAll(countersInIds); return getMaxInteger(namesAndIdsList); } -- 2.16.6