forked from AtlasOfLivingAustralia/biocache-hubs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBiocacheHubsGrailsPlugin.groovy
159 lines (133 loc) · 6.41 KB
/
BiocacheHubsGrailsPlugin.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Copyright (C) 2014 Atlas of Living Australia
* All Rights Reserved.
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*/
import au.org.ala.biocache.hubs.EnglishValueConverter
import au.org.ala.biocache.hubs.ExtendedPluginAwareResourceBundleMessageSource
import grails.util.Environment
class BiocacheHubsGrailsPlugin {
// the plugin version
def version = "1.3-SNAPSHOT"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "2.3 > *"
// resources that are excluded from plugin packaging
def pluginExcludes = [
"grails-app/views/error.gsp"
]
def title = "Biocache Hubs Plugin" // Headline display name of the plugin
def author = "Nick dos Remedios"
def authorEmail = "[email protected]"
def description = '''\
A Grails plugin to provide the core functionality for searching and displaying biodiversity data from
biocache web services. Data access is via JSON REST web services
from the ALA biocache-service app (no local DB is required for this app).
'''
// URL to the plugin's documentation
def documentation = "https://github.com/AtlasOfLivingAustralia/biocache-hubs"
// License: one of 'APACHE', 'GPL2', 'GPL3'
def license = "MPL2"
// Details of company behind the plugin (if there is one)
def organization = [ name: "Atlas of Living Australia", url: "http://www.ala.org.au/" ]
// Any additional developers beyond the author specified above.
def developers = [
[ name: "Dave Martin", email: "[email protected]" ],
[ name: "Dave Baird", email: "[email protected]" ]
]
// Location of the plugin's issue tracker.
def issueManagement = [ system: "Google Code", url: "https://github.com/AtlasOfLivingAustralia/biocache-hubs/issues" ]
// Online location of the plugin's browseable source code.
def scm = [ url: "https://github.com/AtlasOfLivingAustralia/biocache-hubs" ]
def loadBefore = ['alaBootstrap2']
def loadAfter = ['dataBinding'] // needed for custom ValueConverter bean
def doWithWebDescriptor = { xml ->
// Note this code only gets executed at compile time (not runtime)
}
def doWithSpring = {
def config = application.config
// EhCache settings
if (!config.grails.cache.config) {
config.grails.cache.config = {
defaults {1
eternal false
overflowToDisk false
maxElementsInMemory 10000
timeToLiveSeconds 3600
}
cache {
name 'collectoryCache'
timeToLiveSeconds (3600 * 4)
}
cache {
name 'longTermCache'
timeToLiveSeconds (3600 * 12)
}
cache {
name 'outageCache'
timeToLiveSeconds (3600 * 24 * 7)
}
}
}
// Apache proxyPass & cached-resources seems to mangle image URLs in plugins, so we exclude caching it
application.config.grails.resources.mappers.hashandcache.excludes = ["**/images/*.*","**/eya-images/*.*"]
// include fonts in resources
application.config.grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*', '/fonts/*']
// Load the "sensible defaults"
//println "config.skin = ${config.skin}"
def loadConfig = new ConfigSlurper(Environment.current.name).parse(application.classLoader.loadClass("defaultConfig"))
application.config = loadConfig.merge(config) // client app will now override the defaultConfig version
//application.config.merge(loadConfig) //
//println "config.security = ${config.security}"
// Custom message source
messageSource(ExtendedPluginAwareResourceBundleMessageSource) {
basenames = ["WEB-INF/grails-app/i18n/messages","${application.config.biocache.baseUrl}/facets/i18n"] as String[]
cacheSeconds = (60 * 60 * 6) // 6 hours
useCodeAsDefaultMessage = false
}
// Define Custom ValueConverter beans (force EN formatting of Floats)
"defaultGrailsjava.lang.FloatConverter"(EnglishValueConverter) // for Float
defaultGrailsfloatConverter(EnglishValueConverter) // for float
println "grails.resources.work.dir = " + config.grails.resources.work.dir
// check custom resources cache dir for permissions
if (config.grails.resources.work.dir) {
if (new File(config.grails.resources.work.dir).isDirectory()) {
// cache dir exists - check if its writable
if (!new File(config.grails.resources.work.dir).canWrite()) {
//grailsConsole.error "grails.resources.work.dir (${config.grails.resources.work.dir}) is NOT WRITABLE, please fix this!"
println "grails.resources.work.dir (${config.grails.resources.work.dir}) is NOT WRITABLE, please fix this!"
}
} else {
// check we can create the directory
if (!new File(config.grails.resources.work.dir).mkdir()) {
println "grails.resources.work.dir (${config.grails.resources.work.dir}) cannot be created, please fix this!"
}
}
}
// check if the "bootstrap' resource is loaded from client app or another plugin
def resourceTagLib = application.getClassForName('org.grails.plugin.resource.ResourceTagLib')
try {
resourceTagLib.require(module: 'bootstrap')
} catch (Exception e) {
println "Required resource 'bootstrap' not declared. Ensure the client app has this in their ApplicationResources.groovy file (or a plugin).", e
}
}
def doWithDynamicMethods = { ctx ->
}
def doWithApplicationContext = { ctx ->
}
def onChange = { event ->
}
def onConfigChange = { event ->
}
def onShutdown = { event ->
}
}