From 0d708e3bb2502abe50e1ed4069b43536b538ceef Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Thu, 27 Oct 2022 12:47:28 +0100 Subject: Support addition of scalar type constraints this also supports the addition of the in_range and the valid_values constraints, and supports delete and editing of current and added constraints Issue-ID: SDC-4223 Change-Id: I5ffb4d17d9f8c2730f650153fb4ff89eccfdd474 Signed-off-by: JvD_Ericsson --- .../sdc/be/model/operations/impl/PropertyOperation.java | 13 ++++++++++--- .../sdc/be/model/tosca/constraints/LessThanConstraint.java | 1 - 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'catalog-model/src/main/java') 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 cd87dd4fe7..b54b401eb0 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 @@ -33,8 +33,10 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; +import com.google.gson.JsonSyntaxException; import fj.data.Either; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -2143,6 +2145,10 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe GreaterThanConstraint greaterThanConstraint = (GreaterThanConstraint) src; jsonArray.add(JsonParser.parseString(greaterThanConstraint.getGreaterThan())); result.add("greaterThan", jsonArray); + } else if (src instanceof LessThanConstraint) { + LessThanConstraint lessThanConstraint = (LessThanConstraint) src; + jsonArray.add(JsonParser.parseString(lessThanConstraint.getLessThan())); + result.add("lessThan", jsonArray); } else if (src instanceof LessOrEqualConstraint) { LessOrEqualConstraint lessOrEqualConstraint = (LessOrEqualConstraint) src; jsonArray.add(JsonParser.parseString(lessOrEqualConstraint.getLessOrEqual())); @@ -2185,8 +2191,9 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe if (value != null) { if (value instanceof JsonArray) { JsonArray rangeArray = (JsonArray) value; - if (rangeArray.size() != 2) { + if (rangeArray.size() != 2 || rangeArray.contains(new JsonPrimitive(""))) { log.error("The range constraint content is invalid. value = {}", value); + throw new JsonSyntaxException("The range constraint content is invalid"); } else { InRangeConstraint rangeConstraint = new InRangeConstraint(); String minValue = rangeArray.get(0).getAsString(); @@ -2248,8 +2255,9 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe case VALID_VALUES: if (value != null) { JsonArray rangeArray = (JsonArray) value; - if (rangeArray.size() == 0) { + if (rangeArray.size() == 0 || rangeArray.contains(new JsonPrimitive(""))) { log.error("The valid values constraint content is invalid. value = {}", value); + throw new JsonSyntaxException("The valid values constraint content is invalid"); } else { ValidValuesConstraint vvConstraint = new ValidValuesConstraint(); List validValues = new ArrayList<>(); @@ -2426,7 +2434,6 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe return null; } - } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java index d0bea82157..740ee8b544 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java @@ -35,7 +35,6 @@ import org.openecomp.sdc.be.model.tosca.constraints.exception.PropertyConstraint public class LessThanConstraint extends AbstractComparablePropertyConstraint { @NotNull - @Getter private String lessThan; @Override -- cgit 1.2.3-korg