- Timestamp:
- Jan 26, 2011, 5:08:25 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/nl/tno/metagenomics/FastaController.groovy
r5 r7 18 18 */ 19 19 def showProcessScreen = { 20 // load study with id specified by param.id 21 def assay = Assay.get(params.id as Long) 22 23 if (!assay) { 24 flash.message = "No assay found with id: $params.id" 25 redirect( controller: 'assay', action: 'errorPage') 26 return 27 } 20 def entityType = params.entityType 28 21 29 22 // Check whether files are given … … 32 25 if( !names ) { 33 26 flash.message = "No files uploaded for processing" 34 redirect( controller: 'assay', action: 'show', 'id': params.id)27 redirect( controller: params.entityType, action: 'show', 'id': params.id) 35 28 return 36 29 } … … 59 52 ] 60 53 61 [ assay: assay, filenames: names, url: createLink( action: 'showProcessResult', id: assay.id, params: [ selectedRun: params.selectedRun] ) ]54 [entityId: params.id, entityType: params.entityType, filenames: names, url: createLink( action: 'showProcessResult', id: params.id, params: [entityType: entityType] ) ] 62 55 } 63 56 … … 66 59 */ 67 60 def process = { 68 // load study with id specified by param.id 69 def assay = Assay.get(params.id as Long) 70 71 if (!assay) { 72 response.setStatus( 404, "No assay found with id: $params.id" ) 61 def entity 62 def assaySamples 63 64 switch( params.entityType ) { 65 case "run": 66 entity = getRun( params.id ); 67 assaySamples = entity.assaySamples; 68 break; 69 case "assay": 70 entity = getAssay( params.id ); 71 assaySamples = entity.assaySamples; 72 break; 73 default: 74 response.setStatus( 404, "No controller found" ); 75 render ""; 76 return; 77 } 78 79 if (!entity) { 80 response.setStatus( 404, flash.error ) 73 81 render ""; 74 82 return … … 113 121 session.processProgress.bytesProcessed = bytes; 114 122 } ); 123 124 // Check which assaySamples to use (only the ones visible to the user) 125 assaySamples = assaySamples.findAll { it.assay.study.canWrite( session.user ) } 115 126 116 127 // Match files with samples in the database 117 def matchedFiles = fastaService.matchFiles( parsedFiles.success, assay .assaySamples );128 def matchedFiles = fastaService.matchFiles( parsedFiles.success, assaySamples ); 118 129 119 130 // Sort files on filename … … 141 152 def showProcessResult = { 142 153 // load study with id specified by param.id 143 def assay = Assay.get(params.id as Long) 144 145 if (!assay) { 146 flash.message = "No assay found with id: $params.id" 147 redirect( controller: 'assay', action: 'errorPage') 148 return 149 } 150 154 def entity 155 156 switch( params.entityType ) { 157 case "run": 158 entity = getRun( params.id ) 159 break; 160 case "assay": 161 entity = getAssay( params.id ) 162 break; 163 default: 164 response.setStatus( 404, "No entity found" ); 165 render ""; 166 return; 167 } 168 169 if (!entity) { 170 response.setStatus( 404, flash.error ) 171 render ""; 172 return 173 } 174 151 175 if( !session.processedFiles ) { 152 176 flash.error = "Processing of files failed. Maybe the session timed out." … … 155 179 } 156 180 157 [ assay: assay, parsedFiles: session.processedFiles.parsed, matchedFiles: session.processedFiles.matched, selectedRun: params.selectedRun ]181 [entityType: params.entityType, entity: entity, id: params.id, parsedFiles: session.processedFiles.parsed, matchedFiles: session.processedFiles.matched, selectedRun: params.selectedRun ] 158 182 } 159 183 … … 162 186 */ 163 187 def saveProcessedFiles = { 164 // load study with id specified by param.id 165 def assay = Assay.get(params.id as Long) 166 167 if (!assay) { 168 flash.message = "No assay found with id: $params.id" 169 redirect( controller: 'assay', action: 'errorPage') 188 // load entity with id specified by param.id 189 def entity 190 191 switch( params.entityType ) { 192 case "run": 193 entity = getRun( params.id ); 194 break; 195 case "assay": 196 entity = getAssay( params.id ); 197 break; 198 default: 199 response.setStatus( 404, "No entity found" ); 200 render ""; 201 return; 202 } 203 204 if (!entity) { 205 response.setStatus( 404, flash.error ) 206 render ""; 170 207 return 171 208 } … … 176 213 if( !files ) { 177 214 flash.message = "No files were selected." 178 redirect( controller: 'assay', action: 'show', 'id': params.id)215 redirect( controller: params.entityType, action: 'show', 'id': params.id) 179 216 return 180 217 } … … 202 239 sd.numSequences = permanent.numSequences 203 240 sd.averageQuality = permanent.avgQuality 204 205 // Couple the data to the right run and sample206 def run = Run.get( filevalue.run )207 if( run )208 run.addToSequenceData( sd );209 241 210 242 def sample = AssaySample.get( filevalue.assaySample ); … … 251 283 } 252 284 253 redirect( controller: 'assay', action: "show", id: params.id )285 redirect( controller: params.entityType, action: "show", id: params.id ) 254 286 } 255 287 256 288 def deleteData = { 257 289 // load study with id specified by param.id 258 def sequenceData = SequenceData.get(params.id as Long) 290 def sequenceData 291 292 try { 293 sequenceData = SequenceData.get(params.id as Long) 294 } catch( Exception e ) {} 259 295 260 296 if (!sequenceData) { 261 297 flash.error = "No sequencedata found with id: $params.id" 262 redirect( controller: 'assay', action: 'errorPage') 263 return 264 } 265 266 def assayId = sequenceData.sample.assay.id; 298 redirect( controller: 'study' ) 299 return 300 } 301 302 def entityId 303 def entityType 304 305 switch( params.entityType ) { 306 case "run": 307 entityId = sequenceData.sample.run?.id; 308 entityType = "run" 309 break; 310 case "assay": 311 default: 312 entityType = "assay"; 313 entityId = sequenceData.sample.assay.id; 314 break; 315 } 316 267 317 def numFiles = sequenceData.numFiles(); 268 318 sequenceData.delete(); 269 319 270 320 flash.message = numFiles + " file" + (numFiles != 1 ? "s have" : " has" ) + " been deleted from this sample" 271 redirect( controller: 'assay', action: 'show', id: assayId ) 321 322 redirect( controller: entityType, action: 'show', id: entityId ) 323 } 324 325 protected Assay getAssay(def assayId) { 326 // load assay with id specified by param.id 327 def assay 328 try { 329 assay = Assay.get(assayId as Long) 330 } catch( Exception e ) { 331 flash.error = "Incorrect id given: " + assayId 332 return null 333 } 334 335 if (!assay) { 336 flash.error = "No assay found with id: " + assayId 337 return null 338 } 339 340 if (!assay.study.canRead( session.user ) ) { 341 flash.error = "You don't have the right authorizaton to access assay " + assay.name 342 return null 343 } 344 345 return assay 346 } 347 348 protected Run getRun(def runId) { 349 // load run with id specified by param.id 350 def run 351 try { 352 run = Run.get(runId as Long) 353 } catch( Exception e ) { 354 flash.error = "Incorrect id given: " + runId 355 return null 356 } 357 358 if (!run) { 359 flash.error = "No run found with id: " + runId 360 return null 361 } 362 363 return run 272 364 } 273 365 }
Note: See TracChangeset
for help on using the changeset viewer.