- Timestamp:
- Nov 6, 2010, 4:01:11 PM (12 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy
r1090 r1093 154 154 * the original value which was read from the Excel file. 155 155 * 156 * @param cell array of cells with updated ontologies156 * @param cell array of cells with corrected cells (ontologies) 157 157 * 158 158 */ … … 161 161 162 162 // Loop through the form with cell fields and values 163 params.cell.index.each { cellhashcode, value ->164 correctedcells.put( cellhashcode, value)163 params.cell.index.each { mappingcolumnhash, value -> 164 correctedcells.put(mappingcolumnhash, value) 165 165 } 166 166 … … 168 168 ImporterService.saveCorrectedCells( 169 169 session.importer_importeddata, 170 session.importe d_failedcells,170 session.importer_failedcells, 171 171 correctedcells) 172 172 … … 290 290 } 291 291 292 // import workbook and store it in a session293 session.importer_importeddata= ImporterService.importData(session.importer_template_id, session.importer_workbook, session.importer_sheetindex, session.importer_datamatrix_start, session.importer_header)294 295 // First handle the "failed cells"296 session.importe d_failedcells = ImporterService.getFailedCells(session.importer_importeddata)297 298 //render(view:"step2a_simple", model:[failedcells:session.imported_failedcells])299 300 if (params.layout=="horizontal")292 // Import the workbook and store the table with entity records and store the failed cells 293 def (table, failedcells) = ImporterService.importData(session.importer_template_id, session.importer_workbook, session.importer_sheetindex, session.importer_datamatrix_start, session.importer_header) 294 295 session.importer_importeddata = table 296 session.importer_failedcells = failedcells 297 298 render(view:"step2a_simple", model:[failedcells:session.importer_failedcells]) 299 300 /*if (params.layout=="horizontal") 301 301 render(view:"step3_simple", model:[datamatrix:session.importer_importeddata]) 302 302 else if (params.layout=="vertical") 303 render(view:"step3", model:[datamatrix:session.importer_importeddata]) 303 render(view:"step3", model:[datamatrix:session.importer_importeddata])*/ 304 304 } 305 305 -
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r1087 r1093 219 219 def sheet = wb.getSheetAt(sheetindex) 220 220 def table = [] 221 def failedcells = [:] // map [recordhash, [mappingcolumnlist]] values 221 222 222 223 // walk through all rows and fill the table with records 223 224 (rowindex..sheet.getLastRowNum()).each { i -> 224 table.add(createRecord(template_id, sheet.getRow(i), mcmap)) 225 //table.add(createRecord(template_id, sheet.getRow(i), mcmap)) 226 // Create an entity record based on a row read from Excel and store the cells which failed to be mapped 227 def (record, failed) = createRecord(template_id, sheet.getRow(i), mcmap) 228 229 // Add record with entity and its values to the table 230 table.add(record) 231 232 // If failed cells have been found, add them to the failed cells map 233 // 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) 225 236 } 226 return table 227 } 228 229 /** Method to extract failed cells from the datamatrix. Failed cells are cell values 237 238 failedcells.each { record -> 239 record.each { cell -> 240 cell.each { 241 println it.value.dump() 242 } 243 } 244 } 245 246 247 return [table,failedcells] 248 } 249 250 /** Method to put failed cells back into the datamatrix. Failed cells are cell values 230 251 * which could not be stored in an entity (e.g. Humu Supiuns in an ontology field). 252 * Empty corrections should not be stored 231 253 * 232 254 * @param datamatrix two dimensional array containing entities and possibly also failed cells 233 * @return array of failed cells in [mappingcolumn, cell] format 234 * */ 235 def getFailedCells(datamatrix) { 236 def failedcells = [] 237 238 datamatrix.each { record -> 239 record.each { column -> 240 column.each { 241 if (it.getClass().getName().equals('java.util.LinkedHashMap$Entry')) { 242 failedcells.add(it) 243 } 244 } 245 } 246 } 247 248 return failedcells 249 } 250 251 /** Method to put failed cells back into the datamatrix. Failed cells are cell values 252 * which could not be stored in an entity (e.g. Humu Supiuns in an ontology field). 253 * 254 * @param datamatrix two dimensional array containing entities and possibly also failed cells 255 * @param failedcells map of failed cells in [mappingcolumn, cell] format 256 * @param correctedcells map of corrected cells 255 * @param failedcells list with maps of failed cells in [mappingcolumn, cell] format 256 * @param correctedcells map of corrected cells in [cellhashcode, value] format 257 257 **/ 258 def saveCorrectedCells(datamatrix, failedcells, correctedcells) { 259 /*failedcells.each { 260 println it 261 }*/ 262 def newdatamatrix = [] 263 264 // Remove failed cells 'entity' / clean up datamatrix 265 datamatrix.each { record -> 266 def newrecord = [] 267 268 record.each { entity -> 269 // LinkedHashMap means a "mappingcolumn:cell" object is inside the record (= failed to map to entity) 270 if (!entity.getClass().getName().equals('java.util.LinkedHashMap')) 271 newrecord.add(entity) 272 } 273 274 newdatamatrix.add(newrecord) 275 } 276 277 newdatamatrix.each { record -> 278 record.each { entity -> 279 entity.giveFields().each { field -> 280 println "das"+ field 281 } 282 } 283 } 284 285 println "-----" 286 correctedcells.each { 287 println it.dump() 288 } 258 def saveCorrectedCells(datamatrix, failedcells, correctedcells) { 259 // Loop through all failed cells 260 failedcells.each { mcrecord -> 261 mcrecord.each { mappingcolumn -> 262 // Get the corrected value 263 def correctedvalue = correctedcells.find { it.key.toInteger() == mappingcolumn.hashCode()}.value 264 265 // Find the record in the table which the mappingcolumn belongs to 266 def tablerecord = datamatrix.find { it.hashCode() == mcrecord.key } 267 268 // Loop through all entities in the record 269 tablerecord.each { rec -> 270 rec.each { entity -> 271 try { 272 // Update the entity field 273 entity.setFieldValue(mappingcolumn.value.property[0], correctedvalue) 274 println "Adjusted " + mappingcolumn.value.property[0] + " to " + correctedvalue 275 } 276 catch (Exception e) { 277 println "Could not map corrected ontology" 278 } 279 } 280 } // end of table record 281 } // end of mapping record 282 } // end of failed cells loop 289 283 } 290 284 … … 347 341 348 342 /** 349 * Check whether an entity already exists within a study. A combination of 350 * the study where the entity will be stored and a unique field in the entity is 343 * Check whether an entity already exist. A unique field in the entity is 351 344 * used to check whether the instantiated entity (read from Excel) is new. 352 * If the entity is found in the database it will be returned as so and 353 * it should update the entity-values (read from Ecel) into the record in the database. 345 * If the entity is found in the database it will be returned as is. 354 346 * 355 347 * @param entity entity object like a Study, Subject, Sample et cetera … … 428 420 * @param excelrow POI based Excel row containing the cells 429 421 * @param mcmap map containing MappingColumn objects 422 * @return list of entities and list of failed cells 430 423 */ 431 424 def createRecord(template_id, Row excelrow, mcmap) { 432 425 def df = new DataFormatter() 433 426 def template = Template.get(template_id) 434 def record = [] 435 def failed = [ :]427 def record = [] // list of entities and the read values 428 def failed = [] // list of failed columns [mappingcolumn] with the value which couldn't be mapped into the entity 436 429 437 430 // Initialize all possible entities with the chosen template … … 480 473 } // end switch 481 474 } catch (IllegalArgumentException iae) { 482 // store the mapping column and the cell in an array 483 failed.put(mc, cell) 484 //println "failed ("+mc.templatefieldtype+"`" + value + "`" 475 // store the mapping column and value which failed 476 def temp = new MappingColumn() 477 temp.properties = mc.properties 478 temp.value = value 479 failed.add(temp) 485 480 } 486 481 } // end 487 482 } // end for 488 489 // add the failed columns to the record (might also be just an empty map if nothing failed) 490 // a failed column means that using the entity.setFieldValue() threw an exception 491 //record.add(failed) 492 return record 483 484 // a failed column means that using the entity.setFieldValue() threw an exception 485 return [record, failed] 493 486 } 494 487 -
trunk/grails-app/views/importer/common/_failedcells.gsp
r1083 r1093 32 32 <g:form name="failedcellsform" action="saveCorrectedCells"> 33 33 <g:each var="record" in="${failedcells}"> 34 <tr> 35 <td>${record.key.name}</td> 36 <td>${record.value.getRowIndex()}</td> 37 <td>${record.value}</td> 38 <td> 39 <input type="text" name="cell.index.${record.value.hashCode()}" rel="ontology-all-name"/> 40 <!-- <input type="hidden" name="cell.index.${record.value}-concept_id"/> 41 <input type="hidden" name="cell.index.${record.value}-ontology_id"/> 42 <input type="hidden" name="cell.index.${record.value}-full_id"/> --> 43 </td> 44 </tr> 34 <g:each var="list" in="${record}"> 35 <g:each var="cell" in="${list}"> 36 <tr> 37 <td>${cell.value.name}</td> 38 <td>-</td> 39 <td>${cell.value.value}</td> 40 <td> 41 <input type="text" name="cell.index.${cell.hashCode()}" rel="ontology-all-name"/> 42 <!-- <input type="hidden" name="cell.index.${cell.value}-concept_id"/> 43 <input type="hidden" name="cell.index.${cell.value}-ontology_id"/> 44 <input type="hidden" name="cell.index.${cell.value}-full_id"/> --> 45 </td> 46 </tr> 47 </g:each> 48 </g:each> 45 49 </g:each> 46 50 <tr>
Note: See TracChangeset
for help on using the changeset viewer.