1 | import dbnp.studycapturing.* |
---|
2 | |
---|
3 | import dbnp.data.Ontology |
---|
4 | import dbnp.data.Term |
---|
5 | import dbnp.rest.common.CommunicationManager |
---|
6 | import org.codehaus.groovy.grails.commons.GrailsApplication |
---|
7 | import grails.util.GrailsUtil |
---|
8 | |
---|
9 | /** |
---|
10 | * Application Bootstrapper |
---|
11 | * @Author Jeroen Wesbeek |
---|
12 | * @Since 20091021 |
---|
13 | * |
---|
14 | * Revision information: |
---|
15 | * $Rev: 812 $ |
---|
16 | * $Author: keesvb $ |
---|
17 | * $Date: 2010-08-16 16:04:00 +0000 (ma, 16 aug 2010) $ |
---|
18 | */ |
---|
19 | class BootStrap { |
---|
20 | def init = {servletContext -> |
---|
21 | // define timezone |
---|
22 | System.setProperty('user.timezone', 'CET') |
---|
23 | |
---|
24 | // If there are no templates yet in the database |
---|
25 | if (Template.count() == 0) { |
---|
26 | println "No templates in the current database."; |
---|
27 | |
---|
28 | // If in development or test mode, add the ontologies manually to the database |
---|
29 | // without contacting the BioPortal website, to avoid annoying hiccups when the server is busy |
---|
30 | if (grails.util.GrailsUtil.environment != GrailsApplication.ENV_PRODUCTION) { |
---|
31 | println "Adding ontology descriptors" |
---|
32 | BootStrapTemplates.initTemplateOntologies() |
---|
33 | } |
---|
34 | |
---|
35 | // Add example study, subject, event etc. templates |
---|
36 | BootStrapTemplates.initTemplates() |
---|
37 | |
---|
38 | // If in development mode and no studies are present, add example studies |
---|
39 | if (Study.count() == 0 && grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) { |
---|
40 | BootStrapStudies.addExampleStudies() |
---|
41 | } |
---|
42 | |
---|
43 | println "Finished adding templates and studies" |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * attach ontologies in runtime. Possible problem is that you need |
---|
48 | * an internet connection when bootstrapping though. |
---|
49 | * @see dbnp.studycapturing.Subject |
---|
50 | * @see dbnp.studycapturing.Sample |
---|
51 | */ |
---|
52 | TemplateEntity.getField(Subject.domainFields, 'species').ontologies = [Ontology.getOrCreateOntologyByNcboId(1132)] |
---|
53 | TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [Ontology.getOrCreateOntologyByNcboId(1005)] |
---|
54 | |
---|
55 | println "Registering SAM REST methods" |
---|
56 | // register methods for accessing SAM's Rest services |
---|
57 | if (grails.util.GrailsUtil.environment == GrailsApplication.ENV_PRODUCTION) { |
---|
58 | CommunicationManager.SAMServerURL = 'http://sam.dbnp.org' |
---|
59 | } |
---|
60 | else { |
---|
61 | CommunicationManager.SAMServerURL = 'http://localhost:8182/sam' |
---|
62 | } |
---|
63 | CommunicationManager.registerRestWrapperMethodsSAMtoGSCF() |
---|
64 | |
---|
65 | println "Done with BootStrap" |
---|
66 | } |
---|
67 | |
---|
68 | def destroy = { |
---|
69 | } |
---|
70 | } |
---|