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 | |
---|
12 | /** |
---|
13 | * Application Bootstrapper |
---|
14 | * @Author Jeroen Wesbeek |
---|
15 | * @Since 20091021 |
---|
16 | * |
---|
17 | * Revision information: |
---|
18 | * $Rev: 1127 $ |
---|
19 | * $Author: work@osx.eu $ |
---|
20 | * $Date: 2010-11-12 11:11:35 +0000 (vr, 12 nov 2010) $ |
---|
21 | */ |
---|
22 | class BootStrap { |
---|
23 | // user spring security |
---|
24 | def springSecurityService |
---|
25 | |
---|
26 | def init = { servletContext -> |
---|
27 | // grom what's happening |
---|
28 | "bootstrapping application".grom() |
---|
29 | |
---|
30 | // define timezone |
---|
31 | System.setProperty('user.timezone', 'CET') |
---|
32 | |
---|
33 | // set up authentication (if required) |
---|
34 | if (!SecRole.count() || !SecUser.count()) BootStrapAuthentication.initDefaultAuthentication(springSecurityService) |
---|
35 | |
---|
36 | // developmental bootstrapping: |
---|
37 | // - templates |
---|
38 | // - ontologies |
---|
39 | // - and/or studies |
---|
40 | if (grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) { |
---|
41 | // add ontologies? |
---|
42 | if (!Ontology.count()) BootStrapTemplates.initTemplateOntologies() |
---|
43 | |
---|
44 | // add templates? |
---|
45 | if (!Template.count()) BootStrapTemplates.initTemplates() |
---|
46 | |
---|
47 | // add example studies? |
---|
48 | if (!Study.count() && grails.util.GrailsUtil.environment != "demo") BootStrapStudies.addExampleStudies(SecUser.findByUsername('user'), SecUser.findByUsername('admin')) |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * attach ontologies in runtime. Possible problem is that you need |
---|
53 | * an internet connection when bootstrapping though. |
---|
54 | * @see dbnp.studycapturing.Subject |
---|
55 | * @see dbnp.studycapturing.Sample |
---|
56 | */ |
---|
57 | TemplateEntity.getField(Subject.domainFields, 'species').ontologies = [Ontology.getOrCreateOntologyByNcboId(1132)] |
---|
58 | TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [Ontology.getOrCreateOntologyByNcboId(1005)] |
---|
59 | |
---|
60 | // register SAM REST methods |
---|
61 | "Registering SAM REST methods".grom() |
---|
62 | CommunicationManager.registerRestWrapperMethodsSAMtoGSCF() |
---|
63 | } |
---|
64 | |
---|
65 | def destroy = { |
---|
66 | println "stopping application..." |
---|
67 | } |
---|
68 | } |
---|