Changeset 1611 for trunk/grails-app/services/dbnp
- Timestamp:
- Mar 9, 2011, 10:24:41 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r1610 r1611 282 282 // walk through all rows and fill the table with records 283 283 for( int i = rowindex; i <= sheet.getLastRowNum(); i++ ) { 284 // Create an entity record based on a row read from Excel and store the cells which failed to be mapped 285 def (record, failed) = importOrUpdateRecord( templates, entities, sheet.getRow(i), mcmap, parent, table, existingEntities[i] ); 286 287 // Setup the relationships between the imported entities 288 relateEntities( record ); 289 290 // Add record with entities and its values to the table 291 table.add(record) 292 293 // If failed cells have been found, add them to the failed cells list 294 if (failed?.importcells?.size() > 0) failedcells.add(failed) 284 def row = sheet.getRow(i); 285 286 if( row && !rowIsEmpty( row ) ) { 287 // Create an entity record based on a row read from Excel and store the cells which failed to be mapped 288 def (record, failed) = importOrUpdateRecord( templates, entities, row, mcmap, parent, table, existingEntities[i] ); 289 290 // Setup the relationships between the imported entities 291 relateEntities( record ); 292 293 // Add record with entities and its values to the table 294 table.add(record) 295 296 // If failed cells have been found, add them to the failed cells list 297 if (failed?.importcells?.size() > 0) failedcells.add(failed) 298 } 295 299 } 296 300 297 301 return [ "table": table, "failedCells": failedcells ] 302 } 303 304 /** 305 * Checks whether an excel row is empty 306 * @param row Row from the excel sheet 307 * @return True if all cells in this row are empty or the given row is null. False otherwise 308 */ 309 def rowIsEmpty( Row excelRow ) { 310 if( !excelRow ) 311 return true; 312 313 def df = new DataFormatter(); 314 for( int i = excelRow.getFirstCellNum(); i < excelRow.getLastCellNum(); i++ ) { 315 Cell cell = excelRow.getCell( i ); 316 317 try { 318 def value = df.formatCellValue(cell) 319 if( value ) 320 return false 321 } catch (NumberFormatException nfe) { 322 // If the number can't be formatted, the row isn't empty 323 return false; 324 } 325 } 326 327 return true; 298 328 } 299 329 … … 344 374 importedEntities = importedRows.flatten().findAll { it.class == dbnp.studycapturing.Sample }.unique(); 345 375 346 def importedSample = null // findEntityInImportedEntities( dbnp.studycapturing.Sample, excelRow, mcmap, importedEntities, df ) 347 def imported = [] // retrieveEntitiesBySample( importedSample ); 376 def importedSample = findEntityInImportedEntities( dbnp.studycapturing.Sample, excelRow, mcmap, importedEntities, df ) 377 def imported = retrieveEntitiesBySample( importedSample ); 378 348 379 for( entity in entities ) { 349 380 // Check whether this entity should be added or updated … … 372 403 373 404 // Go through the Excel row cell by cell 374 for (Cell cell: excelRow) { 405 for( int i = excelRow.getFirstCellNum(); i < excelRow.getLastCellNum(); i++ ) { 406 Cell cell = excelRow.getCell( i ); 407 375 408 // get the MappingColumn information of the current cell 376 409 def mc = mcmap[cell.getColumnIndex()] … … 426 459 */ 427 460 def findEntityByRow( Class entity, Row excelRow, def mcmap, Study parent = null, List importedEntities = [], DataFormatter df = null ) { 461 if( !excelRow ) 462 return 463 428 464 if( df == null ) 429 465 df = new DataFormatter();
Note: See TracChangeset
for help on using the changeset viewer.