Changeset 3 for trunk/grails-app/controllers/nl
- Timestamp:
- Jan 12, 2011, 9:45:08 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 4 4 .classpath 5 5 .project 6 fileuploads
-
- Property svn:ignore
-
trunk/grails-app/controllers/nl/tno/metagenomics/AssayController.groovy
r2 r3 9 9 def fileService 10 10 def excelService 11 def fastaService12 11 13 12 // Fields to be edited using excel file and manually … … 494 493 } 495 494 496 /**************************************************************************497 *498 * Methods for handling uploaded sequence and quality files499 *500 *************************************************************************/501 502 /**503 * Processes uploaded files and tries to combine them with samples504 */505 def process = {506 // load study with id specified by param.id507 def assay = Assay.get(params.id as Long)508 509 if (!assay) {510 flash.message = "No assay found with id: $params.id"511 redirect('action': 'errorPage')512 return513 }514 515 // Check whether files are given516 def names = params.sequencefiles517 518 if( !names ) {519 flash.message = "No files uploaded for processing"520 redirect('action': 'show', 'id': params.id)521 return522 }523 524 // If only 1 file is uploaded, it is given as String525 ArrayList filenames = []526 if( names instanceof String )527 filenames << names528 else529 names.each { filenames << it }530 531 /* Parses uploaded files, discards files we can not handle532 *533 * [534 * success: [535 * [filename: 'abc.fasta', type: FASTA, numSequences: 190]536 * [filename: 'cde.fasta', type: FASTA, numSequences: 140]537 * [filename: 'abc.qual', type: QUAL, numSequences: 190, avgQuality: 38]538 * [filename: 'cde.qual', type: QUAL, numSequences: 140, avgQuality: 29]539 * ],540 * failure: [541 * [filename: 'testing.xls', message: 'Type not recognized']542 * ]543 * ]544 */545 def parsedFiles = fastaService.parseFiles( filenames );546 547 // Match files with samples in the database548 def matchedFiles = fastaService.matchFiles( parsedFiles.success, assay.assaySamples );549 550 // Sort files on filename551 matchedFiles.sort { a,b -> a.fasta?.originalfilename <=> b.fasta?.originalfilename }552 553 // Saved file matches in session to use them later on554 session.processedFiles = [ parsed: parsedFiles, matched: matchedFiles ];555 556 [assay: assay, parsedFiles: parsedFiles, matchedFiles: matchedFiles, selectedRun: params.selectedRun ]557 }558 559 /**560 * Saves processed files to the database, based on the selections made by the user561 */562 def saveProcessedFiles = {563 // load study with id specified by param.id564 def assay = Assay.get(params.id as Long)565 566 if (!assay) {567 flash.message = "No assay found with id: $params.id"568 redirect('action': 'errorPage')569 return570 }571 572 // Check whether files are given573 def files = params.file574 575 if( !files ) {576 flash.message = "No files were selected."577 redirect('action': 'show', 'id': params.id)578 return579 }580 581 File permanentDir = fileService.absolutePath( ConfigurationHolder.config.metagenomics.fileDir )582 int numSuccesful = 0;583 def errors = [];584 585 // Loop through all files Those are the numeric elements in the 'files' array586 def digitRE = ~/^\d+$/;587 files.findAll { it.key.matches( digitRE ) }.each { file ->588 def filevalue = file.value;589 590 // Check if the file is selected591 if( filevalue.include == "on" ) {592 if( fileService.fileExists( filevalue.fasta ) ) {593 try {594 def permanent = fastaService.savePermanent( filevalue.fasta, filevalue.qual, session.processedFiles );595 596 // Save the data into the database597 SequenceData sd = new SequenceData();598 599 sd.sequenceFile = permanent.fasta600 sd.qualityFile = permanent.qual601 sd.numSequences = permanent.numSequences602 sd.averageQuality = permanent.avgQuality603 604 // Couple the data to the right run and sample605 def run = Run.get( filevalue.run )606 if( run )607 run.addToSequenceData( sd );608 609 def sample = AssaySample.get( filevalue.assaySample );610 if( sample )611 sample.addToSequenceData( sd );612 613 if( !sd.validate() ) {614 errors << "an error occurred while saving " + filevalue.fasta + ": validation of SequenceData failed.";615 } else {616 sd.save(flush:true);617 }618 619 numSuccesful++;620 } catch( Exception e ) {621 errors << "an error occurred while saving " + filevalue.fasta + ": " + e.getMessage()622 }623 }624 } else {625 // File doesn't need to be included in the system. Delete it also from disk626 fileService.delete( filevalue.fasta );627 }628 }629 630 // Return a message to the user631 if( numSuccesful == 0 ) {632 flash.error = "None of the files were imported, because "633 634 if( errors.size() > 0 ) {635 errors.each {636 flash.error += "<br />- " + it637 }638 } else {639 flash.error = "none of the files were selected for import."640 }641 } else {642 flash.message = numSuccesful + " files have been added to the system. "643 644 if( errors.size() > 0 ) {645 flash.error += errors.size() + " errors occurred during import: "646 errors.each {647 flash.error += "<br />- " + it648 }649 }650 }651 652 redirect( action: "show", id: params.id )653 }654 655 495 } -
trunk/grails-app/controllers/nl/tno/metagenomics/StudyController.groovy
r2 r3 18 18 // Filter studies for the ones the user is allowed to see 19 19 def studies = Study.findAll(); 20 [studies: studies.findAll { it.canRead( session.user ) }, gscfAddUrl: gscfService.urlAddStudy() ]20 [studies: studies.findAll { it.canRead( session.user ) }, gscfAddUrl: gscfService.urlAddStudy(), lastSynchronized: synchronizationService.lastFullSynchronization ] 21 21 } 22 22 23 } -
trunk/grails-app/controllers/nl/tno/metagenomics/auth/LogoutController.groovy
r2 r3 14 14 log.info("Session.sessionToken is now ${session.sessionToken}") 15 15 16 //logout on GSCF side, and do not redirect back to metagenomics (&spring-security-redirect=${ConfigurationHolder.config. metagenomics.baseURL}/study/list)16 //logout on GSCF side, and do not redirect back to metagenomics (&spring-security-redirect=${ConfigurationHolder.config.grails.serverURL}/study/list) 17 17 def redirectURL = "${ConfigurationHolder.config.gscf.baseURL}/logout/remote?consumer=${ConfigurationHolder.config.metagenomics.ConsumerID}&token=${session.sessionToken}" 18 18 log.info("Redirecting to: ${redirectURL}") -
trunk/grails-app/controllers/nl/tno/metagenomics/integration/RestController.groovy
r2 r3 339 339 } 340 340 341 def url = [ 'url' : ConfigurationHolder.config. metagenomics.baseURL + '/assay/show/' + assay.id.toString() ]341 def url = [ 'url' : ConfigurationHolder.config.grails.serverURL + '/assay/show/' + assay.id.toString() ] 342 342 343 343 render url as JSON 344 344 } 345 } 345 }.metagenomics.baseURL 346 346 347 347 /***************************************************/
Note: See TracChangeset
for help on using the changeset viewer.