Search in sources :

Example 6 with BeanValidationFailure

use of org.apache.cayenne.validation.BeanValidationFailure in project cayenne by apache.

the class ClassGenerationValidator method validateRelationship.

private ValidationFailure validateRelationship(ObjRelationship relationship, boolean clientValidation) {
    String name = relationship.getSourceEntity().getName();
    ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(name, "relationship.name", relationship.getName());
    if (emptyName != null) {
        return emptyName;
    }
    ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(name, "relationship.name", relationship.getName());
    if (badName != null) {
        return badName;
    }
    if (!relationship.isToMany()) {
        ObjEntity targetEntity = relationship.getTargetEntity();
        if (clientValidation && targetEntity != null) {
            targetEntity = targetEntity.getClientEntity();
        }
        if (targetEntity == null) {
            return new BeanValidationFailure(name, "relationship.targetEntity", "No target entity");
        } else if (!targetEntity.isGeneric()) {
            ValidationFailure emptyClass = BeanValidationFailure.validateNotEmpty(name, "relationship.targetEntity.className", targetEntity.getClassName());
            if (emptyClass != null) {
                return emptyClass;
            }
            return BeanValidationFailure.validateJavaClassName(name, "relationship.targetEntity.className", targetEntity.getClassName());
        }
    }
    return null;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) BeanValidationFailure(org.apache.cayenne.validation.BeanValidationFailure) SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure) BeanValidationFailure(org.apache.cayenne.validation.BeanValidationFailure) ValidationFailure(org.apache.cayenne.validation.ValidationFailure)

Example 7 with BeanValidationFailure

use of org.apache.cayenne.validation.BeanValidationFailure in project cayenne by apache.

the class CodeValidationUtil method validateJavaIdentifier.

public static ValidationFailure validateJavaIdentifier(Object bean, String attribute, String identifier) {
    ValidationFailure emptyFailure = BeanValidationFailure.validateNotEmpty(bean, attribute, identifier);
    if (emptyFailure != null) {
        return emptyFailure;
    }
    char c = identifier.charAt(0);
    if (!Character.isJavaIdentifierStart(c)) {
        return new BeanValidationFailure(bean, attribute, validationMessage(attribute, " starts with invalid character: " + c));
    }
    for (int i = 1; i < identifier.length(); i++) {
        c = identifier.charAt(i);
        if (!Character.isJavaIdentifierPart(c)) {
            return new BeanValidationFailure(bean, attribute, validationMessage(attribute, " contains invalid character: " + c));
        }
    }
    return null;
}
Also used : BeanValidationFailure(org.apache.cayenne.validation.BeanValidationFailure) BeanValidationFailure(org.apache.cayenne.validation.BeanValidationFailure) ValidationFailure(org.apache.cayenne.validation.ValidationFailure)

Aggregations

BeanValidationFailure (org.apache.cayenne.validation.BeanValidationFailure)7 ValidationFailure (org.apache.cayenne.validation.ValidationFailure)7 ObjEntity (org.apache.cayenne.map.ObjEntity)3 ValidationResult (org.apache.cayenne.validation.ValidationResult)3 Test (org.junit.Test)3 Artist (org.apache.cayenne.testdo.testmap.Artist)2 SimpleValidationFailure (org.apache.cayenne.validation.SimpleValidationFailure)2 Date (java.util.Date)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 DbEntity (org.apache.cayenne.map.DbEntity)1 DbJoin (org.apache.cayenne.map.DbJoin)1 DbRelationship (org.apache.cayenne.map.DbRelationship)1 EmbeddedAttribute (org.apache.cayenne.map.EmbeddedAttribute)1 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 ObjRelationship (org.apache.cayenne.map.ObjRelationship)1 Exhibit (org.apache.cayenne.testdo.testmap.Exhibit)1 Gallery (org.apache.cayenne.testdo.testmap.Gallery)1