Fix use of Optional in ToscaElementOperation 01/126601/1
authorfranciscovila <javier.paradela.vila@est.tech>
Thu, 13 Jan 2022 19:31:25 +0000 (19:31 +0000)
committerFrancisco Javier Paradela Vila <javier.paradela.vila@est.tech>
Thu, 13 Jan 2022 19:36:15 +0000 (19:36 +0000)
Checking the Optionals are present before getting
their values in the ToscaElementOperation class

Issue-ID: SDC-3831
Signed-off-by: franciscovila <javier.paradela.vila@est.tech>
Change-Id: I411f7d70a0016f0632e6e0daa315dfa70ffe8de9

catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java

index 2ff3b49..9e9b944 100644 (file)
@@ -1232,9 +1232,14 @@ public abstract class ToscaElementOperation extends BaseOperation {
     }
 
     private void generateNewToscaFileName(String componentType, String componentName, ArtifactDataDefinition artifactInfo) {
-        Map<String, Object> getConfig = (Map<String, Object>) ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts()
-            .entrySet().stream().filter(p -> p.getKey().equalsIgnoreCase(artifactInfo.getArtifactLabel())).findAny().get().getValue();
-        artifactInfo.setArtifactName(componentType + "-" + componentName + getConfig.get("artifactName"));
+        Optional<Entry<String, Object>> oConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts()
+                .entrySet().stream().filter(p -> p.getKey().equalsIgnoreCase(artifactInfo.getArtifactLabel())).findAny();
+        if (oConfig.isPresent()) {
+            artifactInfo.setArtifactName(componentType + "-" + componentName + ((Map<String, Object>)oConfig.get().getValue()).get("artifactName"));
+        }
+        else {
+            artifactInfo.setArtifactName(componentType + "-" + componentName);
+        }
     }
 
     protected <T extends ToscaElement> StorageOperationStatus validateResourceCategory(T toscaElementToUpdate, GraphVertex elementV) {