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

Last change on this file since 1384 was 1384, checked in by business@…, 10 years ago

added webtest plugin and first (working) webtest, renamed 'test' configuration to 'nmcdsptest' to avoid conflicts with grails default test environment

  • Property svn:keywords set to Author Date Rev
File size: 2.8 KB
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: 1384 $
20 * $Author: business@keesvanbochove.nl $
21 * $Date: 2011-01-12 21:00:59 +0000 (wo, 12 jan 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 what's happening
32                "bootstrapping application".grom()
33
34                // get configuration
35                def config = ConfigurationHolder.config
36
37                // define timezone
38                System.setProperty('user.timezone', 'CET')
39
40                // set up authentication (if required)
41                if (!SecRole.count() || !SecUser.count()) BootStrapAuthentication.initDefaultAuthentication(springSecurityService)
42
43                // set up the SAM communication manager
44                // this should probably more dynamic and put into the modules
45                // section instead of the bootstrap as not all instances will
46                // probably run WITH sam. GSCF should be able to run independently
47                // from other modules. Part of gscf ticket #185
48                if (config.modules) {
49                        // register SAM REST methods
50                        "Registering SAM REST methods".grom()
51                        CommunicationManager.registerModule('gscf', config.grails.serverURL, config.modules)
52                        CommunicationManager.registerRestWrapperMethodsFromSAM()
53                }
54
55                // automatically handle database upgrades
56                DatabaseUpgrade.handleUpgrades(dataSource)
57
58                // developmental bootstrapping:
59                //      - templates
60                //      - ontologies
61                //      - and/or studies
62                if (grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT || grails.util.GrailsUtil.environment == GrailsApplication.ENV_TEST || grails.util.GrailsUtil.environment == "dbnpdemo") {
63                        // add ontologies?
64                        if (!Ontology.count()) BootStrapTemplates.initTemplateOntologies()
65
66                        // add templates?
67                        if (!Template.count()) BootStrapTemplates.initTemplates()
68
69                        // add example studies?
70                        if (!Study.count() && grails.util.GrailsUtil.environment != "demo") BootStrapStudies.addExampleStudies(SecUser.findByUsername('user'), SecUser.findByUsername('admin'))
71                }
72
73                /**
74                 * attach ontologies in runtime. Possible problem is that you need
75                 * an internet connection when bootstrapping though.
76                 * @see dbnp.studycapturing.Subject
77                 * @see dbnp.studycapturing.Sample
78                 */
79                TemplateEntity.getField(Subject.domainFields, 'species').ontologies = [Ontology.getOrCreateOntologyByNcboId(1132)]
80                TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [Ontology.getOrCreateOntologyByNcboId(1005)]
81        }
82
83        def destroy = {
84                "stopping application...".grom()
85        }
86} 
Note: See TracBrowser for help on using the repository browser.