Bug 139415

Summary: Implement Business Object validation service
Product: Red Hat Network Reporter: Mike McCune <mmccune>
Component: RHN/R&DAssignee: Mike McCune <mmccune>
Status: CLOSED CURRENTRELEASE QA Contact: Red Hat Satellite QA List <satellite-qa-list>
Severity: medium Docs Contact:
Priority: medium    
Version: RHN Devel   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-12-06 06:38:13 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Bug Depends On:    
Bug Blocks: 125080    

Description Mike McCune 2004-11-15 21:32:53 UTC
Will reside in rhn.common.validator.

I spent some time thinking/reading about how we should provide a
mechanism for validating our business objects and came up with some
thoughts.

The brute-force method would be to put validation code directly in our
domain objects:

User {

public void setEmail(String emailIn) {
    if (emailIn == null) {
        throw new ValidationException("email must not be null");
    }

    if (!FormatHelper.isEmail(emailIn)) {
        throw new ValidationException("Not valid email format");
    }

    // perhaps some other criteria
     this.email = emailIn;
}

This approach has a lot of drawbacks.  One, it requires a lot of code
to be sprinkled throughout our domain objects.  Two, it will make it
difficult for consumers to deal with error conditions in that they
would have to catch ValidationException and interpret it, but this
would only allow for one error to be caught during a transaction.
With a web-based architecture we need to be able to perform a
transaction and return a *list* of validation errors.

This leads me to want to externalize the validation process to being
outside the domain object itself.  Instead , like we currently do with
Struts, we should validate at transaction time in one operation.  My
initial thought is to have our Manager layer perform validation at
storage time:

UserManager {

    public ValidationErrors storeUser(User usr) {
         ValidationErrors retval =
            SomeSortOfValidationService.validateObject(usr);
         if (retval != null) {
             UserFactory.commit(usr);
         }
         return retval;
    }
}

Consumers of our Manager layer (web UI and webservices) will be able
to perform operations and receive back a set of errors (or not if
everything was OK).  This will provide our goal of a re-usable
validation scheme for our business objects.

The mechanics of the ValidationService is TBD but I wanted to throw
out this approach to see what people think.

Mike