- Timestamp:
- Feb 10, 2011, 5:03:02 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/nl/tno/metagenomics/integration/GscfService.groovy
r9 r13 12 12 */ 13 13 class GscfService { 14 15 14 def config = ConfigurationHolder.config 16 15 17 16 static transactional = true 18 19 20 17 21 18 /** … … 51 48 return "${config.gscf.baseURL}/study/showByToken/" + studyToken 52 49 } 53 54 /** 55 * Returns the url to add a new study in GSCF56 *57 * @return URL to redirect the user to58 */59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 50 51 /** 52 * Returns the url to add a new study in GSCF 53 * 54 * @return URL to redirect the user to 55 */ 56 public String urlAddStudy( String studyToken ) { 57 return config.gscf.baseURL + config.gscf.addStudyPath 58 } 59 60 /** 61 * Retrieves the currently logged in user from GSCF 62 * 63 * @param sessionToken String 64 * 65 * @return Map 66 */ 67 public Map getUser(String sessionToken) { 68 def user = [:] 69 this.callGSCF(sessionToken, "getUser").each { 70 user[ it.key ] = it.value; 71 } 72 return user 73 } 74 78 75 /** 79 76 * Retrieve a list of Studies from the GSCF … … 87 84 } 88 85 89 86 90 87 /** 91 88 * Retrieve a list of Studies from the GSCF … … 116 113 } catch( ResourceNotFoundException e ) { 117 114 throw new ResourceNotFoundException( "Study with token " + studyToken + " not found in GSCF" ) 118 throw e // Other exceptions are thrown as they appear 119 } 115 } // Other exceptions are thrown as they appear 120 116 121 117 // Return only the first element of the list, since we are only interested in one study 122 if( list.size() == 0 ) { 118 if( list?.size() ) { 119 return list[0]; 120 } else { 123 121 return [] 124 } else {125 return list[0];126 122 } 127 123 } … … 172 168 } 173 169 174 /** 175 * Retrieve a list of Samples from the GSCF 176 * 177 * @param sessionToken String 178 * @param assay Assay (parameter assay is optional, only used when you want to limit the list of samples of an Assay within a Study) 179 * 180 * @return ArrayList 181 */ 182 public ArrayList getSamples(String sessionToken, String assayToken) throws NotAuthorizedException, ResourceNotFoundException { 183 // Samples of a Study limited to a single Assay 184 try { 185 return this.callGSCF(sessionToken, "getSamples", ["assayToken":assayToken]) 186 } catch( NotAuthorizedException e ) { 187 throw new NotAuthorizedException( "User is not authorized to access study for assay with token " + assayToken ) 188 } catch( ResourceNotFoundException e ) {1 189 throw new ResourceNotFoundException( "Assay with token " + assayToken + " not found in GSCF" ) 190 } // Other exceptions are thrown as they appear 191 192 } 193 170 194 171 /** 195 172 * Retrieve a single Sample from the GSCF 196 * 173 * 197 174 * @param sessionToken String 198 175 * @param assay Assay 199 * @param sample Sample 200 * 201 * @return ArrayList 176 * @param sample Sample 177 * 178 * @return ArrayList 202 179 */ 203 180 public def getSample(String sessionToken, String assayToken, String sampleToken) throws NotAuthorizedException, ResourceNotFoundException { … … 219 196 220 197 } 198 199 /** 200 * Retrieve a list of Samples from the GSCF 201 * 202 * @param sessionToken String 203 * @param assay Assay (parameter assay is optional, only used when you want to limit the list of samples of an Assay within a Study) 204 * 205 * @return ArrayList 206 */ 207 public ArrayList getSamples(String sessionToken, String assayToken) throws NotAuthorizedException, ResourceNotFoundException { 208 // Samples of a Study limited to a single Assay 209 try { 210 return this.callGSCF(sessionToken, "getSamples", ["assayToken":assayToken]) 211 } catch( NotAuthorizedException e ) { 212 throw new NotAuthorizedException( "User is not authorized to access study for assay with token " + assayToken ) 213 } catch( ResourceNotFoundException e ) {1 214 throw new ResourceNotFoundException( "Assay with token " + assayToken + " not found in GSCF" ) 215 } // Other exceptions are thrown as they appear 216 217 } 218 219 /** 220 * Retrieve a list of samples from the GSCF 221 * 222 * @param sessionToken String 223 * @param sampleTokens List of sampleTokens 224 * 225 * @return ArrayList 226 */ 227 public def getSamples(String sessionToken, List sampleTokens) throws NotAuthorizedException, ResourceNotFoundException { 228 def list 229 230 try { 231 list = this.callGSCF(sessionToken, "getSamples", ["sampleToken": sampleTokens]) 232 } catch( NotAuthorizedException e ) { 233 throw new NotAuthorizedException( "User is not authorized to access samples" ) 234 } catch( ResourceNotFoundException e ) { 235 throw new ResourceNotFoundException( "Samples with token " + sampleTokens + " not found in GSCF" ) 236 } // Other exceptions are thrown as they appear 237 238 // Return only the first element of the list, since we are only interested in one sample 239 return list 240 } 241 221 242 222 243 /** … … 273 294 274 295 // concat all Rest Call specific arguments behind addr 275 restParams.each {parameter -> 296 restParams.each {parameter -> 276 297 // If a list is given as value, the parameter should show up multiple times 277 298 if( parameter.value instanceof Collection ) { … … 281 302 } else { 282 303 addr += "&${parameter.key}=" + parameter.value.toString().encodeAsURL() 283 } 304 } 284 305 } 285 306
Note: See TracChangeset
for help on using the changeset viewer.