Discussion: Entity Engine Field Validators

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Discussion: Entity Engine Field Validators

Adrian Crum-2
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




Reply | Threaded
Open this post in threaded view
|

Re: Discussion: Entity Engine Field Validators

David E. Jones-2

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
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Discussion: Entity Engine Field Validators

Adrian Crum-2
Cool - thanks!

-Adrian

--- On Sat, 6/26/10, David E Jones <[hidden email]> wrote:

> From: David E Jones <[hidden email]>
> Subject: Re: Discussion: Entity Engine Field Validators
> To: [hidden email]
> 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
> >
> >
> >
> >
>
>


   
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: Entity Engine Field Validators

Adrian Crum-2
In reply to this post by David E. Jones-2
Would there be any objections to me removing the validators from the fieldtype*.xml files?

-Adrian

--- On Sat, 6/26/10, David E Jones <[hidden email]> wrote:

> From: David E Jones <[hidden email]>
> Subject: Re: Discussion: Entity Engine Field Validators
> To: [hidden email]
> 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
> >
> >
> >
> >
>
>


   
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: Entity Engine Field Validators

David E. Jones-2

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 <[hidden email]> wrote:
>
>> From: David E Jones <[hidden email]>
>> Subject: Re: Discussion: Entity Engine Field Validators
>> To: [hidden email]
>> 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
>>>
>>>
>>>
>>>
>>
>>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Discussion: Entity Engine Field Validators

Jacques Le Roux
Administrator
+1

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

Jacques

From: "David E Jones" <[hidden email]>

> 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 <[hidden email]> wrote:
>>
>>> From: David E Jones <[hidden email]>
>>> Subject: Re: Discussion: Entity Engine Field Validators
>>> To: [hidden email]
>>> 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
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: Discussion: Entity Engine Field Validators

Adrian Crum
In reply to this post by David E. Jones-2
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<[hidden email]>  wrote:
>>
>>> From: David E Jones<[hidden email]>
>>> Subject: Re: Discussion: Entity Engine Field Validators
>>> To: [hidden email]
>>> 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
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>
>