source: trunk/grails-app/domain/dbnp/studycapturing/SamplingEvent.groovy @ 1457

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