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 | /** |
---|
12 | * Application Bootstrapper |
---|
13 | * @Author Jeroen Wesbeek |
---|
14 | * @Since 20091021 |
---|
15 | * |
---|
16 | * Revision information: |
---|
17 | * $Rev: 976 $ |
---|
18 | * $Author: robert@isdat.nl $ |
---|
19 | * $Date: 2010-10-21 15:28:04 +0000 (do, 21 okt 2010) $ |
---|
20 | */ |
---|
21 | class BootStrap { |
---|
22 | def springSecurityService |
---|
23 | |
---|
24 | def init = {servletContext -> |
---|
25 | // define timezone |
---|
26 | System.setProperty('user.timezone', 'CET') |
---|
27 | |
---|
28 | def adminRole = SecRole.findByAuthority( 'ROLE_ADMIN' ) ?: new SecRole( authority: 'ROLE_ADMIN' ).save() |
---|
29 | |
---|
30 | def user = SecUser.findByUsername('user') ?: new SecUser( |
---|
31 | username: 'user', |
---|
32 | password: springSecurityService.encodePassword( 'useR123!', 'user' ), |
---|
33 | email: 'user@dbnp.org', |
---|
34 | userConfirmed: true, adminConfirmed: true).save(failOnError: true) |
---|
35 | |
---|
36 | def userAdmin = SecUser.findByUsername('admin') ?: new SecUser( |
---|
37 | username: 'admin', |
---|
38 | password: springSecurityService.encodePassword( 'admiN123!', 'admin' ), |
---|
39 | email: 'admin@dbnp.org', |
---|
40 | userConfirmed: true, adminConfirmed: true).save(failOnError: true) |
---|
41 | |
---|
42 | // Make the admin user an administrator |
---|
43 | SecUserSecRole.create userAdmin, adminRole, true |
---|
44 | |
---|
45 | def userTest = SecUser.findByUsername('test') ?: new SecUser( |
---|
46 | username: 'test', |
---|
47 | password: springSecurityService.encodePassword( 'useR123!', 'test' ), |
---|
48 | email: 'test@dbnp.org', |
---|
49 | userConfirmed: true, adminConfirmed: true).save(failOnError: true) |
---|
50 | |
---|
51 | println "Done with SpringSecurity bootstrap, created [user, admin, test]." |
---|
52 | |
---|
53 | // If there are no templates yet in the database |
---|
54 | if (Template.count() == 0) { |
---|
55 | println "No templates in the current database."; |
---|
56 | |
---|
57 | // If in development or test mode, add the ontologies manually to the database |
---|
58 | // without contacting the BioPortal website, to avoid annoying hiccups when the server is busy |
---|
59 | if (grails.util.GrailsUtil.environment != GrailsApplication.ENV_PRODUCTION) { |
---|
60 | println "Adding ontology descriptors" |
---|
61 | BootStrapTemplates.initTemplateOntologies() |
---|
62 | } |
---|
63 | |
---|
64 | // Add example study, subject, event etc. templates |
---|
65 | BootStrapTemplates.initTemplates() |
---|
66 | |
---|
67 | // If in development mode and no studies are present, add example studies |
---|
68 | if (Study.count() == 0 && grails.util.GrailsUtil.environment != GrailsApplication.ENV_TEST) { |
---|
69 | // check if special file is present in project directory |
---|
70 | if ((new File(System.properties['user.dir']+"/.skip-studies").exists())) { |
---|
71 | // yes it is, skip study bootstrapping |
---|
72 | println ".skipping study bootstrapping" |
---|
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 | // general study boostrapping |
---|
91 | BootStrapStudies.addExampleStudies(user, userAdmin) |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | println "Finished adding templates and studies" |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * attach ontologies in runtime. Possible problem is that you need |
---|
100 | * an internet connection when bootstrapping though. |
---|
101 | * @see dbnp.studycapturing.Subject |
---|
102 | * @see dbnp.studycapturing.Sample |
---|
103 | */ |
---|
104 | TemplateEntity.getField(Subject.domainFields, 'species').ontologies = [Ontology.getOrCreateOntologyByNcboId(1132)] |
---|
105 | TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [Ontology.getOrCreateOntologyByNcboId(1005)] |
---|
106 | |
---|
107 | println "Registering SAM REST methods" |
---|
108 | // register methods for accessing SAM's Rest services |
---|
109 | if (grails.util.GrailsUtil.environment == GrailsApplication.ENV_PRODUCTION) { |
---|
110 | CommunicationManager.SAMServerURL = 'http://sam.nmcdsp.org' |
---|
111 | } |
---|
112 | else { |
---|
113 | CommunicationManager.SAMServerURL = 'http://localhost:8182/sam' |
---|
114 | } |
---|
115 | CommunicationManager.registerRestWrapperMethodsSAMtoGSCF() |
---|
116 | |
---|
117 | println "Done with BootStrap" |
---|
118 | } |
---|
119 | |
---|
120 | def destroy = { |
---|
121 | } |
---|
122 | } |
---|