use of grails.validation.Constraint in project grails-core by grails.
the class ScaleConstraintTests method testBigDecimal.
private void testBigDecimal(int scale, String value, String result) {
Constraint constraint = getConstraint("testBigDecimal", scale);
assertEquals(new BigDecimal(result), proceedValidation(constraint, new BigDecimal(value)));
}
use of grails.validation.Constraint in project grails-core by grails.
the class ConstrainedPropertyBuilder method handleImportFrom.
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object handleImportFrom(Map attributes, Class importFromClazz) {
Map importFromConstrainedProperties = new DefaultConstraintEvaluator().evaluate(importFromClazz);
PropertyDescriptor[] targetPropertyDescriptorArray = classPropertyFetcher.getPropertyDescriptors();
List toBeIncludedPropertyNamesParam = (List) attributes.get("include");
List toBeExcludedPropertyNamesParam = (List) attributes.get("exclude");
List<String> resultingPropertyNames = new ArrayList<String>();
for (PropertyDescriptor targetPropertyDescriptor : targetPropertyDescriptorArray) {
String targetPropertyName = targetPropertyDescriptor.getName();
if (toBeIncludedPropertyNamesParam == null) {
resultingPropertyNames.add(targetPropertyName);
} else if (isListOfRegexpsContainsString(toBeIncludedPropertyNamesParam, targetPropertyName)) {
resultingPropertyNames.add(targetPropertyName);
}
if (toBeExcludedPropertyNamesParam != null && isListOfRegexpsContainsString(toBeExcludedPropertyNamesParam, targetPropertyName)) {
resultingPropertyNames.remove(targetPropertyName);
}
}
resultingPropertyNames.remove("class");
resultingPropertyNames.remove("metaClass");
for (String targetPropertyName : resultingPropertyNames) {
ConstrainedProperty importFromConstrainedProperty = (ConstrainedProperty) importFromConstrainedProperties.get(targetPropertyName);
if (importFromConstrainedProperty != null) {
// Map importFromConstrainedPropertyAttributes = importFromConstrainedProperty.getAttributes();
// createNode(targetPropertyName, importFromConstrainedPropertyAttributes);
Map importFromConstrainedPropertyAttributes = new HashMap();
for (Constraint importFromAppliedConstraint : importFromConstrainedProperty.getAppliedConstraints()) {
String importFromAppliedConstraintName = importFromAppliedConstraint.getName();
Object importFromAppliedConstraintParameter = importFromAppliedConstraint.getParameter();
importFromConstrainedPropertyAttributes.put(importFromAppliedConstraintName, importFromAppliedConstraintParameter);
}
createNode(targetPropertyName, importFromConstrainedPropertyAttributes);
}
}
return null;
}
Aggregations