Changeset 1440


Ignore:
Timestamp:
Jan 25, 2011, 5:57:37 PM (13 years ago)
Author:
robert@…
Message:

Made the studytoken, assaytoken and sampletoken stable identifiers, as explained in #255.

Location:
trunk/grails-app
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/RestController.groovy

    r1430 r1440  
    137137                }
    138138                else if( params.studyToken instanceof String ) {
    139                         def study = Study.findByCode( params.studyToken )
     139                        def study = Study.findByStudyUUID( params.studyToken )
    140140                        if( study ) {
    141141                                if( !study.canRead(AuthenticationService.getRemotelyLoggedInUser( params.consumer, params.token )) ) {
     
    153153                else {
    154154                        params.studyToken.each{ studyToken ->
    155                                 def study = Study.findByCode( studyToken );
     155                                def study = Study.findByStudyUUID( studyToken );
    156156                                if( study )
    157157                                        studies.push study
     
    166166                                if( study.canRead(AuthenticationService.getRemotelyLoggedInUser( params.consumer, params.token ))) {
    167167
    168                     def items = [:]
     168                    def items = [studyToken:study.giveUUID()]
    169169                    study.giveFields().each { field ->
    170170                        def name = field.name
    171171                        def value = study.getFieldValue( name )
    172                         if( name=='code' ) {
    173                             name = 'studyToken'
    174                         }
    175172                        items[name] = value
    176173                    }
     
    215212                        return false
    216213                } else {
    217                         study = Study.findByCode( params.studyToken )
     214                        study = Study.findByStudyUUID( params.studyToken )
    218215                        if( study ) {
    219216                                if( !study.canRead(AuthenticationService.getRemotelyLoggedInUser( params.consumer, params.token )) ) {
     
    248245                List subjects = []
    249246                if( params.studyToken ) {
    250                         def id = params.studyToken
    251                         def study = Study.find( "from Study as s where s.code=?", [id])
     247                        def study = Study.findByStudyUUID( params.studyToken)
    252248
    253249                        if(study) {
     
    321317                if( params.studyToken ) {
    322318
    323                         def id = params.studyToken
    324                         def study = Study.findByCode(id)
     319                        def study = Study.findByStudyUUID(params.studyToken)
    325320
    326321                        if(study) {
     
    336331                                }
    337332                                else if( params.assayToken instanceof String ) {
    338                                         def assay = study.assays.find{ it.externalAssayID==params.assayToken }
     333                                        def assay = study.assays.find{ it.giveUUID() == params.assayToken }
    339334                                        if( assay ) {
    340335                                                 assays.push assay
     
    343338                                else {                                                                                                  // there are multiple assayTokens instances
    344339                                        params.assayToken.each { assayToken ->
    345                                                 def assay = study.assays.find{ it.externalAssayID==assayToken }
     340                                                def assay = study.assays.find{ it.giveUUID() == assayToken }
    346341                                                if(assay) {
    347342                                                        assays.push assay
     
    353348                                        if (assay.module.url.equals(params.consumer)) {
    354349                                                if(assay) {
    355                                                         def map = [:]
     350                                                        def map = [assayToken : assay.giveUUID()]
    356351                                                        assay.giveFields().each { field ->
    357352                                                                def name = field.name
    358353                                                                def value = assay.getFieldValue( name )
    359                                                                 if(field.name=='externalAssayID') {
    360                                                                         name = 'assayToken'
    361                                                                 }
    362354                                                                map[name] = value
    363355                                                        }
    364                                                         map["parentStudyToken"] = assay.parent.getToken()
     356                                                        map["parentStudyToken"] = assay.parent.giveUUID()
    365357                                                        returnList.push( map )
    366358                                                }
     
    375367                render returnList as JSON
    376368        }
    377 
    378 
    379 
    380 
    381 
    382 
    383369
    384370        /**
     
    442428                def items = []
    443429                if( params.assayToken ) {
    444                         def assay = Assay.find( "from Assay as a where externalAssayID=?",[params.assayToken])
     430                        def assay = Assay.findByAssayUUID( params.assayToken );
    445431
    446432                        if( assay )  {
     
    458444                                        samples = []
    459445                                        sampleTokens.each{ sampleToken ->
    460                                                 samples.addAll(assay.getSamples().find{ sample -> sampleToken == sample.name })
     446                                                samples.addAll(assay.getSamples().find{ sample -> sampleToken == sample.giveUUID() })
    461447                                        }
    462448                                }
     
    465451
    466452                                        def item = [
     453                                                'sampleToken' : sample.giveUUID(),
    467454                                                'material'        : sample.material?.name,
    468455                                                'subject'         : sample.parentSubject?.name,
     
    485472                                                parentEvent.giveFields().each { field ->
    486473                                                        def name = field.name
    487                                                         if( name!='sampleTemplate' && name!='fields') {
     474                                                        if( name !='sampleTemplate' && name != 'fields') {
    488475                                                                def value = parentEvent.getFieldValue( name )
    489476                                                                eventHash[name]=value
     
    517504        }
    518505
    519 
    520 
    521 
    522 
    523 
    524 
    525 
    526506        /**
    527507         * Returns the authorization level the user has for a given study.
     
    537517        def getAuthorizationLevel = {
    538518                if( params.studyToken ) {
    539                         def id = params.studyToken
    540                         def study = Study.find( "from Study as s where s.code=?", [id])
     519                        def study = Study.findByStudyUUID(params.studyToken)
    541520
    542521                        if( !study ) {
  • trunk/grails-app/controllers/dbnp/studycapturing/AssayController.groovy

    r1430 r1440  
    5252
    5353        def showByToken = {
    54             def assayInstance = Assay.findByExternalAssayID(params.id)
     54            def assayInstance = Assay.findByAssayUUID(params.id)
    5555            if (!assayInstance) {
    5656                flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'assay.label', default: 'Assay'), params.id])}"
  • trunk/grails-app/controllers/dbnp/studycapturing/StudyController.groovy

    r1436 r1440  
    252252
    253253    def showByToken = {
    254         def studyInstance = Study.findByCode(params.id)
     254        def studyInstance = Study.findByStudyUUID(params.id)
    255255        if (!studyInstance) {
    256256            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'study.label', default: 'Study'), params.id])}"
  • trunk/grails-app/domain/dbnp/studycapturing/Assay.groovy

    r1430 r1440  
    11package dbnp.studycapturing
    22import nl.grails.plugins.gdt.*
     3import java.util.UUID;
    34
    45/**
     
    1718        // This ID is generated in GSCF, but is used in the submodules to refer to this particular Assay.
    1819        String externalAssayID
     20
     21        /**
     22        * UUID of this assay
     23        */
     24    String assayUUID
    1925
    2026        /**
     
    5056        static constraints = {
    5157                externalAssayID(nullable:false, blank:false, unique: true)
     58                assayUUID(nullable:true, unique: true)
    5259        }
    5360
     
    6471
    6572    def getToken() {
    66                 return externalAssayID
     73                return giveUUID()
    6774    }
     75       
     76        /**
     77         * Returns the UUID of this sample and generates one if needed
     78         */
     79        public String giveUUID() {
     80                if( !this.assayUUID ) {
     81                        this.assayUUID = UUID.randomUUID().toString();
     82                        this.save();
     83                }
     84               
     85                return this.assayUUID;
     86        }
    6887}
  • trunk/grails-app/domain/dbnp/studycapturing/Sample.groovy

    r1430 r1440  
    22
    33import nl.grails.plugins.gdt.*
     4import java.util.UUID;
    45
    56/**
     
    3435        String name             // should be unique with respect to the parent study (which can be inferred)
    3536        Term material           // material of the sample (should normally be bound to the BRENDA ontology)
    36 
     37       
     38        /**
     39         * UUID of this sample
     40         */
     41        String sampleUUID
     42       
    3743        /**
    3844         * return the domain fields for this domain class
     
    6975                // The material domain field is optional
    7076                material(nullable: true)
     77               
     78                sampleUUID(nullable: true, unique: true)
    7179
    7280                // Check if the externalSampleId (currently defined as name) is really unique within each parent study of this sample.
     
    123131                return name
    124132        }
     133       
     134        /**
     135         * Returns the UUID of this sample and generates one if needed
     136         */
     137        public String giveUUID() {
     138                if( !this.sampleUUID ) {
     139                        this.sampleUUID = UUID.randomUUID().toString();
     140                        this.save();
     141                }
     142               
     143                return this.sampleUUID;
     144        }
    125145}
  • trunk/grails-app/domain/dbnp/studycapturing/Study.groovy

    r1430 r1440  
    33import dbnp.authentication.SecUser
    44import nl.grails.plugins.gdt.*
     5import java.util.UUID;
    56
    67/**
     
    3334        boolean publicstudy = false  // Determines whether anonymous users are allowed to see this study. This has only effect when published = true
    3435
     36        /**
     37        * UUID of this study
     38        */
     39        String studyUUID
     40
     41       
    3542        static hasMany = [
    3643                subjects: Subject,
     
    4956                owner(nullable: true, blank: true)
    5057                code(nullable: false, blank: true, unique: true)
    51 
     58                studyUUID(nullable:true, unique:true)
    5259                // TODO: add custom validator for 'published' to assess whether the study meets all quality criteria for publication
    5360                // tested by SampleTests.testStudyPublish
     
    6875        // It is used from within dbNP submodules to refer to particular study in this GSCF instance.
    6976
    70         def getToken() { code }
     77        def getToken() { return giveUUID() }
    7178
    7279        /**
     
    502509                }
    503510        }
     511       
     512        /**
     513         * Returns the UUID of this study and generates one if needed
     514         */
     515        public String giveUUID() {
     516                if( !this.studyUUID ) {
     517                        this.studyUUID = UUID.randomUUID().toString();
     518                        this.save();
     519                }
     520               
     521                return this.studyUUID;
     522        }
    504523
    505524        // Send messages to modules about changes in this study
Note: See TracChangeset for help on using the changeset viewer.