Changeset 1118 for trunk/grails-app/conf
- Timestamp:
- Nov 11, 2010, 12:18:20 PM (13 years ago)
- Location:
- trunk/grails-app/conf
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/BootStrap.groovy
r1107 r1118 1 import dbnp.studycapturing.* 2 1 import dbnp.authentication.SecRole 2 import dbnp.authentication.SecUser 3 import org.codehaus.groovy.grails.commons.GrailsApplication 3 4 import dbnp.data.Ontology 4 import dbnp.data.Term 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 5 10 import dbnp.rest.common.CommunicationManager 6 import org.codehaus.groovy.grails.commons.GrailsApplication7 import grails.util.GrailsUtil8 import dbnp.authentication.*9 11 10 12 /** … … 19 21 */ 20 22 class BootStrap { 23 // user spring security 21 24 def springSecurityService 22 25 23 def init = {servletContext -> 26 def init = { servletContext -> 27 // grom what's happening 28 "bootstrapping application".grom() 29 24 30 // define timezone 25 31 System.setProperty('user.timezone', 'CET') 26 32 27 "Bootstrapping application".grom() 33 // set up authentication (if required) 34 if (!SecRole.count() || !SecUser.count()) BootStrapAuthentication.initDefaultAuthentication() 28 35 29 def adminRole = SecRole.findByAuthority('ROLE_ADMIN') ?: new SecRole(authority: 'ROLE_ADMIN').save() 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() 30 43 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) 44 // add templates? 45 if (!Template.count()) BootStrapTemplates.initTemplates() 36 46 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" 47 // add example studies? 48 if (!Study.count()) BootStrapStudies.addExampleStudies(SecUser.findByUsername('user'), SecUser.findByUsername('admin')) 98 49 } 99 50 … … 107 58 TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [Ontology.getOrCreateOntologyByNcboId(1005)] 108 59 109 println "Registering SAM REST methods" 60 // register SAM REST methods 61 "Registering SAM REST methods".grom() 110 62 CommunicationManager.registerRestWrapperMethodsSAMtoGSCF() 111 112 println "Done with BootStrap"113 63 } 114 64 115 65 def destroy = { 66 println "stopping application..." 116 67 } 117 68 } -
trunk/grails-app/conf/BootStrapStudies.groovy
r1107 r1118 23 23 24 24 public static void addExampleStudies(dbnp.authentication.SecUser owner, dbnp.authentication.SecUser otherUser ) { 25 "inserting initial studies".grom() 25 26 26 27 // Look up the used ontologies which should be in the database by now … … 45 46 46 47 // Add terms manually, to avoid having to do many HTTP requests to the BioPortal website 47 println ".adding terms"48 49 50 48 def mouseTerm = new Term( 51 49 name: 'Mus musculus', … … 97 95 98 96 // Create a few persons, roles and Affiliations 99 println ".adding persons, roles and affiliations"100 97 def affiliation1 = new PersonAffiliation( 101 98 institute: "Science Institute NYC", … … 144 141 145 142 // Create a few publications 146 println ".adding publications"147 143 def publication1 = new Publication( 148 144 title: "Postnatal development of hypothalamic leptin receptors", … … 164 160 165 161 // Add example mouse study 166 println ".adding NuGO PPS3 leptin example study..."167 162 def mouseStudy = new Study( 168 163 template: studyTemplate, … … 369 364 .with { if (!validate()) { errors.each { println it} } else save()} 370 365 371 // Add example human study372 println ".adding NuGO PPSH example study..."373 374 366 def humanStudy = new Study( 375 367 template: studyTemplate, … … 464 456 } 465 457 466 println ".adding persons and saving PPSH study..."467 458 // Add persons to study 468 459 def studyperson3 = new StudyPerson( person: person1, role: role2 ) … … 471 462 .addToPublications( publication2 ) 472 463 .with { if (!validate()) { errors.each { println it} } else save()} 473 474 println ".adding assay references to mouse example study..."475 464 476 465 // sam urls are in config.groovy, where they belong... … … 520 509 mouseStudy.addToAssays(metAssayRef); 521 510 mouseStudy.save() 522 523 println ".adding assay references to human example study..."524 511 525 512 def glucoseAssayBRef = new Assay( -
trunk/grails-app/conf/BootStrapTemplates.groovy
r1110 r1118 20 20 */ 21 21 public static void initTemplateOntologies() { 22 "inserting initial ontologies".grom() 22 23 def speciesOntology = Ontology.getOrCreateOntologyByNcboId(1132) 23 24 def brendaOntology = Ontology.getOrCreateOntologyByNcboId(1005) … … 30 31 */ 31 32 public static void initTemplates() { 32 33 // Create templates 34 println ".adding example templates" 33 "inserting initial templates".grom() 35 34 36 35 def genderField = new TemplateField( … … 68 67 .with { if (!validate()) { errors.each { println it} } else save()} 69 68 70 71 69 // Nutritional study template 72 println ".adding academic study template..."73 70 def studyTemplate = new Template( 74 71 name: 'Academic study', … … 85 82 86 83 // Mouse template 87 println ".adding mouse subject template..."88 84 def mouseTemplate = new Template( 89 85 name: 'Mouse', entity: dbnp.studycapturing.Subject) … … 109 105 110 106 // Human template 111 println ".adding human subject template..."112 107 def humanTemplate = new Template( 113 108 name: 'Human', entity: dbnp.studycapturing.Subject) … … 138 133 .with { if (!validate()) { errors.each { println it} } else save()} 139 134 140 println ".adding sample remarks field"141 135 def sampleRemarksField = new TemplateField( 142 136 name: 'Remarks', … … 146 140 .with { if (!validate()) { errors.each { println it} } else save()} 147 141 148 println ".adding sample vial textfield"149 142 def sampleVialTextField = new TemplateField( 150 143 name: 'Text on vial', … … 155 148 156 149 // Human tissue sample template 157 println ".adding human sample template..."158 150 def humanSampleTemplate = new Template( 159 151 name: 'Human tissue sample', … … 173 165 174 166 // Human blood sample template 175 println ".adding human sample template..."176 167 def humanBloodSampleTemplate = new Template( 177 168 name: 'Human blood sample', … … 197 188 * For the Pilot running in Leiden (NOV2010) 198 189 */ 199 println ".adding sample DCL-Sample-Reference"200 190 def sampleDCLTextField = new TemplateField( 201 191 name: 'DCL Sample Reference', … … 206 196 207 197 // Human tissue sample template 208 println ".adding DCL Sample template..."209 198 def dclSampleTemplate = new Template( 210 199 name: 'DCL Sample information', … … 233 222 234 223 //Plant template 235 println ".adding geenhouse plant template..."236 224 def greenHouseTemplate = new Template( 237 225 name: 'Plant-green house ', … … 305 293 .with { if (!validate()) { errors.each { println it} } else save()} 306 294 307 println ".adding open-field plant template..."308 295 def FieldTemplate = new Template( 309 296 name: 'Plant-open field', … … 327 314 328 315 //Plant template 329 println ".adding chamber plant template..."330 316 def chamberTemplate = new Template( 331 317 name: 'Plant-chamber', … … 381 367 .with { if (!validate()) { errors.each { println it} } else save()} 382 368 383 println ".adding plant sample template..."384 369 def plantSampleTemplate = new Template( 385 370 name: 'Plant sample', … … 390 375 .with { if (!validate()) { errors.each { println it} } else save()} 391 376 392 println ".adding material prep template"393 377 def materialPrepTemplate = new Template( 394 378 name: 'Plant-material preparation', … … 439 423 440 424 // diet treatment template 441 println ".adding diet treatement template"442 425 def dietTreatmentTemplate = new Template( 443 426 name: 'Diet treatment', … … 460 443 461 444 // boost treatment template 462 println ".adding boost treatment template"463 445 def boostTreatmentTemplate = new Template( 464 446 name: 'Compound challenge', … … 485 467 486 468 // fasting treatment template 487 println ".adding fasting treatment template"488 469 def fastingTreatment = new Template( 489 470 name: 'Fasting treatment', … … 501 482 502 483 // SamplingEvent templates 503 println ".adding sampling protocol template field"504 484 def samplingProtocolField = new TemplateField( 505 485 name: 'Sample Protocol', … … 511 491 512 492 // liver sampling event template 513 println ".adding liver sampling event template"514 493 def liverSamplingEventTemplate = new Template( 515 494 name: 'Liver extraction', … … 530 509 531 510 // blood sampling 532 println ".adding blood sampling event template"533 511 def bloodSamplingEventTemplate = new Template( 534 512 name: 'Blood extraction', … … 549 527 550 528 // plant sample extraction event template 551 println ".adding plant sample extraction event template"552 529 def plantSamplingExtractEventTemplate = new Template( 553 530 name: 'Plant sample extraction', … … 580 557 581 558 // plant sampling event template 582 println ".adding plant sampling event template"583 559 def plantSamplingEventTemplate = new Template( 584 560 name: 'Plant-sample', … … 622 598 623 599 // assay templates 624 625 600 def assayDescriptionField = new TemplateField( 626 601 name: 'Description', … … 631 606 assayDescriptionField.with { if (!validate()) { errors.each { println it} } else save()} 632 607 633 println ".adding clinical chemistry assay template"634 608 def ccAssayTemplate = new Template( 635 609 name: 'Clinical chemistry assay', … … 640 614 .with { if (!validate()) { errors.each { println it} } else save()} 641 615 642 println ".adding metabolomics assay template"643 616 def metAssayTemplate = new Template( 644 617 name: 'Metabolomics assay',
Note: See TracChangeset
for help on using the changeset viewer.