1 | import dbnp.authentication.SecRole |
---|
2 | import dbnp.authentication.SecUser |
---|
3 | import org.codehaus.groovy.grails.commons.GrailsApplication |
---|
4 | import dbnp.data.Ontology |
---|
5 | import dbnp.studycapturing.Template |
---|
6 | import dbnp.studycapturing.Study |
---|
7 | import dbnp.studycapturing.TemplateEntity |
---|
8 | import dbnp.studycapturing.Subject |
---|
9 | import dbnp.studycapturing.Sample |
---|
10 | import dbnp.rest.common.CommunicationManager |
---|
11 | import org.codehaus.groovy.grails.commons.* |
---|
12 | |
---|
13 | /** |
---|
14 | * Application Bootstrapper |
---|
15 | * @Author Jeroen Wesbeek |
---|
16 | * @Since 20091021 |
---|
17 | * |
---|
18 | * Revision information: |
---|
19 | * $Rev: 1247 $ |
---|
20 | * $Author: work@osx.eu $ |
---|
21 | * $Date: 2010-12-09 14:47:47 +0000 (do, 09 dec 2010) $ |
---|
22 | */ |
---|
23 | class 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 == "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 | } |
---|