From be7ba43b95f13bb390cdd77a15c35072781e5546 Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Mon, 21 Nov 2022 09:55:26 +0000 Subject: Fix numeric constraint values generated as strings When importing a vfc the property constraints are now checked to see if they are the same type as the property If not it will attempt to convert to that type Issue-ID: SDC-4274 Signed-off-by: JvD_Ericsson Change-Id: I32c1d930166d10142ad9ca6914550c7946e9128c --- .../sdc/be/components/impl/ImportUtils.java | 37 ++++++++++++++++++++++ .../openecomp/sdc/be/tosca/PropertyConvertor.java | 7 ++-- .../tosca/model/ToscaPropertyConstraintEqual.java | 2 +- .../ToscaPropertyConstraintGreaterOrEqual.java | 2 +- .../model/ToscaPropertyConstraintGreaterThan.java | 2 +- .../model/ToscaPropertyConstraintInRange.java | 3 +- .../tosca/model/ToscaPropertyConstraintLength.java | 2 +- .../model/ToscaPropertyConstraintLessOrEqual.java | 2 +- .../model/ToscaPropertyConstraintLessThan.java | 2 +- .../model/ToscaPropertyConstraintValidValues.java | 2 +- 10 files changed, 49 insertions(+), 12 deletions(-) (limited to 'catalog-be/src/main/java') 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 181c860b9f..9c2c070c74 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 @@ -63,6 +63,9 @@ import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations; import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser; import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; import org.openecomp.sdc.be.datatypes.enums.ConstraintType; +import org.openecomp.sdc.be.model.tosca.constraints.AbstractComparablePropertyConstraint; +import org.openecomp.sdc.be.model.tosca.constraints.EqualConstraint; +import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint; import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint; import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException; import org.openecomp.sdc.be.utils.TypeUtils; @@ -315,12 +318,46 @@ public final class ImportUtils { if (propertyConstraint instanceof ValidValuesConstraint) { try { ((ValidValuesConstraint) propertyConstraint).validateType(propertyType); + boolean valid = ((ValidValuesConstraint) propertyConstraint).validateValueType(propertyType); + if (!valid) { + ((ValidValuesConstraint) propertyConstraint).changeConstraintValueTypeTo(propertyType); + } } catch (ConstraintValueDoNotMatchPropertyTypeException e) { BeEcompErrorManager.getInstance() .logInternalFlowError("GetInitializedPropertyConstraint", e.getMessage(), BeEcompErrorManager.ErrorSeverity.ERROR); throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_CONSTRAINTS, ConstraintType.VALID_VALUES.name(), ((ValidValuesConstraint) propertyConstraint).getValidValues().toString(), propertyType); } + } else if (propertyConstraint instanceof AbstractComparablePropertyConstraint) { + try { + boolean valid = ((AbstractComparablePropertyConstraint) propertyConstraint).validateValueType(propertyType); + if (!valid) { + ((AbstractComparablePropertyConstraint) propertyConstraint).changeConstraintValueTypeTo(propertyType); + } + } catch (ConstraintValueDoNotMatchPropertyTypeException e) { + throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_CONSTRAINTS, propertyConstraint.getConstraintType().name(), + ((AbstractComparablePropertyConstraint) propertyConstraint).getConstraintValueAsString(), propertyType); + } + } else if (propertyConstraint instanceof EqualConstraint) { + try { + boolean valid = ((EqualConstraint) propertyConstraint).validateValueType(propertyType); + if (!valid) { + ((EqualConstraint) propertyConstraint).changeConstraintValueTypeTo(propertyType); + } + } catch (ConstraintValueDoNotMatchPropertyTypeException e) { + throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_CONSTRAINTS, ConstraintType.EQUAL.name(), + String.valueOf(((EqualConstraint) propertyConstraint).getEqual()), propertyType); + } + } else if (propertyConstraint instanceof InRangeConstraint) { + try { + boolean valid = ((InRangeConstraint) propertyConstraint).validateValueType(propertyType); + if (!valid) { + ((InRangeConstraint) propertyConstraint).changeConstraintValueTypeTo(propertyType); + } + } catch (ConstraintValueDoNotMatchPropertyTypeException e) { + throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_CONSTRAINTS, ConstraintType.IN_RANGE.name(), + String.valueOf(((InRangeConstraint) propertyConstraint).getInRange()), propertyType); + } } return propertyConstraint; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java index f1c8a17108..2ad6a942d0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java @@ -158,16 +158,17 @@ public class PropertyConvertor { } if (constraint instanceof InRangeConstraint) { InRangeConstraint inRangeConstraint = (InRangeConstraint) constraint; - List range = new ArrayList<>(); + List range = new ArrayList<>(); range.add(inRangeConstraint.getRangeMinValue()); range.add(inRangeConstraint.getRangeMaxValue()); convertedConstraints.add(new ToscaPropertyConstraintInRange(range)); } if (constraint instanceof ValidValuesConstraint) { - convertedConstraints.add(new ToscaPropertyConstraintValidValues(((ValidValuesConstraint) constraint).getValidValues())); + List validValues = ((ValidValuesConstraint) constraint).getValidValues(); + convertedConstraints.add(new ToscaPropertyConstraintValidValues(validValues)); } if (constraint instanceof LengthConstraint) { - convertedConstraints.add(new ToscaPropertyConstraintLength(((LengthConstraint) constraint).getLength().toString())); + convertedConstraints.add(new ToscaPropertyConstraintLength(((LengthConstraint) constraint).getLength())); } if (constraint instanceof MinLengthConstraint) { convertedConstraints.add(new ToscaPropertyConstraintMinLength(((MinLengthConstraint) constraint).getMinLength())); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintEqual.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintEqual.java index 532cb8c91b..e52f8dfa87 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintEqual.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintEqual.java @@ -31,7 +31,7 @@ import org.openecomp.sdc.be.datatypes.enums.ConstraintType; @AllArgsConstructor public class ToscaPropertyConstraintEqual implements ToscaPropertyConstraint { - private String equal; + private Object equal; private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.EQUAL; @Override diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterOrEqual.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterOrEqual.java index fcc9dcc884..89c563bdbc 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterOrEqual.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterOrEqual.java @@ -31,7 +31,7 @@ import org.openecomp.sdc.be.datatypes.enums.ConstraintType; @AllArgsConstructor public class ToscaPropertyConstraintGreaterOrEqual implements ToscaPropertyConstraint { - private String greaterOrEqual; + private Object greaterOrEqual; private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.GREATER_OR_EQUAL; @Override diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterThan.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterThan.java index 6f2268bd9e..2168cf4b67 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterThan.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterThan.java @@ -31,7 +31,7 @@ import org.openecomp.sdc.be.datatypes.enums.ConstraintType; @AllArgsConstructor public class ToscaPropertyConstraintGreaterThan implements ToscaPropertyConstraint { - private String greaterThan; + private Object greaterThan; private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.GREATER_THAN; @Override diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java index 6c8cfba620..91e1f553f5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java @@ -32,7 +32,7 @@ import org.openecomp.sdc.be.datatypes.enums.ConstraintType; @AllArgsConstructor public class ToscaPropertyConstraintInRange implements ToscaPropertyConstraint { - private List inRange; + private List inRange; private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.IN_RANGE; @Override @@ -40,7 +40,6 @@ public class ToscaPropertyConstraintInRange implements ToscaPropertyConstraint { if ("inRange".equals(attributeName)) { return CONSTRAINT_TYPE.getType(); } - return attributeName; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLength.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLength.java index 67aaca0188..998a7283bb 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLength.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLength.java @@ -31,7 +31,7 @@ import org.openecomp.sdc.be.datatypes.enums.ConstraintType; @AllArgsConstructor public class ToscaPropertyConstraintLength implements ToscaPropertyConstraint { - private String length; + private Integer length; private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.LENGTH; @Override diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessOrEqual.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessOrEqual.java index 3d51ec9419..75e661d15c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessOrEqual.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessOrEqual.java @@ -31,7 +31,7 @@ import org.openecomp.sdc.be.datatypes.enums.ConstraintType; @AllArgsConstructor public class ToscaPropertyConstraintLessOrEqual implements ToscaPropertyConstraint { - private String lessOrEqual; + private Object lessOrEqual; private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.LESS_OR_EQUAL; @Override diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessThan.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessThan.java index ad51f66fde..a64382d8a8 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessThan.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessThan.java @@ -31,7 +31,7 @@ import org.openecomp.sdc.be.datatypes.enums.ConstraintType; @AllArgsConstructor public class ToscaPropertyConstraintLessThan implements ToscaPropertyConstraint { - private String lessThan; + private Object lessThan; private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.LESS_THAN; @Override diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java index c23be5725c..4f9a65cfc1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java @@ -32,7 +32,7 @@ import org.openecomp.sdc.be.datatypes.enums.ConstraintType; @AllArgsConstructor public class ToscaPropertyConstraintValidValues implements ToscaPropertyConstraint { - private List validValues; + private List validValues; @Override public String getEntryToscaName(final String attributeName) { -- cgit 1.2.3-korg