Ignore:
Timestamp:
Jun 29, 2011, 10:10:48 AM (11 years ago)
Author:
robert@…
Message:
  • Updated the import algorithm in the simpleWizard, so it won't be too slow with > 200 samples
  • Changed the warning added in r1944 so the user knows why the import will be slow
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/dbnp/importer/ImporterService.groovy

    r1684 r1945  
    2222class ImporterService {
    2323        def authenticationService
     24        def sessionFactory
    2425
    2526        static transactional = false
     
    258259                if( !mcmap )
    259260                        return;
     261                       
     262                def hibernateSession = sessionFactory.getCurrentSession()
    260263
    261264                // Check whether the rows should be imported in one or more entities
     
    269272                def sheet = wb.getSheetAt(sheetindex)
    270273                def table = []
     274                def samples = []
    271275                def failedcells = [] // list of cells that have failed to import
    272276               
     
    287291                        if( row && !rowIsEmpty( row ) ) {
    288292                                // 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
    291295                                // Setup the relationships between the imported entities
    292296                                relateEntities( record );
    293        
     297
    294298                                // Add record with entities and its values to the table
    295299                                table.add(record)
    296        
     300
    297301                                // If failed cells have been found, add them to the failed cells list
    298302                                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
    299308                        }
    300309                }
     
    357366         * @param       mcmap           Hashmap of mappingcolumns, with the first entry in the hashmap containing information about the first column, etc.
    358367         * @param       parent          Study to import all data into. Is used for determining which sample/event/subject/assay to update
    359          * @param       importedRows    Rows that have been imported before this row. These rows might contain the same entities as are
    360          *                                                      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.
    361370         * @return      List            List with two entries:
    362371         *                      0                       List with ImportRecords, one for each row in the excelsheet
     
    364373         *                                              (because the value in the excelsheet can't be entered into the template field)
    365374         */
    366         def importOrUpdateRecord(def templates, def entities, Row excelRow, mcmap, Study parent = null, List importedRows, Map existingEntities ) {
     375        def importOrUpdateRecord(def templates, def entities, Row excelRow, mcmap, Study parent = null, List importedSamples, Map existingEntities ) {
    367376                DataFormatter df = new DataFormatter();
    368377                def record = [] // list of entities and the read values
    369378                def failed = new ImportRecord() // map with entity identifier and failed mappingcolumn
    370379
     380                def currentTime = System.currentTimeMillis();
     381               
    371382                // Check whether this record mentions a sample that has been imported before. In that case,
    372383                // we update that record, in order to prevent importing the same sample multiple times
    373384                def importedEntities = [];
    374                 if( importedRows )
    375                         importedEntities = importedRows.flatten().findAll { it.class == dbnp.studycapturing.Sample }.unique();
     385                if( importedSamples )
     386                        importedEntities = importedSamples
    376387
    377388                def importedSample = findEntityInImportedEntities( dbnp.studycapturing.Sample, excelRow, mcmap, importedEntities, df )
Note: See TracChangeset for help on using the changeset viewer.