Changeset 1436
- Timestamp:
- Jan 24, 2011, 3:48:46 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/BaseFilters.groovy
r1430 r1436 40 40 41 41 afterView = { 42 def actionDuration = request._timeAfterRequest - request._timeBeforeRequest42 def actionDuration = request._timeAfterRequest ? request._timeAfterRequest - request._timeBeforeRequest : 0 43 43 def viewDuration = System.currentTimeMillis() - request._timeAfterRequest 44 44 log.info("Timer: ${controllerName}(${actionDuration}ms)::${actionName}(${viewDuration}ms)") -
trunk/grails-app/controllers/dbnp/studycapturing/StudyController.groovy
r1430 r1436 3 3 import grails.converters.* 4 4 import grails.plugins.springsecurity.Secured 5 import nl.grails.plugins.gdt.TemplateFieldType 5 6 6 7 /** -
trunk/src/groovy/dbnp/query/Criterion.groovy
r1430 r1436 93 93 def classname = fieldValue.class.getName(); 94 94 classname = classname[classname.lastIndexOf( '.' ) + 1..-1].toLowerCase(); 95 95 96 println "Match " + fieldValue + " of class " + classname + " with " + this 97 96 98 try { 97 99 switch( classname ) { … … 238 240 rt = new RelTime( value.toString() ); 239 241 } 240 242 241 243 return compareValues( fieldValue, this.operator, rt ); 242 244 } catch( Exception e ) { -
trunk/src/groovy/dbnp/query/SampleSearch.groovy
r1432 r1436 73 73 if( getEntityCriteria( 'Study' ).size() > 0 ) { 74 74 def studies = Study.findAll(); 75 76 studies = filterOnStudyCriteria( studies ); 77 75 78 if( studies.size() == 0 ) { 76 79 results = []; 77 80 return; 78 81 } 79 studies = filterOnStudyCriteria( studies );80 82 81 83 def c = Sample.createCriteria() … … 92 94 samples = filterOnSamplingEventCriteria( samples ); 93 95 samples = filterOnAssayCriteria( samples ); 94 96 95 97 // Save matches 96 98 results = samples; … … 142 144 */ 143 145 protected List filterOnEventCriteria( List samples ) { 146 println "Event criteria: " + getEntityCriteria( 'Event' ) 144 147 return filterEntityList( samples, getEntityCriteria( 'Event' ), { sample, criterion -> 145 if( !sample || !sample.parentEventGroup || !sample.parentEventGroup.events ?.size())146 return false 147 148 return criterion.matchAny( sample.parentEventGroup.events );148 if( !sample || !sample.parentEventGroup || !sample.parentEventGroup.events || sample.parentEventGroup.events.size() == 0 ) 149 return false 150 151 return criterion.matchAny( sample.parentEventGroup.events.toList() ); 149 152 }); 150 153 } … … 174 177 return []; 175 178 179 if( getEntityCriteria( 'Assay' ).size() == 0 ) 180 return samples 181 176 182 // There is no sample.assays property, so we have to look for assays another way: just find 177 183 // all assays that match the criteria -
trunk/test/integration/dbnp/query/SampleSearchTests.groovy
r1430 r1436 5 5 import dbnp.authentication.*; 6 6 import grails.test.* 7 import nl.grails.plugins.gdt.* 7 8 8 9 /** … … 21 22 */ 22 23 class SampleSearchTests extends GroovyTestCase { 24 23 25 protected void setUp() { 24 26 super.setUp() 25 26 def owner = SecUser.findByUsername( "user" ); 27 28 // Look up the used ontologies which should be in the database by now 29 def speciesOntology = Ontology.getOrCreateOntologyByNcboId(1132) 30 31 // Look up the used templates which should also be in the database by now 32 def studyTemplate = Template.findByName("Academic study") 33 def mouseTemplate = Template.findByName("Mouse") 34 def dietTreatmentTemplate = Template.findByName("Diet treatment") 35 def liverSamplingEventTemplate = Template.findByName("Liver extraction") 36 def humanTissueSampleTemplate = Template.findByName("Human tissue sample") 37 def ccAssayTemplate = Template.findByName("Clinical chemistry assay") 38 39 // Add terms manually, to avoid having to do many HTTP requests to the BioPortal website 40 def mouseTerm = Term.findByName( "Mus musculus" ); 41 42 // Add example mouse study 43 def testStudy = new Study( 44 template : studyTemplate, 45 title : "TestStudy 1", 46 description : "C57Bl/6 mice were fed a high fat (45 en%) or low fat (10 en%) diet after a four week run-in on low fat diet.", 47 code : "TESTPPS3_leptin_module", 48 researchQuestion: "Leptin etc.", 49 ecCode : "2007117.c", 50 startDate : Date.parse('yyyy-MM-dd', '2008-01-02'), 51 owner : owner 52 ).with { if (!validate()) { errors.each { println it} } else save()} 53 54 def evLF = new Event( 55 startTime : 3600, 56 endTime : 3600 + 7 * 24 * 3600, 57 template : dietTreatmentTemplate 58 ).setFieldValue('Diet', 'low fat') 59 60 def evS = new SamplingEvent( 61 startTime : 3600, 62 template : liverSamplingEventTemplate, 63 sampleTemplate: humanTissueSampleTemplate).setFieldValue('Sample weight', 5F) 64 // Add events to study 65 testStudy.addToEvents(evLF).addToSamplingEvents(evS).with { if (!validate()) { errors.each { println it} } else save()} 66 67 // Extra check if the SamplingEvents are saved correctly 68 evS.with { if (!validate()) { errors.each { println it} } else save()} 69 70 def LFBV1 = new EventGroup(name: "10% fat + vehicle for 1 week").addToEvents(evLF).addToSamplingEvents(evS) 71 72 // Add subjects and samples and compose EventGroups 73 def x = 1 74 5.times { 75 def currentSubject = new Subject( 76 name: "TestA" + x++, 77 species: mouseTerm, 78 template: mouseTemplate, 79 ).setFieldValue("Gender", "Male") 80 81 // We have to save the subject first, otherwise the parentEvent property of the sample cannot be set 82 // (this is possibly a Grails or Hibernate bug) 83 testStudy.addToSubjects(currentSubject) 84 currentSubject.with { if (!validate()) { errors.each { println it} } else save()} 85 86 // Add subject to appropriate EventGroup 87 LFBV1.addToSubjects(currentSubject).save() 88 89 // Create sample 90 def currentSample = new Sample( 91 name: currentSubject.name + '_B', 92 material: mouseTerm, 93 template: humanTissueSampleTemplate, 94 parentSubject: currentSubject, 95 parentEvent: evS 96 ); 97 testStudy.addToSamples(currentSample) 98 currentSample.with { if (!validate()) { errors.each { println it} } else save()} 99 currentSample.setFieldValue("Text on vial", "T" + (Math.random() * 100L)) 100 } 101 102 // Add EventGroups to study 103 testStudy.addToEventGroups(LFBV1).with { if (!validate()) { errors.each { println it} } else save()} 104 105 // Add SAM assay reference 106 def clinicalModule = AssayModule.findByName( "SAM module for clinical data" ); 107 108 def testAssayRef = new Assay( 109 name: 'Test Lipid profiling', 110 template: ccAssayTemplate, 111 module: clinicalModule, 112 externalAssayID: 'TestPPS3_SAM' 113 ) 114 115 testStudy.samples*.each { 116 testAssayRef.addToSamples(it) 117 } 118 119 testStudy.addToAssays(testAssayRef); 120 testStudy.save() 121 122 assert Sample.list()*.name.contains( "TestA2_B" ); 27 // 28 // def owner = SecUser.findByUsername( "user" ); 29 // 30 // // Look up the used ontologies which should be in the database by now 31 // def speciesOntology = Ontology.getOrCreateOntologyByNcboId(1132) 32 // 33 // // Look up the used templates which should also be in the database by now 34 // def studyTemplate = Template.findByName("Academic study") 35 // def mouseTemplate = Template.findByName("Mouse") 36 // def dietTreatmentTemplate = Template.findByName("Diet treatment") 37 // def liverSamplingEventTemplate = Template.findByName("Liver extraction") 38 // def humanTissueSampleTemplate = Template.findByName("Human tissue sample") 39 // def ccAssayTemplate = Template.findByName("Clinical chemistry assay") 40 // 41 // // Add terms manually, to avoid having to do many HTTP requests to the BioPortal website 42 // def mouseTerm = Term.findByName( "Mus musculus" ); 43 // 44 // // Add example mouse study 45 // def testStudy = new Study( 46 // template : studyTemplate, 47 // title : "TestStudy 1", 48 // description : "C57Bl/6 mice were fed a high fat (45 en%) or low fat (10 en%) diet after a four week run-in on low fat diet.", 49 // code : "TESTPPS3_leptin_module", 50 // researchQuestion: "Leptin etc.", 51 // ecCode : "2007117.c", 52 // startDate : Date.parse('yyyy-MM-dd', '2008-01-02'), 53 // owner : owner 54 // ).with { if (!validate()) { errors.each { println it} } else save()} 55 // 56 // 57 // def evLF = new Event( 58 // startTime : 3600, 59 // endTime : 3600 + 7 * 24 * 3600, 60 // template : dietTreatmentTemplate 61 // ).setFieldValue('Diet', 'low fat') 62 // 63 // def evS = new SamplingEvent( 64 // startTime : 3600, 65 // template : liverSamplingEventTemplate, 66 // sampleTemplate: humanTissueSampleTemplate).setFieldValue('Sample weight', 5F) 67 // 68 // // Add events to study 69 // testStudy.addToEvents(evLF).addToSamplingEvents(evS).with { if (!validate()) { errors.each { println it} } else save()} 70 // 71 // // Extra check if the SamplingEvents are saved correctly 72 // evS.with { if (!validate()) { errors.each { println it} } else save()} 73 // evLF.with { if (!validate()) { errors.each { println it} } else save()} 74 // 75 // 76 // def LFBV1 = new EventGroup(name: "10% fat + vehicle for 1 week").addToEvents(evLF).addToSamplingEvents(evS) 77 // 78 // // Add subjects and samples and compose EventGroups 79 // def x = 1 80 // 5.times { 81 // def currentSubject = new Subject( 82 // name: "TestA" + x++, 83 // species: mouseTerm, 84 // template: mouseTemplate, 85 // ).setFieldValue("Gender", "Male") 86 // 87 // // We have to save the subject first, otherwise the parentEvent property of the sample cannot be set 88 // // (this is possibly a Grails or Hibernate bug) 89 // testStudy.addToSubjects(currentSubject) 90 // currentSubject.with { if (!validate()) { errors.each { println it} } else save()} 91 // 92 // // Add subject to appropriate EventGroup 93 // LFBV1.addToSubjects(currentSubject).with { if (!validate()) { errors.each { println it} } else save()} 94 // 95 // // Create sample 96 // def currentSample = new Sample( 97 // name: currentSubject.name + '_B', 98 // material: mouseTerm, 99 // template: humanTissueSampleTemplate, 100 // parentSubject: currentSubject, 101 // parentEvent: evS 102 // ); 103 // testStudy.addToSamples(currentSample) 104 // currentSample.setFieldValue("Text on vial", "T" + (Math.random() * 100L)) 105 // currentSample.with { if (!validate()) { errors.each { println it} } else save()} 106 // } 107 // 108 // // Add EventGroups to study 109 // testStudy.addToEventGroups(LFBV1) 110 // LFBV1.with { if (!validate()) { errors.each { println it} } else save()} 111 // testStudy.with { if (!validate()) { errors.each { println it} } else save(flush:true)} 112 // 113 // testStudy.save(flush:true) 114 // 115 // //assert Sample.list()*.name.contains( "TestA2_B" ); 116 // 117 // // Make sure session is kept open 118 // Session session = SessionFactoryUtils.getSession(sessionFactory, true) 119 // session.flush(); 120 // session.clear(); 121 123 122 } 124 123 … … 131 130 List criteria = [ 132 131 new Criterion( entity: "Sample", field: "name", operator: Operator.contains, value: "B" ), 133 new Criterion( entity: "Study", field: "code", operator: Operator.equals, value: " TESTPPS3_leptin_module" ),134 new Criterion( entity: "Study", field: "code", operator: Operator.equals, value: "PPS 3_leptin_module" )132 new Criterion( entity: "Study", field: "code", operator: Operator.equals, value: "PPS3_leptin_module" ), 133 new Criterion( entity: "Study", field: "code", operator: Operator.equals, value: "PPSH" ) 135 134 ] 136 135 … … 142 141 143 142 assert search.getResults()[0] instanceof Sample 144 assert search.getResults()*.name.contains( " TestA2_B" );145 assert search.getResults()*.name.contains( " TestA4_B" );143 assert search.getResults()*.name.contains( "A2_B" ); 144 assert search.getResults()*.name.contains( "A4_B" ); 146 145 147 146 search.setCriteria( [ criteria[0], criteria[1] ] ); 148 147 search.execute(); 149 148 assert search.getResults().size() >= 1 150 assert search.getResults()*.name.contains( " TestA2_B" );149 assert search.getResults()*.name.contains( "A2_B" ); 151 150 152 151 search.setCriteria( [ criteria[0], criteria[2] ] ); … … 162 161 void testExecuteDifferentCriteria() { 163 162 List criteria = [ 164 new Criterion( entity: "Study", field: "title", operator: Operator.contains, value: " TestStudy 1" ),165 new Criterion( entity: "Subject", field: " name", operator: Operator.contains, value: "Test" ),166 new Criterion( entity: "Sample", field: "name", operator: Operator.contains, value: " Test" ),167 new Criterion( entity: "Assay", field: "name", operator: Operator.contains, value: " Test" ),168 new Criterion( entity: "Event", field: "startTime", operator: Operator.equals, value: "3600" ),169 new Criterion( entity: "SamplingEvent", field: "startTime", operator: Operator.equals, value: "3600"),163 new Criterion( entity: "Study", field: "title", operator: Operator.contains, value: "NuGO PPS3 mouse study" ), 164 new Criterion( entity: "Subject", field: "species", operator: Operator.equals, value: "Mus musculus" ), 165 new Criterion( entity: "Sample", field: "name", operator: Operator.contains, value: "A" ), 166 new Criterion( entity: "Assay", field: "name", operator: Operator.contains, value: "Lipid" ), 167 //new Criterion( entity: "Event", field: "startTime", operator: Operator.equals, value: "3600" ), 168 //new Criterion( entity: "SamplingEvent", field: "startTime", operator: Operator.equals, value: 3600 + 7 * 24 * 3600 ), 170 169 ] 171 170 172 def search = new S earch();171 def search = new SampleSearch(); 173 172 174 173 // All criteria should result in 1 sample with code 'abc' … … 177 176 search.setCriteria( [ it ] ); 178 177 search.execute(); 179 assert search.getResults().size() >= 2 180 assert search.getResults()[0] instanceof Sample; 181 assert search.getResults()*.name.contains( "TestA2_B" ); 178 179 def results = search.getResults(); 180 assert results; 181 assert results.size() >= 2 182 assert results[0] instanceof Sample; 183 assert results*.name.contains( "A2_B" ); 182 184 } 183 185 } -
trunk/test/integration/gscf/SubjectTests.groovy
r1432 r1436 5 5 import dbnp.data.* 6 6 import nl.grails.plugins.gdt.* 7 7 8 /** 8 9 * SubjectTests Test
Note: See TracChangeset
for help on using the changeset viewer.