Ignore:
Timestamp:
Jan 26, 2011, 5:08:25 PM (13 years ago)
Author:
robert@…
Message:
  • Created tests for the synchronization and trash
  • Improved synchronizationservice and trash
  • Put authorization checks in several pages
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/nl/tno/metagenomics/integration/SynchronizationService.groovy

    r6 r7  
    9696        public ArrayList<Study> synchronizeStudies() {
    9797                if( !performSynchronization() )
    98                         return Study.list()
     98                        return Study.findAllWhereTrashcan(false)
    9999
    100100                // When eager fetching is enabled, ask for all studies, otherwise only ask for studies marked dirty
     
    106106                        log.trace "Eager synchronization";
    107107                } else {
    108                         studies = Study.findAllWhere( [isDirty: true] );
     108                        studies = Study.findAllWhere( [trashcan: false, isDirty: true] );
    109109                        log.trace "Default synchronization: " + studies.size()
    110110
     
    184184                                        // Synchronize authorization and study assays (since the study itself is already synchronized)
    185185                                        synchronizeAuthorization(studyFound);
    186                                         synchronizeStudyAssays(studyFound);
     186                                        if( studyFound.canRead( user ) )
     187                                                synchronizeStudyAssays(studyFound);
    187188
    188189                                        // Mark the study as clean
     
    204205                // should be deleted from this module as well. Looping backwards in order to avoid conflicts
    205206                // when removing elements from the list
     207               
     208                println "Handle deleted studies: " + studies.size() + " -> " + newStudies.size();
    206209                def numStudies = studies.size();
    207210                for( int i = numStudies - 1; i >= 0; i-- ) {
     
    300303                study.isDirty = true;
    301304                synchronizeAuthorization( study );
    302                 synchronizeStudyAssays( study );
     305                if( study.canRead( user ) )
     306                        synchronizeStudyAssays( study );
    303307
    304308                // Update properties and mark as clean
    305309                study.name = newStudy.title
    306310                study.isDirty = false;
    307                 study.save()
     311                study.save(flush:true)
    308312
    309313                return study
     
    466470
    467471                // Copy properties from gscf object
    468                 a.canRead = gscfAuthorization.canRead
    469                 a.canWrite = gscfAuthorization.canWrite
    470                 a.isOwner = gscfAuthorization.isOwner
     472                println "GSCF auth: " + gscfAuthorization
     473               
     474                if( gscfAuthorization.canRead instanceof Boolean  )
     475                        a.canRead = gscfAuthorization.canRead.booleanValue()
     476               
     477                if( gscfAuthorization.canWrite instanceof Boolean )
     478                        a.canWrite = gscfAuthorization.canWrite.booleanValue()
     479               
     480                if( gscfAuthorization.isOwner instanceof Boolean )
     481                        a.isOwner = gscfAuthorization.isOwner.booleanValue()
     482                       
     483                println "Saved auth: " + a.canRead.toString() + " - " + a.canWrite.toString() + " - " + a.isOwner.toString()
    471484
    472485                a.save()
     
    606619                // already exist in the list of samples
    607620                newSamples.each { gscfSample ->
    608                         log.trace( "Processing GSCF sample " + gscfSample.name + ": " + gscfSample )
     621                        log.trace( "Processing GSCF sample " + gscfSample.sampleToken + ": " + gscfSample )
    609622                        if( gscfSample.name ) {
    610623
    611                                 AssaySample assaySampleFound = assay.assaySamples.find { it.sample.sampleToken == gscfSample.name }
     624                                AssaySample assaySampleFound = assay.assaySamples.find { it.sample.sampleToken == gscfSample.sampleToken }
    612625                                Sample sampleFound
    613626
    614627                                if(assaySampleFound) {
    615628                                        sampleFound = assaySampleFound.sample
    616                                         log.trace( "AssaySample found with sample " + sampleFound.name )
     629                                        log.trace( "AssaySample found with sample name " + sampleFound.name )
    617630
    618631                                        // Update the sample object if necessary
     
    625638
    626639                                        // Check if the sample already exists in the database.
    627                                         sampleFound = Sample.findBySampleTokenAndStudy( gscfSample.name as String, assay.study )
     640                                        sampleFound = Sample.findBySampleTokenAndStudy( gscfSample.sampleToken as String, assay.study )
    628641
    629642                                        if( sampleFound ){
    630                                                 log.trace( "Sample " + gscfSample.name + " is found in database. Updating if necessary" )
     643                                                log.trace( "Sample " + gscfSample.sampleToken + " is found in database. Updating if necessary" )
    631644
    632645                                                // Update the sample object if necessary
    633646                                                if( sampleFound.name != gscfSample.name ) {
    634                                                         sampleFound.name =gscfSample.name
     647                                                        sampleFound.name = gscfSample.name
    635648                                                        sampleFound.save();
    636649                                                }
    637650                                        } else {
    638                                                 log.trace( "Sample " + gscfSample.name + " not found in database. Creating a new object." )
     651                                                log.trace( "Sample " + gscfSample.sampleToken + " not found in database. Creating a new object." )
    639652
    640653                                                // If it doesn't exist, create a new object
    641                                                 sampleFound = new Sample( sampleToken: gscfSample.name, name: gscfSample.name, study: assay.study );
     654                                                sampleFound = new Sample( sampleToken: gscfSample.sampleToken, name: gscfSample.name, study: assay.study );
     655                                                assay.study.addToSamples( sampleFound );
    642656                                                sampleFound.save();
    643657                                        }
     
    649663                                        assay.addToAssaySamples( assaySampleFound );
    650664                                        sampleFound.addToAssaySamples( assaySampleFound );
    651                                         assaySampleFound.save();
     665
     666                                        assaySampleFound.save()
    652667                                }
    653668                        }
     
    670685                                def existingSample = assaySamples[i];
    671686
    672                                 AssaySample sampleFound = newSamples.find { it.name == existingSample.sample.sampleToken }
     687                                AssaySample sampleFound = newSamples.find { it.sampleToken == existingSample.sample.sampleToken }
    673688
    674689                                if( !sampleFound ) {
     
    676691
    677692                                        // The sample has been removed
    678                                         trashService.moveToTrash( existingSample.sample );
     693                                        trashService.moveToTrash( existingSample );
    679694                                }
    680695                        }
     
    682697
    683698                // Create a list of samples to return
    684                 return assay.assaySamples.toList()
    685 
     699                if( assay.assaySamples )
     700                        return assay.assaySamples.toList()
     701                else
     702                        return []
    686703        }
    687704}
Note: See TracChangeset for help on using the changeset viewer.