Minimum Criteria Plugin

  • Tags : validation, constraints
  • Latest : 0.1.1
  • Last Updated: 21 November 2009
  • Grails version : *
  • Authors : null
2 votes
Dependency :
compile ":min-criteria:0.1.1"

Documentation

Summary

Installation

grails install-plugin min-criteria

Description

What is Grails Minimum Criteria plugin?

DSL (Domain Specific Language) for expressing, applying and validating domain minimum criteria in Grails

Can you give me an example?

Business requirement: Address is valid if and only if "it has" one of the following combinations (of properties) set:

'zipCode'
     OR 'street, city and country'
     OR 'city and state'
     OR 'city and country'
     OR 'latitude and longitude'

With minCriteria plugin this can be expressed in the Address domain object as:

static minCriteria = [

[ 'zipCode' ], [ 'street', 'city', 'country' ], [ 'city', 'state' ], [ 'city', 'country' ], [ 'latitude', 'longitude' ] ]

Every time "Address.validate()" is called, whether it is automatically on ".save()" or explicitly in the controller, the plugin will ensure that Address minimum criteria (Business requirement) is met

What error do I get in case a minimum criteria was not met?

Currently a default message returned/displayed in case a minimum criteria is not met:

Minimum criteria for [Address] is not met

"Address" here is the domain object name discussed above. By default the plugin would pick up a domain name and would use it within the error message (e.g. if your domain name is 'Car', the default error message would be "Minimum criteria for [Car] is not met").

But this message is configurable through 'validation.error.min.criteria' message property. And since v0.1.1, the plugin supports message parameters (something that is called "errorArgs" in Spring). For example, if you put the following property under "grails-app/i18n/messages.properties":

validation.error.min.criteria=Minimum search criteria for {0} is not met.

and your domain name is 'Car', the message your end-user would get is:

Minimum search criteria for Car is not met.

_see_ TODO.markdown document to read about future enhancements

So, is it like Grails native constraints?

The idea is to make sure that Domain objects have a set of different criterias that should be met once they are validated. It is similar to Grails "native" constraints, however this plugin allows to set a minimum criteria as different combinations of Domain properties

Sounds pretty 'like any other plugin' to me, so how can I use it?

Besides the obvious (validating Domain objects), this plugin can be used to specify/validate the minimum search criteria, as well as any minimum other criterias

author

Anatoly Polinsky e-mail me

Please let me know about any issues / suggestions / general thought via e-mail or the Grails User mailing list and/or create an issue in JIRA at http://jira.codehaus.org/browse/GRAILSPLUGINS under (still waiting for a JIRA account).

change log

  • November 22nd, 2009
    • adding message property parameters e.g. {0} support
  • November 18th, 2009
    • released version 0.1

home page

here is where I live