root/trunk/grails-app/domain/dbnp/studycapturing/SamplingEvent.groovy @ 1198

Revision 1198, 3.1 KB (checked in by t.e.roos@…, 3 years ago)

Added workarounds for known template text fields bug

  • Property svn:keywords set to Author Date Rev
Line 
1package dbnp.studycapturing
2
3/**
4 * The SamplingEvent class describes a sampling event, an event that also results in one or more samples.
5 *
6 * NOTE: according to Grails documentation, super classes and subclasses share the same table.
7 *       thus, we could merge the sampling with the Event super class and include a boolean
8 *       However, using a separate class makes it more clear in the code that Event and SamplingEvent are treated differently
9 *
10 * Revision information:
11 * $Rev$
12 * $Author$
13 * $Date$
14 */
15class SamplingEvent extends TemplateEntity {
16        // A SamplingEvent always belongs to one study.
17        // Although this is technically inherited from Event, we have to specify it here again.
18        // Otherwise, Grails expects the SamplingEvent to be referenced in Study.events,
19        // where it is actually referenced in Study.samplingEvents
20        static belongsTo = [parent : Study]
21        static hasMany = [samples : Sample]
22
23        /** Start time of the event, relative to the start time of the study */
24        long startTime
25
26        /** Duration of the sampling event, if it has any (default is 0) */
27        long duration
28
29        // define what template samples should have
30        Template sampleTemplate
31
32        // define domain constraints
33        static constraints = {
34                duration(default: 0L)
35                sampleTemplate(nullable: false, blank: false)
36        }
37
38        /**
39         * return the domain fields for this domain class
40         * @return List<TemplateField>
41         */
42        static List<TemplateField> giveDomainFields() { return SamplingEvent.domainFields }
43
44        // To improve performance, the domain fields list is stored as a static final variable in the class.
45        static final List<TemplateField> domainFields = [
46                new TemplateField(
47                        name: 'startTime',
48                        type: TemplateFieldType.RELTIME,
49                        comment: "Please enter the start time as a relative time from study start date."+RelTime.getHelpText(),
50                        required: true),
51                new TemplateField(
52                        name: 'duration',
53                        type: TemplateFieldType.RELTIME,
54                        comment: "Please enter the duration of the sampling action, if applicable. "+RelTime.getHelpText(),
55                        required: true),
56                new TemplateField(
57                        name: 'sampleTemplate',
58                        type: TemplateFieldType.TEMPLATE,
59                        entity: dbnp.studycapturing.Sample,
60                        comment: "Please select the template of the resulting samples",
61                        required: true)
62        ]
63
64       static mapping = {
65            // Workaround for bug http://jira.codehaus.org/browse/GRAILS-6754
66            templateTextFields type: 'text'
67        }
68
69         /**
70          * Return the start time of the event, which should be relative to the start of the study
71          * @return String a human readable representation of the start time of the event
72         */
73        def getStartTimeString() {
74                return new RelTime(startTime).toPrettyString();
75        }
76
77        /**
78         * Checks whether this Event is part of one or more of the given EventGroups
79         * @param groups
80         * @return
81         */
82        def belongsToGroup(Collection<EventGroup> groups) {
83                def eventFound = false;
84                def that = this;
85                groups.each { eventgroup ->
86                        if (!eventFound && eventgroup.samplingEvents) {
87                                eventFound = (that.id in eventgroup.samplingEvents.id);
88                        }
89                }
90
91                return eventFound;
92        }
93
94        def String toString() {
95                return fieldExists('Description') ? getFieldValue('Description') : ""
96        }
97       
98}
Note: See TracBrowser for help on using the browser.