Fix use of Optional in ComponentInstanceInputsMergeBL 58/126558/5
authorfranciscovila <javier.paradela.vila@est.tech>
Tue, 11 Jan 2022 12:29:08 +0000 (12:29 +0000)
committerMichael Morris <michael.morris@est.tech>
Thu, 13 Jan 2022 09:29:35 +0000 (09:29 +0000)
Issue-ID: SDC-3830
Signed-off-by: franciscovila <javier.paradela.vila@est.tech>
Change-Id: I3504f3fdb449e2b236501eaa31dbe4e2cbda1247

catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceInputsMergeBL.java

index d8b5020..020c8a9 100644 (file)
@@ -25,6 +25,7 @@ import fj.data.Either;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.stream.Collectors;
 import org.openecomp.sdc.be.components.merge.VspComponentsMergeCommand;
 import org.openecomp.sdc.be.components.merge.property.DataDefinitionsValuesMergingBusinessLogic;
@@ -111,10 +112,13 @@ public class ComponentInstanceInputsMergeBL implements VspComponentsMergeCommand
 
     private void mergeOldInstanceInputsValues(Component oldComponent, Component newComponent, String instanceId,
                                               List<ComponentInstanceInput> instInputs) {
-        ComponentInstance currentCompInstance = newComponent.getComponentInstanceById(instanceId).get();
-        List<ComponentInstanceInput> oldInstInputs =
-            oldComponent == null ? Collections.emptyList() : oldComponent.safeGetComponentInstanceInputsByName(currentCompInstance.getName());
-        List<InputDefinition> oldInputs = oldComponent == null ? Collections.emptyList() : oldComponent.getInputs();
-        propertyValuesMergingBusinessLogic.mergeInstanceDataDefinitions(oldInstInputs, oldInputs, instInputs, newComponent.getInputs());
+        Optional<ComponentInstance> oCurrentCompInstance = newComponent.getComponentInstanceById(instanceId);
+        if (oCurrentCompInstance.isPresent()) {
+            ComponentInstance currentCompInstance = oCurrentCompInstance.get();
+            List<ComponentInstanceInput> oldInstInputs =
+                    oldComponent == null ? Collections.emptyList() : oldComponent.safeGetComponentInstanceInputsByName(currentCompInstance.getName());
+            List<InputDefinition> oldInputs = oldComponent == null ? Collections.emptyList() : oldComponent.getInputs();
+            propertyValuesMergingBusinessLogic.mergeInstanceDataDefinitions(oldInstInputs, oldInputs, instInputs, newComponent.getInputs());
+        }
     }
 }