From 8183ade590e367f28e13484201d2c9526be221dc Mon Sep 17 00:00:00 2001 From: franciscovila Date: Wed, 15 Feb 2023 17:14:59 +0000 Subject: Support additional operands for node filters Issue-ID: SDC-4395 Signed-off-by: franciscovila Change-Id: I66b172d100ffd2757de88bc7640761f31fd20c28 --- .../PropertyFilterConstraintDataDefinition.java | 1 + ...erConstraintDataDefinitionJsonDeserializer.java | 25 +++++++++++++++++++++- .../sdc/be/datatypes/enums/ConstraintType.java | 8 +++++++ .../sdc/be/datatypes/enums/FilterValueType.java | 3 ++- 4 files changed, 35 insertions(+), 2 deletions(-) (limited to 'common-be/src') diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyFilterConstraintDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyFilterConstraintDataDefinition.java index 9284b530eb..3dc11248f2 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyFilterConstraintDataDefinition.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyFilterConstraintDataDefinition.java @@ -38,4 +38,5 @@ public class PropertyFilterConstraintDataDefinition { private ConstraintType operator; private FilterValueType valueType; private Object value; + private String originalType; } diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyFilterConstraintDataDefinitionJsonDeserializer.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyFilterConstraintDataDefinitionJsonDeserializer.java index a767133a4c..894b54b291 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyFilterConstraintDataDefinitionJsonDeserializer.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyFilterConstraintDataDefinitionJsonDeserializer.java @@ -22,11 +22,13 @@ package org.openecomp.sdc.be.datatypes.elements; import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Map; import org.openecomp.sdc.be.datatypes.enums.ConstraintType; @@ -73,6 +75,9 @@ public class PropertyFilterConstraintDataDefinitionJsonDeserializer extends StdD if (node.get("valueType") != null) { propertyFilterConstraint.setValueType(FilterValueType.valueOf(node.get("valueType").asText())); } + if (node.get("originalType") != null) { + propertyFilterConstraint.setOriginalType(node.get("originalType").asText()); + } propertyFilterConstraint.setValue(deserializeValue(node.get("value"))); return propertyFilterConstraint; @@ -91,7 +96,25 @@ public class PropertyFilterConstraintDataDefinitionJsonDeserializer extends StdD LOGGER.debug(COULD_NOT_PARSE_CLASS, PropertyFilterConstraintDataDefinition.class.getName(), Map.class.getName(), e); } try { - return objectMapper.treeToValue(value, List.class); + if (value.isArray()) { + try { + objectMapper.treeToValue(value.get(0), ToscaFunction.class); + } catch (JsonProcessingException e) { + return objectMapper.treeToValue(value, List.class); + } + List listToscaFunction = new ArrayList<>(); + value.forEach(nodeListValue -> { + try { + listToscaFunction.add(objectMapper.treeToValue(nodeListValue, ToscaFunction.class)); + } catch (JsonProcessingException e) { + LOGGER.debug(COULD_NOT_PARSE_CLASS, PropertyFilterConstraintDataDefinition.class.getName(), List.class.getName(), e); + } + }); + return listToscaFunction; + } + else { + return objectMapper.treeToValue(value, List.class); + } } catch (final Exception e) { LOGGER.debug(COULD_NOT_PARSE_CLASS, PropertyFilterConstraintDataDefinition.class.getName(), List.class.getName(), e); } diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ConstraintType.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ConstraintType.java index 2963b6bcd1..263bd70ab7 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ConstraintType.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ConstraintType.java @@ -48,6 +48,10 @@ public enum ConstraintType { ConstraintType.GREATER_OR_EQUAL, ConstraintType.LESS_OR_EQUAL, ConstraintType.LESS_THAN); + private static final Set lengthConstraints = Set.of( + ConstraintType.LENGTH, + ConstraintType.MIN_LENGTH, + ConstraintType.MAX_LENGTH); private final String type; private final List typeAlias; @@ -74,4 +78,8 @@ public enum ConstraintType { return comparableConstraints.contains(this); } + public boolean isLengthConstraint() { + return lengthConstraints.contains(this); + } + } diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/FilterValueType.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/FilterValueType.java index cacc4b1bac..62a19b8041 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/FilterValueType.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/FilterValueType.java @@ -35,7 +35,8 @@ public enum FilterValueType { GET_INPUT("get_input", "service_input"), GET_ATTRIBUTE("get_attribute", null), YAML("yaml", null), - CONCAT("concat", null); + CONCAT("concat", null), + SEVERAL("several", null); private final String name; private final String legacyName; -- cgit 1.2.3-korg