Search in sources :

Example 6 with Constraint

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)));
}
Also used : Constraint(grails.validation.Constraint) BigDecimal(java.math.BigDecimal)

Example 7 with Constraint

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;
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Constraint(grails.validation.Constraint) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ConstrainedProperty(grails.validation.ConstrainedProperty) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Constraint (grails.validation.Constraint)7 ConstrainedProperty (grails.validation.ConstrainedProperty)1 TestClass (grails.validation.TestClass)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1