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

Last change on this file since 1196 was 1196, checked in by j.saito@…, 10 years ago

Streamlined CommunicationManager? and adjusted it to suit CommunicationManager? in SAM.
Removed horrible debugoutputs from SimpleQueryController?. (Is this used any longer at all??)

  • Property svn:keywords set to Author Date Rev
File size: 2.7 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: 1196 $
20 * $Author: j.saito@maastrichtuniversity.nl $
21 * $Date: 2010-11-24 10:47:41 +0000 (wo, 24 nov 2010) $
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) {
46                        // register SAM REST methods
47                        "Registering SAM REST methods".grom()
48                        CommunicationManager.GSCFServerURL = config.grails.serverURL
49                        CommunicationManager.SAMServerURL = config.modules.sam.url
50                        CommunicationManager.DSPServerURL = config.modules.metabolomics.url
51                        CommunicationManager.ServerURL = config.grails.serverURL
52                        CommunicationManager.registerRestWrapperMethodsFromSAM()
53                }
54
55                // developmental bootstrapping:
56                //      - templates
57                //      - ontologies
58                //      - and/or studies
59                if (grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) {
60                        // add ontologies?
61                        if (!Ontology.count()) BootStrapTemplates.initTemplateOntologies()
62
63                        // add templates?
64                        if (!Template.count()) BootStrapTemplates.initTemplates()
65
66                        // add example studies?
67                        if (!Study.count() && grails.util.GrailsUtil.environment != "demo") BootStrapStudies.addExampleStudies(SecUser.findByUsername('user'), SecUser.findByUsername('admin'))
68                }
69
70                /**
71                 * attach ontologies in runtime. Possible problem is that you need
72                 * an internet connection when bootstrapping though.
73                 * @see dbnp.studycapturing.Subject
74                 * @see dbnp.studycapturing.Sample
75                 */
76                TemplateEntity.getField(Subject.domainFields, 'species').ontologies = [Ontology.getOrCreateOntologyByNcboId(1132)]
77                TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [Ontology.getOrCreateOntologyByNcboId(1005)]
78        }
79
80        def destroy = {
81                println "stopping application..."
82        }
83} 
Note: See TracBrowser for help on using the repository browser.