-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from rmorrise/vdog-merge
Merged in virtualdogbert's changes from grails consortium; tested with grails 3.3.4
- Loading branch information
Showing
7 changed files
with
162 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/groovy/grails/cascade/validation/CascadeValidationGrailsPlugin.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package grails.cascade.validation | ||
|
||
import com.cscinfo.platform.constraint.CascadeConstraint | ||
import grails.plugins.Plugin | ||
import org.grails.datastore.gorm.validation.constraints.factory.DefaultConstraintFactory | ||
import org.grails.datastore.gorm.validation.constraints.eval.ConstraintsEvaluator | ||
import org.grails.datastore.gorm.validation.constraints.eval.DefaultConstraintEvaluator | ||
import org.grails.datastore.gorm.validation.constraints.registry.ConstraintRegistry | ||
import org.springframework.context.ApplicationContext | ||
|
||
class CascadeValidationGrailsPlugin extends Plugin { | ||
|
||
def grailsVersion = "3.3.0 > *" | ||
def title = "Cascade Validation Plugin" | ||
def author = "Russell Morrisey" | ||
def authorEmail = "rmorrise@cscinfo.com" | ||
def description = '''\ | ||
Establishes a 'cascade' constraint property for validateable objects. If "cascade:true" is set | ||
on a nested object, the nested object's validate() method will be invoked and the results will | ||
be reported as part of the parent object's validation. | ||
Based on a blog post by Eric Kelm: | ||
http://asoftwareguy.com/2013/07/01/grails-cascade-validation-for-pogos/ | ||
Used with permission. | ||
''' | ||
def documentation = "https://github.com/rmorrise/grails-cascade-validation/wiki/How-to-use-cascade-validation" | ||
def license = "APACHE" | ||
def organization = [name: "CSC", url: "http://www.cscglobal.com/"] | ||
def issueManagement = [system: 'GITHUB', url: 'https://github.com/rmorrise/grails-cascade-validation/issues'] | ||
def scm = [url: 'https://github.com/rmorrise/grails-cascade-validation'] | ||
|
||
def developers = [ | ||
[name: "Burt Beckwith"], | ||
[name: "Soeren Glasius", email: "soeren@glasius.dk"], | ||
[name: "Eric Kelm"], | ||
[name: "Russell Morrisey", email: "russell.morrisey@cscglobal.com"], | ||
[name: "Christian Oestreich"], | ||
[name: "Virtualdogbert"] | ||
] | ||
|
||
void doWithApplicationContext() { | ||
registerCustomConstraints(applicationContext) | ||
} | ||
|
||
private void registerCustomConstraints(ApplicationContext ctx) { | ||
//This method for registering constraints came from longwa | ||
List<ConstraintRegistry> registries = [] | ||
DefaultConstraintEvaluator evaluator = ctx.getBean(ConstraintsEvaluator) as DefaultConstraintEvaluator | ||
|
||
// Register with both the default constraint as well as the gorm registry (it's stupid that it needs both) | ||
// Also the ConstraintsEvaluator evaluator constructs a new internal registry and doesn't seem to expose it | ||
// so we are forced to invade it's privacy if we want custom constraints for Validateable instances. | ||
registries << evaluator.constraintRegistry | ||
registries << ctx.getBean("gormValidatorRegistry", ConstraintRegistry) | ||
|
||
registries.each { ConstraintRegistry registry -> | ||
registry.addConstraint(CascadeConstraint) | ||
} | ||
} | ||
|
||
} |
34 changes: 0 additions & 34 deletions
34
src/main/groovy/grails/cascade/validation/GrailsCascadeValidationGrailsPlugin.groovy
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.