Ignore:
Timestamp:
May 27, 2010, 1:13:50 PM (14 years ago)
Author:
tabma
Message:
  • refactored (now using configuration file where entities to be used are configured)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/dbnp/importer/ImporterService.groovy

    r415 r485  
    4646    /**
    4747     * @param wb high level representation of the workbook
     48     * @param sheetindex sheet to use within the workbook
    4849     * @return header representation as a MappingColumn hashmap
    4950     */
    50     def getHeader(HSSFWorkbook wb, int sheetindex){
     51    def getHeader(HSSFWorkbook wb, int sheetindex, theEntity=0){
    5152
    5253        def sheet = wb.getSheetAt(sheetindex)
     
    5556        def header = [:]
    5657        def df = new DataFormatter()
    57 
     58        def property = new dbnp.studycapturing.TemplateField()
    5859
    5960        for (HSSFCell c: sheet.getRow(datamatrix_start)) {
     
    6768            switch (datamatrix_celltype) {
    6869                    case HSSFCell.CELL_TYPE_STRING:
    69                             header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.STRING, index:index);
     70                            header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.STRING, index:index, entity:theEntity, property:property);
    7071                            break
    7172                    case HSSFCell.CELL_TYPE_NUMERIC:                   
    7273                            if (HSSFDateUtil.isCellDateFormatted(c)) {
    73                                 header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.DATE, index:index)
     74                                header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.DATE, index:index, entity:theEntity, property:property)
    7475                            }
    7576                            else
    76                                 header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.INTEGER,index:index);
     77                                header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.INTEGER,index:index, entity:theEntity, property:property);
    7778                            break
    7879                    case HSSFCell.CELL_TYPE_BLANK:
    79                             header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.STRING, index:index);
     80                            header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.STRING, index:index, entity:theEntity, property:property);
    8081                            break
    8182                    default:
    82                             header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.STRING,index:index);
     83                            header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.STRING,index:index, entity:theEntity, property:property);
    8384                            break
    8485            }
     
    160161        def sheet = wb.getSheetAt(sheetindex)
    161162        def table = []
     163
    162164       
    163165        // walk through all rows       
    164166        (rowindex..sheet.getLastRowNum()).each { i ->
    165             table.add(createRecord(template_id, sheet.getRow(i), mcmap))           
     167            table.add(createRecord(template_id, sheet.getRow(i), mcmap))
    166168        }
    167169
     
    263265        def sample = new Sample(name:"New sample", template:template)
    264266
    265         for (HSSFCell cell: excelrow) {
     267        for (HSSFCell cell: excelrow) {     
    266268            def mc = mcmap[cell.getColumnIndex()]
    267             def value = formatValue(df.formatCellValue(cell), mc.templatefieldtype)         
     269            def value = formatValue(df.formatCellValue(cell), mc.templatefieldtype)
    268270
    269271            switch(mc.entity) {
Note: See TracChangeset for help on using the changeset viewer.