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