Bug 139415 - Implement Business Object validation service
Summary: Implement Business Object validation service
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Network
Classification: Red Hat
Component: RHN/R&D
Version: RHN Devel
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Mike McCune
QA Contact: Red Hat Satellite QA List
URL:
Whiteboard:
Depends On:
Blocks: rhnMilestone1
TreeView+ depends on / blocked
 
Reported: 2004-11-15 21:32 UTC by Mike McCune
Modified: 2007-04-18 17:15 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2004-12-06 06:38:13 UTC


Attachments (Terms of Use)

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


Note You need to log in before you can comment on or make changes to this bug.