Changeset 7 for trunk/grails-app/services/nl/tno/metagenomics/integration/SynchronizationService.groovy
- Timestamp:
- Jan 26, 2011, 5:08:25 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/nl/tno/metagenomics/integration/SynchronizationService.groovy
r6 r7 96 96 public ArrayList<Study> synchronizeStudies() { 97 97 if( !performSynchronization() ) 98 return Study. list()98 return Study.findAllWhereTrashcan(false) 99 99 100 100 // When eager fetching is enabled, ask for all studies, otherwise only ask for studies marked dirty … … 106 106 log.trace "Eager synchronization"; 107 107 } else { 108 studies = Study.findAllWhere( [ isDirty: true] );108 studies = Study.findAllWhere( [trashcan: false, isDirty: true] ); 109 109 log.trace "Default synchronization: " + studies.size() 110 110 … … 184 184 // Synchronize authorization and study assays (since the study itself is already synchronized) 185 185 synchronizeAuthorization(studyFound); 186 synchronizeStudyAssays(studyFound); 186 if( studyFound.canRead( user ) ) 187 synchronizeStudyAssays(studyFound); 187 188 188 189 // Mark the study as clean … … 204 205 // should be deleted from this module as well. Looping backwards in order to avoid conflicts 205 206 // when removing elements from the list 207 208 println "Handle deleted studies: " + studies.size() + " -> " + newStudies.size(); 206 209 def numStudies = studies.size(); 207 210 for( int i = numStudies - 1; i >= 0; i-- ) { … … 300 303 study.isDirty = true; 301 304 synchronizeAuthorization( study ); 302 synchronizeStudyAssays( study ); 305 if( study.canRead( user ) ) 306 synchronizeStudyAssays( study ); 303 307 304 308 // Update properties and mark as clean 305 309 study.name = newStudy.title 306 310 study.isDirty = false; 307 study.save( )311 study.save(flush:true) 308 312 309 313 return study … … 466 470 467 471 // 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() 471 484 472 485 a.save() … … 606 619 // already exist in the list of samples 607 620 newSamples.each { gscfSample -> 608 log.trace( "Processing GSCF sample " + gscfSample. name+ ": " + gscfSample )621 log.trace( "Processing GSCF sample " + gscfSample.sampleToken + ": " + gscfSample ) 609 622 if( gscfSample.name ) { 610 623 611 AssaySample assaySampleFound = assay.assaySamples.find { it.sample.sampleToken == gscfSample. name}624 AssaySample assaySampleFound = assay.assaySamples.find { it.sample.sampleToken == gscfSample.sampleToken } 612 625 Sample sampleFound 613 626 614 627 if(assaySampleFound) { 615 628 sampleFound = assaySampleFound.sample 616 log.trace( "AssaySample found with sample " + sampleFound.name )629 log.trace( "AssaySample found with sample name " + sampleFound.name ) 617 630 618 631 // Update the sample object if necessary … … 625 638 626 639 // Check if the sample already exists in the database. 627 sampleFound = Sample.findBySampleTokenAndStudy( gscfSample. nameas String, assay.study )640 sampleFound = Sample.findBySampleTokenAndStudy( gscfSample.sampleToken as String, assay.study ) 628 641 629 642 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" ) 631 644 632 645 // Update the sample object if necessary 633 646 if( sampleFound.name != gscfSample.name ) { 634 sampleFound.name = gscfSample.name647 sampleFound.name = gscfSample.name 635 648 sampleFound.save(); 636 649 } 637 650 } 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." ) 639 652 640 653 // 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 ); 642 656 sampleFound.save(); 643 657 } … … 649 663 assay.addToAssaySamples( assaySampleFound ); 650 664 sampleFound.addToAssaySamples( assaySampleFound ); 651 assaySampleFound.save(); 665 666 assaySampleFound.save() 652 667 } 653 668 } … … 670 685 def existingSample = assaySamples[i]; 671 686 672 AssaySample sampleFound = newSamples.find { it. name== existingSample.sample.sampleToken }687 AssaySample sampleFound = newSamples.find { it.sampleToken == existingSample.sample.sampleToken } 673 688 674 689 if( !sampleFound ) { … … 676 691 677 692 // The sample has been removed 678 trashService.moveToTrash( existingSample .sample);693 trashService.moveToTrash( existingSample ); 679 694 } 680 695 } … … 682 697 683 698 // 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 [] 686 703 } 687 704 }
Note: See TracChangeset
for help on using the changeset viewer.