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