Changeset 1798


Ignore:
Timestamp:
May 2, 2011, 11:55:13 AM (12 years ago)
Author:
robert@…
Message:

After searching, several actions can be performed on search results. These actions are called by sending data to a URL. This was done using the HTTP GET method, but that resulted in error with the length of the query string (see #422). This is solved by sending all data using the HTTP POST method.

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        1010.settings
        1111*.log
         12dtd
  • trunk/grails-app/controllers/dbnp/exporter/ExporterController.groovy

    r1794 r1798  
    5151    def export = {
    5252                def ids = params.list( 'ids' );
     53                def tokens = params.list( 'tokens' );
    5354        def studies = []
    5455               
     
    5960                                        studies << study
    6061                        }
     62                }
     63               
     64                // Also accept tokens for defining studies
     65                tokens.each {
     66                        def study = Study.findByStudyUUID( it );
     67                        if( study )
     68                                studies << study;
    6169                }
    6270       
  • trunk/grails-app/controllers/dbnp/query/AdvancedQueryController.groovy

    r1752 r1798  
    125125                def view = determineView( s.entity );
    126126                render( view: view, model: [search: s, queryId: queryId, actions: determineActions(s)] );
    127         }
    128 
    129         /**
    130          * Performs an action on specific searchResults
    131          * @param       queryId         queryId of the search to show
    132          * @param       id                      list with the ids of the results to perform the action on
    133          * @param       actionName      Name of the action to perform
    134          */
    135         def performAction = {
    136                 def queryId = params.int( 'queryId' );
    137                 def selectedIds = params.list( 'id' ).findAll { it.isLong() }.collect { Long.parseLong(it) }
    138                 def actionName = params.actionName;
    139                 def moduleName = params.moduleName;
    140 
    141                 if( !queryId ) {
    142                         flash.error = "Incorrect search ID given to show"
    143                         redirect( action: "index" );
    144                         return
    145                 }
    146                
    147                 // Retrieve the search from session
    148                 Search s = retrieveSearch( queryId );
    149                 if( !s ) {
    150                         flash.message = "Specified search could not be found"
    151                         redirect( action: "list" );
    152                         return;
    153                 }
    154 
    155                 // Determine the possible actions and build correct urls
    156                 def actions = determineActions(s, selectedIds );
    157 
    158                 // Find the right action to perform
    159                 def redirectUrl;
    160                 for( action in actions ) {
    161                         if( action.module == moduleName && action.name == actionName ) {
    162                                 redirectUrl = action.url;
    163                                 break;
    164                         }
    165                 }
    166                
    167                 if( !redirectUrl ) {
    168                         flash.error = "No valid action is given to perform";
    169                         redirect( action: "show", id: queryId );
    170                         return;
    171                 }
    172                
    173                 redirect( url: redirectUrl );
    174127        }
    175128       
     
    578531         * Determine a list of actions that can be performed on specific entities by GSCF
    579532         * @param entity        Name of the entity that the actions could be performed on
    580          * @param selectedIds   List with ids of the selected items to perform an action on
    581          */
    582         protected List gscfActions(Search s, def selectedIds = null) {
     533         * @param selectedTokens        List with tokens (UUID) of the selected items to perform an action on
     534         */
     535        protected List gscfActions(Search s, def selectedTokens = null) {
    583536                switch(s.entity) {
    584537                        case "Study":
    585538                                def ids = []
    586                                 s.filterResults(selectedIds).each {
     539                                s.filterResults(selectedTokens).each {
    587540                                        ids << it.id
    588541                                }
     542
     543                                def paramString = ids.collect { return 'ids=' + it }.join( '&' );
    589544                               
    590545                                return [[
     
    592547                                                name:"simpletox",
    593548                                                description: "Export as SimpleTox",
    594                                                 url: createLink( controller: "exporter", action: "export", params: [ 'format': 'list', 'ids' : ids ] )
     549                                                url: createLink( controller: "exporter", action: "export", params: [ 'format': 'list', 'ids' : ids ] ),
     550                                                submitUrl: createLink( controller: "exporter", action: "export", params: [ 'format': 'list' ] ),
     551                                                paramString: paramString
    595552                                        ], [
    596553                                                module: "gscf",
    597554                                                name:"excel",
    598555                                                description: "Export as Excel",
    599                                                 url: createLink( controller: "study", action: "exportToExcel", params: [ 'format': 'list', 'ids' : ids ] )
     556                                                url: createLink( controller: "study", action: "exportToExcel", params: [ 'format': 'list', 'ids' : ids ] ),
     557                                                submitUrl: createLink( controller: "study", action: "exportToExcel", params: [ 'format': 'list' ] ),
     558                                                paramString: paramString
    600559                                        ]]
    601560                        case "Assay":
    602561                                def ids = []
    603                                 s.filterResults(selectedIds).each {
     562                                s.filterResults(selectedTokens).each {
    604563                                        ids << it.id
    605564                                }
     565
     566                                def paramString = ids.collect { return 'ids=' + it }.join( '&' );
    606567                               
    607568                                return [[
     
    609570                                                name:"excel",
    610571                                                description: "Export as Excel",
    611                                                 url: createLink( controller: "assay", action: "exportToExcel", params: [ 'format': 'list', 'ids' : ids ] )
     572                                                url: createLink( controller: "assay", action: "exportToExcel", params: [ 'format': 'list', 'ids' : ids ] ),
     573                                                submitUrl: createLink( controller: "assay", action: "exportToExcel", params: [ 'format': 'list' ] ),
     574                                                paramString: paramString
    612575                                        ]]
    613576                        case "Sample":
     
    622585         * @param entity        Name of the entity that the actions could be performed on
    623586         */
    624         protected List moduleActions(Search s, def selectedIds = null) {
     587        protected List moduleActions(Search s, def selectedTokens = null) {
    625588                def actions = []
    626589
     
    639602                                if( json[ s.entity ] ) {
    640603                                        json[ s.entity ].each { action ->
    641                                                 def url = action.url ?: module.url + "/action/" + action.name
     604                                                def baseUrl = action.url ?: module.url + "/action/" + action.name
     605                                                def paramString = s.filterResults(selectedTokens).collect { "tokens=" + it.giveUUID() }.join( "&" )
    642606                                               
    643                                                 if( url.find( /\?/ ) )
    644                                                         url += "&"
     607                                                if( baseUrl.find( /\?/ ) )
     608                                                        baseUrl += "&"
    645609                                                else
    646                                                         url += "?"
     610                                                        baseUrl += "?"
    647611                                               
    648                                                 url += "entity=" + s.entity
    649                                                 url += "&" + s.filterResults(selectedIds).collect { "tokens=" + it.giveUUID() }.join( "&" )
     612                                                baseUrl += "entity=" + s.entity
     613                                               
     614                                                def url = baseUrl;
     615                                               
    650616                                                actions << [
    651617                                                                        module: moduleName,
    652618                                                                        name: action.name,
    653619                                                                        description: action.description + " (" + moduleName + ")",
    654                                                                         url: url
     620                                                                        url: url + "&" + paramString,
     621                                                                        submitUrl: baseUrl,
     622                                                                        paramString: paramString
    655623                                                                ];
    656624                                        }
  • trunk/grails-app/controllers/dbnp/studycapturing/AssayController.groovy

    r1790 r1798  
    55        def assayService
    66        def authenticationService
    7     def fileService
     7        def fileService
    88
    99        static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
     
    174174                                flow.rowData            = assayService.convertColumnToRowStructure(assayData)
    175175
    176                 def previewRows         = Math.min(flow.rowData.size()    as int, 5) - 1
    177                 def previewCols         = Math.min(flow.rowData[0].size() as int, 5) - 1
     176                                def previewRows         = Math.min(flow.rowData.size()    as int, 5) - 1
     177                                def previewCols         = Math.min(flow.rowData[0].size() as int, 5) - 1
    178178
    179179                                flow.assayDataPreview   = flow.rowData[0..previewRows].collect{ it[0..previewCols] as ArrayList }
     
    198198        }
    199199
    200     /**
    201     * Export the row data in session.rowData to the outputStream of the http
    202     * response.
    203     */
     200        /**
     201        * Export the row data in session.rowData to the outputStream of the http
     202        * response.
     203        */
    204204        def doExport = {
    205205
     
    209209                try {
    210210
    211 //                      assayService.exportRowWiseDataToExcelFile(session.rowData, response.outputStream)
     211                        //                      assayService.exportRowWiseDataToExcelFile(session.rowData, response.outputStream)
    212212                        assayService.exportRowWiseDataToCSVFile(session.rowData, response.outputStream)
    213213
    214             // clear the data from the session
    215             session.removeAttribute('rowData')
     214                        // clear the data from the session
     215                        session.removeAttribute('rowData')
    216216
    217217                } catch (Exception e) {
     
    245245         */
    246246        def exportToExcelAsSheets = {
    247                 def ids = params.list( 'ids' ).findAll { it.isLong() }.collect { Long.valueOf( it ) };
    248 
    249                 if( !ids ) {
    250                         flash.errorMessage = "No assay ids given";
    251                         redirect( action: "errorPage" );
     247                def assays = getAssaysFromParams( params );
     248               
     249                if( !assays )
    252250                        return;
    253                 }
    254 
    255                 // Find all assays for the given ids
    256                 def assays = ids.unique().collect { id -> Assay.get( id ) }.findAll { it }
    257251
    258252                // Send headers to the browser so the user can download the file
     
    293287         */
    294288        def exportToExcelAsList = {
    295                 def ids = params.list( 'ids' ).findAll { it.isLong() }.collect { Long.valueOf( it ) };
    296 
    297                 if( !ids ) {
    298                         flash.errorMessage = "No assay ids given";
    299                         redirect( action: "errorPage" );
     289                def assays = getAssaysFromParams( params );
     290               
     291                if( !assays )
    300292                        return;
    301                 }
    302293
    303294                // If only 1 assay is asked for, don't bother with merging multiple assays.
    304295                // In that case just use the export method to export one assay per sheet
    305                 if( ids.size() == 1 )
     296                if( assays.size() == 1 )
    306297                        return exportToExcelAsSheets( params );
    307 
    308                 // Find all assays for the given ids
    309                 def assays = ids.unique().collect { id -> Assay.get( id ) }.findAll { it }
    310298
    311299                // Send headers to the browser so the user can download the file
     
    325313                                // Retrieve row based data for this assay
    326314                                def assayData = assayService.collectAssayData( assay, fieldMap, measurementTokens );
    327                                
     315
    328316                                // Prepend study and assay data to the list
    329317                                assayData = assayService.prependAssayData( assayData, assay, assay.samples?.size() )
    330318                                assayData = assayService.prependStudyData( assayData, assay, assay.samples?.size() )
    331                                
     319
    332320                                // Put each assay on another sheet
    333321                                columnWiseAssayData << assayData;
    334322                        }
    335                        
     323
    336324                        // Merge data from all assays
    337325                        def mergedColumnWiseData = assayService.mergeColumnWiseDataOfMultipleStudies( columnWiseAssayData );
     
    347335        }
    348336
     337        def getAssaysFromParams( params ) {
     338                def ids = params.list( 'ids' ).findAll { it.isLong() }.collect { Long.valueOf( it ) };
     339                def tokens = params.list( 'tokens' );
     340
     341                if( !ids && !tokens ) {
     342                        flash.errorMessage = "No assay ids given";
     343                        redirect( action: "errorPage" );
     344                        return [];
     345                }
     346
     347                // Find all assays for the given ids
     348                def assays = [];
     349                ids.each { id ->
     350                        def assay = Assay.get( id );
     351                        if( assay )
     352                                assays << assay;
     353                }
     354
     355                // Also accept tokens for defining studies
     356                tokens.each { token ->
     357                        def assay = Assay.findByAssayUUID( token );
     358                        if( assay )
     359                                assays << assay;
     360                }
     361               
     362                if( !assays ) {
     363                        flash.errorMessage = "No assays found";
     364                        redirect( action: "errorPage" );
     365                        return [];
     366                }
     367               
     368                return assays.unique();
     369        }
    349370
    350371        def errorPage = {
  • trunk/grails-app/controllers/dbnp/studycapturing/StudyController.groovy

    r1794 r1798  
    396396        def exportToExcel = {
    397397                def ids = params.list( 'ids' ).findAll { it.isLong() }.collect { Long.valueOf( it ) };
    398 
    399                 if( !ids ) {
     398                def tokens = params.list( 'tokens' );
     399
     400                if( !ids && !tokens ) {
    400401                        flash.errorMessage = "No study ids given";
    401402                        redirect( controller: "assay", action: "errorPage" );
     
    404405               
    405406                // Find all assay ids for these studies
    406                 def assayIds = ids.collect { id ->
     407                def assayIds = [];
     408                ids.each { id ->
    407409                        def study = Study.get( id );
    408410                        if( study ) {
    409                                 return study.assays.collect { assay -> assay.id }
    410                         } else {
    411                                 return []
     411                                assayIds += study.assays.collect { assay -> assay.id }
    412412                        }
    413                 }.flatten()
     413                }
    414414               
     415                // Also accept tokens for defining studies
     416                tokens.each { token ->
     417                        def study = Study.findByStudyUUID( token );
     418                        if( study )
     419                                assayIds += study.assays.collect { assay -> assay.id }
     420                }
     421                 
    415422                if( !assayIds ) {
    416423                        flash.errorMessage = "No assays found for the given studies";
  • trunk/grails-app/views/advancedQuery/_resultbuttons.gsp

    r1581 r1798  
    1818                </g:if>
    1919                <g:else>
    20                         <a class="performAction ${action.name}" href="${action.url}" onClick="performAction( $('form#results'), '${action.name}', '${action.module}' ); return false;">${action.description}</a>
     20                        <a class="performAction ${action.name}" href="${action.url}" onClick="performAction( $('form#results'), '${action.name}', '${action.module}', '${action.submitUrl}' ); return false;">${action.description}</a>
    2121                </g:else>
    2222                <br />
  • trunk/grails-app/views/advancedQuery/assayresults.gsp

    r1649 r1798  
    4141                                                also http://datatables.net/examples/api/form.html and advancedQueryResults.js
    4242                                        */ %>
    43                                         <g:checkBox name="id" value="${assayInstance.id}" checked="${false}" onClick="updateCheckAll(this);" />
     43                                        <g:checkBox name="uuid" value="${assayInstance.giveUUID()}" checked="${false}" onClick="updateCheckAll(this);" />
    4444                                </td>
    4545                                <td>
  • trunk/grails-app/views/advancedQuery/results.gsp

    r1548 r1798  
    4040                                                also http://datatables.net/examples/api/form.html and advancedQueryResults.js
    4141                                        */ %>
    42                                         <g:checkBox name="id" value="${result.id}" checked="${false}" onClick="updateCheckAll(this);" />
     42                                        <g:checkBox name="uuid" value="${result.giveUUID()}" checked="${false}" onClick="updateCheckAll(this);" />
    4343                                </td>                   
    4444                                <td>${search.entity}</td>
  • trunk/grails-app/views/advancedQuery/sampleresults.gsp

    r1548 r1798  
    4141                                                also http://datatables.net/examples/api/form.html and advancedQueryResults.js
    4242                                        */ %>
    43                                         <g:checkBox name="id" value="${sampleInstance.id}" checked="${false}" onClick="updateCheckAll(this);" />
     43                                        <g:checkBox name="uuid" value="${sampleInstance.giveUUID()}" checked="${false}" onClick="updateCheckAll(this);" />
    4444                                </td>
    4545                                <td>${fieldValue(bean: sampleInstance, field: "name")}</td>
  • trunk/grails-app/views/advancedQuery/studyresults.gsp

    r1689 r1798  
    4444                                                also http://datatables.net/examples/api/form.html and advancedQueryResults.js
    4545                                        */ %>
    46                                         <g:checkBox name="id" value="${studyInstance.id}" checked="${false}" onClick="updateCheckAll(this);" />
     46                                        <g:checkBox name="uuid" value="${studyInstance.giveUUID()}" checked="${false}" onClick="updateCheckAll(this);" />
    4747                                </td>
    4848                                <td>
  • trunk/src/groovy/dbnp/query/Search.groovy

    r1717 r1798  
    795795        * @return       A list with only those results for which the id is in the selectedIds
    796796        */
    797    public List filterResults( List selectedIds ) {
    798            if( !selectedIds || !results )
     797   public List filterResults( List selectedTokens ) {
     798           if( !selectedTokens || !results )
    799799                   return results
    800800
    801801           return results.findAll {
    802                    selectedIds.contains( it.id )
     802                   selectedTokens.contains( it.giveUUID() )
    803803           }
    804804   }
  • trunk/web-app/js/advancedQueryResults.js

    r1668 r1798  
    5858}
    5959
    60 function performAction( form, action, module ) {
     60function performAction( form, action, module, url ) {
    6161        // Make sure the data from the paginated table is submitted
    6262        // This is performed with javascript, because otherwise
    6363        // checkboxes of hidden rows won't be taken into account
    6464        // See also http://datatables.net/examples/api/form.html
     65       
     66        if( url == undefined )
     67                url = '/advancedQuery/performAction';
    6568       
    6669        // First remove all previously created inputs, in order to avoid any collissions
     
    7477        $('input', oTable.fnGetNodes()).each(function(idx,el) {
    7578                var $el = $(el);
    76                 if( $el.attr( 'name' ) == "id" && $(el).attr( 'checked' ) ) {
     79                if( $el.attr( 'name' ) == "uuid" && $(el).attr( 'checked' ) ) {
    7780                        checked = true;
    78                         form.append( $( '<input type="hidden" name="id" value="' + $el.attr( 'value' ) + '" class="created" />' ) );
     81                        form.append( $( '<input type="hidden" name="tokens" value="' + $el.attr( 'value' ) + '" class="created" />' ) );
    7982                }
    8083        })
     
    8891        $( '[name=actionName]', form ).val( action );
    8992        $( '[name=moduleName]', form ).val( module );
    90         submitForm( form, '/advancedQuery/performAction' );
     93       
     94        form.attr( 'action', url );
     95        form.submit();
    9196}
Note: See TracChangeset for help on using the changeset viewer.