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

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

Made the studytoken, assaytoken and sampletoken stable identifiers, as explained in #255.

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