From 4898da84c488cd51f872be95be5512f1fc6273a3 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Fri, 16 Jun 2023 13:17:01 +0100 Subject: Fix issue changing sub. mapping node version Signed-off-by: MichaelMorris Issue-ID: SDC-4539 Change-Id: I04f23a41971c173ae29be82556cf321735232236 --- .../be/components/impl/ServiceBusinessLogic.java | 56 ++++++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-) (limited to 'catalog-be/src') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java index a9014b4b21..cacbd1369d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java @@ -46,6 +46,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -1242,21 +1243,56 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { if (!StringUtils.equals(currentService.getDerivedFromGenericType(), serviceUpdate.getDerivedFromGenericType())) { return currentProps.stream().map(PropertyDefinition::getName).collect(Collectors.toList()); } - List updatedPropNames = updatedProps.stream().map(PropertyDefinition::getName).collect(Collectors.toList()); - List propNamesToBeRemoved = currentProps.stream().map(PropertyDefinition::getName).collect(Collectors.toList()); - propNamesToBeRemoved.removeIf(updatedPropNames::contains); + + Map currentPropsMap = currentProps.stream().collect(Collectors.toMap(prop -> prop.getName(), prop -> prop)); + Map updatedPropsMap = updatedProps.stream().collect(Collectors.toMap(prop -> prop.getName(), prop -> prop)); + + List propNamesToBeRemoved = new ArrayList<>(); + for (String currentPropertyName: currentPropsMap.keySet()) { + if (updatedPropsMap.containsKey(currentPropertyName)) { + if (!haveSameType(currentPropsMap.get(currentPropertyName), updatedPropsMap.get(currentPropertyName))) { + propNamesToBeRemoved.add(currentPropertyName); + } + } else { + propNamesToBeRemoved.add(currentPropertyName); + } + } + return propNamesToBeRemoved; } - + + private boolean haveSameType(final PropertyDefinition property1, final PropertyDefinition property2){ + if (property1.getType().equals("list")) { + return property2.getType().equals("list") && property1.getSchema().equals(property2.getSchema()); + } + if (property1.getType().equals("map")) { + return property2.getType().equals("map") && property1.getSchema().equals(property2.getSchema()); + } + return property1.getType().equals(property2.getType()); + } + private List getSubstitutionNodePropertiesToBeAdded(Service currentService, Service serviceUpdate) { - List currentProps = ListUtils.emptyIfNull(fetchDerivedFromGenericType(currentService, null).getProperties()); - List updatedProps = ListUtils.emptyIfNull(fetchDerivedFromGenericType(serviceUpdate, null).getProperties()); + List propsInCurrentVersion = ListUtils.emptyIfNull(fetchDerivedFromGenericType(currentService, null).getProperties()); + List propsInUpdatedVersion = ListUtils.emptyIfNull(fetchDerivedFromGenericType(serviceUpdate, null).getProperties()); if (!StringUtils.equals(currentService.getDerivedFromGenericType(), serviceUpdate.getDerivedFromGenericType())) { - return updatedProps; + return propsInUpdatedVersion; + } + + Map mapOfPropsInCurrentVersion = propsInCurrentVersion.stream().collect(Collectors.toMap(prop -> prop.getName(), prop -> prop)); + Map mapOfPropsInUpdatedVersion = propsInUpdatedVersion.stream().collect(Collectors.toMap(prop -> prop.getName(), prop -> prop)); + + List propsToBeAdded = new ArrayList<>(); + for (Entry propertyInUpdatedVersion: mapOfPropsInUpdatedVersion.entrySet()) { + if (mapOfPropsInCurrentVersion.containsKey(propertyInUpdatedVersion.getKey())) { + if (!haveSameType(mapOfPropsInCurrentVersion.get(propertyInUpdatedVersion.getKey()), propertyInUpdatedVersion.getValue())) { + propsToBeAdded.add(propertyInUpdatedVersion.getValue()); + } + } else { + propsToBeAdded.add(propertyInUpdatedVersion.getValue()); + } } - Set currentPropNames = currentProps.stream().map(PropertyDefinition::getName).collect(Collectors.toSet()); - updatedProps.removeIf(prop -> currentPropNames.contains(prop.getName())); - return updatedProps; + + return propsToBeAdded; } -- cgit 1.2.3-korg