diff options
author | 2021-12-22 12:41:19 +0000 | |
---|---|---|
committer | 2022-01-05 11:14:12 +0000 | |
commit | a811119a9c380bf01f482f08828a9a4b7a8dff6e (patch) | |
tree | 2628f4a185b9140f705c33f9aedbddf318c8aa82 /openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java | |
parent | a8a5863cfb100d4cbbecd0aefe5512234e101d97 (diff) |
Fix use of Optional in HeatToToscaUtil
Checking the Optionals are present before getting their values in the
HeatToToscaUtil class. Adding a new test class for this purpose
Issue-ID: SDC-3018
Signed-off-by: franciscovila <javier.paradela.vila@est.tech>
Change-Id: I9fbfbb6f9ebff1f0259b9c9113da6730bfa01cfa
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java')
-rw-r--r-- | openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java index b7f1ff2cb9..6864aafffc 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java @@ -360,7 +360,10 @@ public class HeatToToscaUtil { if (FunctionTranslationFactory.getInstance(entry.getKey()).isPresent()) { FunctionTranslator functionTranslator = new FunctionTranslator( getFunctionTranslateTo(null, null, heatFileName, heatOrchestrationTemplate, context), null, entry.getValue(), null); - translatedId = FunctionTranslationFactory.getInstance(entry.getKey()).get().translateFunction(functionTranslator); + Optional<FunctionTranslation> optionalFunctionTranslation = FunctionTranslationFactory.getInstance(entry.getKey()); + if (optionalFunctionTranslation.isPresent()) { + translatedId = optionalFunctionTranslation.get().translateFunction(functionTranslator); + } if (translatedId instanceof String && !new FunctionTranslator().isResourceSupported((String) translatedId)) { translatedId = null; } @@ -615,7 +618,10 @@ public class HeatToToscaUtil { * @return true if the resource represents a VFC and false otherwise. */ public static boolean isNestedVfcResource(Resource resource, TranslationContext context) { - Optional<String> nestedHeatFileName = HeatToToscaUtil.getNestedHeatFileName(resource); + Optional<String> nestedHeatFileName = getNestedHeatFileName(resource); + if (nestedHeatFileName.isEmpty()) { + return false; + } HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil() .yamlToObject(context.getFileContentAsStream(nestedHeatFileName.get()), HeatOrchestrationTemplate.class); Map<String, Resource> resources = nestedHeatOrchestrationTemplate.getResources(); |