source: trunk/grails-app/domain/dbnp/studycapturing/Event.groovy @ 1170

Last change on this file since 1170 was 1170, checked in by business@…, 13 years ago

reverting the searchable property of Event, bug is still there and causes errors in the wizard when events are created

  • Property svn:keywords set to Author Date Rev
File size: 3.6 KB
Line 
1package dbnp.studycapturing
2
3/**
4 * The Event class describes an actual event, as it has happened to a certain subject. Often, the same event occurs
5 * to multiple subjects at the same time. That is why the actual description of the event is factored out into a more
6 * general EventDescription class. Events that also lead to sample(s) should be instantiated as SamplingEvents.
7 *
8 * Revision information:
9 * $Rev: 1170 $
10 * $Author: business@keesvanbochove.nl $
11 * $Date: 2010-11-18 13:51:09 +0000 (do, 18 nov 2010) $
12 */
13class Event extends TemplateEntity {
14
15        // uncommented due to searchable issue
16        // @see http://jira.codehaus.org/browse/GRAILSPLUGINS-1577
17        // Enabling this causes the error: Trying to marshall a null id [id] for alias [Event] in the study create wizard when you add events
18        // static searchable = true
19
20        static belongsTo = [parent : Study]     
21
22        /** Start time of the event, relative to the start time of the study */
23        long startTime
24        /** end time of the event, relative to the start time of the study */
25        long endTime
26
27        /**
28         * Constraints
29         */
30        static constraints = {
31                endTime(validator: { fields, obj, errors ->
32                        def error = false
33
34                        // endTime must be >= the startTime
35                        if (fields && fields.compareTo(obj.startTime) < 0) {
36                                error = true
37                                errors.rejectValue(
38                                        'endTime',
39                                        'event.endTime.greaterThanStartTime',
40                                        ['endTime', fields] as Object[],
41                                        'End time should be greater than or equal to the Start Time'
42                                )
43                        }
44
45                        return (!error)
46                })
47        }
48
49        /**
50         * return the domain fields for this domain class
51         * @return List<TemplateField>
52         */
53        static List<TemplateField> giveDomainFields() { return Event.domainFields }
54
55        // To improve performance, the domain fields list is stored as a static final variable in the class.
56        static final List<TemplateField> domainFields = [
57                new TemplateField(
58                        name: 'startTime',
59                        type: TemplateFieldType.RELTIME,
60                        comment: "Please enter the start time as a relative time from study start date. "+RelTime.getHelpText(),
61                        required: true),
62                new TemplateField(
63                        name: 'endTime',
64                        type: TemplateFieldType.RELTIME,
65                        comment: "Please enter the end time as a relative time from study start date. "+RelTime.getHelpText(),
66                        required: true)
67        ]
68
69    static mapping = {
70        sort "startTime"
71    }
72
73        /**
74         * Get the duration of the event as RelTime
75         * @return RelTime
76         */
77        def getDuration() {
78                return new RelTime(startTime, endTime)
79        }
80
81         /**
82          * Return the start time of the event, which should be relative to the start of the study
83          * @return String a human readable representation of the start time of the event
84         */
85        def getStartTimeString() {
86                return new RelTime(startTime).toPrettyString();
87        }
88
89        /**
90         * Get extended, human readable string representing the duration between startTime and endTime
91     *
92         * @return String
93         */
94        def getDurationString() {
95                return new RelTime(startTime, endTime).toPrettyString();
96        }
97
98        /**
99         * Get human readable string representing the duration between startTime and endTime, rounded to one unit (weeks/days/hours etc.)
100     *
101         * @return String
102         */
103        def getRoundedDuration() {
104                return new RelTime(startTime, endTime).toPrettyRoundedString();
105        }
106
107        /**
108         *    Return whether this is SamplingEvent
109         * @return    boolean
110         */
111        def isSamplingEvent() {
112                return (this instanceof SamplingEvent)
113        }
114
115        /**
116         * Checks whether this Event is part of one or more of the given EventGroups
117         * @param groups
118         * @return
119         */
120        def belongsToGroup(Collection<EventGroup> groups) {
121                def eventFound = false;
122                def that = this;
123                groups.each { eventgroup ->
124                        if (!eventFound && eventgroup.events) {
125                                eventFound = (that.id in eventgroup.events.id);
126                        }
127                }
128
129                return eventFound;
130        }
131
132        def String toString() {
133                return fieldExists('Description') ? getFieldValue('Description') : ""
134        }
135}
Note: See TracBrowser for help on using the repository browser.