Changeset 1199 for trunk/src/groovy
- Timestamp:
- Nov 25, 2010, 10:56:40 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/groovy/dbnp/rest/common/CommunicationManager.groovy
r1196 r1199 27 27 28 28 29 /* this should moved somewhere else */30 /* The static URLs are set in grails-app/conf/Config.groovy */31 29 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 = '' 37 33 38 34 39 35 /** 40 * Get the results ofprovided by a rest Rest resource.36 * Get the results provided by a rest Rest resource. 41 37 * 42 38 * @params String resource The name of the resource, e.g. importer/pages … … 48 44 return JSON.parse( url.newReader() ) 49 45 } 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 50 62 51 63 … … 59 71 * @return String url 60 72 */ 61 public static URL getRestURL( RestServerURL, resource, params ) {62 def url = RestServerURL + '/' + resource73 public static URL getRestURL( serverName, resource, params ) { 74 def url = getURL(serverName) + '/rest/' + resource 63 75 def first = true 64 params['consumer'] =ServerURL76 params['consumer'] = getURL( ModuleName ) 65 77 params.each { name, value -> 66 78 if(first) { … … 111 123 */ 112 124 113 public static addRestWrapper( server URL, restName, params = [], closure = { return it } ) {114 if(!server URL) { 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") } 115 127 def result 116 128 try { … … 125 137 } 126 138 } 127 result = closure( getRestResource( server URL, restName, map ) )139 result = closure( getRestResource( serverName, restName, map ) ) 128 140 } 129 141 } catch ( Exception e ) { … … 133 145 return result 134 146 } 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 = SAMServerURL143 addRestWrapper( url+'/rest', 'getQueryResult', ['query'] )144 }145 147 146 148 … … 158 160 159 161 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 160 182 }
Note: See TracChangeset
for help on using the changeset viewer.