diff options
author | MichaelMorris <michael.morris@est.tech> | 2023-02-10 10:25:14 +0000 |
---|---|---|
committer | Vasyl Razinkov <vasyl.razinkov@est.tech> | 2023-02-10 17:32:09 +0000 |
commit | 90aabfaff5773498cd233e0bbc27896db84c9103 (patch) | |
tree | da2396d56d3317a7036c1073b5729e8b657c35f5 /catalog-model/src/main/java | |
parent | 1f4a46768bd1cf1771b9f2a11cfc916fc59229de (diff) |
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 <michael.morris@est.tech>
Issue-ID: SDC-4382
Change-Id: I6d9b540b671c34a155ec639afe59d00b90d099d4
Diffstat (limited to 'catalog-model/src/main/java')
-rw-r--r-- | catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java | 32 |
1 files 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<? extends PropertyConstraint> 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<? extends PropertyConstraint> constraintClass) { @@ -2496,14 +2485,29 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe ValidValuesConstraint vvConstraint = new ValidValuesConstraint(); List<Object> 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(); + } + } + } |