Fix inconsistencies in interface property removal 80/133180/3
authorMichaelMorris <michael.morris@est.tech>
Tue, 31 Jan 2023 22:42:55 +0000 (22:42 +0000)
committerVasyl Razinkov <vasyl.razinkov@est.tech>
Fri, 10 Feb 2023 00:12:39 +0000 (00:12 +0000)
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-4377
Change-Id: Iaeebddfbc7c9e2d7249040db031ccda93746e9b3

catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java

index 2f71959..1d0be1f 100644 (file)
@@ -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());
             }
index 076dd50..7710a48 100644 (file)
@@ -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<String, Object> toscaJson, Resource resource, Either<Resource, StorageOperationStatus> existingResource) {
         final Either<Map<String, Object>, ResultStatusEnum> toscaInterfaces = ImportUtils
             .findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.INTERFACES);
+        final Map<String, InterfaceDefinition> moduleInterfaces = new HashMap<>();
+        final Map<String, Object> map;
         if (toscaInterfaces.isLeft()) {
-            final Map<String, InterfaceDefinition> moduleInterfaces = new HashMap<>();
-            final Map<String, Object> map = toscaInterfaces.left().value();
+            map = toscaInterfaces.left().value();
             for (final Entry<String, Object> interfaceNameValue : map.entrySet()) {
                 final Either<InterfaceDefinition, ResultStatusEnum> eitherInterface = createModuleInterface(interfaceNameValue.getValue(),
                     resource.getModel());
@@ -466,20 +468,22 @@ public class ResourceImportManager {
                     moduleInterfaces.put(interfaceDefinition.getType(), interfaceDefinition);
                 }
             }
-            if (existingResource.isLeft()) {
-                final Map<String, InterfaceDefinition> 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<String, InterfaceDefinition> 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);
         }
     }