Magritte2 validation behaviour question

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

Magritte2 validation behaviour question

Bart Gauquie
Dear list,

I have a question about the validation behaviour of Magritte 2.

I have a root entity an Animal. This animal has some properties that are required. (beRequired specified on the descriptions). And a condition between some properties:

Animal class>>conditionDateOfDeathVerplichtBijStatusDeath
    ^[:value|
        |dateOfDeath status|
        dateOfDeath := value readUsing: self descriptionDateOfDeath.
        status := value readUsing: self descriptionStatus.
        (status == AnimalStatus dead)
            ifTrue: [dateOfDeath isNil not]
            ifFalse: [true]]

and:

Animal class>>descriptionContainer
    ^super descriptionContainer
        addCondition: (self conditionDateOfDeathVerplichtBijStatusDeath) labelled: 'Date of death is verplicht bij status Death';
        yourself.


Validation of this Animal entity works fine if I don't fill in the required fields => 3 error messages appear. If I choose status=death, but forget to fill in a date of death the message appears.

However if I do both: forget to fill in required fields, and choose status=death and forget to fill in date of death; only the date of death message appears... This is something I'm not expecting.

I've looked into the code and:

MAValidationVisitor>>visitContainer: aDescription
    | errors |
    super visitContainer: aDescription.
    self object ifNil: [ ^ self ].
    errors := OrderedCollection new.
    aDescription do: [ :description |
        [ self
            use: (object readUsing: description)
            during: [ self visit: description ] ]
                on: MAValidationError
                do: [ :err | errors add: err ] ].
    errors isEmpty ifFalse: [
        MAMultipleErrors
            description: aDescription
            errors: errors
            signal: aDescription label ]

is the code that validates a container with its children.
the line:    
    super visitContainer: aDescription.
validates the container itself, so the extra condition=> if that one failes, an error thrown up the stack and it does not validate the children any more (the required conditions).

If I change the code to something like:
MAValidationVisitor>>visitContainer: aDescription
    | errors |
    errors := OrderedCollection new.
    [super visitContainer: aDescription]
        on: MAValidationError
        do: [:err|errors add: err].
    self object ifNil: [ ^ self ].

    aDescription do: [ :description |
        [ self
            use: (object readUsing: description)
            during: [ self visit: description ] ]
                on: MAValidationError
                do: [ :err | errors add: err ] ].
    errors isEmpty ifFalse: [
        MAMultipleErrors
            description: aDescription
            errors: errors
            signal: aDescription label ]

I collect both errors and see a list of all errors in my gui. I'm not sure if this is a correct fix.
Any advice on this problem? Or is it by design that Magritte behaves like this.

Thanks for any help,

Bart

--
imagination is more important than knowledge - Albert Einstein
Logic will get you from A to B. Imagination will take you everywhere - Albert Einstein
Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning. - Albert Einstein
The true sign of intelligence is not knowledge but imagination. - Albert Einstein
However beautiful the strategy, you should occasionally look at the results. - Sir Winston Churchill
It's not enough that we do our best; sometimes we have to do what's required. - Sir Winston Churchill

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Magritte2 validation behaviour question

Lukas Renggli
Hi Bart,

That validation code is indeed very ugly and tricky. The current
design assumes that if a parent object fails to validate it shouldn't
further try to validate its children. I suspect this is why you don't
see some of the errors.

Depending on context this might be the correct way of validation, in
other cases you might need something more like you've implemented. I
suggest that you create your own subclass of MAValidationVisitor (so
that you don't need to change the core code) and set it for validation
in your container description

If people think the validation you propose is generally more useful we
can of course change that in the Magritte code as well, but I am not
sure. For validation of nested objects, as well as for references the
different requirements of displaying and performing explode :-(

Lukas



On 8 September 2010 21:55, Bart Gauquie <[hidden email]> wrote:

> Dear list,
>
> I have a question about the validation behaviour of Magritte 2.
>
> I have a root entity an Animal. This animal has some properties that are
> required. (beRequired specified on the descriptions). And a condition
> between some properties:
>
> Animal class>>conditionDateOfDeathVerplichtBijStatusDeath
>     ^[:value|
>         |dateOfDeath status|
>         dateOfDeath := value readUsing: self descriptionDateOfDeath.
>         status := value readUsing: self descriptionStatus.
>         (status == AnimalStatus dead)
>             ifTrue: [dateOfDeath isNil not]
>             ifFalse: [true]]
>
> and:
>
> Animal class>>descriptionContainer
>     ^super descriptionContainer
>         addCondition: (self conditionDateOfDeathVerplichtBijStatusDeath)
> labelled: 'Date of death is verplicht bij status Death';
>         yourself.
>
>
> Validation of this Animal entity works fine if I don't fill in the required
> fields => 3 error messages appear. If I choose status=death, but forget to
> fill in a date of death the message appears.
>
> However if I do both: forget to fill in required fields, and choose
> status=death and forget to fill in date of death; only the date of death
> message appears... This is something I'm not expecting.
>
> I've looked into the code and:
>
> MAValidationVisitor>>visitContainer: aDescription
>     | errors |
>     super visitContainer: aDescription.
>     self object ifNil: [ ^ self ].
>     errors := OrderedCollection new.
>     aDescription do: [ :description |
>         [ self
>             use: (object readUsing: description)
>             during: [ self visit: description ] ]
>                 on: MAValidationError
>                 do: [ :err | errors add: err ] ].
>     errors isEmpty ifFalse: [
>         MAMultipleErrors
>             description: aDescription
>             errors: errors
>             signal: aDescription label ]
>
> is the code that validates a container with its children.
> the line:
>     super visitContainer: aDescription.
> validates the container itself, so the extra condition=> if that one failes,
> an error thrown up the stack and it does not validate the children any more
> (the required conditions).
>
> If I change the code to something like:
> MAValidationVisitor>>visitContainer: aDescription
>     | errors |
>     errors := OrderedCollection new.
>     [super visitContainer: aDescription]
>         on: MAValidationError
>         do: [:err|errors add: err].
>     self object ifNil: [ ^ self ].
>
>     aDescription do: [ :description |
>         [ self
>             use: (object readUsing: description)
>             during: [ self visit: description ] ]
>                 on: MAValidationError
>                 do: [ :err | errors add: err ] ].
>     errors isEmpty ifFalse: [
>         MAMultipleErrors
>             description: aDescription
>             errors: errors
>             signal: aDescription label ]
>
> I collect both errors and see a list of all errors in my gui. I'm not sure
> if this is a correct fix.
> Any advice on this problem? Or is it by design that Magritte behaves like
> this.
>
> Thanks for any help,
>
> Bart
>
> --
> imagination is more important than knowledge - Albert Einstein
> Logic will get you from A to B. Imagination will take you everywhere -
> Albert Einstein
> Learn from yesterday, live for today, hope for tomorrow. The important thing
> is not to stop questioning. - Albert Einstein
> The true sign of intelligence is not knowledge but imagination. - Albert
> Einstein
> However beautiful the strategy, you should occasionally look at the results.
> - Sir Winston Churchill
> It's not enough that we do our best; sometimes we have to do what's
> required. - Sir Winston Churchill
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
>



--
Lukas Renggli
www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Magritte2 validation behaviour question

Bart Gauquie
Lukas,

Thanks for your reply.
I also thought that was the rationale behind it.
I will make a local extension that suits my needs and check if 'strange things' happen.

Regards,

Bart

On Wed, Sep 8, 2010 at 10:15 PM, Lukas Renggli <[hidden email]> wrote:
Hi Bart,

That validation code is indeed very ugly and tricky. The current
design assumes that if a parent object fails to validate it shouldn't
further try to validate its children. I suspect this is why you don't
see some of the errors.

Depending on context this might be the correct way of validation, in
other cases you might need something more like you've implemented. I
suggest that you create your own subclass of MAValidationVisitor (so
that you don't need to change the core code) and set it for validation
in your container description

If people think the validation you propose is generally more useful we
can of course change that in the Magritte code as well, but I am not
sure. For validation of nested objects, as well as for references the
different requirements of displaying and performing explode :-(

Lukas



On 8 September 2010 21:55, Bart Gauquie <[hidden email]> wrote:
> Dear list,
>
> I have a question about the validation behaviour of Magritte 2.
>
> I have a root entity an Animal. This animal has some properties that are
> required. (beRequired specified on the descriptions). And a condition
> between some properties:
>
> Animal class>>conditionDateOfDeathVerplichtBijStatusDeath
>     ^[:value|
>         |dateOfDeath status|
>         dateOfDeath := value readUsing: self descriptionDateOfDeath.
>         status := value readUsing: self descriptionStatus.
>         (status == AnimalStatus dead)
>             ifTrue: [dateOfDeath isNil not]
>             ifFalse: [true]]
>
> and:
>
> Animal class>>descriptionContainer
>     ^super descriptionContainer
>         addCondition: (self conditionDateOfDeathVerplichtBijStatusDeath)
> labelled: 'Date of death is verplicht bij status Death';
>         yourself.
>
>
> Validation of this Animal entity works fine if I don't fill in the required
> fields => 3 error messages appear. If I choose status=death, but forget to
> fill in a date of death the message appears.
>
> However if I do both: forget to fill in required fields, and choose
> status=death and forget to fill in date of death; only the date of death
> message appears... This is something I'm not expecting.
>
> I've looked into the code and:
>
> MAValidationVisitor>>visitContainer: aDescription
>     | errors |
>     super visitContainer: aDescription.
>     self object ifNil: [ ^ self ].
>     errors := OrderedCollection new.
>     aDescription do: [ :description |
>         [ self
>             use: (object readUsing: description)
>             during: [ self visit: description ] ]
>                 on: MAValidationError
>                 do: [ :err | errors add: err ] ].
>     errors isEmpty ifFalse: [
>         MAMultipleErrors
>             description: aDescription
>             errors: errors
>             signal: aDescription label ]
>
> is the code that validates a container with its children.
> the line:
>     super visitContainer: aDescription.
> validates the container itself, so the extra condition=> if that one failes,
> an error thrown up the stack and it does not validate the children any more
> (the required conditions).
>
> If I change the code to something like:
> MAValidationVisitor>>visitContainer: aDescription
>     | errors |
>     errors := OrderedCollection new.
>     [super visitContainer: aDescription]
>         on: MAValidationError
>         do: [:err|errors add: err].
>     self object ifNil: [ ^ self ].
>
>     aDescription do: [ :description |
>         [ self
>             use: (object readUsing: description)
>             during: [ self visit: description ] ]
>                 on: MAValidationError
>                 do: [ :err | errors add: err ] ].
>     errors isEmpty ifFalse: [
>         MAMultipleErrors
>             description: aDescription
>             errors: errors
>             signal: aDescription label ]
>
> I collect both errors and see a list of all errors in my gui. I'm not sure
> if this is a correct fix.
> Any advice on this problem? Or is it by design that Magritte behaves like
> this.
>
> Thanks for any help,
>
> Bart
>
> --
> imagination is more important than knowledge - Albert Einstein
> Logic will get you from A to B. Imagination will take you everywhere -
> Albert Einstein
> Learn from yesterday, live for today, hope for tomorrow. The important thing
> is not to stop questioning. - Albert Einstein
> The true sign of intelligence is not knowledge but imagination. - Albert
> Einstein
> However beautiful the strategy, you should occasionally look at the results.
> - Sir Winston Churchill
> It's not enough that we do our best; sometimes we have to do what's
> required. - Sir Winston Churchill
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
>



--
Lukas Renggli
www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



--
imagination is more important than knowledge - Albert Einstein
Logic will get you from A to B. Imagination will take you everywhere - Albert Einstein
Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning. - Albert Einstein
The true sign of intelligence is not knowledge but imagination. - Albert Einstein
However beautiful the strategy, you should occasionally look at the results. - Sir Winston Churchill
It's not enough that we do our best; sometimes we have to do what's required. - Sir Winston Churchill

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside