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 | import dbnp.authentication.* |
---|
9 | |
---|
10 | /** |
---|
11 | * Application Bootstrapper |
---|
12 | * @Author Jeroen Wesbeek |
---|
13 | * @Since 20091021 |
---|
14 | * |
---|
15 | * Revision information: |
---|
16 | * $Rev: 1107 $ |
---|
17 | * $Author: work@osx.eu $ |
---|
18 | * $Date: 2010-11-09 17:12:29 +0000 (di, 09 nov 2010) $ |
---|
19 | */ |
---|
20 | class BootStrap { |
---|
21 | def springSecurityService |
---|
22 | |
---|
23 | def init = {servletContext -> |
---|
24 | // define timezone |
---|
25 | System.setProperty('user.timezone', 'CET') |
---|
26 | |
---|
27 | "Bootstrapping application".grom() |
---|
28 | |
---|
29 | def adminRole = SecRole.findByAuthority('ROLE_ADMIN') ?: new SecRole(authority: 'ROLE_ADMIN').save() |
---|
30 | |
---|
31 | def user = SecUser.findByUsername('user') ?: new SecUser( |
---|
32 | username: 'user', |
---|
33 | password: springSecurityService.encodePassword('useR123!', 'user'), |
---|
34 | email: 'user@dbnp.org', |
---|
35 | userConfirmed: true, adminConfirmed: true).save(failOnError: true) |
---|
36 | |
---|
37 | def userAdmin = SecUser.findByUsername('admin') ?: new SecUser( |
---|
38 | username: 'admin', |
---|
39 | password: springSecurityService.encodePassword('admiN123!', 'admin'), |
---|
40 | email: 'admin@dbnp.org', |
---|
41 | userConfirmed: true, adminConfirmed: true).save(failOnError: true) |
---|
42 | |
---|
43 | // Make the admin user an administrator |
---|
44 | SecUserSecRole.create userAdmin, adminRole, true |
---|
45 | |
---|
46 | def userTest = SecUser.findByUsername('test') ?: new SecUser( |
---|
47 | username: 'test', |
---|
48 | password: springSecurityService.encodePassword('useR123!', 'test'), |
---|
49 | email: 'test@dbnp.org', |
---|
50 | userConfirmed: true, adminConfirmed: true).save(failOnError: true) |
---|
51 | |
---|
52 | println "Done with SpringSecurity bootstrap, created [user, admin, test]." |
---|
53 | |
---|
54 | // If there are no templates yet in the database |
---|
55 | if (Template.count() == 0) { |
---|
56 | println "No templates in the current database."; |
---|
57 | |
---|
58 | // If in development or test mode, add the ontologies manually to the database |
---|
59 | // without contacting the BioPortal website, to avoid annoying hiccups when the server is busy |
---|
60 | if (grails.util.GrailsUtil.environment != GrailsApplication.ENV_PRODUCTION) { |
---|
61 | println "Adding ontology descriptors" |
---|
62 | BootStrapTemplates.initTemplateOntologies() |
---|
63 | } |
---|
64 | |
---|
65 | // Add example study, subject, event etc. templates |
---|
66 | BootStrapTemplates.initTemplates() |
---|
67 | |
---|
68 | // If in development mode and no studies are present, add example studies |
---|
69 | if (Study.count() == 0 && grails.util.GrailsUtil.environment != GrailsApplication.ENV_TEST) { |
---|
70 | // check if special file is present in project directory |
---|
71 | if ((new File(System.properties['user.dir'] + "/.skip-studies").exists())) { |
---|
72 | "Skipping study bootstrapping".grom() |
---|
73 | |
---|
74 | // get species ontology |
---|
75 | def speciesOntology = Ontology.getOrCreateOntologyByNcboId(1132) |
---|
76 | |
---|
77 | // add terms |
---|
78 | def mouseTerm = new Term( |
---|
79 | name: 'Mus musculus', |
---|
80 | ontology: speciesOntology, |
---|
81 | accession: '10090' |
---|
82 | ).with { if (!validate()) { errors.each { println it} } else save(flush: true)} |
---|
83 | |
---|
84 | def humanTerm = new Term( |
---|
85 | name: 'Homo sapiens', |
---|
86 | ontology: speciesOntology, |
---|
87 | accession: '9606' |
---|
88 | ).with { if (!validate()) { errors.each { println it} } else save(flush: true)} |
---|
89 | } else { |
---|
90 | "Bootstrapping Studies".grom() |
---|
91 | |
---|
92 | // general study boostrapping |
---|
93 | BootStrapStudies.addExampleStudies(user, userAdmin) |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | println "Finished adding templates and studies" |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * attach ontologies in runtime. Possible problem is that you need |
---|
102 | * an internet connection when bootstrapping though. |
---|
103 | * @see dbnp.studycapturing.Subject |
---|
104 | * @see dbnp.studycapturing.Sample |
---|
105 | */ |
---|
106 | TemplateEntity.getField(Subject.domainFields, 'species').ontologies = [Ontology.getOrCreateOntologyByNcboId(1132)] |
---|
107 | TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [Ontology.getOrCreateOntologyByNcboId(1005)] |
---|
108 | |
---|
109 | println "Registering SAM REST methods" |
---|
110 | CommunicationManager.registerRestWrapperMethodsSAMtoGSCF() |
---|
111 | |
---|
112 | println "Done with BootStrap" |
---|
113 | } |
---|
114 | |
---|
115 | def destroy = { |
---|
116 | } |
---|
117 | } |
---|