From 9c057c26f14de77dff432403941322edaca7ea4e Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Tue, 31 Jan 2023 22:42:55 +0000 Subject: Fix inconsistencies in interface property removal Signed-off-by: MichaelMorris Issue-ID: SDC-4377 Change-Id: Iaeebddfbc7c9e2d7249040db031ccda93746e9b3 --- .../be/components/impl/ResourceBusinessLogic.java | 4 +-- .../be/components/impl/ResourceImportManager.java | 32 ++++++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) (limited to 'catalog-be/src') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 2f71959d9d..1d0be1f4c1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -3643,9 +3643,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (MapUtils.isEmpty(newResource.getToscaArtifacts())) { setToscaArtifactsPlaceHolders(newResource, user); } - if (MapUtils.isEmpty(newResource.getInterfaces())) { - newResource.setInterfaces(oldResource.getInterfaces()); - } + if (CollectionUtils.isEmpty(newResource.getAttributes())) { newResource.setAttributes(oldResource.getAttributes()); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java index 076dd50655..7710a4878b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java @@ -27,6 +27,7 @@ import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementO import fj.data.Either; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Comparator; import java.util.EnumMap; import java.util.HashMap; @@ -453,9 +454,10 @@ public class ResourceImportManager { private void setInterfaceLifecycle(Map toscaJson, Resource resource, Either existingResource) { final Either, ResultStatusEnum> toscaInterfaces = ImportUtils .findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.INTERFACES); + final Map moduleInterfaces = new HashMap<>(); + final Map map; if (toscaInterfaces.isLeft()) { - final Map moduleInterfaces = new HashMap<>(); - final Map map = toscaInterfaces.left().value(); + map = toscaInterfaces.left().value(); for (final Entry interfaceNameValue : map.entrySet()) { final Either eitherInterface = createModuleInterface(interfaceNameValue.getValue(), resource.getModel()); @@ -466,20 +468,22 @@ public class ResourceImportManager { moduleInterfaces.put(interfaceDefinition.getType(), interfaceDefinition); } } - if (existingResource.isLeft()) { - final Map userCreatedInterfaceDefinitions = - existingResource.left().value().getInterfaces().entrySet().stream() - .filter(i -> i.getValue().isUserCreated()) - .filter(i -> !map.containsKey(i.getValue().getType())) - .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); - if (MapUtils.isNotEmpty(userCreatedInterfaceDefinitions)) { - moduleInterfaces.putAll(userCreatedInterfaceDefinitions); - } + } else { + map = Collections.emptyMap(); + } + if (existingResource.isLeft()) { + final Map userCreatedInterfaceDefinitions = + existingResource.left().value().getInterfaces().entrySet().stream() + .filter(i -> i.getValue().isUserCreated()) + .filter(i -> !map.containsKey(i.getValue().getType())) + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + if (MapUtils.isNotEmpty(userCreatedInterfaceDefinitions)) { + moduleInterfaces.putAll(userCreatedInterfaceDefinitions); } + } - if (MapUtils.isNotEmpty(moduleInterfaces)) { - resource.setInterfaces(moduleInterfaces); - } + if (MapUtils.isNotEmpty(moduleInterfaces)) { + resource.setInterfaces(moduleInterfaces); } } -- cgit 1.2.3-korg