Ignore:
Timestamp:
Jun 17, 2011, 1:54:56 PM (8 years ago)
Author:
robert@…
Message:
  • Installed templates (in order to extend session lifetime to 2 hours)
  • Implemented background worker to do work outside the HTTP request
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/nl/tno/massSequencing/AssaySampleController.groovy

    r67 r70  
    22
    33import java.util.List;
     4import org.codehaus.groovy.grails.commons.ConfigurationHolder
    45
    56class AssaySampleController {
    67        def fastaService
    78        def sampleExcelService
     9        def fileService
     10        def workerService
    811
    912        /**
     
    99102         */
    100103        def exportAsFasta = {
    101                 def assaySamples = getAssaySamples( params );
    102                 def name
     104                def assaySamples = getAssaySamples( params )?.unique();
    103105
    104106                if( assaySamples?.size() == 0 ) {
     
    108110                }
    109111
    110                 name = "samples";
    111 
     112                // Start the export in the background
     113                def name = "samples";
     114                def returnUrl = createLink( controller: params.entityType, action: "show", id: params.entityId ).toString()
     115                def finishUrl = createLink( controller: "assaySample", action: 'downloadFasta', params: [ processId: '%s' ] ).toString();
     116                def url = fastaService.startExportProcess( assaySamples, session, name, returnUrl, finishUrl )
     117
     118                // Show a waiting screen
     119                redirect( url: url );
     120        }
     121       
     122        def downloadFasta = {
     123                def processId = params.processId;
     124               
    112125                // Export the sequences and quality scores
    113                 response.setHeader "Content-disposition", "attachment; filename=${name}.zip"
     126                response.setHeader "Content-disposition", "attachment; filename=" + session.process[ processId ].name  + ".zip"
    114127                try {
    115                         fastaService.export( assaySamples.unique(), response.getOutputStream() );
     128                        response.outputStream << fileService.get( session.process[ processId ].filename ).newInputStream();
    116129                        response.outputStream.flush();
    117130                } catch( Exception e ) {
    118131                        log.error( "Exception occurred during export of sequences. Probably the user has cancelled the download." );
    119132                        e.printStackTrace();
     133                } finally {
     134                        // Delete the file since it has to be downloaded only once
     135                        fileService.delete( session.process[ processId ].filename );
    120136                }
    121137        }
     
    145161                        }
    146162                        response.setHeader "Content-disposition", "attachment; filename=${name}.xls"
    147 
     163                       
     164                        sampleExcelService.sessionToken = session.sessionToken
     165                       
    148166                        if( !sampleExcelService.exportExcelSampleData( assaySamples.unique(), tags, response.outputStream ) ) {
    149167                                flash.error = "An error occurred while fetching sample data. Maybe the session has timed out.";
Note: See TracChangeset for help on using the changeset viewer.