001/**
002 * Copyright 2005-2016 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 */
016package org.kuali.rice.kcb.bo;
017
018import java.sql.Timestamp;
019
020import javax.persistence.Basic;
021import javax.persistence.Column;
022import javax.persistence.Entity;
023import javax.persistence.FetchType;
024import javax.persistence.GeneratedValue;
025import javax.persistence.Id;
026import javax.persistence.Lob;
027import javax.persistence.Table;
028import javax.persistence.Version;
029
030import org.apache.commons.lang.StringUtils;
031import org.apache.commons.lang.builder.ToStringBuilder;
032import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
033
034/**
035 * This class represents an abstract message that has been sent to a single user
036 * recipient and may result in several {@link MessageDelivery}s.
037 * @author Kuali Rice Team (rice.collab@kuali.org)
038 */
039// this class could possibly just extend the MessageDTO
040@Entity
041@Table(name="KREN_MSG_T")
042public class Message {
043    /**
044     * Field names
045     */
046    public static final String ID_FIELD = "id";
047    public static final String ORIGINID_FIELD = "originId";
048
049    @Id
050    @GeneratedValue(generator="KREN_MSG_S")
051    @PortableSequenceGenerator(name="KREN_MSG_S")
052    @Column(name="MSG_ID")
053        private Long id;
054    /**
055     * The origin id is an id provided by the originating system that creates the message
056     */
057    @Column(name="ORGN_ID", nullable=false)
058        private String originId;
059    @Column(name="DELIV_TYP", nullable=false)
060        private String deliveryType;
061    @Column(name="CHNL", nullable=false)
062        private String channel;
063    @Column(name="PRODCR", nullable=true)
064        private String producer;
065    @Column(name="CRTE_DTTM", nullable=false)
066    private Timestamp creationDateTime = new Timestamp(System.currentTimeMillis());
067    @Column(name="TTL", nullable=true)
068        private String title;
069    @Lob
070        @Basic(fetch=FetchType.LAZY)
071        @Column(name="CNTNT", nullable=false)
072        private String content;
073    @Column(name="CNTNT_TYP", nullable=true)
074        private String contentType;
075    @Column(name="URL", nullable=true)
076        private String url;
077    @Column(name="RECIP_ID", nullable=false)
078        private String recipient;
079
080    /**
081     * Lock column for OJB optimistic locking
082     */
083    @Version
084        @Column(name="VER_NBR")
085        private Integer lockVerNbr;
086
087    /**
088     * Normal no-arg constructor
089     */
090    public Message() {}
091
092    /**
093     * Shallow-copy constructor
094     * @param m Message object to (shallow) copy
095     */
096    public Message(Message m) {
097        this.id = m.id;
098        this.channel = m.channel;
099        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}