summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);