I would like my templates to be smarter about generating controllers. In my domain classes I have specified an enum with the properties that should be added to the security annotation in the controller.
static enum SecurityProperties {
ROLE_SUPER_USER( "ROLE_SUPER_USER" ),
IS_AUTHENTICATED_FULLY( "IS_AUTHENTICATED_FULLY" )
SecurityProperties( String s ) {
this.s = s
}
@Override
public String toString() {
return s;
}
}
I would like the template to look at this enum and create the security annotation in a controller when the controller is generated. I use the templates a lot and it is a major annoyance to run generate-all then have to add the security annotations back in for all of my controllers.
My problem is that I am having issues accessing the enum from the template because I cannot get the domain class.
I usually get a domain class like this:
grailsApplication.getArtefact( "Domain", "myDomainClass" )?.getClazz()
But grailsApplication is not available in the template.
What other Grails / Groovy way is there to get the class or make grailsApplication available?
Within the scaffolding templates you have a
domainClassvariable available to you which contains theGrailsDomainClass, sodomainClass.clazzshould give you what you need.