Changeset 2030
- Timestamp:
- Sep 22, 2011, 5:10:17 PM (11 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/AssayController.groovy
r1969 r2030 211 211 handleError() { 212 212 render(view: 'errorPage') 213 } 214 } 215 216 /** 217 * This method is called when a user wants to fetch data from GSCF 218 */ 219 def galaxyExport = { 220 def galaxy_url = params.get( "GALAXY_URL" ); 221 def tool_id = params.get( "tool_id" ); 222 223 // Without galaxy url, we can't do anything 224 if( !galaxy_url || !tool_id ) { 225 redirect( action: "assayExport" ); 226 } 227 228 def user = authenticationService.getLoggedInUser() 229 def userStudies = Study.giveReadableStudies(user) 230 231 [ galaxy_url: galaxy_url, tool_id: tool_id, userStudies: userStudies ] 232 } 233 234 def sendToGalaxy = { 235 // Generate the url to redirect the user to 236 def galaxy_url = params.get( "GALAXY_URL" ); 237 def tool_id = params.get( "tool_id" ); 238 239 // Without galaxy url, we can't do anything 240 if( !galaxy_url || !tool_id ) { 241 redirect( action: "assayExport" ); 242 } 243 244 def assayId = params.long( "assayId" ); 245 def assay = assayId ? Assay.get( assayId ) : null; 246 247 // If no assay is given, return to galaxyExport screen 248 if( !assay ) { 249 redirect( action: "galaxyExport", params: [ "GALAXY_URL": galaxy_url ] ); 250 } 251 252 // create a random session token that will be used to allow to module to 253 // sync with gscf prior to presenting the measurement data 254 def sessionToken = UUID.randomUUID().toString() 255 def consumer = "galaxy"; 256 257 // put the session token to work 258 authenticationService.logInRemotely( consumer, sessionToken, authenticationService.getLoggedInUser() ) 259 260 // Create a url where the data can be fetched 261 def fetchUrl = g.createLink( absolute: true, controller: "assay", action: "fetchGalaxyData", params: [ assayToken: assay.assayUUID, sessionToken: sessionToken ] ); 262 263 // Generate url to redirect the user to 264 def url = galaxy_url + "?tool_id=" + URLEncoder.encode( tool_id.toString(), "UTF-8" ) + "&URL=" + URLEncoder.encode( fetchUrl.toString(), "UTF-8" ) 265 266 log.trace "Redirecting galaxy user back to " + url; 267 268 redirect( url: url ); 269 } 270 271 // This method is accessible for each user. However, he should return with a valid 272 // session token 273 @Secured(['true']) 274 def fetchGalaxyData = { 275 // Check accessibility 276 def consumer = "galaxy"; 277 def user = authenticationService.getRemotelyLoggedInUser( consumer, params.sessionToken ); 278 if( !user ) { 279 response.status = 401; 280 render "You must be logged in"; 281 return 282 } 283 284 // Invalidate session token 285 authenticationService.logOffRemotely( consumer, params.sessionToken ); 286 287 // retrieve assay 288 def assay = Assay.findByAssayUUID( params.assayToken ); 289 290 if( !assay ) { 291 response.status = 404; 292 render "No assay found"; 293 return 294 } 295 296 // Return assay data 297 def fieldMap = assayService.collectAssayTemplateFields( assay ) 298 def measurementTokens = fieldMap.remove('Module Measurement Data'); 299 def assayData = assayService.collectAssayData(assay, fieldMap, measurementTokens) 300 def rowData = assayService.convertColumnToRowStructure(assayData) 301 302 def outputDelimiter = '\t' 303 def outputFileExtension = 'txt' 304 305 def filename = "export.$outputFileExtension" 306 response.setHeader("Content-disposition", "attachment;filename=\"${filename}\"") 307 response.setContentType("application/octet-stream") 308 try { 309 assayService.exportRowWiseDataToCSVFile(rowData, response.outputStream, outputDelimiter, java.util.Locale.US) 310 } catch (Exception e) { 311 flash.errorMessage = e.message 312 redirect action: 'errorPage' 213 313 } 214 314 }
Note: See TracChangeset
for help on using the changeset viewer.