Changeset 1121 for trunk/grails-app/services
- Timestamp:
- Nov 11, 2010, 2:29:16 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r1103 r1121 219 219 def sheet = wb.getSheetAt(sheetindex) 220 220 def table = [] 221 def failedcells = [:] // map [recordhash, [mappingcolumnlist]] values221 def failedcells = [:] // map [recordhash, importrecord] values 222 222 223 223 // walk through all rows and fill the table with records 224 (rowindex..sheet.getLastRowNum()).each { i -> 225 //table.add(createRecord(template_id, sheet.getRow(i), mcmap)) 224 (rowindex..sheet.getLastRowNum()).each { i -> 226 225 // Create an entity record based on a row read from Excel and store the cells which failed to be mapped 227 226 def (record, failed) = createRecord(template_id, sheet.getRow(i), mcmap) … … 232 231 // If failed cells have been found, add them to the failed cells map 233 232 // the record hashcode is later on used to put the failed data back 234 // in the data matrix 235 if (failed. size()!=0) failedcells.put(record.hashCode(), failed)233 // in the data matrix 234 if (failed.importcells.size()>0) failedcells.put(record.hashCode(), failed) 236 235 } 237 238 failedcells.each { record ->239 record.each { cell ->240 cell.each {241 println it.value.dump()242 }243 }244 }245 246 236 247 237 return [table,failedcells] … … 257 247 **/ 258 248 def saveCorrectedCells(datamatrix, failedcells, correctedcells) { 259 // Loop through all failed cells 260 261 failedcells.each { mcrecord -> 262 mcrecord.each { mappingcolumn -> 249 250 // Loop through all failed cells (stored as 251 failedcells.each { record -> 252 record.value.importcells.each { cell -> 253 263 254 // Get the corrected value 264 def correctedvalue = correctedcells.find { it.key.toInteger() == mappingcolumn.hashCode()}.value255 def correctedvalue = correctedcells.find { it.key.toInteger() == cell.getIdentifier()}.value 265 256 266 257 // Find the record in the table which the mappingcolumn belongs to 267 def tablerecord = datamatrix.find { it.hashCode() == mcrecord.key }268 269 // Loop through all entities in the record 258 def tablerecord = datamatrix.find { it.hashCode() == record.key } 259 260 // Loop through all entities in the record and correct them if necessary 270 261 tablerecord.each { rec -> 271 262 rec.each { entity -> 272 263 try { 273 264 // Update the entity field 274 entity.setFieldValue( mappingcolumn.value.property[0], correctedvalue)275 println "Adjusted " + mappingcolumn.value.property[0]+ " to " + correctedvalue265 entity.setFieldValue(cell.mappingcolumn.property, correctedvalue) 266 //println "Adjusted " + cell.mappingcolumn.property + " to " + correctedvalue 276 267 } 277 268 catch (Exception e) { 278 println "Could not map corrected ontology"269 //println "Could not map corrected ontology: " + cell.mappingcolumn.property + " to " + correctedvalue 279 270 } 280 271 } 281 272 } // end of table record 282 } // end of mappingrecord283 } // end of failed cells loop273 } // end of cell record 274 } // end of failedlist 284 275 } 285 276 … … 428 419 def tft = TemplateFieldType 429 420 def record = [] // list of entities and the read values 430 def failed = [] // list of failed columns [mappingcolumn]with the value which couldn't be mapped into the entity421 def failed = new ImportRecord() // list of failed cells with the value which couldn't be mapped into the entity 431 422 432 423 // Initialize all possible entities with the chosen template … … 460 451 temp.value = "undefined" 461 452 failed.add(temp) 462 }*/ 453 }*/ 463 454 464 455 465 456 try { 466 /*if ((mc.templatefieldtype == TemplateFieldType.ONTOLOGYTERM) && (value == ""))467 {468 def temp = new MappingColumn()469 temp.properties = mc.properties470 temp.value="unknown"471 failed.add(temp)472 }*/473 474 457 // which entity does the current cell (field) belong to? 475 458 switch (mc.entity) { … … 495 478 } catch (IllegalArgumentException iae) { 496 479 // store the mapping column and value which failed 497 def temp = new MappingColumn() 498 temp.properties = mc.properties 499 temp.value = value 500 failed.add(temp) 480 def mcInstance = new MappingColumn() 481 mcInstance.properties = mc.properties 482 failed.addToImportcells( 483 new ImportCell(mappingcolumn:mcInstance, 484 value:value) 485 ) 501 486 } 502 487 } // end 503 488 } // end for 504 505 489 // a failed column means that using the entity.setFieldValue() threw an exception 506 490 return [record, failed]
Note: See TracChangeset
for help on using the changeset viewer.