001 /*
002 * Copyright 2007 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.ken.bo;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.hibernate.annotations.GenericGenerator;
020 import org.hibernate.annotations.Parameter;
021 import org.kuali.rice.ken.util.NotificationConstants;
022 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
023
024 import javax.persistence.*;
025 import java.sql.Timestamp;
026 import java.util.ArrayList;
027 import java.util.List;
028
029 /**
030 * This class represents an instace of a notification message that is received by the overall
031 * system.
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034 @Entity
035 @Table(name="KREN_NTFCTN_T")
036 public class Notification extends PersistableBusinessObjectBase implements Lockable {
037
038 @Id
039 @GeneratedValue(generator="KREN_NTFCTN_S")
040 @GenericGenerator(name="KREN_NTFCTN_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
041 @Parameter(name="sequence_name",value="KREN_NTFCTN_S"),
042 @Parameter(name="value_column",value="id")
043 })
044 @Column(name="NTFCTN_ID")
045 private Long id;
046 @Column(name="DELIV_TYP", nullable=false)
047 private String deliveryType;
048 @Column(name="CRTE_DTTM", nullable=false)
049 private Timestamp creationDateTime;
050 @Column(name="SND_DTTM", nullable=true)
051 private Timestamp sendDateTime;
052 @Column(name="AUTO_RMV_DTTM", nullable=true)
053 private Timestamp autoRemoveDateTime;
054 @Column(name="TTL", nullable=true)
055 private String title;
056 @Lob
057 @Basic(fetch=FetchType.LAZY)
058 @Column(name="CNTNT", nullable=false)
059 private String content;
060 @Column(name="PROCESSING_FLAG", nullable=false)
061 private String processingFlag;
062 @Column(name="LOCKD_DTTM", nullable=true)
063 private Timestamp lockedDate;
064 /**
065 * Lock column for OJB optimistic locking
066 */
067 // @Version
068 // @Column(name="VER_NBR")
069 // private Integer lockVerNbr;
070
071 // object references
072 @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.DETACH})
073 @JoinColumn(name="PRIO_ID")
074 private NotificationPriority priority;
075 @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.DETACH})
076 @JoinColumn(name="CNTNT_TYP_ID")
077 private NotificationContentType contentType;
078 @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.DETACH})
079 @JoinColumn(name="CHNL_ID")
080 private NotificationChannel channel;
081 @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.DETACH})
082 @JoinColumn(name="PRODCR_ID")
083 private NotificationProducer producer;
084
085 // lists
086 @OneToMany(cascade={CascadeType.ALL},
087 targetEntity=org.kuali.rice.ken.bo.NotificationRecipient.class, mappedBy="notification")
088 @OrderBy("id ASC")
089 private List<NotificationRecipient> recipients;
090 @OneToMany(cascade={CascadeType.ALL},
091 targetEntity=org.kuali.rice.ken.bo.NotificationSender.class, mappedBy="notification")
092 @OrderBy("id ASC")
093 private List<NotificationSender> senders;
094
095 /**
096 * Constructs a Notification instance.
097 */
098 public Notification() {
099 recipients = new ArrayList<NotificationRecipient>();
100 senders = new ArrayList<NotificationSender>();
101 processingFlag = NotificationConstants.PROCESSING_FLAGS.UNRESOLVED;
102 }
103
104 /**
105 * Returns when this Notification entry was created
106 * @return when this Notification entry was created
107 */
108 public Timestamp getCreationDateTime() {
109 return creationDateTime;
110 }
111
112 /**
113 * Sets the creation date of this Notification entry
114 * @param created the creation date of this Notification entry
115 */
116 public void setCreationDateTime(Timestamp created) {
117 this.creationDateTime = created;
118 }
119
120 /**
121 * Return value of lock column for OJB optimistic locking
122 * @return value of lock column for OJB optimistic locking
123 */
124 // should discard this method and call super directly
125 public Integer getLockVerNbr() {
126 return Integer.valueOf(super.getVersionNumber().intValue());
127 }
128
129 /**
130 * Set value of lock column for OJB optimistic locking
131 * @param lockVerNbr value of lock column for OJB optimistic locking
132 */
133 // should discard this method and call super directly
134 public void setLockVerNbr(Integer lockVerNbr) {
135 super.setVersionNumber(lockVerNbr.longValue());
136 }
137
138 /**
139 * Gets the recipients attribute.
140 * @return Returns the recipients.
141 */
142 public List<NotificationRecipient> getRecipients() {
143 return recipients;
144 }
145
146 /**
147 * Sets the recipients attribute value.
148 * @param recipients The recipients to set.
149 */
150 public void setRecipients(List<NotificationRecipient> recipients) {
151 this.recipients = recipients;
152 }
153
154 /**
155 * Retrieves a recipient at the specified index
156 * @param index the index in the recipients collection
157 * @return the recipient if found or null
158 */
159 public NotificationRecipient getRecipient(int index) {
160 return (NotificationRecipient) recipients.get(index);
161 }
162
163 /**
164 * Adds a recipient
165 * @param recipient The recipient to add
166 */
167 public void addRecipient(NotificationRecipient recipient) {
168 recipients.add(recipient);
169 }
170
171 /**
172 * Gets the senders attribute.
173 * @return Returns the senders.
174 */
175 public List<NotificationSender> getSenders() {
176 return senders;
177 }
178
179 /**
180 * Sets the senders attribute value.
181 * @param senders The senders to set.
182 */
183 public void setSenders(List<NotificationSender> senders) {
184 this.senders = senders;
185 }
186
187 /**
188 * Retrieves a sender at the specified index
189 * @param index the index in the senders collection
190 * @return the sender if found or null
191 */
192 public NotificationSender getSender(int index) {
193 return (NotificationSender) senders.get(index);
194 }
195 /**
196 * Adds a sender
197 * @param sender The sender to add
198 */
199 public void addSender(NotificationSender sender) {
200 senders.add(sender);
201 }
202
203 /**
204 * Gets the autoRemoveDateTime attribute.
205 * @return Returns the autoRemoveDateTime.
206 */
207 public Timestamp getAutoRemoveDateTime() {
208 return autoRemoveDateTime;
209 }
210
211 /**
212 * Sets the autoRemoveDateTime attribute value.
213 * @param autoRemoveDateTime The autoRemoveDateTime to set.
214 */
215 public void setAutoRemoveDateTime(Timestamp autoRemoveDateTime) {
216 this.autoRemoveDateTime = autoRemoveDateTime;
217 }
218
219 /**
220 * Gets the channel attribute.
221 * @return Returns the channel.
222 */
223 public NotificationChannel getChannel() {
224 return channel;
225 }
226
227 /**
228 * Sets the channel attribute value.
229 * @param channel The channel to set.
230 */
231 public void setChannel(NotificationChannel channel) {
232 this.channel = channel;
233 }
234
235 /**
236 * Gets the content attribute.
237 * @return Returns the content.
238 */
239 public String getContent() {
240 return content;
241 }
242
243 /**
244 * Sets the content attribute value.
245 * @param content The content to set.
246 */
247 public void setContent(String content) {
248 this.content = content;
249 }
250
251 /**
252 * Gets the contentType attribute.
253 * @return Returns the contentType.
254 */
255 public NotificationContentType getContentType() {
256 return contentType;
257 }
258
259 /**
260 * Sets the contentType attribute value.
261 * @param contentType The contentType to set.
262 */
263 public void setContentType(NotificationContentType contentType) {
264 this.contentType = contentType;
265 }
266
267 /**
268 * Gets the deliveryType attribute.
269 * @return Returns the deliveryType.
270 */
271 public String getDeliveryType() {
272 return deliveryType;
273 }
274
275 /**
276 * Sets the deliveryType attribute value.
277 * @param deliveryType The deliveryType to set.
278 */
279 public void setDeliveryType(String deliveryType) {
280 this.deliveryType = deliveryType.toUpperCase();
281 }
282
283 /**
284 * Gets the id attribute.
285 * @return Returns the id.
286 */
287 public Long getId() {
288 return id;
289 }
290
291 /**
292 * Sets the id attribute value.
293 * @param id The id to set.
294 */
295 public void setId(Long id) {
296 this.id = id;
297 }
298
299 /**
300 * Gets the priority attribute.
301 * @return Returns the priority.
302 */
303 public NotificationPriority getPriority() {
304 return priority;
305 }
306
307 /**
308 * Sets the priority attribute value.
309 * @param priority The priority to set.
310 */
311 public void setPriority(NotificationPriority priority) {
312 this.priority = priority;
313 }
314
315 /**
316 * Gets the producer attribute.
317 * @return Returns the producer.
318 */
319 public NotificationProducer getProducer() {
320 return producer;
321 }
322
323 /**
324 * Sets the producer attribute value.
325 * @param producer The producer to set.
326 */
327 public void setProducer(NotificationProducer producer) {
328 this.producer = producer;
329 }
330
331 /**
332 * Gets the sendDateTime attribute.
333 * @return Returns the sendDateTime.
334 */
335 public Timestamp getSendDateTime() {
336 return sendDateTime;
337 }
338
339 /**
340 * Sets the sendDateTime attribute value.
341 * @param sendDateTime The sendDateTime to set.
342 */
343 public void setSendDateTime(Timestamp sendDateTime) {
344 this.sendDateTime = sendDateTime;
345 }
346
347 /**
348 * Gets the processingFlag attribute.
349 * @return Returns the processingFlag.
350 */
351 public String getProcessingFlag() {
352 return processingFlag;
353 }
354
355 /**
356 * Sets the processingFlag attribute value.
357 * @param processingFlag The processingFlag to set.
358 */
359 public void setProcessingFlag(String processingFlag) {
360 this.processingFlag = processingFlag;
361 }
362
363 /**
364 * Gets the lockedDate attribute.
365 * @return Returns the lockedDate.
366 */
367 public Timestamp getLockedDate() {
368 return lockedDate;
369 }
370
371 /**
372 * Sets the lockedDate attribute value.
373 * @param lockedDate The lockedDate to set.
374 */
375 public void setLockedDate(Timestamp lockedDate) {
376 this.lockedDate = lockedDate;
377 }
378
379 /**
380 * Gets the title
381 * @return the title of this notification
382 */
383 public String getTitle() {
384 return title;
385 }
386
387 /**
388 * Sets the title
389 * @param title the title of this notification
390 */
391 public void setTitle(String title) {
392 this.title = title;
393 }
394
395 /**
396 * This method just uses StringUtils to get at the content of the <message> tag
397 * that exists in the notification content.
398 * @return String
399 */
400 public String getContentMessage() {
401 return StringUtils.substringBetween(content, NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_OPEN, NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_CLOSE);
402 }
403 }