summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2022-11-21 09:55:26 +0000
committerMichael Morris <michael.morris@est.tech>2022-12-02 09:44:21 +0000
commitbe7ba43b95f13bb390cdd77a15c35072781e5546 (patch)
treeae20f499478a455e9355ff0bc6bd47010184b5ea /catalog-be/src/main/java
parent1336da0b9a713b9d6cf1e3f6ea709c50be43d4ab (diff)
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 <jeff.van.dam@est.tech> Change-Id: I32c1d930166d10142ad9ca6914550c7946e9128c
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java37
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintEqual.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterOrEqual.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterThan.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLength.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessOrEqual.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessThan.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java2
10 files changed, 49 insertions, 12 deletions
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<String> range = new ArrayList<>();
+ List<Object> 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<String> inRange;
+ private List<Object> 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<String> validValues;
+ private List<Object> validValues;
@Override
public String getEntryToscaName(final String attributeName) {