Ignore:
Timestamp:
Aug 24, 2010, 5:26:25 PM (6 years ago)
Author:
keesvb
Message:

added metabolomics assay examples, cleaned up RestController?, changed assay show link for SAM

File:
1 edited

Legend:

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

    r834 r835  
    3131
    3232        def authService
    33         def beforeInterceptor = [action:this.&auth]
     33        def beforeInterceptor = [action:this.&auth,except:["isUser"]]
    3434        def credentials
    3535        def requestUser
    36 // defined as a regular method so its private
    3736
    3837        /**
     
    4241         * @return
    4342         */
    44         def auth() {
     43        private def auth() {
    4544            credentials = BasicAuthentication.credentialsFromRequest(request)
    4645                requestUser = authService.authUser(credentials.u,credentials.p)
     
    5453        }
    5554
    56 
     55        /**
     56        * REST resource for data modules.
     57        * Username and password should be supplied via HTTP Basic Authentication.
     58        * Determines whether the given user/password combination is a valid GSCF account.
     59        *
     60        * @return bool True when user/password is a valid GSCF account, false otherwise.
     61        */
     62        def isUser= {
     63                boolean isUser
     64                def reqUser = authService.authUser(credentials.u,credentials.p)
     65                if (reqUser) {
     66                        isUser = true
     67                }
     68                else {
     69                        isUser = false
     70                }
     71                render isUser as JSON
     72        }
    5773
    5874        /**
    59         * REST resource for the Simple Assay Module.
    60         * Provide a list of all studies.
     75        * REST resource for data modules.
     76        * Username and password should be supplied via HTTP Basic Authentication.
     77        * Provide a list of all studies owned by the supplied user.
    6178        *
    62         *
    63         * @return as JSON object list of members externalStudyID, and title for all studies
     79        * @return JSON object list containing 'externalStudyID', and 'name' (title) for each study
    6480        */
    6581        def getStudies = {
     
    7389
    7490        /**
    75         * REST resource for the Simple Assay Module.
    76         * Provide a list of all subjects belonging to a study.
     91        * REST resource for data modules.
     92        * Username and password should be supplied via HTTP Basic Authentication.
     93        * Provide a list of all subjects belonging to a study.
    7794        *
    78         * @param  externalStudyID
    79         * @return as JSON object list of subject names
     95        * @param externalStudyID String The external study id (code) of the target GSCF Study object
     96        * @return JSON object list of subject names
    8097        */
    8198        def getSubjects = {
     
    91108
    92109        /**
    93         * REST resource for the Simple Assay Module.
     110        * REST resource for data modules.
     111        * Username and password should be supplied via HTTP Basic Authentication.
    94112        * Provide a list of all assays for a given study
    95113        *
    96114        * Example call of the getAssays REST resource: http://localhost:8080/gscf/rest/getAssays?externalStudyID=PPSH&moduleURL=http://localhost:8182/sam
    97115        *
    98         * @param externalStudyID The external study id (code) of the target GSCF Study object
    99         * @param moduleURL The base URL of the calling dbNP module
    100         * @return list of assays in the study as JSON object, filtered to only contain assays for the specified module
     116        * @param externalStudyID String The external study id (code) of the target GSCF Study object
     117        * @param moduleURL String The base URL of the calling dbNP module
     118        * @return list of assays in the study as JSON object list, filtered to only contain assays for the specified module, with 'externalAssayID' and 'name' for each assay
    101119        */
    102120        def getAssays = {
     
    116134
    117135        /**
    118         * REST resource for the Simple Assay Module.
    119         * Provide all samples of a given Assay. The result is an enriched list with additional informatin on a sample.
     136        * REST resource for data modules.
     137        * Username and password should be supplied via HTTP Basic Authentication.
     138        * Provide all samples of a given Assay. The result is an enriched list with additional information for each sample.
    120139        *
    121         * @param  assayID (externalAssayID of some Assay in GSCF)
    122         * @return list of element of  Sample.name x Sample.material x Sample.subject.name x Sample.Event.name x Sample.Event.time
     140        * @param externalAssayID String (externalAssayID of some Assay in GSCF)
     141        * @return As a JSON object list, for each sample in that assay:
     142        * @return 'name' (Sample name, which is unique)
     143        * @return 'material' (Sample material)
     144        * @return 'subject' (The name of the subject from which the sample was taken)
     145        * @return 'event' (the name of the template of the SamplingEvent describing the sampling)
     146        * @return 'startTime' (the time the sample was taken relative to the start of the study, as a string)
    123147        */
    124148        def getSamples = {
     
    132156                                        'subject'             : sample.parentSubject.name,
    133157                                        'event'               : sample.parentEvent.template.name,
    134                                         'startTime'           : sample.parentEvent.getStartTimeString(),
    135                                         'externalSampleId': sample.externalSampleId
    136                                 ]
     158                                        'startTime'           : sample.parentEvent.getStartTimeString()
     159                                ]
    137160                                items.push item
    138161                        }
     
    142165
    143166
    144 
    145 
    146 
    147        /****************************/
    148       /** Rest resources for DSP **/
    149      /****************************/
    150    
    151        
    152         /* still not complete!! */
    153 
    154         /**
    155         * REST resource for DSP.
    156         * call: gscf/rest/isUser/?username=username&password=password
    157         *
    158         * @param  String username   
    159         * @param  String password
    160         * @return bool
    161         */
    162         def isUser= {
    163                 def isUser = isVerifiedUser( params )
    164                 render isUser as JSON
    165         }
    166 
    167 
    168         /* still not complete!! */
    169         /**
    170         * REST resource for DSP.
    171         * call: gscf/rest/listStudies/?username=username&password=password
    172         *
    173         * @param  String username
    174         * @param  String password
    175         * @return list of studies
    176         */
    177         def listStudies = {
    178 
    179                 if( !isVerifiedUser( params ) ) {
    180                         render [:] as JSON
    181                         return
    182                 }
    183 
    184                 List studies = []
    185 
    186                 // add code for filtering studies that belong to given user
    187                 // (use Study.findAll( ... ) 
    188                 // ...
    189                 Study.list().each {
    190                         def map = ["study_token":it.code, "name":it.name]
    191                         studies.add( map )
    192                 }
    193                
    194                 render studies as JSON
    195         }
    196 
    197 
    198 
    199         /* still not complete!! */
    200         /**
    201         * REST resource for DSP.
    202         * call: gscf/rest/getStudy/?username=username&password=password&study_token=studytoken
    203         *
    204         * @param  String username
    205         * @param  String password
    206         * @param  String study_token
    207         * @return list of studies
    208         */
    209         def getStudy = {
    210 
    211                 if( !isVerifiedUser( params ) ) {
    212                         render [:] as JSON
    213                         return
    214                 }
    215 
    216                 List studyResult = [:]
    217                 def code   = params.study_token
    218 
    219                 def query = "from Study as s where s.code = ?"
    220                 def study = Study.find( query, code )
    221                 studyResult = [ 'study_token' : study.code, 'name' : study.name ]
    222                         /*  still not complete!!
    223                                 Add features
    224                                         ... study_token:”GHyJeR#g”,
    225                                         ... created: “20/06/2010 22:34:52”,
    226                                         ... meta: [
    227                                         ... greenhouse_id: “GH010938.AB.5”,
    228                                         ... greenhouse_type: “lean-to, detached, and ridge and gutter connected” ]
    229                         */
    230                
    231                 render studyResult as JSON
    232         }
    233 
    234 
    235 
    236 
    237         /* still not complete!! */
    238         /**
    239         * REST resource for DSP.
    240         * call: gscf/rest/listStudySamples/?username=username&password=password&study_token=studytoken
    241         *
    242         * @param  String user name
    243         * @param  String password
    244         * @param  String a valid GSCF Study.code
    245         * @return List of pairs; each pair is a map with keys sample_token and name and values Study.code and Sample.name.
    246         */
    247         def listStudySamples = {
    248 
    249                 if( !isVerifiedUser( params ) ) {
    250                         render [:] as JSON
    251                         return
    252                 }
    253 
    254                 List samples = [:]
    255                 def code = params.study_token
    256                 def query = "from Samples as s where s.study = ?"
    257                 def study = Study.find( query, code )
    258                 if(study) study.samples.each { sample ->
    259                         def map = [ sample_token:code, name:sample.name ]
    260                         samples.add( map )
    261                 }
    262                
    263                 render samples as JSON
    264         }
    265 
    266 
    267 
    268         /* still not complete!! */
    269         /**
    270         * REST resource for DSP.
    271         * call: getStudySample/?username=me&password=123&study_token=GHyJeR#g&sample_name=”AHVJwR”)
    272         *
    273         * @param  String username
    274         * @param  String password
    275         * @param  String study_token
    276         * @param  String sample_name
    277         * @return list of studies
    278         */
    279         def getStudySample = {
    280 
    281                 if( !isVerifiedUser( params ) ) {
    282                         render [:] as JSON
    283                         return
    284                 }
    285 
    286                 List sample = [:]
    287                 def code = params.study_token
    288                 def name = params.sample_name
    289 
    290                 def query = "from Sample as s where s.name = ? AND s.parentStudy "
    291                 def study = Sample.find( query, name )
    292                 sample = [ 'study_token' : sample.code, 'name' : sample.name ]
    293                 // samples will have unique identifier strings
    294                 /*  still not complete!!
    295                                 Add features
    296                                 [
    297                                         study_token:”GHyJeR#g”,
    298                                         sample_token:”AHVJwR”,
    299                                         name: “Sample SMPL002”,
    300                                         created: “25/06/2010 09:14:32”,
    301                                         meta: [ subject: “SUB000294-34942.A”, subject_bmi: “29.3”, ... study_token:”GHyJeR#g”,
    302                                         ... created: “20/06/2010 22:34:52”, greenhouse_id: “GH010938.AB.5”,
    303                                         greenhouse_type: “lean-to, detached, and ridge and gutter connected”
    304                                 ]
    305                         */
    306                 render sample as JSON
    307         }
    308 
    309 
    310 
    311 
    312         /* still not complete!! */
    313         /** Convenience method for isUser and listStudies.
    314         *   Verify user and password.
    315         *   @param  params object with two map keys: (1) 'username', (2) 'password'
    316         *   @param  String password
    317         *   @return bool
    318         */
    319         private isVerifiedUser( params ) {
    320                 def isVerified = false
    321                 def user = params?.username
    322                 def pass = params?.password
    323 
    324                 if( user && pass ) {
    325                         // insert code for verification of user and
    326                         // ...
    327                         isVerified = true
    328                 }
    329                 return isVerified
    330         }
    331 
    332 
    333 
    334167    /* this is just for testing! */
    335     def test = {
     168    /*def test = {
    336169                render( dbnp.rest.common.CommunicationManager.getQueryResultWithOperator("Insulin",">",200) )
    337     }
     170    }*/
    338171}
Note: See TracChangeset for help on using the changeset viewer.