From 3a7add7ec56db4a7c0d62e2c86150f9a216ad041 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Fri, 17 Feb 2023 13:05:37 +0000 Subject: Fix incorrect behaviour for list valid_values Signed-off-by: MichaelMorris Issue-ID: SDC-4398 Change-Id: Ic8c8a6565089000d1517110283e4bb7c6f989c27 --- .../java/org/openecomp/sdc/be/components/impl/ImportUtils.java | 10 +++++----- .../datamodel/utils/PropertyValueConstraintValidationUtil.java | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java index b773f1fbbc..fff9f0bf1c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java @@ -271,13 +271,13 @@ public final class ImportUtils { } private static void setPropertyConstraints(Map propertyValue, PropertyDefinition property) { - List constraints = getPropertyConstraints(propertyValue, property.getType()); + List constraints = getPropertyConstraints(propertyValue, property.getType(), property.getSchema()); if (CollectionUtils.isNotEmpty(constraints)) { property.setConstraints(constraints); } } - private static List getPropertyConstraints(final Map propertyValue, final String propertyType) { + private static List getPropertyConstraints(final Map propertyValue, final String propertyType, final SchemaDefinition schema) { final List propertyFieldConstraints = findCurrentLevelConstraintsElement(propertyValue); if (CollectionUtils.isEmpty(propertyFieldConstraints)) { return Collections.emptyList(); @@ -287,7 +287,7 @@ public final class ImportUtils { }.getType(); final Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create(); for (final Object constraintJson : propertyFieldConstraints) { - final PropertyConstraint propertyConstraint = validateAndGetPropertyConstraint(propertyType, constraintType, gson, constraintJson); + final PropertyConstraint propertyConstraint = validateAndGetPropertyConstraint(propertyType, constraintType, gson, constraintJson, schema); if (propertyConstraint != null) { constraintList.add(propertyConstraint); } @@ -308,7 +308,7 @@ public final class ImportUtils { return constraints; } - private static PropertyConstraint validateAndGetPropertyConstraint(String propertyType, Type constraintType, Gson gson, Object constraintJson) { + private static PropertyConstraint validateAndGetPropertyConstraint(String propertyType, Type constraintType, Gson gson, Object constraintJson, SchemaDefinition schema) { PropertyConstraint propertyConstraint; try { propertyConstraint = gson.fromJson(gson.toJson(constraintJson), constraintType); @@ -317,7 +317,7 @@ public final class ImportUtils { } if (propertyConstraint instanceof ValidValuesConstraint) { try { - ((ValidValuesConstraint) propertyConstraint).validateType(propertyType); + ((ValidValuesConstraint) propertyConstraint).validateType(propertyType, schema); boolean valid = ((ValidValuesConstraint) propertyConstraint).validateValueType(propertyType); if (!valid) { ((ValidValuesConstraint) propertyConstraint).changeConstraintValueTypeTo(propertyType); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java index 6c820a1af2..966f13c952 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java @@ -140,8 +140,8 @@ public class PropertyValueConstraintValidationUtil { if (isPropertyNotMappedAsInput(propertyDefinition) && CollectionUtils.isNotEmpty(propertyDefinition.getConstraints())) { for (PropertyConstraint propertyConstraint : propertyDefinition.getConstraints()) { try { - propertyConstraint.initialize(toscaType); - propertyConstraint.validate(toscaType, propertyDefinition.getValue()); + propertyConstraint.initialize(toscaType, propertyDefinition.getSchema()); + propertyConstraint.validate(toscaType, propertyDefinition.getSchema(), propertyDefinition.getValue()); } catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException exception) { errorMessages.add(propertyConstraint.getErrorMessage(toscaType, exception, getCompletePropertyName(propertyDefinition))); } catch (IllegalArgumentException ie) { -- cgit 1.2.3-korg