From 90aabfaff5773498cd233e0bbc27896db84c9103 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Fri, 10 Feb 2023 10:25:14 +0000 Subject: Fix valid_values constraint problem Not able to set a value on a property of a instance in a service if the property has a valid vales constraint Signed-off-by: MichaelMorris Issue-ID: SDC-4382 Change-Id: I6d9b540b671c34a155ec639afe59d00b90d099d4 --- .../model/operations/impl/PropertyOperation.java | 32 ++++++++++++---------- 1 file changed, 18 insertions(+), 14 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 516474331b..8756ac4ee2 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 @@ -2419,18 +2419,7 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe } private PropertyConstraint deserializeConstraint(JsonNode value, Class constraintClass) { - JsonNodeType type = value.getNodeType(); - if (type.equals(JsonNodeType.NUMBER)) { - float asFloat = (float) value.asDouble(); - if ((asFloat % 1) == 0) { - return deserializeConstraintWithObjectOperand(value.asInt(), constraintClass); - } - return deserializeConstraintWithObjectOperand(asFloat, constraintClass); - } else if (type.equals(JsonNodeType.BOOLEAN)) { - return deserializeConstraintWithObjectOperand(value.asBoolean(), constraintClass); - } else { - return deserializeConstraintWithObjectOperand(value.asText(), constraintClass); - } + return deserializeConstraintWithObjectOperand(convertToType(value), constraintClass); } private PropertyConstraint deserializeConstraintWithObjectOperand(Object value, Class constraintClass) { @@ -2496,14 +2485,29 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe ValidValuesConstraint vvConstraint = new ValidValuesConstraint(); List validValues = new ArrayList<>(); for (JsonNode jsonElement : rangeArray) { - String item = jsonElement.asText(); - validValues.add(item); + validValues.add(convertToType(jsonElement)); } vvConstraint.setValidValues(validValues); return vvConstraint; } return null; } + + private Object convertToType(JsonNode jsonElement) { + if (jsonElement.getNodeType().equals(JsonNodeType.NUMBER)) { + float asFloat = (float) jsonElement.asDouble(); + if ((asFloat % 1) == 0) { + return jsonElement.asInt(); + } else { + return asFloat; + } + } else if (jsonElement.getNodeType().equals(JsonNodeType.BOOLEAN)) { + return jsonElement.asBoolean(); + } else { + return jsonElement.asText(); + } + } + } -- cgit 1.2.3-korg