Changeset 259


Ignore:
Timestamp:
Mar 12, 2010, 11:51:33 AM (13 years ago)
Author:
tabma
Message:
Location:
trunk/grails-app
Files:
1 deleted
2 edited

Legend:

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

    r255 r259  
    2020import org.apache.poi.ss.usermodel.DataFormatter
    2121import org.apache.poi.hssf.usermodel.HSSFDateUtil
    22 import dbnp.importer.Column
    2322import dbnp.studycapturing.TemplateFieldType
     23import dbnp.studycapturing.Study
     24import dbnp.studycapturing.Subject
     25import dbnp.studycapturing.Event
     26import dbnp.studycapturing.Protocol
     27import dbnp.studycapturing.Sample
     28
    2429
    2530class ImporterService {
     
    3944    /**
    4045     * @param wb high level representation of the workbook
    41      * @return header representation as a string array
     46     * @return header representation as a MappingColumn array
    4247     */
    4348    def getHeader(HSSFWorkbook wb, int sheetindex){
     
    9499        def rows  = []
    95100        def df = new DataFormatter()
    96 
     101        def datamatrix_start = 1
     102
     103        // walk through all rows
    97104        (count <= sheet.getLastRowNum()) ?
    98         ((1+sheet.getFirstRowNum())..count).each { rowindex ->
    99 
     105        ((datamatrix_start+sheet.getFirstRowNum())..count).each { rowindex ->
    100106            def row = []
     107
     108            // walk through every cell
    101109            for (HSSFCell c: sheet.getRow(rowindex))
    102110                row.add(c)
     
    138146    * by using mapping information
    139147    *
    140     *
    141148    * @param wb POI horrible spreadsheet formatted workbook object
    142149    * @param mc array of MappingColumns
     
    146153    * @see dbnp.importer.MappingColumn
    147154    */
    148     def importdata(HSSFWorkbook wb, int sheetindex, int rowindex, MappingColumn[] mc) {
     155    def importdata(HSSFWorkbook wb, int sheetindex, int rowindex, MappingColumn[] mcarray) {
    149156        def sheet = wb.getSheetAt(sheetindex)
    150157        def rows  = []
    151 
    152         (count <= sheet.getLastRowNum()) ?
    153         (rowindex..count).each { i ->
    154 
    155             def row = []
    156             for (HSSFCell c: sheet.getRow(i))
    157                 //row.add(c)
    158                 //row.add(df.formatCellValue(c))
    159                 switch(mc[c.getColumnIndex()].celltype) {
    160                     case 0  : break
    161                     default : break
    162                 }
    163 
    164                 rows.add(row)
    165         } : 0
     158        def df = new DataFormatter()
     159
     160        // walk through all rows       
     161        rowindex..sheet.getLastRowNum().each { i ->
     162            def record = [:]
     163
     164            // get the value of the cells in the row
     165            for (HSSFCell c: sheet.getRow(i))           
     166                mc = mcarray[c.getColumnIndex()]               
     167                record.add(createColumn(c, mc))
     168        }
     169    }
     170
     171    /**
     172    * This function creates a column based on the current cell and mapping
     173    *
     174    * @param cell POI cell read from Excel
     175    * @param mc mapping column
     176    * @return entity object
     177    *
     178    */
     179    def createColumn(HSSFCell cell, MappingColumn mc) {
     180        def df = new DataFormatter()
     181
     182        // check the templatefield type of the cell
     183        switch(mc.entity) {
     184            case Study  :   def st = new Study()
     185                            st.setFieldValue(mc.name, df.formatCellValue(c))
     186                            return st
     187                            break
     188            case Subject:   def su = new Subject()
     189                            su.setFieldValue(mc.name, df.formatCellValue(c))
     190                            return su
     191                            break
     192            case Event  :   def ev = new Event()
     193                            ev.setFieldValue(mc.name, df.formatCellValue(c))
     194                            return ev
     195                            break
     196            case Protocol:  def pr = new Protocol()
     197                            pr.setFieldValue(mc.name, df.formatCellValue(c))
     198                            return pr
     199                            break
     200            case Sample :   def sa = new Sample()
     201                            sa.setFieldValue(mc.name, df.formatCellValue(c))
     202                            return sa
     203                            break
     204            case Object :   break
     205           
     206        }
     207
    166208    }
    167209}
  • trunk/grails-app/taglib/dbnp/importer/ImporterTagLib.groovy

    r256 r259  
    5656    }
    5757
    58     def createSelect(selected, String name, options, String customvalue) {
    59         def res = "<select style=\"font-size:10px\" name=\"${name}\">"
    60 
    61         options.each { e ->
    62             res += "<option value=\"${customvalue}:${e}\""
    63             res += (e == selected) ? " selected" : ""
    64             res += ">${e}</option>"
    65         }
    66 
    67         res += "</select>"
    68         return res
    69     }
    70 
    7158    /**
    7259     * Possibly this will later on return an AJAX-like autocompletion chooser for the fields?
     
    11097        res += "</select>"
    11198        return res
    112     }   
     99    }
     100
     101    /**
     102    * @param selected selected TemplateFieldType
     103    * @param custval custom value to be combined in the option(s) of the selector
     104    * @param name name of the HTML select object
     105    * @return HTML select object
     106    *
     107    * @see dbnp.studycapturing.TemplateFieldType
     108    */
    113109
    114110     def entitySelect = { attrs ->
     
    130126
    131127    /**
    132     * @param selected selected celltype
     128    * @param selected selected TemplateFieldType
     129    * @param customvalue custom value to be combined in the option(s) of the selector
    133130    * @param name name of the HTML select object
    134     * @see org.apache.poi.ss.usermodel.Cell for the possible cell types
    135131    * @return HTML select object
     132    *
     133    * @see dbnp.studycapturing.TemplateFieldType
    136134    */
    137135    def templatefieldtypeSelect = { attrs ->
    138136        def selected = (attrs['selected']==null) ? -1 : attrs['selected']
    139137        def customvalue = (attrs['customvalue']==null) ? "" : attrs['customvalue']
    140         def name = (attrs['name']==null) ? "" : attrs['name']
    141         //out << createSelect(selected, attrs['name'], standardcelltypes, customvalue)
     138        def name = (attrs['name']==null) ? "" : attrs['name']   
    142139
    143140        def res = "<select style=\"font-size:10px\" name=\"${name}\">"
Note: See TracChangeset for help on using the changeset viewer.