root/trunk/grails-app/conf/BootStrap.groovy @ 1178

Revision 1178, 2.6 KB (checked in by work@…, 3 years ago)

- this change is part of #185
- moved object instantes out of Config.groovy (this should only contain configuration)
- moved module specific configuration for SAM and Metabolomics out of BootStrapStudies?.groovy and into Config.groovy

  • Property svn:keywords set to Author Date Rev
Line 
1import dbnp.authentication.SecRole
2import dbnp.authentication.SecUser
3import org.codehaus.groovy.grails.commons.GrailsApplication
4import dbnp.data.Ontology
5import dbnp.studycapturing.Template
6import dbnp.studycapturing.Study
7import dbnp.studycapturing.TemplateEntity
8import dbnp.studycapturing.Subject
9import dbnp.studycapturing.Sample
10import dbnp.rest.common.CommunicationManager
11import org.codehaus.groovy.grails.commons.*
12
13/**
14 * Application Bootstrapper
15 * @Author Jeroen Wesbeek
16 * @Since 20091021
17 *
18 * Revision information:
19 * $Rev$
20 * $Author$
21 * $Date$
22 */
23class BootStrap {
24        // user spring security
25        def springSecurityService
26
27        def init = { servletContext ->
28                // grom what's happening
29                "bootstrapping application".grom()
30
31                // get configuration
32                def config = ConfigurationHolder.config
33
34                // define timezone
35                System.setProperty('user.timezone', 'CET')
36
37                // set up authentication (if required)
38                if (!SecRole.count() || !SecUser.count()) BootStrapAuthentication.initDefaultAuthentication(springSecurityService)
39
40                // set up the SAM communication manager
41                // this should probably more dynamic and put into the modules
42                // section instead of the bootstrap as not all instances will
43                // probably run WITH sam. GSCF should be able to run independently
44                // from other modules. Part of gscf ticket #185
45                if (config.modules?.sam) {
46                        // register SAM REST methods
47                        "Registering SAM REST methods".grom()
48                        CommunicationManager.SAMServerURL = config.modules.sam.url
49                        CommunicationManager.registerRestWrapperMethodsGSCFtoSAM()
50                }
51
52                // developmental bootstrapping:
53                //      - templates
54                //      - ontologies
55                //      - and/or studies
56                if (grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) {
57                        // add ontologies?
58                        if (!Ontology.count()) BootStrapTemplates.initTemplateOntologies()
59
60                        // add templates?
61                        if (!Template.count()) BootStrapTemplates.initTemplates()
62
63                        // add example studies?
64                        if (!Study.count() && grails.util.GrailsUtil.environment != "demo") BootStrapStudies.addExampleStudies(SecUser.findByUsername('user'), SecUser.findByUsername('admin'))
65                }
66
67                /**
68                 * attach ontologies in runtime. Possible problem is that you need
69                 * an internet connection when bootstrapping though.
70                 * @see dbnp.studycapturing.Subject
71                 * @see dbnp.studycapturing.Sample
72                 */
73                TemplateEntity.getField(Subject.domainFields, 'species').ontologies = [Ontology.getOrCreateOntologyByNcboId(1132)]
74                TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [Ontology.getOrCreateOntologyByNcboId(1005)]
75        }
76
77        def destroy = {
78                println "stopping application..."
79        }
80}
Note: See TracBrowser for help on using the browser.