source: trunk/grails-app/conf/BootStrap.groovy @ 1635

Last change on this file since 1635 was 1635, checked in by work@…, 12 years ago
  • added checks to Grom calls if Grom is available so we can uninstall the plugin on packaging time... resolves issue #359
  • Property svn:keywords set to Rev Author Date
File size: 3.7 KB
Line 
1import dbnp.authentication.SecRole
2import dbnp.authentication.SecUser
3import org.codehaus.groovy.grails.commons.GrailsApplication
4import org.dbnp.gdt.*
5import dbnp.studycapturing.Study
6import dbnp.studycapturing.Subject
7import dbnp.studycapturing.Sample
8import dbnp.rest.common.CommunicationManager
9import org.codehaus.groovy.grails.commons.*
10import dbnp.configuration.*
11
12
13/**
14 * Application Bootstrapper
15 * @Author Jeroen Wesbeek
16 * @Since 20091021
17 *
18 * Revision information:
19 * $Rev: 1635 $
20 * $Author: work@osx.eu $
21 * $Date: 2011-03-15 13:06:25 +0000 (di, 15 mrt 2011) $
22 */
23class BootStrap {
24        // user spring security
25        def springSecurityService
26
27        // inject the datasource
28        def dataSource
29
30        def init = { servletContext ->
31                // Grom a development message
32                if (String.metaClass.getMetaMethod("grom")) "bootstrapping application".grom()
33
34                // get configuration
35                def config = ConfigurationHolder.config
36
37                // set the mail configuration properties in runtime, as
38                // this is not definable in a .properties file due to the
39                // fact for the mail properties a map is used
40                if (config.grails.mail.username && config.grails.mail.password) {
41                        // use TLS
42                        config.grails.mail.port = 465
43                        config.grails.mail.props= [
44                                "mail.smtp.auth": "true",
45                                "mail.smtp.socketFactory.port": '465',
46                                "mail.smtp.socketFactory.class": "javax.net.ssl.SSLSocketFactory",
47                                "mail.smtp.socketFactory.fallback": "false"
48                        ]
49                }
50
51                // define timezone
52                System.setProperty('user.timezone', 'CET')
53
54                // set up authentication (if required)
55                if (!SecRole.count() || !SecUser.count()) BootStrapAuthentication.initDefaultAuthentication(springSecurityService)
56
57                // set up the SAM communication manager
58                // this should probably more dynamic and put into the modules
59                // section instead of the bootstrap as not all instances will
60                // probably run WITH sam. GSCF should be able to run independently
61                // from other modules. Part of gscf ticket #185
62                if (config.modules) {
63                        // Grom a development message
64                        if (String.metaClass.getMetaMethod("grom")) "Registering SAM REST methods".grom()
65                        CommunicationManager.registerModule('gscf', config.grails.serverURL, config.modules)
66                        CommunicationManager.registerRestWrapperMethodsFromSAM()
67                }
68
69                // automatically handle database upgrades
70                DatabaseUpgrade.handleUpgrades(dataSource)
71
72                // developmental/test/demo bootstrapping:
73                //      - templates
74                //      - ontologies
75                //      - and/or studies
76                if (    grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT ||
77                grails.util.GrailsUtil.environment == GrailsApplication.ENV_TEST ||
78                grails.util.GrailsUtil.environment == "dbnpdemo") {
79                        // add ontologies?
80                        if (!Ontology.count()) ExampleTemplates.initTemplateOntologies()
81
82                        // add templates?
83                        if (!Template.count()) ExampleTemplates.initTemplates()
84
85                        // add data required for the webtests?
86                        if (grails.util.GrailsUtil.environment == GrailsApplication.ENV_TEST) ExampleStudies.addTestData()
87
88                        // add example studies?
89                        if (!Study.count() && grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT)
90                                ExampleStudies.addExampleStudies(SecUser.findByUsername('user'), SecUser.findByUsername('admin'))
91                }
92
93                /**
94                 * attach ontologies in runtime. Possible problem is that you need
95                 * an internet connection when bootstrapping though.
96                 * @see dbnp.studycapturing.Subject
97                 * @see dbnp.studycapturing.Sample
98                 */
99                TemplateEntity.getField(Subject.domainFields, 'species').ontologies = [Ontology.getOrCreateOntologyByNcboId(1132)]
100                TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [Ontology.getOrCreateOntologyByNcboId(1005)]
101        }
102
103        def destroy = {
104                // Grom a development message
105                if (String.metaClass.getMetaMethod("grom")) "stopping application...".grom()
106        }
107} 
Note: See TracBrowser for help on using the repository browser.