Condition Handling - WIP?

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

Condition Handling - WIP?

Sean P. DeNigris
Administrator
I'm wondering whether conditions could be fleshed out some more or if I'm
missing some intention/design…

I was employing a technique described by Ramon Leon [1] for conditions that
affect multiple descriptions, namely:
```
descriptionContainer
    ^(super descriptionContainer)
        addCondition: [:memento |
            (memento cache at: self descriptionEndDate) > (memento cache at:
self descriptionStartDate)]            
        labelled: 'End date must be after start date';
        yourself
```

I noticed a few seeming limitations of this technique (and conditions in
general):
1. The example above only works when using a cached memento. It fails due to
DNU #cache for other Memento types, as well as when validating objects
directly (e.g. `myDomainObject magritteDescription validate: self.`)
2. When the above fails, the exception bubbles up on its own instead of
being grouped together with failed conditions from individual descriptions
because `MAValidatorVisitor>>#visitContainer:` handles the container
validation separately (via `super visitContainer: aDescription.`) before
looping through the element descriptions to validate them.
3. In both the container and element validations, once one condition
per-[container | element] fails, others are not processed (for the same
[container | element]). I experimented with expanding the error handling
block, but couldn't see a great way to overcome this without a more
significant rewrite because MAValidationErrors are not resumable.

My quick fix idea would be to make MAValidationErrors resumable and expand
the error block to include the container along with the element validations.
Would that be the best way to address the issues above?

1. http://onsmalltalk.com/multiple-field-validation-rules-in-magritte



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Magritte-Pier-and-Related-Tools-f115649.html
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.list.inf.unibe.ch/listinfo/smallwiki
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Condition Handling - WIP?

Stephan Eggermont-3
Sean P. DeNigris <[hidden email]> wrote:
> I'm wondering whether conditions could be fleshed out some more or if I'm
missing some intention/design…

I'm pretty sure you want to consider calculating derived values at the same
time as doing your validations, so yes, some more involved surgery seems
needed

Stephan

_______________________________________________
Magritte, Pier and Related Tools ...
https://www.list.inf.unibe.ch/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Condition Handling - WIP?

Sean P. DeNigris
Administrator
In reply to this post by Sean P. DeNigris
Sean P. DeNigris wrote
> 1. The example above only works when using a cached memento. It fails due
> to
> DNU #cache for other Memento types, as well as when validating objects
> directly (e.g. `myDomainObject magritteDescription validate: self.`)

This one was actually a bug/limitation in the example code. Replacing `cache
at:` with `readUsing:`, which is polymorphic among all Memento types and
Object, solves the problem.

So:
```
addCondition: [:memento |
            (memento cache at: self descriptionEndDate) > (memento cache at:
self descriptionStartDate)]
```
becomes
```
addCondition: [:memento |
            (memento readUsing: self descriptionEndDate) > (memento
readUsing:
self descriptionStartDate)]
```



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Magritte-Pier-and-Related-Tools-f115649.html
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.list.inf.unibe.ch/listinfo/smallwiki
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Condition Handling - WIP?

Sean P. DeNigris
Administrator
In reply to this post by Stephan Eggermont-3
Stephan Eggermont-3 wrote
> yes, some more involved surgery seems needed

All points in the OP are fixed [1]. It's hard to show #2 in a script, but
this illustrates #3:
```
desc := MADurationDescription new
        addCondition: [ :d | d hours = d minutes ];
        addCondition: [ :d | d hours = d days ];
        yourself.
duration := '1:02:03:04' asDuration.
desc validate: duration. "Returns a MAMultipleErrors with both failed
conditions instead of stopping validation after the first failure"
```

1.
https://github.com/seandenigris/Magritte3/commit/5f295a5e075a3246b7c726281667055f8aa53505



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Magritte-Pier-and-Related-Tools-f115649.html
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.list.inf.unibe.ch/listinfo/smallwiki
Cheers,
Sean