Changeset 259
- Timestamp:
- Mar 12, 2010, 11:51:33 AM (13 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r255 r259 20 20 import org.apache.poi.ss.usermodel.DataFormatter 21 21 import org.apache.poi.hssf.usermodel.HSSFDateUtil 22 import dbnp.importer.Column23 22 import dbnp.studycapturing.TemplateFieldType 23 import dbnp.studycapturing.Study 24 import dbnp.studycapturing.Subject 25 import dbnp.studycapturing.Event 26 import dbnp.studycapturing.Protocol 27 import dbnp.studycapturing.Sample 28 24 29 25 30 class ImporterService { … … 39 44 /** 40 45 * @param wb high level representation of the workbook 41 * @return header representation as a stringarray46 * @return header representation as a MappingColumn array 42 47 */ 43 48 def getHeader(HSSFWorkbook wb, int sheetindex){ … … 94 99 def rows = [] 95 100 def df = new DataFormatter() 96 101 def datamatrix_start = 1 102 103 // walk through all rows 97 104 (count <= sheet.getLastRowNum()) ? 98 ((1+sheet.getFirstRowNum())..count).each { rowindex -> 99 105 ((datamatrix_start+sheet.getFirstRowNum())..count).each { rowindex -> 100 106 def row = [] 107 108 // walk through every cell 101 109 for (HSSFCell c: sheet.getRow(rowindex)) 102 110 row.add(c) … … 138 146 * by using mapping information 139 147 * 140 *141 148 * @param wb POI horrible spreadsheet formatted workbook object 142 149 * @param mc array of MappingColumns … … 146 153 * @see dbnp.importer.MappingColumn 147 154 */ 148 def importdata(HSSFWorkbook wb, int sheetindex, int rowindex, MappingColumn[] mc ) {155 def importdata(HSSFWorkbook wb, int sheetindex, int rowindex, MappingColumn[] mcarray) { 149 156 def sheet = wb.getSheetAt(sheetindex) 150 157 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 166 208 } 167 209 } -
trunk/grails-app/taglib/dbnp/importer/ImporterTagLib.groovy
r256 r259 56 56 } 57 57 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 res69 }70 71 58 /** 72 59 * Possibly this will later on return an AJAX-like autocompletion chooser for the fields? … … 110 97 res += "</select>" 111 98 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 */ 113 109 114 110 def entitySelect = { attrs -> … … 130 126 131 127 /** 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 133 130 * @param name name of the HTML select object 134 * @see org.apache.poi.ss.usermodel.Cell for the possible cell types135 131 * @return HTML select object 132 * 133 * @see dbnp.studycapturing.TemplateFieldType 136 134 */ 137 135 def templatefieldtypeSelect = { attrs -> 138 136 def selected = (attrs['selected']==null) ? -1 : attrs['selected'] 139 137 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'] 142 139 143 140 def res = "<select style=\"font-size:10px\" name=\"${name}\">"
Note: See TracChangeset
for help on using the changeset viewer.