Changeset 1357


Ignore:
Timestamp:
Jan 10, 2011, 4:44:44 PM (13 years ago)
Author:
robert@…
Message:

Implemented module notification when a study changes (#259)

Location:
trunk
Files:
3 added
3 edited

Legend:

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

    r1328 r1357  
    175175                        items[name] = value
    176176                    }
     177                                       
     178                                        // Add study version number
     179                                        items['version'] = study.version;
     180                                       
    177181                    returnStudies.push items
    178182                }
     
    183187        }
    184188
     189        /**
     190         * REST resource for data modules.
     191         * Consumer and token should be supplied via URL parameters.
     192         * Provides the version number of the specified study
     193         *
     194         * @param       studyToken  optional parameter. If no studyToken is given, a 400 error is given
     195         * @param       consumer        consumer name of the calling module
     196         * @param       token           token for the authenticated user (e.g. session_id)
     197         * @return  JSON object list containing 'studyToken', and 'version'
     198         *
     199         * A 404 error might occur if the study doesn't exist, and a 401 error if the user is not
     200         * authorized to access this study.
     201         *
     202         * Example. REST call with one studyToken.
     203         *
     204         * Call: http://localhost:8080/gscf/rest/getStudyVersion?studyToken=PPSH
     205         *
     206         * Result: {"studyToken":"PPSH","version":31}
     207         */
     208        def getStudyVersion = {
     209
     210                def versionInfo = [:];
     211                def study
     212               
     213                if( !params.studyToken || !(params.studyToken instanceof String)) {
     214                        response.sendError(400)
     215                        return false
     216                } else {
     217                        study = Study.findByCode( params.studyToken )
     218                        if( study ) {
     219                                if( !study.canRead(AuthenticationService.getRemotelyLoggedInUser( params.consumer, params.token )) ) {
     220                                        response.sendError(401)
     221                                        return false
     222                                }
     223                        } else {
     224                                response.sendError(404)
     225                                return false
     226                        }
     227                }
     228
     229                versionInfo[ 'studyToken' ] = params.studyToken;
     230                versionInfo[ 'version' ] = study.version;
     231
     232                render versionInfo as JSON
     233        }
    185234
    186235        /**
  • trunk/grails-app/domain/dbnp/studycapturing/AssayModule.groovy

    r1027 r1357  
    1616         */
    1717        String url
     18       
     19        /** Determines whether this module will be notified of changes in studies. This can be used
     20         * to determine when synchronization should take place in a module. The URL called is
     21         *
     22         * [url]/rest/notifyStudyChange?studyToken=abc
     23         *
     24         * @see synchronizationService
     25         */
     26        boolean notify = false;
    1827
    1928        static constraints = {
  • trunk/grails-app/domain/dbnp/studycapturing/Study.groovy

    r1353 r1357  
    1313class Study extends TemplateEntity {
    1414        static searchable = true
     15       
     16        def synchronizationService
    1517
    1618        SecUser owner           // The owner of the study. A new study is automatically owned by its creator.
     
    499501                }
    500502        }
     503
     504        // Send messages to modules about changes in this study
     505        def beforeInsert = {
     506                synchronizationService.invalidateStudy( this );
     507        }
     508        def beforeUpdate = {
     509                synchronizationService.invalidateStudy( this );
     510        }
     511        def beforeDelete = {
     512                synchronizationService.invalidateStudy( this );
     513        }
    501514}
Note: See TracChangeset for help on using the changeset viewer.