diff options
author | JvD_Ericsson <jeff.van.dam@est.tech> | 2023-05-04 13:27:26 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-05-18 10:41:07 +0000 |
commit | bc7dd3ad94acace55a2910abc22cc5cb64e0862d (patch) | |
tree | 43948e332fa27ea7cecc70ba19388bb63e1069d0 /common-be/src/main | |
parent | 38eaf2ddd678a837e2bfed25d5b4b45d72fce338 (diff) |
UI support for default custom function names with get_input structure
Issue-ID: SDC-4493
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: Iba3eda9bb5d57aabbe86045b6150564e17a0ff3e
Diffstat (limited to 'common-be/src/main')
2 files changed, 47 insertions, 5 deletions
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaCustomFunction.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaCustomFunction.java index 3f0c4fa8a5..981d4ecf8e 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaCustomFunction.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaCustomFunction.java @@ -22,19 +22,20 @@ package org.openecomp.sdc.be.datatypes.elements; import com.google.gson.Gson; -import lombok.Getter; -import lombok.Setter; - import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import lombok.Getter; +import lombok.Setter; @Getter @Setter public class ToscaCustomFunction implements ToscaFunction, ToscaFunctionParameter { private String name; + private ToscaFunctionType toscaFunctionType; private List<ToscaFunctionParameter> parameters = new ArrayList<>(); @Override @@ -49,9 +50,18 @@ public class ToscaCustomFunction implements ToscaFunction, ToscaFunctionParamete @Override public Object getJsonObjectValue() { + if (ToscaFunctionType.GET_INPUT.equals(this.toscaFunctionType)) { + Map<String, Object> getInput = parameters.stream().collect(Collectors.toMap( + input -> "$" + name, + input -> { + Map<String, Object> inputMap = (Map<String, Object>) input.getJsonObjectValue(); + return inputMap.get(ToscaFunctionType.GET_INPUT.getName()); + })); + return getInput; + } return Map.of( - "$" + name, - parameters.stream().map(ToscaFunctionParameter::getJsonObjectValue).collect(Collectors.toList()) + "$" + name, + parameters.stream().map(ToscaFunctionParameter::getJsonObjectValue).collect(Collectors.toList()) ); } diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java index 2e57a4158a..de8e30b897 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java @@ -29,7 +29,10 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Optional; 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.enums.PropertySource; import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType; import org.slf4j.Logger; @@ -178,11 +181,40 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction throw context.instantiationException(List.class, "Expecting a string for the 'name' entry"); } toscaCustomFunction.setName(name); + toscaCustomFunction.setToscaFunctionType(getCustomFunctionType(name)); List<ToscaFunctionParameter> functionParameterList = getParameters(customFunctionJsonNode, context); toscaCustomFunction.setParameters(functionParameterList); + if (ToscaFunctionType.GET_INPUT.equals(toscaCustomFunction.getToscaFunctionType())) { + validateGetInput(toscaCustomFunction, context); + } return toscaCustomFunction; } + private ToscaFunctionType getCustomFunctionType(String name) { + List<Configuration.CustomToscaFunction> customFunctions = + ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultCustomToscaFunctions(); + if (customFunctions.isEmpty()) { + return ToscaFunctionType.CUSTOM; + } + Optional<Configuration.CustomToscaFunction> 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(); + } + + private void validateGetInput(ToscaCustomFunction toscaCustomFunction, final DeserializationContext context) throws IOException { + List<ToscaFunctionParameter> functionParameterList = toscaCustomFunction.getParameters(); + if (functionParameterList.size() != 1) { + throw context.instantiationException(List.class, "Custom GET_INPUT function must contain one GET_INPUT parameter"); + } + ToscaFunctionParameter parameter = functionParameterList.get(0); + if (!ToscaFunctionType.GET_INPUT.equals(parameter.getType())) { + throw context.instantiationException(List.class, "Custom GET_INPUT function must contain a GET_INPUT parameter"); + } + } + private List<ToscaFunctionParameter> getParameters(final JsonNode functionJsonNode, final DeserializationContext context) throws IOException { final List<ToscaFunctionParameter> functionParameterList = new ArrayList<>(); final JsonNode parametersNode = functionJsonNode.get("parameters"); |