View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kcb.bo;
17  
18  import java.sql.Timestamp;
19  
20  import javax.persistence.Basic;
21  import javax.persistence.Column;
22  import javax.persistence.Entity;
23  import javax.persistence.FetchType;
24  import javax.persistence.GeneratedValue;
25  import javax.persistence.Id;
26  import javax.persistence.Lob;
27  import javax.persistence.Table;
28  import javax.persistence.Version;
29  
30  import org.apache.commons.lang.StringUtils;
31  import org.apache.commons.lang.builder.ToStringBuilder;
32  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
33  
34  /**
35   * This class represents an abstract message that has been sent to a single user
36   * recipient and may result in several {@link MessageDelivery}s.
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  // this class could possibly just extend the MessageDTO
40  @Entity
41  @Table(name="KREN_MSG_T")
42  public class Message {
43      /**
44       * Field names
45       */
46      public static final String ID_FIELD = "id";
47      public static final String ORIGINID_FIELD = "originId";
48  
49      @Id
50      @GeneratedValue(generator="KREN_MSG_S")
51      @PortableSequenceGenerator(name="KREN_MSG_S")
52      @Column(name="MSG_ID")
53  	private Long id;
54      /**
55       * The origin id is an id provided by the originating system that creates the message
56       */
57      @Column(name="ORGN_ID", nullable=false)
58  	private String originId;
59      @Column(name="DELIV_TYP", nullable=false)
60  	private String deliveryType;
61      @Column(name="CHNL", nullable=false)
62  	private String channel;
63      @Column(name="PRODCR", nullable=true)
64  	private String producer;
65      @Column(name="CRTE_DTTM", nullable=false)
66      private Timestamp creationDateTime = new Timestamp(System.currentTimeMillis());
67      @Column(name="TTL", nullable=true)
68  	private String title;
69      @Lob
70  	@Basic(fetch=FetchType.LAZY)
71  	@Column(name="CNTNT", nullable=false)
72  	private String content;
73      @Column(name="CNTNT_TYP", nullable=true)
74  	private String contentType;
75      @Column(name="URL", nullable=true)
76  	private String url;
77      @Column(name="RECIP_ID", nullable=false)
78  	private String recipient;
79  
80      /**
81       * Lock column for OJB optimistic locking
82       */
83      @Version
84  	@Column(name="VER_NBR")
85  	private Integer lockVerNbr;
86  
87      /**
88       * Normal no-arg constructor
89       */
90      public Message() {}
91  
92      /**
93       * Shallow-copy constructor
94       * @param m Message object to (shallow) copy
95       */
96      public Message(Message m) {
97          this.id = m.id;
98          this.channel = m.channel;
99          this.content = m.content;
100         this.contentType = m.contentType;
101         this.creationDateTime = m.creationDateTime;
102         this.deliveryType = m.deliveryType;
103         this.lockVerNbr = m.lockVerNbr;
104         this.producer = m.producer;
105         this.recipient = m.recipient;
106         this.title = m.title;
107     }
108     
109     /**
110      * Gets the id attribute. 
111      * @return Returns the id.
112      */
113     public Long getId() {
114         return id;
115     }
116 
117     /**
118      * Sets the id attribute value.
119      * @param id The id to set.
120      */
121     public void setId(Long id) {
122         this.id = id;
123     }
124 
125     /**
126      * Gets the origin id
127      * @return the origin id
128      */
129     public String getOriginId() {
130         return this.originId;
131     }
132 
133     /**
134      * Sets the origin id
135      * @param originId the origin id
136      */
137     public void setOriginId(String originId) {
138         this.originId = originId;
139     }
140 
141     /**
142      * Returns when this Notification entry was created 
143      * @return when this Notification entry was created
144      */
145     public Timestamp getCreationDateTime() {
146         return creationDateTime;
147     }
148 
149     /**
150      * Sets the creation date of this Notification entry
151      * @param created the creation date of this Notification entry
152      */
153     public void setCreationDateTime(Timestamp created) {
154         this.creationDateTime = created;
155     }
156 
157     /**
158      * Return value of lock column for OJB optimistic locking
159      * @return value of lock column for OJB optimistic locking
160      */
161     public Integer getLockVerNbr() {
162         return lockVerNbr;
163     }
164 
165     /**
166      * Set value of lock column for OJB optimistic locking
167      * @param lockVerNbr value of lock column for OJB optimistic locking
168      */
169     public void setLockVerNbr(Integer lockVerNbr) {
170         this.lockVerNbr = lockVerNbr;
171     }
172 
173     /**
174      * Gets the recipient attribute. 
175      * @return Returns the recipient.
176      */
177     public String getRecipient() {
178         return recipient;
179     }
180 
181     /**
182      * Sets the recipient attribute value.
183      * @param recipients The recipient to set.
184      */
185     public void setRecipient(String recipient) {
186         this.recipient = recipient;
187     }
188 
189     /**
190      * Gets the content attribute. 
191      * @return Returns the content.
192      */
193     public String getContent() {
194         return content;
195     }
196 
197     /**
198      * Sets the content attribute value.
199      * @param content The content to set.
200      */
201     public void setContent(String content) {
202         this.content = content;
203     }
204 
205     /**
206      * Gets the contentType attribute. 
207      * @return Returns the contentType.
208      */
209     public String getContentType() {
210         return contentType;
211     }
212 
213     /**
214      * Sets the contentType attribute value.
215      * @param contentType The contentType to set.
216      */
217     public void setContentType(String contentType) {
218         this.contentType = contentType;
219     }
220 
221     /**
222      * @return the url
223      */
224     public String getUrl() {
225         return this.url;
226     }
227 
228     /**
229      * @param url the url
230      */
231     public void setUrl(String url) {
232         this.url = url;
233     }
234 
235     /**
236      * Gets the deliveryType attribute. 
237      * @return Returns the deliveryType.
238      */
239     public String getDeliveryType() {
240         return deliveryType;
241     }
242 
243     /**
244      * Sets the deliveryType attribute value.
245      * @param deliveryType The deliveryType to set.
246      */
247     public void setDeliveryType(String deliveryType) {
248         this.deliveryType = deliveryType.toUpperCase();
249     }
250 
251     /**
252      * Gets the title
253      * @return the title of this notification
254      */
255     public String getTitle() {
256         return title;
257     }
258 
259     /**
260      * Sets the title
261      * @param title the title of this notification
262      */
263     public void setTitle(String title) {
264         this.title = title;
265     }
266 
267     /**
268      * Gets the channel
269      * @return the channel
270      */
271     public String getChannel() {
272         return this.channel;
273     }
274 
275     /**
276      * Sets the channel
277      * @param channel the channel
278      */
279     public void setChannel(String channel) {
280         this.channel = channel;
281     }
282 
283     /**
284      * Gets the producer
285      * @return the producer
286      */
287     public String getProducer() {
288         return this.producer;
289     }
290 
291     /**
292      * Sets the producer
293      * @param producer the producer
294      */
295     public void setProducer(String producer) {
296         this.producer = producer;
297     }
298 
299     /**
300      * @see java.lang.Object#toString()
301      */
302     @Override
303     public String toString() {
304         return new ToStringBuilder(this)
305                        .append("id", id)
306                        .append("creationDateTime", creationDateTime)
307                        .append("deliveryType", deliveryType)
308                        .append("recipient", recipient)
309                        .append("title", title)
310                        .append("channel", channel)
311                        .append("producer", producer)
312                        .append("content", StringUtils.abbreviate(content, 100))
313                        .append("contentType", contentType)
314                        .append("lockVerNbr", lockVerNbr)
315                        .toString();
316     }
317 
318 }