aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2023-02-17 16:55:53 +0000
committerJEFF VAN DAM <jeff.van.dam@est.tech>2023-02-22 14:22:15 +0000
commitb275933c9cee0b36fc4038040b8417c80b08e603 (patch)
tree39d5b2a30448aa3d37694c68b85ca05e7c9490a6
parent9b8d90c9cdc012ca444d35465dc2e77662e4becf (diff)
Fix error validation equals constraint
Error thrown when validating value for list property with an equal constraint, even when valid valid is given Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-4399 Change-Id: Iec1746561351acc026050bf8571c060cc5705c2e
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java6
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintUtil.java31
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java13
3 files changed, 31 insertions, 19 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
index 8756ac4ee2..2d88f38977 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
@@ -2503,6 +2503,12 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
} else if (jsonElement.getNodeType().equals(JsonNodeType.BOOLEAN)) {
return jsonElement.asBoolean();
+ } else if (jsonElement.getNodeType().equals(JsonNodeType.ARRAY)) {
+ List<Object> listValues = new ArrayList<>();
+ for (JsonNode jsonArrayElement : jsonElement) {
+ listValues.add(convertToType(jsonArrayElement));
+ }
+ return listValues;
} else {
return jsonElement.asText();
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintUtil.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintUtil.java
index fee828c1be..83b3ab82d8 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintUtil.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintUtil.java
@@ -53,16 +53,8 @@ public final class ConstraintUtil {
throw new ConstraintValueDoNotMatchPropertyTypeException("Invalid property type <" + propertyType.toString() + ">");
}
}
-
- /**
- * Verify that the given tosca type is supported for comparison
- *
- * @param propertyType the tosca type to check
- * @throws ConstraintValueDoNotMatchPropertyTypeException if the property type cannot be compared
- */
- public static void checkComparableType(final ToscaType propertyType) throws ConstraintValueDoNotMatchPropertyTypeException {
- // The validity of the value is already assured by us with our ToscaType.convert() method
- // here we just want to check that the constraint is not used on unsupported type as boolean
+
+ public static boolean isComparableType(final ToscaType propertyType) {
final ToscaType toscaType = ToscaType.getToscaType(propertyType.getType());
switch (toscaType) {
case FLOAT:
@@ -76,12 +68,21 @@ public final class ConstraintUtil {
case SCALAR_UNIT_TIME:
case SCALAR_UNIT_BITRATE:
case SCALAR_UNIT_FREQUENCY:
- break;
- case BOOLEAN:
- case SCALAR_UNIT:
- throw new ConstraintValueDoNotMatchPropertyTypeException("Constraint is invalid for property type <" + propertyType.getType() + ">");
+ return true;
default:
- throw new ConstraintValueDoNotMatchPropertyTypeException("Invalid property type <" + propertyType.getType() + ">");
+ return false;
+ }
+ }
+
+ /**
+ * Verify that the given tosca type is supported for comparison
+ *
+ * @param propertyType the tosca type to check
+ * @throws ConstraintValueDoNotMatchPropertyTypeException if the property type cannot be compared
+ */
+ public static void checkComparableType(final ToscaType propertyType) throws ConstraintValueDoNotMatchPropertyTypeException {
+ if (!isComparableType(propertyType)) {
+ throw new ConstraintValueDoNotMatchPropertyTypeException("Constraint is invalid for property type <" + propertyType.getType() + ">");
}
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java
index 3017a0532d..a565580d38 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java
@@ -20,6 +20,8 @@
package org.openecomp.sdc.be.model.tosca.constraints;
+import java.util.List;
+
import javax.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@@ -52,10 +54,9 @@ public class EqualConstraint extends AbstractComparablePropertyConstraint {
public void initialize(ToscaType propertyType) throws ConstraintValueDoNotMatchPropertyTypeException {
if (propertyType.isValidValue(String.valueOf(equal))) {
typed = propertyType.convert(String.valueOf(equal));
- if (propertyType.equals(ToscaType.BOOLEAN)) {
- return;
+ if (ConstraintUtil.isComparableType(propertyType)) {
+ initialize(String.valueOf(equal), propertyType);
}
- initialize(String.valueOf(equal), propertyType);
} else {
throw new ConstraintValueDoNotMatchPropertyTypeException(
"constraintValue constraint has invalid value <" + equal + "> property type is <" + propertyType.toString() + ">");
@@ -104,11 +105,15 @@ public class EqualConstraint extends AbstractComparablePropertyConstraint {
if (propertyValue == null) {
throw new ConstraintViolationException("Value to check is null");
}
- if (!(propertyValue instanceof Boolean)) {
+ if (isComparableValue(propertyValue)) {
super.validate(propertyValue);
}
doValidate(propertyValue);
}
+
+ private boolean isComparableValue(Object propertyValue) {
+ return Comparable.class.isAssignableFrom(propertyValue.getClass());
+ }
public boolean validateValueType(String propertyType) throws ConstraintValueDoNotMatchPropertyTypeException {
ToscaType toscaType = ToscaType.getToscaType(propertyType);