Custom tosca functions with valid_values and in_range operators not showing properly
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / utils / PropertyFilterConstraintDataDefinitionHelper.java
index 1f7459c..fa9e4d5 100644 (file)
@@ -67,10 +67,25 @@ public class PropertyFilterConstraintDataDefinitionHelper {
         final Optional<ToscaFunction> toscaFunction = createToscaFunctionFromLegacyConstraintValue(valueYaml);
         if (toscaFunction.isPresent()) {
             propertyFilterConstraint.setValue(toscaFunction.get());
-        } else {
+            propertyFilterConstraint.setValueType(detectValueType(valueYaml));
+        }
+        else {
             propertyFilterConstraint.setValue(valueYaml);
+            if (valueYaml instanceof List) {
+                List<ToscaFunction> listToscaFunction = new ArrayList<>();
+                ((List<?>) valueYaml).stream().forEach(val -> {
+                    final Optional<ToscaFunction> optToscaFunctionLst = createToscaFunctionFromLegacyConstraintValue(val);
+                    if (optToscaFunctionLst.isPresent()) {
+                        listToscaFunction.add(optToscaFunctionLst.get());
+                    }
+                });
+                propertyFilterConstraint.setValue(listToscaFunction);
+                propertyFilterConstraint.setValueType(FilterValueType.SEVERAL);
+            }
+            else {
+                propertyFilterConstraint.setValueType(detectValueType(valueYaml));
+            }
         }
-        propertyFilterConstraint.setValueType(detectValueType(valueYaml));
         propertyFilterConstraint.setTargetType(PropertyFilterTargetType.PROPERTY);
         return propertyFilterConstraint;
     }
@@ -90,9 +105,7 @@ public class PropertyFilterConstraintDataDefinitionHelper {
         }
         ToscaFunctionType toscaFunctionType = ToscaFunctionType.findType((String) toscaFunctionTypeObject).orElse(null);
         if (toscaFunctionType == null) {
-            if (((String) toscaFunctionTypeObject).equalsIgnoreCase("$get_input_ext") ||
-                ((String) toscaFunctionTypeObject).equalsIgnoreCase("$juel") ||
-                ((String) toscaFunctionTypeObject).equalsIgnoreCase("$other")) {
+            if (((String) toscaFunctionTypeObject).startsWith("$")) {
                 toscaFunctionType = ToscaFunctionType.CUSTOM;
             }
             else {
@@ -509,6 +522,26 @@ public class PropertyFilterConstraintDataDefinitionHelper {
                 return FilterValueType.CUSTOM;
             }
         }
+        else if (value instanceof List) {
+            final Map<?, ?> valueAsMap = (Map<?, ?>) ((List<?>) value).get(0);
+            if (valueAsMap.containsKey(ToscaFunctionType.CONCAT.getName())) {
+                return FilterValueType.CONCAT;
+            }
+            if (valueAsMap.containsKey(ToscaFunctionType.GET_ATTRIBUTE.getName())) {
+                return FilterValueType.GET_ATTRIBUTE;
+            }
+            if (valueAsMap.containsKey(ToscaFunctionType.GET_PROPERTY.getName())) {
+                return FilterValueType.GET_PROPERTY;
+            }
+            if (valueAsMap.containsKey(ToscaFunctionType.GET_INPUT.getName())) {
+                return FilterValueType.GET_INPUT;
+            }
+            if (valueAsMap.containsKey("$get_input_ext") ||
+                valueAsMap.containsKey("$juel") ||
+                valueAsMap.containsKey("$other")) {
+                return FilterValueType.CUSTOM;
+            }
+        }
         return FilterValueType.STATIC;
     }