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
}
} 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();
}
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:
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() + ">");
}
}
package org.openecomp.sdc.be.model.tosca.constraints;
+import java.util.List;
+
import javax.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
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() + ">");
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);