1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ken.bo;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.hibernate.annotations.GenericGenerator;
21 import org.hibernate.annotations.Parameter;
22 import org.joda.time.DateTime;
23 import org.kuali.rice.ken.api.notification.Notification;
24 import org.kuali.rice.ken.api.notification.NotificationContract;
25 import org.kuali.rice.ken.api.notification.NotificationRecipient;
26 import org.kuali.rice.ken.api.notification.NotificationRecipientContract;
27 import org.kuali.rice.ken.api.notification.NotificationSender;
28 import org.kuali.rice.ken.api.notification.NotificationSenderContract;
29 import org.kuali.rice.ken.util.NotificationConstants;
30 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
31
32 import javax.persistence.Basic;
33 import javax.persistence.CascadeType;
34 import javax.persistence.Column;
35 import javax.persistence.Entity;
36 import javax.persistence.FetchType;
37 import javax.persistence.GeneratedValue;
38 import javax.persistence.Id;
39 import javax.persistence.JoinColumn;
40 import javax.persistence.Lob;
41 import javax.persistence.OneToMany;
42 import javax.persistence.OneToOne;
43 import javax.persistence.OrderBy;
44 import javax.persistence.Table;
45 import java.sql.Timestamp;
46 import java.util.ArrayList;
47 import java.util.List;
48
49
50
51
52
53
54 @Entity
55 @Table(name="KREN_NTFCTN_T")
56 public class NotificationBo extends PersistableBusinessObjectBase implements NotificationContract, Lockable {
57
58 @Id
59 @GeneratedValue(generator="KREN_NTFCTN_S")
60 @GenericGenerator(name="KREN_NTFCTN_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
61 @Parameter(name="sequence_name",value="KREN_NTFCTN_S"),
62 @Parameter(name="value_column",value="id")
63 })
64 @Column(name="NTFCTN_ID")
65 private Long id;
66 @Column(name="DELIV_TYP", nullable=false)
67 private String deliveryType;
68 @Column(name="CRTE_DTTM", nullable=false)
69 private Timestamp creationDateTimeValue;
70 @Column(name="SND_DTTM", nullable=true)
71 private Timestamp sendDateTimeValue;
72 @Column(name="AUTO_RMV_DTTM", nullable=true)
73 private Timestamp autoRemoveDateTimeValue;
74 @Column(name="TTL", nullable=true)
75 private String title;
76 @Lob
77 @Basic(fetch=FetchType.LAZY)
78 @Column(name="CNTNT", nullable=false)
79 private String content;
80 @Column(name="PROCESSING_FLAG", nullable=false)
81 private String processingFlag;
82 @Column(name="LOCKD_DTTM", nullable=true)
83 private Timestamp lockedDateValue;
84
85
86
87
88
89
90
91
92 @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.DETACH})
93 @JoinColumn(name="PRIO_ID")
94 private NotificationPriorityBo priority;
95 @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.DETACH})
96 @JoinColumn(name="CNTNT_TYP_ID")
97 private NotificationContentTypeBo contentType;
98 @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.DETACH})
99 @JoinColumn(name="CHNL_ID")
100 private NotificationChannelBo channel;
101 @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.DETACH})
102 @JoinColumn(name="PRODCR_ID")
103 private NotificationProducerBo producer;
104
105
106 @OneToMany(cascade={CascadeType.ALL},
107 targetEntity=NotificationRecipientBo.class, mappedBy="notification")
108 @OrderBy("id ASC")
109 private List<NotificationRecipientBo> recipients;
110 @OneToMany(cascade={CascadeType.ALL},
111 targetEntity=NotificationSenderBo.class, mappedBy="notification")
112 @OrderBy("id ASC")
113 private List<NotificationSenderBo> senders;
114
115
116
117
118 public NotificationBo() {
119 recipients = new ArrayList<NotificationRecipientBo>();
120 senders = new ArrayList<NotificationSenderBo>();
121 processingFlag = NotificationConstants.PROCESSING_FLAGS.UNRESOLVED;
122 }
123
124
125
126
127
128 public Timestamp getCreationDateTimeValue() {
129 return creationDateTimeValue;
130 }
131
132 @Override
133 public DateTime getCreationDateTime() {
134 return this.creationDateTimeValue == null ? null : new DateTime(this.creationDateTimeValue);
135 }
136
137
138
139
140
141 public void setCreationDateTimeValue(Timestamp created) {
142 this.creationDateTimeValue = created;
143 }
144
145
146
147
148
149
150 public Integer getLockVerNbr() {
151 return Integer.valueOf(super.getVersionNumber().intValue());
152 }
153
154
155
156
157
158
159 public void setLockVerNbr(Integer lockVerNbr) {
160 super.setVersionNumber(lockVerNbr.longValue());
161 }
162
163
164
165
166
167 public List<NotificationRecipientBo> getRecipients() {
168 return recipients;
169 }
170
171
172
173
174
175 public void setRecipients(List<NotificationRecipientBo> recipients) {
176 this.recipients = recipients;
177 }
178
179
180
181
182
183
184 public NotificationRecipientBo getRecipient(int index) {
185 return (NotificationRecipientBo) recipients.get(index);
186 }
187
188
189
190
191
192 public void addRecipient(NotificationRecipientBo recipient) {
193 recipients.add(recipient);
194 }
195
196
197
198
199
200 public List<NotificationSenderBo> getSenders() {
201 return senders;
202 }
203
204
205
206
207
208 public void setSenders(List<NotificationSenderBo> senders) {
209 this.senders = senders;
210 }
211
212
213
214
215
216
217 public NotificationSenderBo getSender(int index) {
218 return (NotificationSenderBo) senders.get(index);
219 }
220
221
222
223
224 public void addSender(NotificationSenderBo sender) {
225 senders.add(sender);
226 }
227
228
229
230
231
232 public Timestamp getAutoRemoveDateTimeValue() {
233 return this.autoRemoveDateTimeValue;
234 }
235
236 @Override
237 public DateTime getAutoRemoveDateTime() {
238 return this.autoRemoveDateTimeValue == null ? null : new DateTime(this.autoRemoveDateTimeValue);
239 }
240
241
242
243
244
245 public void setAutoRemoveDateTimeValue(Timestamp autoRemoveDateTimeValue) {
246 this.autoRemoveDateTimeValue = autoRemoveDateTimeValue;
247 }
248
249
250
251
252
253 public NotificationChannelBo getChannel() {
254 return channel;
255 }
256
257
258
259
260
261 public void setChannel(NotificationChannelBo channel) {
262 this.channel = channel;
263 }
264
265
266
267
268
269 public String getContent() {
270 return content;
271 }
272
273
274
275
276
277 public void setContent(String content) {
278 this.content = content;
279 }
280
281
282
283
284
285 public NotificationContentTypeBo getContentType() {
286 return contentType;
287 }
288
289
290
291
292
293 public void setContentType(NotificationContentTypeBo contentType) {
294 this.contentType = contentType;
295 }
296
297
298
299
300
301 public String getDeliveryType() {
302 return deliveryType;
303 }
304
305
306
307
308
309 public void setDeliveryType(String deliveryType) {
310 this.deliveryType = deliveryType.toUpperCase();
311 }
312
313
314
315
316
317 public Long getId() {
318 return id;
319 }
320
321
322
323
324
325 public void setId(Long id) {
326 this.id = id;
327 }
328
329
330
331
332
333 public NotificationPriorityBo getPriority() {
334 return priority;
335 }
336
337
338
339
340
341 public void setPriority(NotificationPriorityBo priority) {
342 this.priority = priority;
343 }
344
345
346
347
348
349 public NotificationProducerBo getProducer() {
350 return producer;
351 }
352
353
354
355
356
357 public void setProducer(NotificationProducerBo producer) {
358 this.producer = producer;
359 }
360
361
362
363
364
365 public Timestamp getSendDateTimeValue() {
366 return this.sendDateTimeValue;
367 }
368
369 @Override
370 public DateTime getSendDateTime() {
371 return this.sendDateTimeValue == null ? null : new DateTime(this.sendDateTimeValue);
372 }
373
374
375
376
377
378 public void setSendDateTimeValue(Timestamp sendDateTimeValue) {
379 this.sendDateTimeValue = sendDateTimeValue;
380 }
381
382
383
384
385
386 public String getProcessingFlag() {
387 return processingFlag;
388 }
389
390
391
392
393
394 public void setProcessingFlag(String processingFlag) {
395 this.processingFlag = processingFlag;
396 }
397
398
399
400
401
402 public Timestamp getLockedDateValue() {
403 return this.lockedDateValue;
404 }
405
406 @Override
407 public DateTime getLockedDate() {
408 return this.lockedDateValue == null ? null : new DateTime(this.lockedDateValue);
409 }
410
411
412
413
414
415 public void setLockedDateValue(Timestamp lockedDateValue) {
416 this.lockedDateValue = lockedDateValue;
417 }
418
419
420
421
422
423 public String getTitle() {
424 return title;
425 }
426
427
428
429
430
431 public void setTitle(String title) {
432 this.title = title;
433 }
434
435
436
437
438
439
440 public String getContentMessage() {
441 return StringUtils.substringBetween(content, NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_OPEN, NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_CLOSE);
442 }
443
444
445
446
447
448
449
450 public static Notification to(NotificationBo bo) {
451 if (bo == null) {
452 return null;
453 }
454
455 return Notification.Builder.create(bo).build();
456 }
457
458
459
460
461
462
463 public static NotificationBo from(Notification im) {
464 if (im == null) {
465 return null;
466 }
467
468 NotificationBo bo = new NotificationBo();
469 bo.setId(im.getId());
470 bo.setVersionNumber(im.getVersionNumber());
471 bo.setObjectId(im.getObjectId());
472 bo.setDeliveryType(im.getDeliveryType());
473 bo.setCreationDateTimeValue(im.getCreationDateTime() == null ? null : new Timestamp(im.getCreationDateTime().getMillis()));
474 bo.setSendDateTimeValue(im.getSendDateTime() == null ? null : new Timestamp(im.getSendDateTime().getMillis()));
475 bo.setAutoRemoveDateTimeValue(im.getAutoRemoveDateTime() == null ? null : new Timestamp(im.getAutoRemoveDateTime().getMillis()));
476 bo.setTitle(im.getTitle());
477 bo.setContent(im.getContent());
478 bo.setLockedDateValue(im.getLockedDate() == null ? null : new Timestamp(im.getLockedDate().getMillis()));
479
480
481 bo.setPriority(NotificationPriorityBo.from(im.getPriority()));
482 bo.setContentType(NotificationContentTypeBo.from(im.getContentType()));
483 bo.setChannel(NotificationChannelBo.from(im.getChannel()));
484 bo.setProducer(NotificationProducerBo.from(im.getProducer()));
485
486
487 List<NotificationRecipientBo> tempRecipients = new ArrayList<NotificationRecipientBo>();
488 if (CollectionUtils.isNotEmpty(im.getRecipients())) {
489 for (NotificationRecipient recipient : im.getRecipients()) {
490 tempRecipients.add(NotificationRecipientBo.from(recipient));
491 }
492 bo.setRecipients(tempRecipients);
493 }
494 List<NotificationSenderBo> tempSenders = new ArrayList<NotificationSenderBo>();
495 if (CollectionUtils.isNotEmpty(im.getSenders())) {
496 for (NotificationSender sender : im.getSenders()) {
497 tempSenders.add(NotificationSenderBo.from(sender));
498 }
499 bo.setSenders(tempSenders);
500 }
501
502 return bo;
503 }
504 }