Changeset 1199


Ignore:
Timestamp:
Nov 25, 2010, 10:56:40 AM (6 years ago)
Author:
j.saito@…
Message:

Further streamlined CommunicationManager?. It now builds fetches its URL from config.modules and is further minimized.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/conf/BootStrap.groovy

    r1196 r1199  
    4646                        // register SAM REST methods
    4747                        "Registering SAM REST methods".grom()
    48                         CommunicationManager.GSCFServerURL = config.grails.serverURL
    49                         CommunicationManager.SAMServerURL = config.modules.sam.url
    50                         CommunicationManager.DSPServerURL = config.modules.metabolomics.url
    51                         CommunicationManager.ServerURL = config.grails.serverURL
     48                        CommunicationManager.registerModule('gscf', config.grails.serverURL, config.modules)
    5249                        CommunicationManager.registerRestWrapperMethodsFromSAM()
    5350                }
  • trunk/grails-app/controllers/RestController.groovy

    r1101 r1199  
    252252
    253253                        def id = params.studyToken
    254                         def study = Study.find( "from Study as s where s.code=?", [id] )
     254                        def study = Study.findByCode(id)
    255255
    256256                        if(study) {
     
    302302
    303303                }
    304 
    305304                render returnList as JSON
    306305        }
  • trunk/src/groovy/dbnp/rest/common/CommunicationManager.groovy

    r1196 r1199  
    2727
    2828
    29     /* this should moved somewhere else */
    30     /* The static URLs are set in grails-app/conf/Config.groovy */
    3129    def        static Encoding      = "UTF-8"
    32     def public static ServerURL     = "http://localhost:8182/sam"
    33     def public static SAMServerURL  = "http://localhost:8182/sam"
    34     def public static GSCFServerURL = "http://localhost:8080/gscf"
    35     def public static DSPServerURL  = "http://localhost:8080/ncdsp"
    36 
     30                                         // map that maps name strings of dbNP modules to urls
     31        def public static URLMap = [:]   // e.g., 'gscf' -> 'http://sam.
     32        def public static ModuleName = ''
    3733
    3834
    3935    /**
    40      * Get the results of provided by a rest Rest resource.
     36     * Get the results provided by a rest Rest resource.
    4137     *
    4238     * @params String resource The name of the resource, e.g. importer/pages
     
    4844                return  JSON.parse( url.newReader() )
    4945    }
     46
     47        private static getURL( serverName ) {
     48                return URLMap[serverName]?.url
     49        }
     50
     51    /** Register this module once before run time.
     52      * @params moduleName      the string name for this module, e.g., 'sam' or 'gscf'
     53      * @params serverURL           the URL of this module, e.g., 'localhost:8080/sam'
     54      * @params map             a map that maps module names to urls
     55      */
     56        public static registerModule( moduleName, serverURL, urlMap ) {
     57                ModuleName = moduleName
     58                URLMap = urlMap
     59                URLMap[ModuleName] = ['url':serverURL]
     60        }
     61
    5062
    5163
     
    5971     * @return String url   
    6072     */
    61     public static URL getRestURL( RestServerURL, resource, params ) {
    62         def url = RestServerURL + '/' + resource
     73    public static URL getRestURL( serverName, resource, params ) {
     74        def url = getURL(serverName) + '/rest/' + resource
    6375                def first = true
    64                 params['consumer']=ServerURL
     76                params['consumer'] = getURL( ModuleName )
    6577                params.each { name, value ->
    6678                        if(first) {
     
    111123     */
    112124
    113     public static addRestWrapper( serverURL, restName, params = [], closure = { return it } ) {
    114                 if(!serverURL) { throw new Exception("addRestWrapper: REST serverURL is null") }
     125    public static addRestWrapper( serverName, restName, params = [], closure = { return it } ) {
     126                if(!serverName) { throw new Exception("addRestWrapper: REST serverURL is null") }
    115127                def result
    116128                try {
     
    125137                                        }
    126138                                }
    127                                 result = closure( getRestResource( serverURL, restName, map ) )
     139                                result = closure( getRestResource( serverName, restName, map ) )
    128140                        }
    129141                } catch ( Exception e ) {
     
    133145                return result
    134146        }
    135 
    136 
    137     /**
    138      *  This method creates on run time new methods for accessing Grails views that SAM provides for GSCF.
    139      *  This method should be called in grails-app/conf/BootStrap.groovy in the GSCF module.
    140      */         
    141     public static registerRestWrapperMethodsFromSAM() {
    142                 def url = SAMServerURL
    143                 addRestWrapper( url+'/rest', 'getQueryResult',  ['query'] )
    144     }
    145147
    146148
     
    158160
    159161
     162
     163    /**
     164     *  This creates on run time new methods for accessing Rest resources that GSCF provides for SAM.
     165     *  This method should be called in grails-app/conf/BootStrap.groovy in the SAM module.
     166     */
     167    public static registerRestWrapperMethodsFromGSCF() {
     168                addRestWrapper( 'gscf', 'getStudies', ['token'] )
     169                addRestWrapper( 'gscf', 'getSubjects', ['token','studyToken'] )
     170                addRestWrapper( 'gscf', 'getAssays',   ['token','studyToken','url'] )
     171                addRestWrapper( 'gscf', 'getSamples',  ['token','assayToken'] )
     172    }
     173
     174    /**
     175     *  This method creates on run time new methods for accessing Grails views that SAM provides for GSCF.
     176     *  This method should be called in grails-app/conf/BootStrap.groovy in the GSCF module.
     177     */         
     178    public static registerRestWrapperMethodsFromSAM() {
     179                addRestWrapper( 'gscf', 'getQueryResult',  ['query'] )
     180    }
     181
    160182}
Note: See TracChangeset for help on using the changeset viewer.