for (PropertyConstraint propertyConstraint : propertyDefinition.getConstraints()) {
try {
propertyConstraint.initialize(toscaType, propertyDefinition.getSchema());
- propertyConstraint.validate(toscaType, propertyDefinition.getSchema(), propertyDefinition.getValue());
+ propertyConstraint.validate(propertyDefinition);
} catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException exception) {
errorMessages.add(propertyConstraint.getErrorMessage(toscaType, exception, getCompletePropertyName(propertyDefinition)));
} catch (IllegalArgumentException ie) {
if (rangeArray.size() != 2) {
log.error("The range constraint content is invalid. value = {}", value);
} else {
- final String minValue = rangeArray.get(0).asText();
- final String maxValue = rangeArray.get(1).asText();
+ final Object minValue = convertToType(rangeArray.get(0));
+ final Object maxValue = convertToType(rangeArray.get(1));
final Comparable min = ConstraintUtil.convertToComparable(
ToscaType.getToscaType(minValue.getClass().getSimpleName().toLowerCase()), String.valueOf(minValue));
final Comparable max = ConstraintUtil.convertToComparable(
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException;
private static final String INVALID_VALUE_ERROR_MESSAGE = "Unsupported value provided for %s property supported value type is %s.";
@Override
- public void validate(ToscaType toscaType, SchemaDefinition schema, String propertyTextValue) throws ConstraintViolationException {
- validate(toscaType, propertyTextValue);
+ public void validate(PropertyDefinition property) throws ConstraintViolationException {
+ validate(ToscaType.isValidType(property.getType()), property.getValue());
}
protected void validate(ToscaType toscaType, String propertyTextValue) throws ConstraintViolationException {
import static java.util.stream.Collectors.toList;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException;
}
@Override
- public void validate(ToscaType toscaType, SchemaDefinition schema, String propertyTextValue) throws ConstraintViolationException {
+ public void validate(PropertyDefinition propertyDefinition) throws ConstraintViolationException {
+ ToscaType toscaType = ToscaType.isValidType(propertyDefinition.getType());
try {
Collection<Object> valuesToValidate;
if (ToscaType.LIST == toscaType) {
- valuesToValidate = ConstraintUtil.parseToCollection(propertyTextValue, new TypeReference<>() {});
+ valuesToValidate = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {});
} else if (ToscaType.MAP == toscaType) {
- final Map<String, Object> map = ConstraintUtil.parseToCollection(propertyTextValue, new TypeReference<>() {});
+ final Map<String, Object> map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {});
valuesToValidate = map.values();
} else {
- valuesToValidate = Collections.singleton(propertyTextValue);
+ valuesToValidate = Collections.singleton(propertyDefinition.getValue());
}
- ToscaType valuesType = getValuesType(toscaType, schema);
+ if (propertyDefinition.getSubPropertyToscaFunctions() != null) {
+ propertyDefinition.getSubPropertyToscaFunctions().forEach(subPropToscaFunction -> {
+ valuesToValidate.remove(subPropToscaFunction.getToscaFunction().getJsonObjectValue());
+ });
+ }
+ ToscaType valuesType = getValuesType(toscaType, propertyDefinition.getSchema());
for (final Object value: valuesToValidate) {
validate(valuesType, value.toString());
}