Changeset 649


Ignore:
Timestamp:
Jul 13, 2010, 5:49:15 PM (13 years ago)
Author:
jahn
Message:

Added five controller actions (RestController?) and corresponding Rest Wrapper (CommunicationManager?) methods for Rest communication with DSP.
The contents of three actions still need to be completed.
Authentication is still in a dummy method. When Michael has figured out how to do the authentication, it will be added.

Location:
trunk
Files:
2 edited

Legend:

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

    r631 r649  
    1111 * key-value pairs in the params object of each Grails action we comment on.
    1212 *
    13  * @author      Jahn 
     13 * @author      Jahn-Takeshi Saito
    1414 * @since       20100601
    1515 *
     
    2727
    2828
    29         /* REST resources for Simple Assay Module (SAM) */
     29
     30       /**************************************************/
     31      /** Rest resources for Simple Assay Module (SAM) **/
     32     /**************************************************/
     33   
    3034
    3135
     
    109113        }
    110114
     115
     116
     117
     118
     119       /****************************/
     120      /** Rest resources for DSP **/
     121     /****************************/
     122   
     123       
     124        /* still not complete!! */
     125
     126        /**
     127        * REST resource for DSP.
     128        * call: gscf/rest/isUser/?username=username&password=password
     129        *
     130        * @param  String username   
     131        * @param  String password
     132        * @return bool
     133        */
     134        def isUser= {
     135                def isUser = isVerifiedUser( params )
     136                render isUser as JSON
     137        }
     138
     139
     140        /* still not complete!! */
     141        /**
     142        * REST resource for DSP.
     143        * call: gscf/rest/listStudies/?username=username&password=password
     144        *
     145        * @param  String username
     146        * @param  String password
     147        * @return list of studies
     148        */
     149        def listStudies = {
     150
     151                if( !isVerifiedUser( params ) ) {
     152                        render [:] as JSON
     153                        return
     154                }
     155
     156                List studies = []
     157
     158                // add code for filtering studies that belong to given user
     159                // (use Study.findAll( ... ) 
     160                // ...
     161                Study.list().each {
     162                        def map = ["study_token":it.code, "name":it.name]
     163                        studies.add( map )
     164                }
     165               
     166                render studies as JSON
     167        }
     168
     169
     170
     171        /* still not complete!! */
     172        /**
     173        * REST resource for DSP.
     174        * call: gscf/rest/getStudy/?username=username&password=password&study_token=studytoken
     175        *
     176        * @param  String username
     177        * @param  String password
     178        * @param  String study_token
     179        * @return list of studies
     180        */
     181        def getStudy = {
     182
     183                if( !isVerifiedUser( params ) ) {
     184                        render [:] as JSON
     185                        return
     186                }
     187
     188                List studyResult = [:]
     189                def code   = params.study_token
     190
     191                def query = "from Study as s where s.code = ?"
     192                def study = Study.find( query, code )
     193                studyResult = [ 'study_token' : study.code, 'name' : study.name ]
     194                        /*  still not complete!!
     195                                Add features
     196                                        ... study_token:”GHyJeR#g”,
     197                                        ... created: “20/06/2010 22:34:52”,
     198                                        ... meta: [
     199                                        ... greenhouse_id: “GH010938.AB.5”,
     200                                        ... greenhouse_type: “lean-to, detached, and ridge and gutter connected” ]
     201                        */
     202               
     203                render studyResult as JSON
     204        }
     205
     206
     207
     208
     209        /* still not complete!! */
     210        /**
     211        * REST resource for DSP.
     212        * call: gscf/rest/listStudySamples/?username=username&password=password&study_token=studytoken
     213        *
     214        * @param  String user name
     215        * @param  String password
     216        * @param  String a valid GSCF Study.code
     217        * @return List of pairs; each pair is a map with keys sample_token and name and values Study.code and Sample.name.
     218        */
     219        def listStudySamples = {
     220
     221                if( !isVerifiedUser( params ) ) {
     222                        render [:] as JSON
     223                        return
     224                }
     225
     226                List samples = [:]
     227                def code = params.study_token
     228                def query = "from Samples as s where s.study = ?"
     229                def study = Study.find( query, code )
     230                if(study) study.samples.each { sample ->
     231                        def map = [ sample_token:code, name:sample.name ]
     232                        samples.add( map )
     233                }
     234               
     235                render samples as JSON
     236        }
     237
     238
     239
     240        /* still not complete!! */
     241        /**
     242        * REST resource for DSP.
     243        * call: getStudySample/?username=me&password=123&study_token=GHyJeR#g&sample_name=”AHVJwR”)
     244        *
     245        * @param  String username
     246        * @param  String password
     247        * @param  String study_token
     248        * @param  String sample_name
     249        * @return list of studies
     250        */
     251        def getStudySample = {
     252
     253                if( !isVerifiedUser( params ) ) {
     254                        render [:] as JSON
     255                        return
     256                }
     257
     258                List sample = [:]
     259                def code = params.study_token
     260                def name = params.sample_name
     261
     262                def query = "from Sample as s where s.name = ? AND s.parentStudy "
     263                def study = Sample.find( query, name )
     264                sample = [ 'study_token' : sample.code, 'name' : sample.name ]
     265                // samples will have unique identifier strings
     266                /*  still not complete!!
     267                                Add features
     268                                [
     269                                        study_token:”GHyJeR#g”,
     270                                        sample_token:”AHVJwR”,
     271                                        name: “Sample SMPL002”,
     272                                        created: “25/06/2010 09:14:32”,
     273                                        meta: [ subject: “SUB000294-34942.A”, subject_bmi: “29.3”, ... study_token:”GHyJeR#g”,
     274                                        ... created: “20/06/2010 22:34:52”, greenhouse_id: “GH010938.AB.5”,
     275                                        greenhouse_type: “lean-to, detached, and ridge and gutter connected”
     276                                ]
     277                        */
     278                render sample as JSON
     279        }
     280
     281
     282
     283
     284        /* still not complete!! */
     285        /** Convenience method for isUser and listStudies.
     286        *   Verify user and password.
     287        *   @param  params object with two map keys: (1) 'username', (2) 'password'
     288        *   @param  String password
     289        *   @return bool
     290        */
     291        private isVerifiedUser( params ) {
     292                def isVerified = false
     293                def user = params?.username
     294                def pass = params?.password
     295
     296                if( user && pass ) {
     297                        // insert code for verification of user and
     298                        // ...
     299                        isVerified = true
     300                }
     301                return isVerified
     302        }
     303
     304
     305
     306    /* this is just for testing! */
     307    def test = {
     308                def result = dbnp.rest.common.CommunicationManager.getQueryResult("Insulin")
     309                render result
     310                render result["studies"]
     311                render result["studies"].get(0).class
     312    }
    111313}
  • trunk/src/groovy/dbnp/rest/common/CommunicationManager.groovy

    r648 r649  
    2828    def public static SAMServerURL  = "http://localhost:8182/sam"
    2929    def public static GSCFServerURL = "http://localhost:8080/gscf"
     30    def public static DSPServerURL  = "http://localhost:8080/gscf"
    3031
    3132     
     
    194195                //               "class":"data.SimpleAssay", "externalAssayID":"1", "id":1, "measurements":null, "unit":"Insulin", "inSerum":false,
    195196        //                               "name":"test Simple Assay 1", "referenceValues":"test Reference Values 1"], dbnp.studycapturing.Assay : 1]]]
    196                 def closure = { map -> 
    197                     def studies = []   
    198                     def assays  = []   
     197                def closure = { map ->
     198                    def studies = []
     199                    def assays  = []
    199200                        def studiesHQ = "from dbnp.studycapturing.Study as s where s.code=?"
    200201                        map['studyIds'].each { studies.add( dbnp.studycapturing.Study.find(studiesHQ,[it]) ) }
     
    212213
    213214
     215    /**
     216     *  This method creates on run time new methods for accessing Grails views that SAM provides for GSCF.
     217     *  This method should be called in grails-app/conf/BootStrap.groovy in the GSCF module.
     218     */
     219    public static registerRestWrapperMethodsGSCFtoDSP() {
     220                def url = DSPServerURL
     221                addRestWrapper( url, 'isUser',  ['username','password'] )
     222                addRestWrapper( url, 'listStudies',  ['username','password'] )
     223                addRestWrapper( url, 'listStudySamples',  ['username','password','study_token'] )
     224                addRestWrapper( url, 'getStudy',  ['username','password','study_token'] )
     225                addRestWrapper( url, 'getStudySample',  ['username','password','study_token','sample_token'] )
     226                addRestWrapper( url, 'isUser',  ['username','password'] )
     227    }
     228
     229
     230
    214231}
Note: See TracChangeset for help on using the changeset viewer.