Changeset 1118


Ignore:
Timestamp:
Nov 11, 2010, 12:18:20 PM (13 years ago)
Author:
work@…
Message:
  • cleaned up the Bootstrap
Location:
trunk/grails-app
Files:
5 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/conf/BootStrap.groovy

    r1107 r1118  
    1 import dbnp.studycapturing.*
    2 
     1import dbnp.authentication.SecRole
     2import dbnp.authentication.SecUser
     3import org.codehaus.groovy.grails.commons.GrailsApplication
    34import dbnp.data.Ontology
    4 import dbnp.data.Term
     5import dbnp.studycapturing.Template
     6import dbnp.studycapturing.Study
     7import dbnp.studycapturing.TemplateEntity
     8import dbnp.studycapturing.Subject
     9import dbnp.studycapturing.Sample
    510import dbnp.rest.common.CommunicationManager
    6 import org.codehaus.groovy.grails.commons.GrailsApplication
    7 import grails.util.GrailsUtil
    8 import dbnp.authentication.*
    911
    1012/**
     
    1921 */
    2022class BootStrap {
     23        // user spring security
    2124        def springSecurityService
    2225
    23         def init = {servletContext ->
     26        def init = { servletContext ->
     27                // grom what's happening
     28                "bootstrapping application".grom()
     29
    2430                // define timezone
    2531                System.setProperty('user.timezone', 'CET')
    2632
    27                 "Bootstrapping application".grom()
     33                // set up authentication (if required)
     34                if (!SecRole.count() || !SecUser.count()) BootStrapAuthentication.initDefaultAuthentication()
    2835
    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()
    3043
    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()
    3646
    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'))
    9849                }
    9950
     
    10758                TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [Ontology.getOrCreateOntologyByNcboId(1005)]
    10859
    109                 println "Registering SAM REST methods"
     60                // register SAM REST methods
     61                "Registering SAM REST methods".grom()
    11062                CommunicationManager.registerRestWrapperMethodsSAMtoGSCF()
    111 
    112                 println "Done with BootStrap"
    11363        }
    11464
    11565        def destroy = {
     66                println "stopping application..."
    11667        }
    11768}
  • trunk/grails-app/conf/BootStrapStudies.groovy

    r1107 r1118  
    2323
    2424        public static void addExampleStudies(dbnp.authentication.SecUser owner, dbnp.authentication.SecUser otherUser ) {
     25                "inserting initial studies".grom()
    2526
    2627                // Look up the used ontologies which should be in the database by now
     
    4546
    4647                // Add terms manually, to avoid having to do many HTTP requests to the BioPortal website
    47                 println ".adding terms"
    48 
    49 
    5048                def mouseTerm = new Term(
    5149                        name: 'Mus musculus',
     
    9795
    9896                // Create a few persons, roles and Affiliations
    99                 println ".adding persons, roles and affiliations"
    10097                def affiliation1 = new PersonAffiliation(
    10198                        institute: "Science Institute NYC",
     
    144141
    145142                // Create a few publications
    146                 println ".adding publications"
    147143                def publication1 = new Publication(
    148144                        title: "Postnatal development of hypothalamic leptin receptors",
     
    164160
    165161                // Add example mouse study
    166                 println ".adding NuGO PPS3 leptin example study..."
    167162                def mouseStudy = new Study(
    168163                        template: studyTemplate,
     
    369364                .with { if (!validate()) { errors.each { println it} } else save()}
    370365
    371                 // Add example human study
    372                 println ".adding NuGO PPSH example study..."
    373 
    374366                def humanStudy = new Study(
    375367                        template: studyTemplate,
     
    464456                }
    465457
    466                 println ".adding persons and saving PPSH study..."
    467458                // Add persons to study
    468459                def studyperson3 = new StudyPerson( person: person1, role: role2 )
     
    471462                .addToPublications( publication2 )
    472463                .with { if (!validate()) { errors.each { println it} } else save()}
    473 
    474                 println ".adding assay references to mouse example study..."
    475464
    476465                // sam urls are in config.groovy, where they belong...
     
    520509                mouseStudy.addToAssays(metAssayRef);
    521510                mouseStudy.save()
    522 
    523                 println ".adding assay references to human example study..."
    524511
    525512                def  glucoseAssayBRef = new Assay(
  • trunk/grails-app/conf/BootStrapTemplates.groovy

    r1110 r1118  
    2020         */
    2121        public static void initTemplateOntologies() {
     22                "inserting initial ontologies".grom()
    2223                def speciesOntology = Ontology.getOrCreateOntologyByNcboId(1132)
    2324                def brendaOntology = Ontology.getOrCreateOntologyByNcboId(1005)
     
    3031         */
    3132        public static void initTemplates() {
    32 
    33                 // Create templates
    34                 println ".adding example templates"
     33                "inserting initial templates".grom()
    3534
    3635                def genderField = new TemplateField(
     
    6867                 .with { if (!validate()) { errors.each { println it} } else save()}
    6968
    70 
    7169                // Nutritional study template
    72                 println ".adding academic study template..."
    7370                def studyTemplate = new Template(
    7471                        name: 'Academic study',
     
    8582
    8683                // Mouse template
    87                 println ".adding mouse subject template..."
    8884                def mouseTemplate = new Template(
    8985                        name: 'Mouse', entity: dbnp.studycapturing.Subject)
     
    109105
    110106                // Human template
    111                 println ".adding human subject template..."
    112107                def humanTemplate = new Template(
    113108                        name: 'Human', entity: dbnp.studycapturing.Subject)
     
    138133                .with { if (!validate()) { errors.each { println it} } else save()}
    139134
    140                 println ".adding sample remarks field"
    141135                def sampleRemarksField = new TemplateField(
    142136                        name: 'Remarks',
     
    146140                .with { if (!validate()) { errors.each { println it} } else save()}
    147141
    148                 println ".adding sample vial textfield"
    149142                def sampleVialTextField = new TemplateField(
    150143                        name: 'Text on vial',
     
    155148
    156149                // Human tissue sample template
    157                 println ".adding human sample template..."
    158150                def humanSampleTemplate = new Template(
    159151                        name: 'Human tissue sample',
     
    173165
    174166                // Human blood sample template
    175                 println ".adding human sample template..."
    176167                def humanBloodSampleTemplate = new Template(
    177168                    name: 'Human blood sample',
     
    197188                 * For the Pilot running in Leiden (NOV2010)
    198189                 */
    199                 println ".adding sample DCL-Sample-Reference"
    200190                def sampleDCLTextField = new TemplateField(
    201191                        name: 'DCL Sample Reference',
     
    206196
    207197                // Human tissue sample template
    208                 println ".adding DCL Sample template..."
    209198                def dclSampleTemplate = new Template(
    210199                        name: 'DCL Sample information',
     
    233222
    234223                //Plant template
    235                 println ".adding geenhouse plant template..."
    236224                def greenHouseTemplate = new Template(
    237225                        name: 'Plant-green house ',
     
    305293                .with { if (!validate()) { errors.each { println it} } else save()}
    306294
    307                 println ".adding open-field plant template..."
    308295                def FieldTemplate = new Template(
    309296                        name: 'Plant-open field',
     
    327314
    328315                //Plant template
    329                 println ".adding chamber plant template..."
    330316                def chamberTemplate = new Template(
    331317                        name: 'Plant-chamber',
     
    381367                .with { if (!validate()) { errors.each { println it} } else save()}
    382368
    383                 println ".adding plant sample template..."
    384369                def plantSampleTemplate = new Template(
    385370                        name: 'Plant sample',
     
    390375                .with { if (!validate()) { errors.each { println it} } else save()}
    391376
    392                 println ".adding material prep template"
    393377                def materialPrepTemplate = new Template(
    394378                        name: 'Plant-material preparation',
     
    439423
    440424                // diet treatment template
    441                 println ".adding diet treatement template"
    442425                def dietTreatmentTemplate = new Template(
    443426                        name: 'Diet treatment',
     
    460443
    461444                // boost treatment template
    462                 println ".adding boost treatment template"
    463445                def boostTreatmentTemplate = new Template(
    464446                        name: 'Compound challenge',
     
    485467
    486468                // fasting treatment template
    487                 println ".adding fasting treatment template"
    488469                def fastingTreatment = new Template(
    489470                        name: 'Fasting treatment',
     
    501482
    502483                // SamplingEvent templates
    503                 println ".adding sampling protocol template field"
    504484                def samplingProtocolField = new TemplateField(
    505485                        name: 'Sample Protocol',
     
    511491
    512492                // liver sampling event template
    513                 println ".adding liver sampling event template"
    514493                def liverSamplingEventTemplate = new Template(
    515494                        name: 'Liver extraction',
     
    530509
    531510                // blood sampling
    532                 println ".adding blood sampling event template"
    533511                def bloodSamplingEventTemplate = new Template(
    534512                        name: 'Blood extraction',
     
    549527
    550528                // plant sample extraction event template
    551                 println ".adding plant sample extraction event template"
    552529                def plantSamplingExtractEventTemplate = new Template(
    553530                        name: 'Plant sample extraction',
     
    580557
    581558                // plant sampling event template
    582                 println ".adding plant sampling event template"
    583559                def plantSamplingEventTemplate = new Template(
    584560                        name: 'Plant-sample',
     
    622598
    623599                // assay templates
    624 
    625600                def assayDescriptionField = new TemplateField(
    626601                                name: 'Description',
     
    631606                assayDescriptionField.with { if (!validate()) { errors.each { println it} } else save()}
    632607
    633                 println ".adding clinical chemistry assay template"
    634608                def ccAssayTemplate = new Template(
    635609                        name: 'Clinical chemistry assay',
     
    640614                .with { if (!validate()) { errors.each { println it} } else save()}
    641615
    642                 println ".adding metabolomics assay template"
    643616                def metAssayTemplate = new Template(
    644617                        name: 'Metabolomics assay',
  • trunk/grails-app/domain/dbnp/data/Ontology.groovy

    r1013 r1118  
    55 * in the (global) Term store.
    66 * This information is mapped from the BioPortal NCBO REST service, e.g.: http://rest.bioontology.org/bioportal/ontologies/38802
    7  * @see http://www.bioontology.org/wiki/index.php/NCBO_REST_services
     7 * see http://www.bioontology.org/wiki/index.php/NCBO_REST_services
    88 *
    99 * Revision information:
     
    7575        }
    7676        static Ontology getOrCreateOntologyByNcboId( int ncboId ) {
    77                 println "find ${ncboId} in ${list()*.ncboId}"
    7877                def ontology = findByNcboId( ncboId as String )
    7978
     
    140139                        } else {
    141140                                // it does not validate
    142                                 println ".encountered errors instantiating Ontology by versionedId [" + ncboVersionedId + "] :"
    143                                 ontology.errors.each() {
    144                                         println "  -" + it
    145                                 }
    146141                                throw new Exception("instantiating Ontology by (versioned) id [" + ncboVersionedId + "] failed")
    147142                        }
  • trunk/grails-app/domain/dbnp/studycapturing/Subject.groovy

    r999 r1118  
    1818
    1919        // A Subject always belongs to one Study
    20         static belongsTo = [parent : Study]
     20        static belongsTo = [parent: Study]
    2121
    22         /** The name of the subject, which should be unique within the study */
     22        /** The name of the subject, which should be unique within the study  */
    2323        String name
    2424
    25         /** The species of the subject. In the domainFields property, the ontologies from which this term may come are specified. */
     25        /** The species of the subject. In the domainFields property, the ontologies from which this term may come are specified.  */
    2626        Term species
    2727
    2828        static constraints = {
    2929                // Ensure that the subject name is unique within the study
    30                 name(unique:['parent'])
     30                name(unique: ['parent'])
    3131        }
    3232
    33         static mapping = {
    34                 name column:"subjectname"
     33        static mapping = {
     34                name column: "subjectname"
    3535        }
    36 
    3736
    3837        /**
     
    5857        ]
    5958
    60         /**
    61         * Return by default the name of the subject.
    62         *
    63         * @return name field
    64         */
    65         String toString() {
    66             return name
    67         }
     59        /**
     60        * Return by default the name of the subject.
     61         *
     62        * @return name field
     63        */
     64        String toString() {
     65                return name
     66        }
    6867}
Note: See TracChangeset for help on using the changeset viewer.