-
Notifications
You must be signed in to change notification settings - Fork 0
/
DomainViewsGrailsPlugin.groovy
92 lines (75 loc) · 3.24 KB
/
DomainViewsGrailsPlugin.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import it.openmindonline.domainviews.builder.*
import it.openmindonline.domainviews.DomainViewsService
class DomainViewsGrailsPlugin {
// the plugin version
def version = "0.5.3"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "2.2 > *"
// resources that are excluded from plugin packaging
def pluginExcludes = [
"grails-app/views/error.gsp"
,"grails-app/domain/it/openmindonline/domainviews/test/dataobjects/*.groovy"
,"grails-app/services/it/openmindonline/domainviews/test/dataobjects/*groovy"
,"grails-app/conf/*"
]
// TODO Fill in these fields
def title = "Domain Views Plugin" // Headline display name of the plugin
def author = "Carlo Colombo"
def authorEmail = "[email protected]"
def description = '''\
Grails plugin that allows to define views via a custom DSL to convert beans to maps
'''
// URL to the plugin's documentation
def documentation = "http://grails.org/plugin/domain-views"
// Extra (optional) plugin metadata
// License: one of 'APACHE', 'GPL2', 'GPL3'
def license = "APACHE"
// Details of company behind the plugin (if there is one)
def organization = [ name: "Openmind", url: "http://www.openmindlab.com/" ]
// Any additional developers beyond the author specified above.
def developers = [
[ name: "Manuel Molaschi", email: "[email protected]" ]
]
// Location of the plugin's issue tracker.
def issueManagement = [ system: "GITHUB", url: "https://github.com/openmindlab/grails-domainviews/issues" ]
// Online location of the plugin's browseable source code.
def scm = [ url: "https://github.com/openmindlab/grails-domainviews" ]
def loadAndNormalize(application){
def views = DomainViewsBuilder.load(application)
if (application.config.domainViewsConfig.defaultView){
application.getArtefacts("Domain")
.findAll{
application.config.domainViewsConfig.defaultView.packages.any{ packageName ->
it.clazz.package.toString().contains(packageName)
}
}.each{
if(!views.containsKey(it.logicalPropertyName)){
views[it.logicalPropertyName] = [
views:[
standard : new ViewAll()
]
]
}
}
}
if (views){
application.config.domainViews = views
def domainViewsService = new DomainViewsService(grailsApplication: application)
application.config.domainViews.each{domainName,_ ->
def domainClass = application.getArtefactByLogicalPropertyName("Domain",domainName)
domainViewsService.normalize domainClass?.clazz
}
}
}
def doWithApplicationContext = { applicationContext ->
loadAndNormalize(application)
}
def watchedResources = "file:./grails-app/conf/*Views.groovy"
def onChange = { event ->
loadAndNormalize(event.application)
}
def onConfigChange = { event ->
}
def onShutdown = { event ->
}
}