From 7a98ee137b17a808635b06d72955e01ac84fe55b Mon Sep 17 00:00:00 2001 From: franciscovila Date: Mon, 24 Jan 2022 10:10:40 +0000 Subject: Fix use of Optional in TranslatorHeatToToscaPropertyConverter Checking the Optionals are present before getting their values in the TranslatorHeatToToscaPropertyConverter class Issue-ID: SDC-3834 Signed-off-by: franciscovila Change-Id: I92f9153adea8be4225c0a181fd31b9f7090bde96 --- .../mapping/TranslatorHeatToToscaPropertyConverter.java | 8 ++++++-- 1 file changed, 6 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/mapping/TranslatorHeatToToscaPropertyConverter.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaPropertyConverter.java index b9cad2f474..7b2a93c18d 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaPropertyConverter.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaPropertyConverter.java @@ -25,12 +25,15 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; + import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.onap.sdc.tosca.datatypes.model.Template; import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate; import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext; import org.openecomp.sdc.translator.services.heattotosca.ConfigConstants; import org.openecomp.sdc.translator.services.heattotosca.Constants; +import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslation; import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslationFactory; import org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator; @@ -113,11 +116,12 @@ public class TranslatorHeatToToscaPropertyConverter { Template template, TranslationContext context) { if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) { Map.Entry functionMapEntry = (Map.Entry) ((Map) propertyValue).entrySet().iterator().next(); - if (FunctionTranslationFactory.getInstance(functionMapEntry.getKey()).isPresent()) { + Optional optFunctionTranslation = FunctionTranslationFactory.getInstance(functionMapEntry.getKey()); + if (optFunctionTranslation.isPresent()) { FunctionTranslator functionTranslator = new FunctionTranslator( getFunctionTranslateTo(serviceTemplate, resourceId, heatFileName, heatOrchestrationTemplate, context), propertyName, functionMapEntry.getValue(), template); - return FunctionTranslationFactory.getInstance(functionMapEntry.getKey()).get().translateFunction(functionTranslator); + return optFunctionTranslation.get().translateFunction(functionTranslator); } Map propertyValueMap = new HashMap<>(); for (Map.Entry entry : ((Map) propertyValue).entrySet()) { -- cgit 1.2.3-korg