diff options
author | franciscovila <javier.paradela.vila@est.tech> | 2023-02-15 17:14:59 +0000 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-05-16 15:05:13 +0000 |
commit | 8183ade590e367f28e13484201d2c9526be221dc (patch) | |
tree | 735d600ec26ed9caea7657f7224a7e5f6f05cb62 /catalog-model/src | |
parent | 5768f2e5a056df6b23f7f8a87529d5ca00063c68 (diff) |
Support additional operands for node filters
Issue-ID: SDC-4395
Signed-off-by: franciscovila <javier.paradela.vila@est.tech>
Change-Id: I66b172d100ffd2757de88bc7640761f31fd20c28
Diffstat (limited to 'catalog-model/src')
4 files changed, 60 insertions, 1 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/FilterConstraintDto.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/FilterConstraintDto.java index b9ceb11276..4800c020d2 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/FilterConstraintDto.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/FilterConstraintDto.java @@ -22,6 +22,8 @@ package org.openecomp.sdc.be.model.dto; import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; import lombok.Data; import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition; @@ -38,6 +40,7 @@ public class FilterConstraintDto { private ConstraintType operator; private FilterValueType valueType; private Object value; + private String originalType; public boolean isCapabilityPropertyFilter() { return capabilityName != null; @@ -53,6 +56,18 @@ public class FilterConstraintDto { return Optional.empty(); } } + public Optional<List<ToscaGetFunctionDataDefinition>> getAsListToscaGetFunction() { + List<ToscaGetFunctionDataDefinition> toscaGetFunctionDataDefinitionList = new ArrayList<>(); + if (value instanceof List) { + try { + ((List<?>) value).forEach(toscaValue -> toscaGetFunctionDataDefinitionList.add(new ObjectMapper().convertValue(toscaValue, ToscaGetFunctionDataDefinition.class))); + return Optional.of(toscaGetFunctionDataDefinitionList); + } catch (final Exception ignored) { + return Optional.empty(); + } + } + return Optional.empty(); + } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ListValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ListValidator.java index 20d927f483..46fd44d786 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ListValidator.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ListValidator.java @@ -72,6 +72,27 @@ public class ListValidator implements PropertyTypeValidator { case MAP: innerValidator = ToscaPropertyType.MAP.getValidator(); break; + case RANGE: + innerValidator = ToscaPropertyType.RANGE.getValidator(); + break; + case SCALAR_UNIT_BITRATE: + innerValidator = ToscaPropertyType.SCALAR_UNIT_BITRATE.getValidator(); + break; + case SCALAR_UNIT_FREQUENCY: + innerValidator = ToscaPropertyType.SCALAR_UNIT_FREQUENCY.getValidator(); + break; + case SCALAR_UNIT_TIME: + innerValidator = ToscaPropertyType.SCALAR_UNIT_TIME.getValidator(); + break; + case SCALAR_UNIT_SIZE: + innerValidator = ToscaPropertyType.SCALAR_UNIT_SIZE.getValidator(); + break; + case SCALAR_UNIT: + innerValidator = ToscaPropertyType.SCALAR_UNIT.getValidator(); + break; + case TIMESTAMP: + innerValidator = ToscaPropertyType.TIMESTAMP.getValidator(); + break; default: log.debug("inner Tosca Type is unknown. {}", innerToscaType); return false; diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java index 9c1b6c9f48..59d7ef074f 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java @@ -23,6 +23,7 @@ package org.openecomp.sdc.be.ui.mapper; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -49,6 +50,7 @@ public class FilterConstraintMapper { filterConstraint.setTargetType(StringUtils.isEmpty(uiConstraint.getCapabilityName()) ? PropertyFilterTargetType.PROPERTY : PropertyFilterTargetType.CAPABILITY); FilterValueType.findByName(uiConstraint.getSourceType()).ifPresent(filterConstraint::setValueType); filterConstraint.setValue(mapValueFrom(uiConstraint)); + filterConstraint.setOriginalType(uiConstraint.getOriginalType()); return filterConstraint; } @@ -95,6 +97,7 @@ public class FilterConstraintMapper { propertyFilterConstraint.setOperator(filterConstraintDto.getOperator()); propertyFilterConstraint.setValueType(filterConstraintDto.getValueType()); propertyFilterConstraint.setValue(filterConstraintDto.getValue()); + propertyFilterConstraint.setOriginalType(filterConstraintDto.getOriginalType()); return propertyFilterConstraint; } @@ -106,13 +109,32 @@ public class FilterConstraintMapper { uiConstraint.setServicePropertyName(filterConstraintDto.getPropertyName()); uiConstraint.setSourceType(filterConstraintDto.getValueType().getName()); uiConstraint.setSourceName(uiConstraint.getSourceType()); + uiConstraint.setOriginalType(uiConstraint.getOriginalType()); return uiConstraint; } private Object parseValueFromUiConstraint(final Object value) { - if (!(value instanceof Map || value instanceof String)) { + if (!(value instanceof Map || value instanceof List || value instanceof String)) { return value; } + if (value instanceof List) { + List<ToscaFunction> listValue = new ArrayList<>(); + ToscaFunction valueObject; + for (Object obj: (List)value) { + try { + valueObject = (ToscaFunction) getValueObject(obj); + } + catch (Exception e) { + return value; + } + listValue.add(valueObject); + } + return listValue; + } + return getValueObject(value); + } + + private Object getValueObject(Object value) { final Map<?, ?> valueAsMap; if (value instanceof String) { try { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UIConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UIConstraint.java index 401de95e71..acb0c81d35 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UIConstraint.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UIConstraint.java @@ -35,6 +35,7 @@ public class UIConstraint implements Serializable { private String sourceType; private String sourceName; private Object value; + private String originalType; public UIConstraint() { } |