Changeset 615 for trunk/src


Ignore:
Timestamp:
Jun 25, 2010, 11:55:00 AM (13 years ago)
Author:
jahn
Message:

Made generating of SAM URLs more readable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/groovy/dbnp/rest/CommunicationManager.groovy

    r609 r615  
    147147
    148148
     149
     150
     151    /**
     152     * Convenience method for constructing URLs for SAM that need parameters
     153     *
     154     * @params String resource The name of the resource, e.g. importer/pages
     155     * @params Map params      A Map of parmater names and values., e.g. ['externalAssayID':12]
     156     * @return String url   
     157     */
     158    private URL getSAMURL( resource, params ) {
     159        def url = ServerURL + '/' + resource
     160                def first = true
     161                params.each { name, value ->
     162                        if(first) {
     163                                first = false                                     // this needs to be protected, otherwise might break url
     164                                url += '/nil?' + name + "='" + value.toString() + "'"   
     165                        }
     166                        else {
     167                                url += '&' + name + "='" + value.toString() + "'"   
     168                        }
     169                }
     170                return new URL( url )
     171    }
     172
     173
    149174    /**
    150175     * Get the URL for importing an assay from SAM.
    151176     * This is not a REST method! It only creates a rest resource and returns it's url.
    152177     *
    153      * @params assay
     178     * @params Study
     179     * @params Assay
    154180     * @return URL
    155181     */
    156     public Object getAssayImportURL( assay ) {
    157         return new URL( ServerURL + '/importer/pages/assay?externalAssayID=' + assay.externalAssayID )
     182    public URL getAssayImportURL( study, assay ) {
     183                def params = ['externalAssayID':assay.externalAssayID, 'externalStudyID':study.code ]
     184        return getSAMURL( 'importer/pages', params )
    158185    }
    159186
     
    163190     * This is not a REST method! It only creates a rest resource and returns it's url.
    164191     *
    165      * @params assay
     192     * @params Assay
    166193     * @return URL
    167194     */
    168     public Object getAssayShowURL( assay ) {
    169         return new URL( ServerURL + '/simpleAssay/show/assay?externalAssayID=' + assay.externalAssayID )
     195    public URL getAssayShowURL( assay ) {
     196                def params = ['externalAssayID':assay.externalAssayID ]
     197        return getSAMURL( 'simpleAssay/show', params )
    170198    }
    171199
     
    175203     * This is not a REST method! It only creates a rest resource and returns it's url.
    176204     *
    177      * @params assay
     205     * @params Assay
    178206     * @return URL
    179207     */
    180     public Object getAssayEditURL( assay ) {
    181         return new URL( ServerURL + '/simpleAssay/edit/assay?externalAssayID=' + assay.externalAssayID )
     208    public URL getAssayEditURL( assay ) {
     209                def params = ['externalAssayID':assay.externalAssayID ]
     210        return getSAMURL( 'simpleAssay/edit', params )
    182211    }
    183212
     
    187216     * This is not a REST method! It only creates a rest resource and returns it's url.
    188217     *
    189      * @params URL
    190      * @return list of ClinicalFloatData
    191      */
    192     public Object getMeasurementTypesURL() {
    193         return new URL( ServerURL + '/simpleAssayMeasurementType/list/nil?externalAssayID=' + assay.externalAssayID )
     218     * @params study
     219     * @return list of ClinicalFloatData
     220     */
     221    public URL getMeasurementTypesURL( study ) {
     222                def params = ['externalStudyID':study.code]
     223        return getSAMURL( 'simpleAssayMeasurementType/list', params )
    194224    }
    195225
Note: See TracChangeset for help on using the changeset viewer.