Fix valid_values constraint problem 23/133223/2
authorMichaelMorris <michael.morris@est.tech>
Fri, 10 Feb 2023 10:25:14 +0000 (10:25 +0000)
committerVasyl Razinkov <vasyl.razinkov@est.tech>
Fri, 10 Feb 2023 17:32:09 +0000 (17:32 +0000)
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

catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java

index 5164743..8756ac4 100644 (file)
@@ -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();
+            }
+        }
+
 
     }