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: 1195 $ |
---|
20 | * $Author: j.saito@maastrichtuniversity.nl $ |
---|
21 | * $Date: 2010-11-23 13:07:41 +0000 (di, 23 nov 2010) $ |
---|
22 | */ |
---|
23 | class 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.registerRestWrapperMethodsSAMtoGSCF() |
---|
52 | } |
---|
53 | |
---|
54 | // developmental bootstrapping: |
---|
55 | // - templates |
---|
56 | // - ontologies |
---|
57 | // - and/or studies |
---|
58 | if (grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) { |
---|
59 | // add ontologies? |
---|
60 | if (!Ontology.count()) BootStrapTemplates.initTemplateOntologies() |
---|
61 | |
---|
62 | // add templates? |
---|
63 | if (!Template.count()) BootStrapTemplates.initTemplates() |
---|
64 | |
---|
65 | // add example studies? |
---|
66 | if (!Study.count() && grails.util.GrailsUtil.environment != "demo") BootStrapStudies.addExampleStudies(SecUser.findByUsername('user'), SecUser.findByUsername('admin')) |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * attach ontologies in runtime. Possible problem is that you need |
---|
71 | * an internet connection when bootstrapping though. |
---|
72 | * @see dbnp.studycapturing.Subject |
---|
73 | * @see dbnp.studycapturing.Sample |
---|
74 | */ |
---|
75 | TemplateEntity.getField(Subject.domainFields, 'species').ontologies = [Ontology.getOrCreateOntologyByNcboId(1132)] |
---|
76 | TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [Ontology.getOrCreateOntologyByNcboId(1005)] |
---|
77 | } |
---|
78 | |
---|
79 | def destroy = { |
---|
80 | println "stopping application..." |
---|
81 | } |
---|
82 | } |
---|