1 | import dbnp.authentication.SecRole |
---|
2 | import dbnp.authentication.SecUser |
---|
3 | import org.codehaus.groovy.grails.commons.GrailsApplication |
---|
4 | import org.dbnp.gdt.* |
---|
5 | import dbnp.studycapturing.Study |
---|
6 | import dbnp.studycapturing.Subject |
---|
7 | import dbnp.studycapturing.Sample |
---|
8 | import dbnp.rest.common.CommunicationManager |
---|
9 | import dbnp.configuration.* |
---|
10 | |
---|
11 | /** |
---|
12 | * Application Bootstrapper |
---|
13 | * @Author Jeroen Wesbeek |
---|
14 | * @Since 20091021 |
---|
15 | * |
---|
16 | * Revision information: |
---|
17 | * $Rev: 1815 $ |
---|
18 | * $Author: m.s.vanvliet@lacdr.leidenuniv.nl $ |
---|
19 | * $Date: 2011-05-05 14:50:15 +0000 (do, 05 mei 2011) $ |
---|
20 | */ |
---|
21 | class BootStrap { |
---|
22 | // user spring security |
---|
23 | def springSecurityService |
---|
24 | |
---|
25 | // inject the datasource |
---|
26 | def dataSource |
---|
27 | |
---|
28 | // inject the grails application |
---|
29 | def grailsApplication |
---|
30 | |
---|
31 | def init = { servletContext -> |
---|
32 | // Grom a development message |
---|
33 | if (String.metaClass.getMetaMethod("grom")) "bootstrapping application".grom() |
---|
34 | |
---|
35 | // get configuration |
---|
36 | def config = grailsApplication.config |
---|
37 | |
---|
38 | // define timezone |
---|
39 | System.setProperty('user.timezone', 'CET') |
---|
40 | |
---|
41 | // set up authentication (if required) |
---|
42 | if (!SecRole.count() || !SecUser.count()) BootStrapAuthentication.initDefaultAuthentication(springSecurityService) |
---|
43 | |
---|
44 | // set up the SAM communication manager |
---|
45 | // this should probably more dynamic and put into the modules |
---|
46 | // section instead of the bootstrap as not all instances will |
---|
47 | // probably run WITH sam. GSCF should be able to run independently |
---|
48 | // from other modules. Part of gscf ticket #185 |
---|
49 | if (config.modules) { |
---|
50 | // Grom a development message |
---|
51 | if (String.metaClass.getMetaMethod("grom")) "Registering SAM REST methods".grom() |
---|
52 | CommunicationManager.registerModule('gscf', config.grails.serverURL, config.modules) |
---|
53 | CommunicationManager.registerRestWrapperMethodsFromSAM() |
---|
54 | } |
---|
55 | |
---|
56 | // automatically handle database upgrades |
---|
57 | DatabaseUpgrade.handleUpgrades(dataSource) |
---|
58 | |
---|
59 | // developmental/test/demo bootstrapping: |
---|
60 | // - templates |
---|
61 | // - ontologies |
---|
62 | // - and/or studies |
---|
63 | if ( grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT || |
---|
64 | grails.util.GrailsUtil.environment == GrailsApplication.ENV_TEST || |
---|
65 | grails.util.GrailsUtil.environment == "dbnpdemo") { |
---|
66 | // add ontologies? |
---|
67 | if (!Ontology.count()) ExampleTemplates.initTemplateOntologies() |
---|
68 | |
---|
69 | // add templates? |
---|
70 | if (!Template.count()) ExampleTemplates.initTemplates() |
---|
71 | |
---|
72 | // add data required for the webtests? |
---|
73 | if (grails.util.GrailsUtil.environment == GrailsApplication.ENV_TEST) ExampleStudies.addTestData() |
---|
74 | |
---|
75 | // add example studies? |
---|
76 | if (!Study.count() && grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) |
---|
77 | ExampleStudies.addExampleStudies(SecUser.findByUsername('user'), SecUser.findByUsername('admin')) |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * attach ontologies in runtime. Possible problem is that you need |
---|
82 | * an internet connection when bootstrapping though. |
---|
83 | * @see dbnp.studycapturing.Subject |
---|
84 | * @see dbnp.studycapturing.Sample |
---|
85 | */ |
---|
86 | TemplateEntity.getField(Subject.domainFields, 'species').ontologies = [ |
---|
87 | Ontology.getOrCreateOntologyByNcboId(1132), // NCBI Organismal Classification |
---|
88 | Ontology.getOrCreateOntologyByNcboId(1069) // Environmental Ontology |
---|
89 | ] |
---|
90 | TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [ |
---|
91 | Ontology.getOrCreateOntologyByNcboId(1005) // BRENDA Tissue / enzyme source |
---|
92 | ] |
---|
93 | } |
---|
94 | |
---|
95 | def destroy = { |
---|
96 | // Grom a development message |
---|
97 | if (String.metaClass.getMetaMethod("grom")) "stopping application...".grom() |
---|
98 | } |
---|
99 | } |
---|