if (CollectionUtils.isNotEmpty(property.getConstraints())) {
try {
- prop.setConstraints(convertConstraints(property.getConstraints(), property.getType()));
+ prop.setConstraints(convertConstraints(property.getConstraints(), property.getType(), property.getSchemaType()));
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
log.error(e.getMessage());
}
return prop;
}
- private List<ToscaPropertyConstraint> convertConstraints(List<PropertyConstraint> constraints, String propertyType)
+ private List<ToscaPropertyConstraint> convertConstraints(List<PropertyConstraint> constraints, String propertyType, String schemaType)
throws ConstraintValueDoNotMatchPropertyTypeException {
List<ToscaPropertyConstraint> convertedConstraints = new ArrayList<>();
for (PropertyConstraint constraint : constraints) {
if (constraint instanceof EqualConstraint) {
EqualConstraint equalConstraint = ((EqualConstraint) constraint);
- if (doesPropertyTypeNeedConverted(propertyType)) {
+ if (doesTypeNeedConvertingToIntOrFloat(propertyType)) {
equalConstraint.changeConstraintValueTypeTo(propertyType);
}
if (constraint instanceof GreaterThanConstraint) {
GreaterThanConstraint greaterThanConstraint = ((GreaterThanConstraint) constraint);
- if (doesPropertyTypeNeedConverted(propertyType)) {
+ if (doesTypeNeedConvertingToIntOrFloat(propertyType)) {
greaterThanConstraint.changeConstraintValueTypeTo(propertyType);
}
if (constraint instanceof GreaterOrEqualConstraint) {
GreaterOrEqualConstraint greaterOrEqualConstraint = ((GreaterOrEqualConstraint) constraint);
- if (doesPropertyTypeNeedConverted(propertyType)) {
+ if (doesTypeNeedConvertingToIntOrFloat(propertyType)) {
greaterOrEqualConstraint.changeConstraintValueTypeTo(propertyType);
}
if (constraint instanceof LessThanConstraint) {
LessThanConstraint lessThanConstraint = ((LessThanConstraint) constraint);
- if (doesPropertyTypeNeedConverted(propertyType)) {
+ if (doesTypeNeedConvertingToIntOrFloat(propertyType)) {
lessThanConstraint.changeConstraintValueTypeTo(propertyType);
}
if (constraint instanceof LessOrEqualConstraint) {
LessOrEqualConstraint lessOrEqualConstraint = ((LessOrEqualConstraint) constraint);
- if (doesPropertyTypeNeedConverted(propertyType)) {
+ if (doesTypeNeedConvertingToIntOrFloat(propertyType)) {
lessOrEqualConstraint.changeConstraintValueTypeTo(propertyType);
}
if (constraint instanceof InRangeConstraint) {
InRangeConstraint inRangeConstraint = (InRangeConstraint) constraint;
- if (doesPropertyTypeNeedConverted(propertyType)) {
+ if (doesTypeNeedConvertingToIntOrFloat(propertyType)) {
inRangeConstraint.changeConstraintValueTypeTo(propertyType);
}
- List<Object> range = new ArrayList<>();
- range.add(inRangeConstraint.getMin());
- range.add(inRangeConstraint.getMax());
- convertedConstraints.add(new ToscaPropertyConstraintInRange(range));
+ convertedConstraints.add(new ToscaPropertyConstraintInRange(inRangeConstraint.getInRange()));
}
if (constraint instanceof ValidValuesConstraint) {
ValidValuesConstraint validValues = ((ValidValuesConstraint) constraint);
- if (propertyType.equals(ToscaType.INTEGER.toString()) || propertyType.equals(ToscaType.FLOAT.toString())) {
+ if (isTypeMapOrList(propertyType) && doesTypeNeedConvertingToIntOrFloat(schemaType)) {
+ validValues.changeConstraintValueTypeTo(schemaType);
+ } else if (doesTypeNeedConvertingToIntOrFloat(propertyType)) {
validValues.changeConstraintValueTypeTo(propertyType);
}
return convertedConstraints;
}
- private boolean doesPropertyTypeNeedConverted(String propertyType) {
- return propertyType.equals(ToscaType.INTEGER.getType()) || propertyType.equals(ToscaType.FLOAT.getType());
+ private boolean doesTypeNeedConvertingToIntOrFloat(String propertyType) {
+ return ToscaType.INTEGER.getType().equals(propertyType) || ToscaType.FLOAT.getType().equals(propertyType);
+ }
+
+ private boolean isTypeMapOrList (String type) {
+ return ToscaType.MAP.getType().equals(type) || ToscaType.LIST.getType().equals(type);
}
public Object convertToToscaObject(PropertyDataDefinition property, String value, Map<String, DataTypeDefinition> dataTypes,