Changeset 268 for trunk/grails-app/services/dbnp
- Timestamp:
- Mar 15, 2010, 7:16:02 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r259 r268 21 21 import org.apache.poi.hssf.usermodel.HSSFDateUtil 22 22 import dbnp.studycapturing.TemplateFieldType 23 import dbnp.studycapturing.Template 23 24 import dbnp.studycapturing.Study 24 25 import dbnp.studycapturing.Subject … … 44 45 /** 45 46 * @param wb high level representation of the workbook 46 * @return header representation as a MappingColumn array47 * @return header representation as a MappingColumn hashmap 47 48 */ 48 49 def getHeader(HSSFWorkbook wb, int sheetindex){ … … 68 69 case HSSFCell.CELL_TYPE_NUMERIC: 69 70 if (HSSFDateUtil.isCellDateFormatted(c)) { 70 println("DATE")71 71 header[c.getColumnIndex()] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.DATE) 72 72 } … … 146 146 * by using mapping information 147 147 * 148 * @param template_id template identifier to use fields from 148 149 * @param wb POI horrible spreadsheet formatted workbook object 149 * @param mc arrayof MappingColumns150 * @param mcmap linked hashmap (preserved order) of MappingColumns 150 151 * @param sheetindex sheet to use when using multiple sheets 151 152 * @param rowindex first row to start with reading the actual data (NOT the header) … … 153 154 * @see dbnp.importer.MappingColumn 154 155 */ 155 def importdata( HSSFWorkbook wb, int sheetindex, int rowindex, MappingColumn[] mcarray) {156 def importdata(template_id, HSSFWorkbook wb, int sheetindex, int rowindex, mcmap) { 156 157 def sheet = wb.getSheetAt(sheetindex) 157 158 def rows = [] … … 163 164 164 165 // 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 } 166 for (HSSFCell cell: sheet.getRow(i)) { 167 def mc = mcmap[cell.getColumnIndex()] 168 record.add(createColumn(template_id, cell, mc)) 169 } 170 } 171 println record 169 172 } 170 173 … … 172 175 * This function creates a column based on the current cell and mapping 173 176 * 177 * @param template_id template identifier to use fields from 174 178 * @param cell POI cell read from Excel 175 179 * @param mc mapping column … … 177 181 * 178 182 */ 179 def createColumn( HSSFCell cell, MappingColumn mc) {183 def createColumn(template_id, HSSFCell cell, MappingColumn mc) { 180 184 def df = new DataFormatter() 181 182 // check the templatefield type of the cell 185 def template = Template.get(template_id) 186 187 // check the templatefield entity of the cell 183 188 switch(mc.entity) { 184 case Study : def st = new Study( )185 st.setFieldValue(mc.name, df.formatCellValue(c ))189 case Study : def st = new Study(template:template) 190 st.setFieldValue(mc.name, df.formatCellValue(cell)) 186 191 return st 187 192 break 188 case Subject: def su = new Subject( )189 su.setFieldValue(mc.name, df.formatCellValue(c ))193 case Subject: def su = new Subject(template:template) 194 su.setFieldValue(mc.name, df.formatCellValue(cell)) 190 195 return su 191 196 break 192 case Event : def ev = new Event( )193 ev.setFieldValue(mc.name, df.formatCellValue(c ))197 case Event : def ev = new Event(template:template) 198 ev.setFieldValue(mc.name, df.formatCellValue(cell)) 194 199 return ev 195 200 break 196 case Protocol: def pr = new Protocol( )197 pr.setFieldValue(mc.name, df.formatCellValue(c ))201 case Protocol: def pr = new Protocol(template:template) 202 pr.setFieldValue(mc.name, df.formatCellValue(cell)) 198 203 return pr 199 204 break 200 case Sample : def sa = new Sample( )201 sa.setFieldValue(mc.name, df.formatCellValue(c ))205 case Sample : def sa = new Sample(template:template) 206 sa.setFieldValue(mc.name, df.formatCellValue(cell)) 202 207 return sa 203 208 break 204 case Object : break 205 206 } 207 209 case Object : break 210 } 208 211 } 209 212 }
Note: See TracChangeset
for help on using the changeset viewer.