summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2023-05-04 13:27:26 +0100
committerMichael Morris <michael.morris@est.tech>2023-05-18 10:41:07 +0000
commitbc7dd3ad94acace55a2910abc22cc5cb64e0862d (patch)
tree43948e332fa27ea7cecc70ba19388bb63e1069d0 /catalog-be/src/main/java
parent38eaf2ddd678a837e2bfed25d5b4b45d72fce338 (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 'catalog-be/src/main/java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java44
1 files changed, 42 insertions, 2 deletions
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<String> 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<ToscaFunction> 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<ToscaFunction> handelCustomFunctionGetInputType(ToscaCustomFunction toscaCustomFunction, Object functionValueObj) {
+ if (!(functionValueObj instanceof String)) {
+ return Optional.empty();
+ }
+ final String parameter = (String) functionValueObj;
+ Map<String, Object> 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<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();
+ }
+
/**
* Checks if the property value is a supported TOSCA function.
*