source: trunk/grails-app/domain/dbnp/studycapturing/Assay.groovy @ 1526

Last change on this file since 1526 was 1526, checked in by robert@…, 9 years ago

Added assay search and improved query form

  • Property svn:keywords set to Rev Author Date
File size: 2.6 KB
Line 
1package dbnp.studycapturing
2import org.dbnp.gdt.*
3
4/**
5 * This class describes an Assay, which describes the application of a certain (omics) measurement to multiple samples.
6 * The actual data of these measurements are described in submodules of dbNP. The type property describes in which module
7 * this data can be found.
8 */
9class Assay extends TemplateEntity {
10        // The name of the assay, which should indicate the measurements represented in this assay to the user.
11        String name
12
13        // The dbNP module in which the assay omics data can be found. */
14        AssayModule module
15
16        // The assay ID which is used in the dbNP submodule which contains the actual omics data of this assay.
17        // This ID is generated in GSCF, but is used in the submodules to refer to this particular Assay.
18        String externalAssayID
19
20        /**
21        * UUID of this assay
22        */
23    String assayUUID
24
25        /**
26         * return the domain fields for this domain class
27         * @return List
28         */
29        static List<TemplateField> giveDomainFields() { return Assay.domainFields }
30        static List<TemplateField> domainFields = [
31                new TemplateField(
32                        name: 'name',
33                        type: TemplateFieldType.STRING,
34                        preferredIdentifier: true,
35                        required: true
36                ),
37                new TemplateField(
38                        name: 'module',
39                        type: TemplateFieldType.MODULE,
40                        required: true
41                ),
42                new TemplateField(
43                        name: 'externalAssayID',
44                        type: TemplateFieldType.STRING,
45                        required: true
46                )
47        ]
48
49        // An Assay always belongs to one study.
50        static belongsTo = [parent: Study]
51
52        // An Assay can have many samples on which it is performed, but all samples should be within the 'parent' Study.
53        static hasMany = [samples: Sample]
54
55        static constraints = {
56                externalAssayID(nullable:false, blank:false, unique: true)
57                assayUUID(nullable:true, unique: true)
58        }
59
60    static mapping = {
61        sort "name"
62
63        // Workaround for bug http://jira.codehaus.org/browse/GRAILS-6754
64        templateTextFields type: 'text'
65    }
66
67        def String toString() {
68                return name;
69        }
70
71    def getToken() {
72                return giveUUID()
73    }
74       
75        /**
76         * Basic equals method to check whether objects are equals, by comparing the ids
77         * @param o             Object to compare with
78         * @return              True iff the id of the given Study is equal to the id of this Study
79         */
80        public boolean equals( Object o ) {
81                if( o == null )
82                        return false;
83
84                if( !( o instanceof Assay ) )
85                        return false
86
87                Assay s = (Assay) o;
88
89                return this.id == s.id
90        }
91       
92        /**
93         * Returns the UUID of this sample and generates one if needed
94         */
95        public String giveUUID() {
96                if( !this.assayUUID ) {
97                        this.assayUUID = UUID.randomUUID().toString();
98                        if( !this.save(flush:true) ) {
99                                log.error "Couldn't save assay UUID: " + this.getErrors();
100                        }
101                }
102               
103                return this.assayUUID;
104        }
105}
Note: See TracBrowser for help on using the repository browser.