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: 816 $ |
---|
16 | * $Author: duh $ |
---|
17 | * $Date: 2010-08-17 10:09:35 +0000 (di, 17 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 | // check if special file is present in project directory |
---|
41 | if ((new File(System.properties['user.dir']+"/.skip-studies").exists())) { |
---|
42 | // yes it is, skip study bootstrapping |
---|
43 | println ".skipping study bootstrapping" |
---|
44 | |
---|
45 | // get species ontology |
---|
46 | def speciesOntology = Ontology.getOrCreateOntologyByNcboId(1132) |
---|
47 | |
---|
48 | // add terms |
---|
49 | def mouseTerm = new Term( |
---|
50 | name: 'Mus musculus', |
---|
51 | ontology: speciesOntology, |
---|
52 | accession: '10090' |
---|
53 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
54 | |
---|
55 | def humanTerm = new Term( |
---|
56 | name: 'Homo sapiens', |
---|
57 | ontology: speciesOntology, |
---|
58 | accession: '9606' |
---|
59 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
60 | } else { |
---|
61 | // general study boostrapping |
---|
62 | BootStrapStudies.addExampleStudies() |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | println "Finished adding templates and studies" |
---|
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 | println "Registering SAM REST methods" |
---|
79 | // register methods for accessing SAM's Rest services |
---|
80 | if (grails.util.GrailsUtil.environment == GrailsApplication.ENV_PRODUCTION) { |
---|
81 | CommunicationManager.SAMServerURL = 'http://sam.dbnp.org' |
---|
82 | } |
---|
83 | else { |
---|
84 | CommunicationManager.SAMServerURL = 'http://localhost:8182/sam' |
---|
85 | } |
---|
86 | CommunicationManager.registerRestWrapperMethodsSAMtoGSCF() |
---|
87 | |
---|
88 | println "Done with BootStrap" |
---|
89 | } |
---|
90 | |
---|
91 | def destroy = { |
---|
92 | } |
---|
93 | } |
---|