• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-core / 41717832711

30 Oct 2026 04:16PM UTC coverage: 66.75% (+0.003%) from 66.747%
41717832711

push

github

ibacher
TRUNK-6863: Remove the generation token before clearing a node's cache locally (#6791)

1 of 1 new or added line in 1 file covered. (100.0%)

419 existing lines in 31 files now uncovered.

26279 of 39369 relevant lines covered (66.75%)

0.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.58
/api/src/main/java/org/openmrs/notification/Alert.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 *
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs.notification;
11

12
import java.io.Serializable;
13
import java.util.Collection;
14
import java.util.Date;
15
import java.util.HashSet;
16
import java.util.Set;
17

18
import org.hibernate.envers.Audited;
19
import org.openmrs.Auditable;
20
import org.openmrs.BaseOpenmrsObject;
21
import org.openmrs.User;
22
import org.openmrs.api.context.Context;
23
import org.openmrs.util.CollectionUtil;
24

25
/**
26
 * Alerts are the simplest form of communication. An Administrator (or script) sets the user or role
27
 * to attribute the alert to. Alerts are not intended to be sent from user to user and a user cannot
28
 * send a "reply alert"
29
 */
30
@Audited
31
public class Alert extends BaseOpenmrsObject implements Auditable, Serializable {
32
        
33
        private static final long serialVersionUID = -507111111109152L;
34
        
35
        public static final int TEXT_MAX_LENGTH = 512;
36
        
37
        private Integer alertId;
38
        
39
        private String text;
40
        
41
        private Boolean satisfiedByAny = Boolean.FALSE;
1 ✔
42
        
43
        private Boolean alertRead = Boolean.FALSE;
1 ✔
44
        
45
        private Date dateToExpire;
46
        
47
        private User creator;
48
        
49
        private Date dateCreated;
50
        
51
        private User changedBy;
52
        
53
        private Date dateChanged;
54
        
55
        private Set<AlertRecipient> recipients;
56
        
57
        /**
58
         * Default empty constructor
59
         */
60
        public Alert() {
1 ✔
61
        }
1 ✔
62
        
63
        /**
64
         * Initializes an alert with the given alert id
65
         */
66
        public Alert(Integer alertId) {
×
67
                this.alertId = alertId;
×
UNCOV
68
        }
×
69
        
70
        /**
71
         * Convenience constructor to create an alert with the given text and for the given users
72
         *
73
         * @param text String to display for the alert
74
         * @param users Recipients of this alert
75
         */
76
        public Alert(String text, Collection<User> users) {
1 ✔
77
                setText(text);
1 ✔
78
                for (User user : users) {
1 ✔
79
                        addRecipient(user);
1 ✔
80
                }
1 ✔
81
        }
1 ✔
82
        
83
        /**
84
         * Convenience constructor to create an alert with the given text and for the given users
85
         *
86
         * @param text String to display for the alert
87
         * @param user Recipient of the alert
88
         */
89
        public Alert(String text, User user) {
1 ✔
90
                setText(text);
1 ✔
91
                addRecipient(user);
1 ✔
92
        }
1 ✔
93
        
94
        /**
95
         * @return Returns the alertId.
96
         */
97
        public Integer getAlertId() {
98
                return alertId;
1 ✔
99
        }
100
        
101
        /**
102
         * @param alertId The alertId to set.
103
         */
104
        public void setAlertId(Integer alertId) {
105
                this.alertId = alertId;
1 ✔
106
        }
1 ✔
107
        
108
        /**
109
         * @return Returns the creator.
110
         */
111
        @Override
112
        public User getCreator() {
113
                return creator;
1 ✔
114
        }
115
        
116
        /**
117
         * @param creator The creator to set.
118
         */
119
        @Override
120
        public void setCreator(User creator) {
121
                this.creator = creator;
1 ✔
122
        }
1 ✔
123
        
124
        /**
125
         * @return Returns the dateCreated.
126
         */
127
        @Override
128
        public Date getDateCreated() {
129
                return dateCreated;
1 ✔
130
        }
131
        
132
        /**
133
         * @param dateCreated The dateCreated to set.
134
         */
135
        @Override
136
        public void setDateCreated(Date dateCreated) {
137
                this.dateCreated = dateCreated;
1 ✔
138
        }
1 ✔
139
        
140
        /**
141
         * @return Returns the date this alert expires
142
         */
143
        public Date getDateToExpire() {
144
                return dateToExpire;
1 ✔
145
        }
146
        
147
        /**
148
         * @param dateToExpire The date To Expire this alert
149
         */
150
        public void setDateToExpire(Date dateToExpire) {
151
                this.dateToExpire = dateToExpire;
1 ✔
152
        }
1 ✔
153
        
154
        /**
155
         * @return Returns the text.
156
         */
157
        public String getText() {
158
                return text;
1 ✔
159
        }
160
        
161
        /**
162
         * @param text The text to set.
163
         */
164
        public void setText(String text) {
165
                this.text = text;
1 ✔
166
        }
1 ✔
167
        
168
        /**
169
         * @see #isSatisfiedByAny()
170
         */
171
        public Boolean getSatisfiedByAny() {
172
                return isSatisfiedByAny();
1 ✔
173
        }
174
        
175
        /**
176
         * @return Returns the satisfiedByAny.
177
         */
178
        public Boolean isSatisfiedByAny() {
179
                return satisfiedByAny;
1 ✔
180
        }
181
        
182
        /**
183
         * @param satisfiedByAny The satisfiedByAny to set.
184
         */
185
        public void setSatisfiedByAny(Boolean satisfiedByAny) {
186
                this.satisfiedByAny = satisfiedByAny;
1 ✔
187
        }
1 ✔
188
        
189
        /**
190
         * @see #isAlertRead()
191
         */
192
        public Boolean getAlertRead() {
193
                return isAlertRead();
1 ✔
194
        }
195
        
196
        /**
197
         * @return Returns the alertRead.
198
         */
199
        public Boolean isAlertRead() {
200
                return alertRead;
1 ✔
201
        }
202
        
203
        /**
204
         * @param alertRead The alertRead to set.
205
         */
206
        public void setAlertRead(Boolean alertRead) {
207
                this.alertRead = alertRead;
1 ✔
208
        }
1 ✔
209
        
210
        /**
211
         * @return Returns the changedBy.
212
         */
213
        @Override
214
        public User getChangedBy() {
215
                return changedBy;
1 ✔
216
        }
217
        
218
        /**
219
         * @param changedBy The user that changed this alert
220
         */
221
        @Override
222
        public void setChangedBy(User changedBy) {
223
                this.changedBy = changedBy;
1 ✔
224
        }
1 ✔
225
        
226
        /**
227
         * @return Returns the date this alert was changed
228
         */
229
        @Override
230
        public Date getDateChanged() {
231
                return dateChanged;
1 ✔
232
        }
233
        
234
        /**
235
         * @param dateChanged The date this alert was changed
236
         */
237
        @Override
238
        public void setDateChanged(Date dateChanged) {
239
                this.dateChanged = dateChanged;
1 ✔
240
        }
1 ✔
241
        
242
        /**
243
         * @return Returns the Recipients of this alert
244
         */
245
        public Set<AlertRecipient> getRecipients() {
246
                return recipients;
1 ✔
247
        }
248
        
249
        /**
250
         * @param recipients The recipients of this alert
251
         */
252
        public void setRecipients(Set<AlertRecipient> recipients) {
253
                this.recipients = CollectionUtil.setCollection(this.recipients, recipients);
1 ✔
254
        }
1 ✔
255
        
256
        /**
257
         * Convenience method to add the given AlertRecipient to the list of recipients for this alert
258
         *
259
         * @param r AlertRecipient to add
260
         */
261
        public void addRecipient(AlertRecipient r) {
262
                if (this.recipients == null) {
1 ✔
263
                        this.recipients = new HashSet<>();
1 ✔
264
                }
265
                r.setAlert(this);
1 ✔
266
                // duplicates are avoided by depending on the .equals and .hashcode
267
                //  methods of Alert
268
                recipients.add(r);
1 ✔
269
        }
1 ✔
270
        
271
        /**
272
         * Convenience method to add the given user to this list of recipients for this alert
273
         *
274
         * @param u User to add to list of recipients
275
         */
276
        public void addRecipient(User u) {
277
                addRecipient(new AlertRecipient(u, false));
1 ✔
278
        }
1 ✔
279
        
280
        /**
281
         * Convenience method to remove the given AlertRecipient from this Alert's list of recipients
282
         *
283
         * @param r user to remove from list of recipients
284
         */
285
        public void removeRecipient(AlertRecipient r) {
286
                if (recipients != null) {
×
UNCOV
287
                        recipients.remove(r);
×
288
                }
UNCOV
289
        }
×
290
        
291
        /**
292
         * Convenience method to find the AlertRecipient object within this alert that corresponds to
293
         * the given <code>recipient</code>
294
         *
295
         * @param recipient
296
         * @return AlertRecipient
297
         */
298
        public AlertRecipient getRecipient(User recipient) {
299
                if (getRecipients() != null) {
1 ✔
300
                        for (AlertRecipient ar : recipients) {
1 ✔
301
                                if (ar.getRecipient().equals(recipient)) {
1 ✔
302
                                        return ar;
1 ✔
303
                                }
304
                        }
1 ✔
305
                }
306
                return null;
1 ✔
307
        }
308
        
309
        /**
310
         * Convenience method to mark this alert as read. In order to persist this change in the
311
         * database, AlertService.saveAlert(Alert) will need to be called after this method is done.
312
         *
313
         * @return This alert (for chaining and one-liner purposes)
314
         * @see org.openmrs.notification.AlertService#saveAlert(Alert)
315
         */
316
        public Alert markAlertRead() {
UNCOV
317
                User authUser = Context.getAuthenticatedUser();
×
318
                
319
                if (authUser != null) {
×
320
                        AlertRecipient ar = getRecipient(authUser);
×
321
                        ar.setAlertRead(true);
×
322
                        if (isSatisfiedByAny()) {
×
UNCOV
323
                                setAlertRead(true);
×
324
                        }
325
                }
326
                
UNCOV
327
                return this;
×
328
        }
329
        
330
        /**
331
         * @see java.lang.Object#toString()
332
         */
333
        @Override
334
        public String toString() {
335
                return "Alert: #" + alertId;
1 ✔
336
        }
337
        
338
        /**
339
         * @since 1.5
340
         * @see org.openmrs.OpenmrsObject#getId()
341
         */
342
        @Override
343
        public Integer getId() {
UNCOV
344
                return getAlertId();
×
345
        }
346
        
347
        /**
348
         * @since 1.5
349
         * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
350
         */
351
        @Override
352
        public void setId(Integer id) {
353
                setAlertId(id);
1 ✔
354
        }
1 ✔
355
        
356
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc