Changeset 1945 for trunk/grails-app/services/dbnp
- Timestamp:
- Jun 29, 2011, 10:10:48 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r1684 r1945 22 22 class ImporterService { 23 23 def authenticationService 24 def sessionFactory 24 25 25 26 static transactional = false … … 258 259 if( !mcmap ) 259 260 return; 261 262 def hibernateSession = sessionFactory.getCurrentSession() 260 263 261 264 // Check whether the rows should be imported in one or more entities … … 269 272 def sheet = wb.getSheetAt(sheetindex) 270 273 def table = [] 274 def samples = [] 271 275 def failedcells = [] // list of cells that have failed to import 272 276 … … 287 291 if( row && !rowIsEmpty( row ) ) { 288 292 // Create an entity record based on a row read from Excel and store the cells which failed to be mapped 289 def (record, failed) = importOrUpdateRecord( templates, entities, row, mcmap, parent, table, existingEntities[i] );290 293 def (record, failed) = importOrUpdateRecord( templates, entities, row, mcmap, parent, samples, existingEntities[i] ); 294 291 295 // Setup the relationships between the imported entities 292 296 relateEntities( record ); 293 297 294 298 // Add record with entities and its values to the table 295 299 table.add(record) 296 300 297 301 // If failed cells have been found, add them to the failed cells list 298 302 if (failed?.importcells?.size() > 0) failedcells.add(failed) 303 304 // Add a sample to the list of samples if possible 305 def sample = record.find { it instanceof dbnp.studycapturing.Sample } 306 if( sample && !samples.contains( sample ) ) 307 samples << sample 299 308 } 300 309 } … … 357 366 * @param mcmap Hashmap of mappingcolumns, with the first entry in the hashmap containing information about the first column, etc. 358 367 * @param parent Study to import all data into. Is used for determining which sample/event/subject/assay to update 359 * @param imported Rows Rows that have been imported before this row. These rows might contain the same entities as are360 * imported in this row. These entities should be used again,to avoid importing duplicates.368 * @param importedSamples Samples that have been imported before this row. These entities should be used again if possible, 369 * to avoid importing duplicates. 361 370 * @return List List with two entries: 362 371 * 0 List with ImportRecords, one for each row in the excelsheet … … 364 373 * (because the value in the excelsheet can't be entered into the template field) 365 374 */ 366 def importOrUpdateRecord(def templates, def entities, Row excelRow, mcmap, Study parent = null, List imported Rows, Map existingEntities ) {375 def importOrUpdateRecord(def templates, def entities, Row excelRow, mcmap, Study parent = null, List importedSamples, Map existingEntities ) { 367 376 DataFormatter df = new DataFormatter(); 368 377 def record = [] // list of entities and the read values 369 378 def failed = new ImportRecord() // map with entity identifier and failed mappingcolumn 370 379 380 def currentTime = System.currentTimeMillis(); 381 371 382 // Check whether this record mentions a sample that has been imported before. In that case, 372 383 // we update that record, in order to prevent importing the same sample multiple times 373 384 def importedEntities = []; 374 if( imported Rows )375 importedEntities = imported Rows.flatten().findAll { it.class == dbnp.studycapturing.Sample }.unique();385 if( importedSamples ) 386 importedEntities = importedSamples 376 387 377 388 def importedSample = findEntityInImportedEntities( dbnp.studycapturing.Sample, excelRow, mcmap, importedEntities, df )
Note: See TracChangeset
for help on using the changeset viewer.