Changeset 1044


Ignore:
Timestamp:
Nov 1, 2010, 9:42:38 PM (6 years ago)
Author:
t.w.abma@…
Message:
  • added record which contains failed columns, should be passed to an overview in step 2a
Location:
trunk/grails-app
Files:
2 added
2 edited

Legend:

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

    r989 r1044  
    229229        render(view:"step2", model:[entities:selectedentities, header:session.importer_header, templates:templates])
    230230    }
    231 
    232     /**
    233     * @param columnproperty array of columns containing index and property (represented as a String)
     231   
     232    /**
     233     * Method which stores the properties set per column and then imports the data.
     234     *
     235     * @param columnproperty array of columns containing index and property (represented as a String)
    234236    *
    235237    */
    236     def saveProperties = {
     238    def saveProperties = {       
    237239
    238240        // Find actual Template object from the chosen template name
     
    261263        }
    262264
    263         //import workbook
    264         session.importer_importeddata = ImporterService.importdata(session.importer_template_id, session.importer_workbook, session.importer_sheetindex, session.importer_datamatrix_start, session.importer_header)
     265        //import workbook and store it in a session
     266        session.importer_importeddata = ImporterService.importData(session.importer_template_id, session.importer_workbook, session.importer_sheetindex, session.importer_datamatrix_start, session.importer_header)
     267
     268        //
     269        //render(view:"step2a_simple", model:[datamatrix:session.importer_importeddata])
    265270
    266271        if (params.layout=="horizontal")
  • trunk/grails-app/services/dbnp/importer/ImporterService.groovy

    r1028 r1044  
    222222    * @see dbnp.importer.MappingColumn
    223223    */
    224     def importdata(template_id, HSSFWorkbook wb, int sheetindex, int rowindex, mcmap) {
     224    def importData(template_id, HSSFWorkbook wb, int sheetindex, int rowindex, mcmap) {
    225225        def sheet = wb.getSheetAt(sheetindex)
    226226        def table = []
     
    376376                def template = Template.get(template_id)
    377377                def record = []
     378                def failed = [:]
    378379
    379380                // Initialize all possible entities with the chosen template
     
    388389                        // get the MappingColumn information of the current cell
    389390                        def mc = mcmap[cell.getColumnIndex()]
    390                         def value
     391                        def value                       
    391392
    392393                        // Check if column must be imported
     
    402403                                // which entity does the current cell (field) belong to?
    403404                                    switch (mc.entity) {
    404                                         case Study: (record.any {it.getClass() == mc.entity}) ? 0 : record.add(study)
     405                                        case Study: // does the entity already exist in the record? If not make it so.
     406                                                (record.any {it.getClass() == mc.entity}) ? 0 : record.add(study)
    405407                                                study.setFieldValue(mc.property, value)
    406408                                                break
     
    422424                                } catch (IllegalArgumentException iae) {
    423425                                    // leave the field empty and let the user choose the ontology manually in a later step
    424                                    
     426                                    failed.put(mc, value)
    425427                                }
    426428                        } // end
    427429                } // end for
    428430
    429         return record
     431        // add the failed columns to the record (might also be just an empty map if nothing failed)
     432        // a failed column means that using the entity.setFieldValue() threw an exception
     433        record.add(failed)
     434       
     435        return record
    430436    }
    431437
Note: See TracChangeset for help on using the changeset viewer.