root/trunk/grails-app/domain/dbnp/studycapturing/Sample.groovy @ 667

Revision 667, 2.3 KB (checked in by duh, 4 years ago)

- removed searchable lines from Subject and Sample as the break the cascaded saving of studies (@see  http://jira.codehaus.org/browse/GRAILSPLUGINS-1577 )
- application version 0.4.1

  • Property svn:keywords set to Date Rev Author
Line 
1package dbnp.studycapturing
2
3import dbnp.data.Term
4import dbnp.data.Ontology
5
6/**
7 * The Sample class describes an actual sample which results from a SamplingEvent.
8 */
9class Sample extends TemplateEntity {
10        // uncommented due to searchable issue
11        // @see http://jira.codehaus.org/browse/GRAILSPLUGINS-1577
12        //static searchable = { [only: ['name']] }
13
14        static belongsTo = [ parent : Study]
15
16        Subject parentSubject
17        SamplingEvent parentEvent
18
19        String name             // should be unique with respect to the parent study (which can be inferred)
20        Term material           // material of the sample (should normally be bound to the BRENDA ontology)
21
22        def getExternalSampleId() { name }
23
24        /**
25         * return the domain fields for this domain class
26         * @return List
27         */
28        static List<TemplateField> giveDomainFields() { return Sample.domainFields }
29        static List<TemplateField> domainFields = [
30                new TemplateField(
31                        name: 'name',
32                        type: TemplateFieldType.STRING,
33                        preferredIdentifier: true,
34                        required: true
35                ),
36                new TemplateField(
37                        name: 'material',
38                        type: TemplateFieldType.ONTOLOGYTERM
39                )
40        ]
41
42        static constraints = {
43                parentSubject(nullable:true)
44                material(nullable: true)
45
46                // TODO: Write a validation method that checks if the externalSampleId (currently defined as name)
47                // is really unique within each parent study of this sample.
48                // Maybe this could also be a constraint, but we might run into trouble creating new Sample objects in e.g. the create wizard.
49                // To be checked.
50                // This feature is tested by integration test SampleTests.testSampleUniqueNameConstraint
51
52                /*name(validator: { fields, obj, errors ->
53                        def error = false
54
55                        if (fields) {
56                                // Search through all study
57                                if (obj.parent.samples.findAll({ it.name == fields}).size() != 1) {
58                                        errors.rejectValue(
59                                                'name',
60                                                'sample.name.NotUnique',
61                                                ['name',fields] as Object[],
62                                                'The sample name is not unique within the study'
63                                        )
64                                }
65                        }
66                        else {
67                                // If no value for name is specified, the sample should not validate
68                                error = true
69                        }
70
71                        return (!error)
72                })*/
73        }
74
75        /*static def getParentStudies() {
76                Study.findAll {
77                        it.samples.findAll {
78                                it.name == this.name
79                        }
80                }
81        }*/
82
83        static getSamplesFor( event ) {
84                return  Sample.findAll( 'from Sample s where s.parentEvent =:event', [event:event] )
85        }
86
87}
Note: See TracBrowser for help on using the browser.