Changeset 735
- Timestamp:
- Jul 27, 2010, 4:26:35 PM (13 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy
r732 r735 79 79 def entityClass = Class.forName(entity, true, this.getClass().getClassLoader()) 80 80 81 // Initialize some session variables 81 82 session.importer_workbook = wb 82 83 session.importer_study = Study.get(params.study.id.toInteger()) … … 86 87 session.importer_headerrow = params.headerrow.toInteger() 87 88 89 // Get the header from the Excel file using the arguments given in the first step of the wizard 88 90 session.importer_header = ImporterService.getHeader(wb, 89 91 session.importer_sheetindex, … … 92 94 entityClass) 93 95 94 session.importer_header.each { 96 // Initialize 'selected entities', used to show entities above the columns 97 session.importer_header.each { 95 98 selectedentities.add([name:params.entity, columnindex:it.key.toInteger()]) 96 99 } … … 125 128 126 129 /** 130 * Method to save the missing properties 127 131 * @param entity entity class we are using (dbnp.studycapturing.Subject etc.) 128 132 */ 129 133 130 134 def saveMissingProperties = { 131 135 132 136 session.importer_importeddata.each { table -> 133 137 table.each { entity -> … … 185 189 } 186 190 191 // Set the templatefield type for this column 187 192 session.importer_header[columnindex.toInteger()].templatefieldtype = tft 188 193 } 189 194 195 // Detect the entity type 190 196 params.entity.index.each { columnindex, entityname -> 191 197 Class clazz = null … … 206 212 } 207 213 214 // Store properties for this column 208 215 session.importer_header[columnindex.toInteger()].identifier = (columnindex.toInteger() == identifiercolumnindex) ? true : false 209 216 session.importer_header[columnindex.toInteger()].index = columnindex.toInteger() … … 259 266 } 260 267 268 /** 269 * Method which saves the data matrix to the database 270 */ 261 271 def savePostview = { 262 272 def validatedSuccesfully = ImporterService.saveDatamatrix(session.importer_study, session.importer_importeddata) -
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r732 r735 225 225 def table = [] 226 226 227 // walk through all rows 227 // walk through all rows and fill the table with records 228 228 (rowindex..sheet.getLastRowNum()).each { i -> 229 229 table.add(createRecord(template_id, sheet.getRow(i), mcmap)) 230 230 } 231 232 /*table.each {233 it.each { entity ->234 entity.giveFields().each { field ->235 print field.name + ":" + entity.getFieldValue(field.name) + "/"236 }237 println238 }239 }*/240 241 231 return table 242 232 } … … 254 244 study.refresh() 255 245 246 // go through the data matrix, read every record and validate the entity and try to persist it 256 247 datamatrix.each { record -> 257 248 record.each { entity -> … … 312 303 def template = Template.get(template_id) 313 304 def record = [] 314 def samplingevent = new SamplingEvent(template:template) 315 305 306 // Initialize all possible entities with the chosen template 316 307 def study = new Study(template: template) 317 308 def subject = new Subject(template: template) … … 320 311 def sample = new Sample(template: template) 321 312 313 // Go through the Excel row cell by cell 322 314 for (HSSFCell cell: excelrow) { 315 // get the MappingColumn information of the current cell 323 316 def mc = mcmap[cell.getColumnIndex()] 324 317 def value … … 332 325 } 333 326 327 // which entity does the current cell (field) belong to? 334 328 switch (mc.entity) { 335 329 case Study: (record.any {it.getClass() == mc.entity}) ? 0 : record.add(study)
Note: See TracChangeset
for help on using the changeset viewer.