Changeset 1502


Ignore:
Timestamp:
Feb 7, 2011, 4:32:07 PM (13 years ago)
Author:
t.w.abma@…
Message:
  • uploaded file in import wizard now checked for being an Excel (formatted) file, other file (formats) will display a popup with an error message
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy

    r1499 r1502  
    111111
    112112            on("refresh") {
    113                 flash.importer_params = params               
     113                flash.importer_params = params           
    114114                                success()
    115115                        }.to "pageOne"
     
    117117                        on("next") {
    118118                                flash.wizardErrors = [:]
     119                //flash.importer_params = params
    119120
    120121                                // Study selected?
     
    123124                                // Trying to import data into an existing study?
    124125                                if (flow.importer_study)
    125                                         if (flow.importer_study.canWrite(authenticationService.getLoggedInUser())) {
    126                                                 if (fileImportPage(flow, params)) {
    127                                                         success()
    128                                                 } else {
    129                                                         log.error ".importer wizard not all fields are filled in"
    130                                                         this.appendErrorMap(['error': "Not all fields are filled in, please fill in or select all fields"], flash.wizardErrors)
    131                                                         error()
    132                                                 }
    133                                         } else {
     126                                        if (flow.importer_study.canWrite(authenticationService.getLoggedInUser()))
     127                                                fileImportPage(flow, flash, params) ? success() : error()                                       
     128                                        else {
    134129                                                log.error ".importer wizard wrong permissions"
    135130                                                this.appendErrorMap(['error': "You don't have the right permissions"], flash.wizardErrors)
    136 
    137131                                                error()
    138132                                        }
    139133                                else {
    140                                         if (fileImportPage(flow, params)) {
    141                                                 success()
    142                                         } else {
    143                                                 log.error ".importer wizard not all fields are filled in"
    144                                                 this.appendErrorMap(['error': "Not all fields are filled in, please fill in or select all fields"], flash.wizardErrors)
    145                                                 error()
    146                                         }
     134                                        fileImportPage(flow, flash, params) ? success() : error()
    147135                                }
    148136
     
    299287         * @returns boolean true if correctly validated, otherwise false
    300288         */
    301         boolean fileImportPage(flow, params) {
     289        boolean fileImportPage(flow, flash, params) {
    302290                def importedfile = fileService.get(params['importfile'])
    303291                //fileService.delete(YourFile)
    304292
    305                 if (params.entity && params.template_id && importedfile.exists()) {
    306                         // create a workbook instance of the file
    307                         session.importer_workbook = ImporterService.getWorkbook(new FileInputStream(importedfile))
     293        if (importedfile.exists()) {
     294            try {
     295                session.importer_workbook = ImporterService.getWorkbook(new FileInputStream(importedfile))
     296            } catch (Exception e) {
     297                log.error ".importer wizard could not load file: " + e
     298                this.appendErrorMap(['error': "Wrong file (format), the importer requires an Excel file as input"], flash.wizardErrors)
     299                return false
     300            }
     301        }
     302
     303                if (params.entity && params.template_id) {           
     304                       
     305            try {
     306                session.importer_workbook = ImporterService.getWorkbook(new FileInputStream(importedfile))
     307            } catch (Exception e) {
     308                log.error ".importer wizard could not load file: " + e
     309                this.appendErrorMap(['error': "Excel file required as input"], flash.wizardErrors)
     310                return false
     311            }
    308312
    309313                        def selectedentities = []
     
    345349                        return true
    346350                }
     351
     352        log.error ".importer wizard not all fields are filled in"
     353        this.appendErrorMap(['error': "Not all fields are filled in, please fill in or select all fields"], flash.wizardErrors)
     354        return false
    347355        }
    348356
Note: See TracChangeset for help on using the changeset viewer.