From bc7dd3ad94acace55a2910abc22cc5cb64e0862d Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Thu, 4 May 2023 13:27:26 +0100 Subject: UI support for default custom function names with get_input structure Issue-ID: SDC-4493 Signed-off-by: JvD_Ericsson Change-Id: Iba3eda9bb5d57aabbe86045b6150564e17a0ff3e --- .../csar/ToscaFunctionYamlParsingHandler.java | 44 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'catalog-be/src/main/java/org') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java index 0b9432b3a1..0651e3504e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.be.components.csar; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -28,6 +29,8 @@ import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; +import org.openecomp.sdc.be.config.Configuration; +import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.datatypes.elements.CustomYamlFunction; import org.openecomp.sdc.be.datatypes.elements.ToscaConcatFunction; import org.openecomp.sdc.be.datatypes.elements.ToscaCustomFunction; @@ -74,7 +77,7 @@ public class ToscaFunctionYamlParsingHandler { List propertySourceIndex = functionParameters.subList(1, functionParameters.size()); String toscaIndexValue = propertySourceIndex.get((propertySourceIndex.size() - 1)); if (propertySourceIndex.size() > 1 && (toscaIndexValue.equalsIgnoreCase("INDEX") || StringUtils.isNumeric(toscaIndexValue))) { - toscaGetFunction.setPropertyPathFromSource(propertySourceIndex.subList(0,(propertySourceIndex.size() - 1))); + toscaGetFunction.setPropertyPathFromSource(propertySourceIndex.subList(0, (propertySourceIndex.size() - 1))); toscaGetFunction.setToscaIndex(toscaIndexValue); } else { toscaGetFunction.setPropertyPathFromSource(propertySourceIndex); @@ -105,7 +108,7 @@ public class ToscaFunctionYamlParsingHandler { } String toscaIndexValue = functionParameters.get((functionParameters.size() - 1)); if (functionParameters.size() > 1 && (toscaIndexValue.equalsIgnoreCase("INDEX") || StringUtils.isNumeric(toscaIndexValue))) { - toscaGetFunction.setPropertyPathFromSource(functionParameters.subList(0,(functionParameters.size() - 1))); + toscaGetFunction.setPropertyPathFromSource(functionParameters.subList(0, (functionParameters.size() - 1))); toscaGetFunction.setToscaIndex(toscaIndexValue); } else { toscaGetFunction.setPropertyPathFromSource(functionParameters); @@ -155,6 +158,14 @@ public class ToscaFunctionYamlParsingHandler { final ToscaCustomFunction toscaCustomFunction = new ToscaCustomFunction(); toscaCustomFunction.setName(functionType.substring(1)); final Object functionValueObj = toscaFunctionPropertyValueMap.get(functionType); + toscaCustomFunction.setToscaFunctionType(getCustomFunctionType(toscaCustomFunction.getName())); + if (ToscaFunctionType.GET_INPUT.equals(toscaCustomFunction.getToscaFunctionType())) { + return handelCustomFunctionGetInputType(toscaCustomFunction, functionValueObj); + } + return handelCustomFunctionCustomType(toscaCustomFunction, functionValueObj); + } + + private Optional handelCustomFunctionCustomType(ToscaCustomFunction toscaCustomFunction, Object functionValueObj) { if (!(functionValueObj instanceof List)) { return Optional.empty(); } @@ -181,6 +192,35 @@ public class ToscaFunctionYamlParsingHandler { return Optional.of(toscaCustomFunction); } + private Optional handelCustomFunctionGetInputType(ToscaCustomFunction toscaCustomFunction, Object functionValueObj) { + if (!(functionValueObj instanceof String)) { + return Optional.empty(); + } + final String parameter = (String) functionValueObj; + Map parameterMap = new HashMap<>(); + parameterMap.put(ToscaFunctionType.GET_INPUT.getName(), parameter); + buildToscaFunctionBasedOnPropertyValue(parameterMap).ifPresent(toscaFunction -> { + if (toscaFunction instanceof ToscaFunctionParameter) { + toscaCustomFunction.addParameter((ToscaFunctionParameter) toscaFunction); + } + }); + return Optional.of(toscaCustomFunction); + } + + private ToscaFunctionType getCustomFunctionType(String name) { + List customFunctions = + ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultCustomToscaFunctions(); + if (customFunctions.isEmpty()) { + return ToscaFunctionType.CUSTOM; + } + Optional optionalFunc = customFunctions.stream().filter(func -> func.getName().equals(name)).findFirst(); + if (optionalFunc.isEmpty()) { + return ToscaFunctionType.CUSTOM; + } + String type = optionalFunc.get().getType(); + return ToscaFunctionType.findType(type).get(); + } + /** * Checks if the property value is a supported TOSCA function. * -- cgit 1.2.3-korg