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: 2240 $ |
---|
18 | * $Author: work@osx.eu $ |
---|
19 | * $Date: 2012-05-31 13:10:23 +0000 (do, 31 mei 2012) $ |
---|
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 a client (=external program) role if it does not exist |
---|
42 | def clientRole = SecRole.findByAuthority('ROLE_CLIENT') ?: new SecRole(authority: 'ROLE_CLIENT').save(failOnError: true) |
---|
43 | def templateAdminRole = SecRole.findByAuthority('ROLE_TEMPLATEADMIN') ?: new SecRole(authority: 'ROLE_TEMPLATEADMIN').save(failOnError: true) |
---|
44 | |
---|
45 | // set up authentication (if required) |
---|
46 | if (!SecRole.count() || !SecUser.count()) BootStrapAuthentication.initDefaultAuthentication(springSecurityService) |
---|
47 | |
---|
48 | // set up the SAM communication manager |
---|
49 | // this should probably more dynamic and put into the modules |
---|
50 | // section instead of the bootstrap as not all instances will |
---|
51 | // probably run WITH sam. GSCF should be able to run independently |
---|
52 | // from other modules. Part of gscf ticket #185 |
---|
53 | if (config.modules) { |
---|
54 | // Grom a development message |
---|
55 | if (String.metaClass.getMetaMethod("grom")) "Registering SAM REST methods".grom() |
---|
56 | CommunicationManager.registerModule('gscf', config.grails.serverURL, config.modules) |
---|
57 | CommunicationManager.registerRestWrapperMethodsFromSAM() |
---|
58 | } |
---|
59 | |
---|
60 | // automatically handle database upgrades |
---|
61 | DatabaseUpgrade.handleUpgrades(dataSource) |
---|
62 | |
---|
63 | // developmental/test/demo bootstrapping: |
---|
64 | // - templates |
---|
65 | // - ontologies |
---|
66 | // - and/or studies |
---|
67 | if ( grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT || |
---|
68 | grails.util.GrailsUtil.environment == GrailsApplication.ENV_TEST || |
---|
69 | grails.util.GrailsUtil.environment == "dbnpdemo") { |
---|
70 | // add ontologies? |
---|
71 | if (!Ontology.count()) ExampleTemplates.initTemplateOntologies() |
---|
72 | |
---|
73 | // add templates? |
---|
74 | if (!Template.count()) ExampleTemplates.initTemplates() |
---|
75 | |
---|
76 | // add data required for the webtests? |
---|
77 | if (grails.util.GrailsUtil.environment == GrailsApplication.ENV_TEST) ExampleStudies.addTestData() |
---|
78 | |
---|
79 | // add example studies? |
---|
80 | if (!Study.count() && grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) |
---|
81 | ExampleStudies.addExampleStudies(SecUser.findByUsername('user'), SecUser.findByUsername('admin')) |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | * attach ontologies in runtime. Possible problem is that you need |
---|
86 | * an internet connection when bootstrapping though. |
---|
87 | * @see dbnp.studycapturing.Subject |
---|
88 | * @see dbnp.studycapturing.Sample |
---|
89 | */ |
---|
90 | TemplateEntity.getField(Subject.domainFields, 'species').ontologies = [ |
---|
91 | Ontology.getOrCreateOntologyByNcboId(1132), // NCBI Organismal Classification |
---|
92 | Ontology.getOrCreateOntologyByNcboId(1069) // Environmental Ontology |
---|
93 | ] |
---|
94 | TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [ |
---|
95 | Ontology.getOrCreateOntologyByNcboId(1005) // BRENDA Tissue / enzyme source |
---|
96 | ] |
---|
97 | } |
---|
98 | |
---|
99 | def destroy = { |
---|
100 | // Grom a development message |
---|
101 | if (String.metaClass.getMetaMethod("grom")) "stopping application...".grom() |
---|
102 | } |
---|
103 | } |
---|