You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Adrian Crum <ad...@yahoo.com> on 2010/07/01 07:45:49 UTC

Re: Discussion: Entity Engine Field Validators

Would there be any objections to me removing the validators from the fieldtype*.xml files?

-Adrian

--- On Sat, 6/26/10, David E Jones <de...@me.com> wrote:

> From: David E Jones <de...@me.com>
> Subject: Re: Discussion: Entity Engine Field Validators
> To: dev@ofbiz.apache.org
> Date: Saturday, June 26, 2010, 9:58 AM
> 
> The validators are only used in the WebTools Entity Data
> Maintenance screens.
> 
> They are intentionally not used in other parts of the
> project as validation is best in the logic layer, and not in
> the data layer (makes things far more reusable and
> flexible).
> 
> I actually consider these to be a bad design from very
> early on in the project when the entity engine was one of
> the only tools in the framework, and IMO it would be better
> to remove them than to support them everywhere.
> 
> -David
> 
> 
> On Jun 26, 2010, at 10:54 AM, Adrian Crum wrote:
> 
> > The entity engine allows you to specify field
> validators in two places: in the fieldtypeXxx.xml files and
> in the the entity definition.
> > 
> > The validators in the fieldtype files are not used as
> far as I can tell.
> > 
> > The validators in the entity definitions require
> complicated client code to use them - they are not used
> automatically by the entity engine.
> > 
> > The bottom line is, specifying a validator in either
> location does absolutely nothing. I don't know if this was
> designed this way or not.
> > 
> > I have a design in mind that I think will be
> better...
> > 
> > 1. Create a validator interface that can be used
> throughout the project:
> > 
> > public interface Validator {
> >   void isValid(Object obj;
> > }
> > 
> > The isValid method throws an IllegalArgumentException
> if the object is not valid.
> > 
> > 2. Set up a library of commonly used validators and
> put them in a Validator factory. Modify ModelField and
> ModelFieldType so they load validators from the factory.
> > 
> > 3. Have ModelField and ModelFieldType implement
> Validator. Those classes delegate the isValid method call to
> their contained validators.
> > 
> > 4. Modify GenericEntity.set method to call the
> ModelField's isValid method.
> > 
> > The advantages to this approach are:
> > 
> > 1. Validators are reusable. The same validators could
> be used on service parameters for example.
> > 2. Client code is shielded from validation details.
> Just call the isValid method.
> > 3. OFBiz users can implement custom Validator
> implementations and add them to the Validator factory.
> > 
> > What do you think?
> > 
> > -Adrian
> > 
> > 
> > 
> > 
> 
> 


      

Re: Discussion: Entity Engine Field Validators

Posted by Adrian Crum <ad...@hlmksw.com>.
Cool - I will take care of that.

How do you picture field-level validation being implemented? I agree 
that it needs to be done higher up in the stack, but at first glance it 
seems like that would be a lot of extra work/code.

Let's use partyId as an example. If a user creates a partyId that is 
longer than 20 characters, an exception will be thrown when that ID is 
stored - because data truncation would occur. The user gets a confusing 
SQL exception message. If we use a validator, it could check the ID for 
length and warn the user with a meaningful message before the ID is stored.

There might be hundreds of places where partyId is stored. Do we write 
ID validation code in those hundreds of places or in one place? It seems 
to me that having the validator in the entity engine or service engine 
would make sense.

-Adrian

On 6/30/2010 10:47 PM, David E Jones wrote:
>
> Not from me.
>
> -David
>
>
> On Jun 30, 2010, at 11:45 PM, Adrian Crum wrote:
>
>> Would there be any objections to me removing the validators from the fieldtype*.xml files?
>>
>> -Adrian
>>
>> --- On Sat, 6/26/10, David E Jones<de...@me.com>  wrote:
>>
>>> From: David E Jones<de...@me.com>
>>> Subject: Re: Discussion: Entity Engine Field Validators
>>> To: dev@ofbiz.apache.org
>>> Date: Saturday, June 26, 2010, 9:58 AM
>>>
>>> The validators are only used in the WebTools Entity Data
>>> Maintenance screens.
>>>
>>> They are intentionally not used in other parts of the
>>> project as validation is best in the logic layer, and not in
>>> the data layer (makes things far more reusable and
>>> flexible).
>>>
>>> I actually consider these to be a bad design from very
>>> early on in the project when the entity engine was one of
>>> the only tools in the framework, and IMO it would be better
>>> to remove them than to support them everywhere.
>>>
>>> -David
>>>
>>>
>>> On Jun 26, 2010, at 10:54 AM, Adrian Crum wrote:
>>>
>>>> The entity engine allows you to specify field
>>> validators in two places: in the fieldtypeXxx.xml files and
>>> in the the entity definition.
>>>>
>>>> The validators in the fieldtype files are not used as
>>> far as I can tell.
>>>>
>>>> The validators in the entity definitions require
>>> complicated client code to use them - they are not used
>>> automatically by the entity engine.
>>>>
>>>> The bottom line is, specifying a validator in either
>>> location does absolutely nothing. I don't know if this was
>>> designed this way or not.
>>>>
>>>> I have a design in mind that I think will be
>>> better...
>>>>
>>>> 1. Create a validator interface that can be used
>>> throughout the project:
>>>>
>>>> public interface Validator {
>>>>     void isValid(Object obj;
>>>> }
>>>>
>>>> The isValid method throws an IllegalArgumentException
>>> if the object is not valid.
>>>>
>>>> 2. Set up a library of commonly used validators and
>>> put them in a Validator factory. Modify ModelField and
>>> ModelFieldType so they load validators from the factory.
>>>>
>>>> 3. Have ModelField and ModelFieldType implement
>>> Validator. Those classes delegate the isValid method call to
>>> their contained validators.
>>>>
>>>> 4. Modify GenericEntity.set method to call the
>>> ModelField's isValid method.
>>>>
>>>> The advantages to this approach are:
>>>>
>>>> 1. Validators are reusable. The same validators could
>>> be used on service parameters for example.
>>>> 2. Client code is shielded from validation details.
>>> Just call the isValid method.
>>>> 3. OFBiz users can implement custom Validator
>>> implementations and add them to the Validator factory.
>>>>
>>>> What do you think?
>>>>
>>>> -Adrian
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>
>

Re: Discussion: Entity Engine Field Validators

Posted by Jacques Le Roux <ja...@les7arts.com>.
+1 

It will be clearer, I remember that I spent some time on this when I began on OFBiz...

Jacques

From: "David E Jones" <de...@me.com>
> Not from me.
> 
> -David
> 
> 
> On Jun 30, 2010, at 11:45 PM, Adrian Crum wrote:
> 
>> Would there be any objections to me removing the validators from the fieldtype*.xml files?
>> 
>> -Adrian
>> 
>> --- On Sat, 6/26/10, David E Jones <de...@me.com> wrote:
>> 
>>> From: David E Jones <de...@me.com>
>>> Subject: Re: Discussion: Entity Engine Field Validators
>>> To: dev@ofbiz.apache.org
>>> Date: Saturday, June 26, 2010, 9:58 AM
>>> 
>>> The validators are only used in the WebTools Entity Data
>>> Maintenance screens.
>>> 
>>> They are intentionally not used in other parts of the
>>> project as validation is best in the logic layer, and not in
>>> the data layer (makes things far more reusable and
>>> flexible).
>>> 
>>> I actually consider these to be a bad design from very
>>> early on in the project when the entity engine was one of
>>> the only tools in the framework, and IMO it would be better
>>> to remove them than to support them everywhere.
>>> 
>>> -David
>>> 
>>> 
>>> On Jun 26, 2010, at 10:54 AM, Adrian Crum wrote:
>>> 
>>>> The entity engine allows you to specify field
>>> validators in two places: in the fieldtypeXxx.xml files and
>>> in the the entity definition.
>>>> 
>>>> The validators in the fieldtype files are not used as
>>> far as I can tell.
>>>> 
>>>> The validators in the entity definitions require
>>> complicated client code to use them - they are not used
>>> automatically by the entity engine.
>>>> 
>>>> The bottom line is, specifying a validator in either
>>> location does absolutely nothing. I don't know if this was
>>> designed this way or not.
>>>> 
>>>> I have a design in mind that I think will be
>>> better...
>>>> 
>>>> 1. Create a validator interface that can be used
>>> throughout the project:
>>>> 
>>>> public interface Validator {
>>>>    void isValid(Object obj;
>>>> }
>>>> 
>>>> The isValid method throws an IllegalArgumentException
>>> if the object is not valid.
>>>> 
>>>> 2. Set up a library of commonly used validators and
>>> put them in a Validator factory. Modify ModelField and
>>> ModelFieldType so they load validators from the factory.
>>>> 
>>>> 3. Have ModelField and ModelFieldType implement
>>> Validator. Those classes delegate the isValid method call to
>>> their contained validators.
>>>> 
>>>> 4. Modify GenericEntity.set method to call the
>>> ModelField's isValid method.
>>>> 
>>>> The advantages to this approach are:
>>>> 
>>>> 1. Validators are reusable. The same validators could
>>> be used on service parameters for example.
>>>> 2. Client code is shielded from validation details.
>>> Just call the isValid method.
>>>> 3. OFBiz users can implement custom Validator
>>> implementations and add them to the Validator factory.
>>>> 
>>>> What do you think?
>>>> 
>>>> -Adrian
>>>> 
>>>> 
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
>> 
>


Re: Discussion: Entity Engine Field Validators

Posted by David E Jones <de...@me.com>.
Not from me.

-David


On Jun 30, 2010, at 11:45 PM, Adrian Crum wrote:

> Would there be any objections to me removing the validators from the fieldtype*.xml files?
> 
> -Adrian
> 
> --- On Sat, 6/26/10, David E Jones <de...@me.com> wrote:
> 
>> From: David E Jones <de...@me.com>
>> Subject: Re: Discussion: Entity Engine Field Validators
>> To: dev@ofbiz.apache.org
>> Date: Saturday, June 26, 2010, 9:58 AM
>> 
>> The validators are only used in the WebTools Entity Data
>> Maintenance screens.
>> 
>> They are intentionally not used in other parts of the
>> project as validation is best in the logic layer, and not in
>> the data layer (makes things far more reusable and
>> flexible).
>> 
>> I actually consider these to be a bad design from very
>> early on in the project when the entity engine was one of
>> the only tools in the framework, and IMO it would be better
>> to remove them than to support them everywhere.
>> 
>> -David
>> 
>> 
>> On Jun 26, 2010, at 10:54 AM, Adrian Crum wrote:
>> 
>>> The entity engine allows you to specify field
>> validators in two places: in the fieldtypeXxx.xml files and
>> in the the entity definition.
>>> 
>>> The validators in the fieldtype files are not used as
>> far as I can tell.
>>> 
>>> The validators in the entity definitions require
>> complicated client code to use them - they are not used
>> automatically by the entity engine.
>>> 
>>> The bottom line is, specifying a validator in either
>> location does absolutely nothing. I don't know if this was
>> designed this way or not.
>>> 
>>> I have a design in mind that I think will be
>> better...
>>> 
>>> 1. Create a validator interface that can be used
>> throughout the project:
>>> 
>>> public interface Validator {
>>>    void isValid(Object obj;
>>> }
>>> 
>>> The isValid method throws an IllegalArgumentException
>> if the object is not valid.
>>> 
>>> 2. Set up a library of commonly used validators and
>> put them in a Validator factory. Modify ModelField and
>> ModelFieldType so they load validators from the factory.
>>> 
>>> 3. Have ModelField and ModelFieldType implement
>> Validator. Those classes delegate the isValid method call to
>> their contained validators.
>>> 
>>> 4. Modify GenericEntity.set method to call the
>> ModelField's isValid method.
>>> 
>>> The advantages to this approach are:
>>> 
>>> 1. Validators are reusable. The same validators could
>> be used on service parameters for example.
>>> 2. Client code is shielded from validation details.
>> Just call the isValid method.
>>> 3. OFBiz users can implement custom Validator
>> implementations and add them to the Validator factory.
>>> 
>>> What do you think?
>>> 
>>> -Adrian
>>> 
>>> 
>>> 
>>> 
>> 
>> 
> 
> 
>