aboutsummaryrefslogtreecommitdiffstats
path: root/common-be
diff options
context:
space:
mode:
authorfranciscovila <javier.paradela.vila@est.tech>2023-09-19 08:58:36 +0100
committerMichael Morris <michael.morris@est.tech>2023-10-06 14:08:46 +0000
commitee6e389e64b55615800a81ce43a41fa3e7ff93ce (patch)
treef9728396bcf7773d535ac61db51acf51e5432d92 /common-be
parent7918aa981a4c015a1cc5cd8a63a1fc381ac9f2cc (diff)
Fail to import service with node filter using 'in_range'
Issue-ID: SDC-4628 Signed-off-by: franciscovila <javier.paradela.vila@est.tech> Change-Id: Ibf6edbdfbb51c32256a707acd17a0def217e1bb9
Diffstat (limited to 'common-be')
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/utils/PropertyFilterConstraintDataDefinitionHelper.java95
1 files changed, 56 insertions, 39 deletions
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/utils/PropertyFilterConstraintDataDefinitionHelper.java b/common-be/src/main/java/org/openecomp/sdc/be/utils/PropertyFilterConstraintDataDefinitionHelper.java
index fa9e4d5fc7..791ca24aa1 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/utils/PropertyFilterConstraintDataDefinitionHelper.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/utils/PropertyFilterConstraintDataDefinitionHelper.java
@@ -34,6 +34,7 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
+import org.jetbrains.annotations.Nullable;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.datatypes.elements.CustomYamlFunction;
@@ -66,11 +67,6 @@ public class PropertyFilterConstraintDataDefinitionHelper {
final Object valueYaml = operatorYaml.get(operator);
final Optional<ToscaFunction> toscaFunction = createToscaFunctionFromLegacyConstraintValue(valueYaml);
if (toscaFunction.isPresent()) {
- propertyFilterConstraint.setValue(toscaFunction.get());
- propertyFilterConstraint.setValueType(detectValueType(valueYaml));
- }
- else {
- propertyFilterConstraint.setValue(valueYaml);
if (valueYaml instanceof List) {
List<ToscaFunction> listToscaFunction = new ArrayList<>();
((List<?>) valueYaml).stream().forEach(val -> {
@@ -83,17 +79,39 @@ public class PropertyFilterConstraintDataDefinitionHelper {
propertyFilterConstraint.setValueType(FilterValueType.SEVERAL);
}
else {
+ propertyFilterConstraint.setValue(toscaFunction.get());
propertyFilterConstraint.setValueType(detectValueType(valueYaml));
}
}
+ else {
+ propertyFilterConstraint.setValue(valueYaml);
+ propertyFilterConstraint.setValueType(detectValueType(valueYaml));
+ }
propertyFilterConstraint.setTargetType(PropertyFilterTargetType.PROPERTY);
return propertyFilterConstraint;
}
public static Optional<ToscaFunction> createToscaFunctionFromLegacyConstraintValue(final Object filterValue) {
- if (!(filterValue instanceof Map)) {
+ if (!(filterValue instanceof Map) && !(filterValue instanceof List)) {
return Optional.empty();
}
+ if (filterValue instanceof List) {
+ final Map<String, Object>[] filterValueAsMap = new Map[] {new HashMap<>()};
+ final String[] toscaFunctionType = new String[1];
+ try {
+ ((List<?>) filterValue).stream().forEach(filterArrayValue -> {
+
+ filterValueAsMap[0] = (Map<String, Object>) filterArrayValue;
+ final Set<?> keys = filterValueAsMap[0].keySet();
+ toscaFunctionType[0] = (String) keys.iterator().next();
+
+ });
+ }
+ catch (Exception ex) {
+ return Optional.empty();
+ }
+ return buildToscaFunctionBasedOnPropertyValue(filterValueAsMap[0]);
+ }
final Map<?, ?> filterValueAsMap = (Map<?, ?>) filterValue;
final Set<?> keys = filterValueAsMap.keySet();
if (keys.size() != 1) {
@@ -504,45 +522,44 @@ public class PropertyFilterConstraintDataDefinitionHelper {
private static FilterValueType detectValueType(final Object value) {
if (value instanceof Map) {
final Map<?, ?> valueAsMap = (Map<?, ?>) value;
- 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;
+ FilterValueType filterValueType = getFilterValueType(valueAsMap);
+ if (filterValueType != null) {
+ return filterValueType;
}
}
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;
+ try {
+ final Map<?, ?> valueAsMap = (Map<?, ?>) ((List<?>) value).get(0);
+ FilterValueType filterValueType = getFilterValueType(valueAsMap);
+ if (filterValueType != null) {
+ return filterValueType;
+ }
+ } catch (ClassCastException ex) {
+ return FilterValueType.SEVERAL;
}
}
return FilterValueType.STATIC;
}
+ @Nullable
+ private static FilterValueType getFilterValueType(Map<?, ?> valueAsMap) {
+ 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 null;
+ }
}