Changeset 654


Ignore:
Timestamp:
Jul 15, 2010, 2:26:48 PM (13 years ago)
Author:
keesvb
Message:

updated sample and study tests, added belongsTo to Sample (which gives it its parent), tried to write the unique name constraint of Sample and wrote a test for it

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/dbnp/studycapturing/AssayType.groovy

    r496 r654  
    1212        TRANSCRIPTOMICS('Transcriptomics'),
    1313        METABOLOMICS('Metabolomics'),
    14         CLINICAL_DATA('Clinical data')
     14        SIMPLE_ASSAY('Simple Assay')
    1515
    1616        String name
     
    2121
    2222        static list() {
    23                 [TRANSCRIPTOMICS, METABOLOMICS, CLINICAL_DATA]
     23                [TRANSCRIPTOMICS, METABOLOMICS, SIMPLE_ASSAY]
    2424        }
    2525}
  • trunk/grails-app/domain/dbnp/studycapturing/Event.groovy

    r629 r654  
    1616        long startTime
    1717        long endTime
     18
     19        // TODO: assure the Event has a parent study in validate()
    1820
    1921        /**
  • trunk/grails-app/domain/dbnp/studycapturing/Sample.groovy

    r652 r654  
    88 */
    99class Sample extends TemplateEntity {
    10     static searchable = { [only: ['name']] }
    11  
     10        static searchable = { [only: ['name']] }
     11
     12        static belongsTo = [ parent : Study]
     13
    1214        Subject parentSubject
    1315        SamplingEvent parentEvent
     
    1719
    1820        def getExternalSampleId() { name }
    19 
    20         // TODO: Write a validation method that checks if the externalSampleId (currently defined as name)
    21         // is really unique within each parent study of this sample.
    22         // Maybe this could also be a constraint, but we might run into trouble creating new Sample objects in e.g. the create wizard.
    23         // To be checked.
    2421
    2522        /**
     
    3229                        name: 'name',
    3330                        type: TemplateFieldType.STRING,
    34                         preferredIdentifier: true
     31                        preferredIdentifier: true,
     32                        required: true
    3533                ),
    3634                new TemplateField(
     
    4240        static constraints = {
    4341                parentSubject(nullable:true)
     42                material(nullable: true)
     43
     44                // TODO: Write a validation method that checks if the externalSampleId (currently defined as name)
     45                // is really unique within each parent study of this sample.
     46                // Maybe this could also be a constraint, but we might run into trouble creating new Sample objects in e.g. the create wizard.
     47                // To be checked.
     48                // This feature is tested by integration test SampleTests.testSampleUniqueNameConstraint
     49
     50                /*name(validator: { fields, obj, errors ->
     51                        def error = false
     52
     53                        if (fields) {
     54                                // Search through all study
     55                                if (obj.parent.samples.findAll({ it.name == fields}).size() != 1) {
     56                                        errors.rejectValue(
     57                                                'name',
     58                                                'sample.name.NotUnique',
     59                                                ['name',fields] as Object[],
     60                                                'The sample name is not unique within the study'
     61                                        )
     62                                }
     63                        }
     64                        else {
     65                                // If no value for name is specified, the sample should not validate
     66                                error = true
     67                        }
     68
     69                        return (!error)
     70                })*/
    4471        }
     72
     73        /*static def getParentStudies() {
     74                Study.findAll {
     75                        it.samples.findAll {
     76                                it.name == this.name
     77                        }
     78                }
     79        }*/
    4580
    4681        static getSamplesFor( event ) {
  • trunk/grails-app/domain/dbnp/studycapturing/SamplingEvent.groovy

    r540 r654  
    11package dbnp.studycapturing
    2 
    3 /**
    4  * 888       888 888    888 8888888888 8888888b.  8888888888
    5  * 888   o   888 888    888 888        888   Y88b 888
    6  * 888  d8b  888 888    888 888        888    888 888
    7  * 888 d888b 888 8888888888 8888888    888   d88P 8888888
    8  * 888d88888b888 888    888 888        8888888P"  888
    9  * 88888P Y88888 888    888 888        888 T88b   888
    10  * 8888P   Y8888 888    888 888        888  T88b  888
    11  * 888P     Y888 888    888 8888888888 888   T88b 8888888888
    12  *
    13  * 8888888 .d8888b.     88888888888 888    888 8888888888
    14  *   888  d88P  Y88b        888     888    888 888
    15  *   888  Y88b.             888     888    888 888
    16  *   888   "Y888b.          888     8888888888 8888888
    17  *   888      "Y88b.        888     888    888 888
    18  *   888        "888        888     888    888 888
    19  *   888  Y88b  d88P        888     888    888 888
    20  * 8888888 "Y8888P"         888     888    888 8888888888
    21  *
    22  *   888888        d8888 888     888     d8888 8888888b.   .d88888b.   .d8888b.
    23  *     "88b       d88888 888     888    d88888 888  "Y88b d88P" "Y88b d88P  Y88b
    24  *      888      d88P888 888     888   d88P888 888    888 888     888 888    888
    25  *      888     d88P 888 Y88b   d88P  d88P 888 888    888 888     888 888
    26  *      888    d88P  888  Y88b d88P  d88P  888 888    888 888     888 888
    27  *      888   d88P   888   Y88o88P  d88P   888 888    888 888     888 888    888
    28  *      88P  d8888888888    Y888P  d8888888888 888  .d88P Y88b. .d88P Y88b  d88P
    29  *      888 d88P     888     Y8P  d88P     888 8888888P"   "Y88888P"   "Y8888P"
    30  *    .d88P
    31  *  .d88P"
    32  * 888P"
    33  *
    34  *  .d8888b.  888  .d8888b.  888  .d8888b.  888
    35  * d88P  Y88b 888 d88P  Y88b 888 d88P  Y88b 888
    36  *      .d88P 888      .d88P 888      .d88P 888
    37  *    .d88P"  888    .d88P"  888    .d88P"  888
    38  *    888"    888    888"    888    888"    888
    39  *    888     Y8P    888     Y8P    888     Y8P
    40  *             "              "              "
    41  *    888     888    888     888    888     888
    42  *
    43  *
    44  * TODO: add PROPER class and method documentation, just like have
    45  *       agreed upon hundreds of times!!!!
    46  */
    472
    483/**
     
    5914        }
    6015
     16        /**
     17         * Get all samples that have this sampling event as a parent
     18         */
    6119        def getSamples() {
    6220
  • trunk/test/integration/gscf/SampleTests.groovy

    r653 r654  
    5555                assert samplingEvent.validate()
    5656
     57                assert samplingEvent.save(flush:true)
    5758
    5859                // Look up sample template
     
    109110                assert study
    110111
    111                 // Test giveSamplingEventTemplates
    112                 def templates = study.giveSamplingEventTemplates()
     112                // Test giveSampleTemplates
     113                def templates = study.giveSampleTemplates()
    113114                assert templates
    114115                assert templates.size() == 1
    115                 assert templates
     116                assert templates.asList().first().name == testSampleTemplateName
    116117
    117118                // Test if the sample is in the samples collection
     
    119120                assert study.samples.size() == 1
    120121                assert study.samples.first().name == testSampleName
     122        }
     123
     124
     125        void testParentStudy() {
     126                def sample = Sample.findByName(testSampleName)
     127                assert sample
     128
     129                assert sample.parent
     130                assert sample.parent.code == testStudyCode
     131        }
     132
     133        void testSampleUniqueNameConstraint() {
     134                def sample = Sample.findByName(testSampleName)
     135                assert sample
     136
     137                def study = sample.parent
     138                assert study
     139
     140                def sample2 = new Sample(
     141                    name: testSampleName,
     142                    template: sampleTemplate,
     143                    parentEvent: samplingEvent
     144                )
     145
     146                // Add the sample to the retrieved parent study
     147                study.addToSamples(sample2)
     148
     149                // At this point, the sample should not validate or save, because there is already a sample with that name in the study
     150                assert !sample2.validate()
     151                assert !sample2.save(flush:true)
     152
    121153        }
    122154
     
    134166
    135167        void testDomainFields() {
    136                 def sample = Sample.findByName(testStudyName)
     168                def sample = Sample.findByName(testSampleName)
    137169                assert sample
    138170
  • trunk/test/integration/gscf/StudyTests.groovy

    r653 r654  
    9999
    100100                // Delete the created study
    101                 def study = Study.findByCode(testStudyCode)
     101                /*def study = Study.findByCode(testStudyCode)
    102102                assert study
    103103
    104104                study.delete()
    105105                assert Study.findByCode(testStudyCode) == null
    106 
     106                */
    107107                super.tearDown()
    108108        }
Note: See TracChangeset for help on using the changeset viewer.