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 javax.persistence.CascadeType;
19  import javax.persistence.Column;
20  import javax.persistence.Entity;
21  import javax.persistence.FetchType;
22  import javax.persistence.Id;
23  import javax.persistence.JoinColumn;
24  import javax.persistence.OneToOne;
25  import javax.persistence.Table;
26  import javax.persistence.Version;
27  
28  import org.apache.commons.lang.builder.ToStringBuilder;
29  
30  /**
31   * This class represents an instance of a MessageDelivery.  A Message gets delivered to 
32   * recipients, possibly in various ways.  For each delivery type that a recipient gets sent to them, 
33   * they have an instance of this entity.
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  @Entity
37  @Table(name="KREN_MSG_DELIV_T")
38  public class MessageDelivery extends BaseLockable {
39      private static final Integer ZERO = Integer.valueOf(0);
40  
41      /**
42       * Field names
43       */
44      public static final String ID_FIELD = "id";
45      public static final String SYSTEMID_FIELD = "delivererSystemId";
46      public static final String MESSAGEID_FIELD = "message";
47      public static final String DELIVERY_STATUS = "deliveryStatus";
48      public static final String PROCESS_COUNT = "processCount";
49      
50      @Id
51  	@Column(name="MSG_DELIV_ID")
52  	private Long id;
53      @Column(name="TYP_NM", nullable=false)
54  	private String delivererTypeName;
55      @Column(name="SYS_ID", nullable=true)
56  	private String delivererSystemId;  // can hold an identifier from the endpoint deliverer mechanism system (i.e. workflow id, SMS id, etc)
57      @Column(name="STAT_CD", nullable=true)
58      private String deliveryStatus = MessageDeliveryStatus.UNDELIVERED.name();
59      @Column(name="PROC_CNT", nullable=true)
60      private Integer processCount = ZERO;
61  
62      /**
63       * This delivery's message
64       */
65      @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
66  	@JoinColumn(name="MSG_ID")
67  	private Message message;
68  
69      /**
70       * Lock column for OJB optimistic locking
71       */
72      @Version
73  	@Column(name="VER_NBR")
74  	private Integer lockVerNbr;
75      
76      /**
77       * Constructs a MessageDelivery instance.
78       */
79      public MessageDelivery() {
80      }
81  
82      /**
83       * Shallow-copy constructor
84       * @param md MessageDelivery to (shallow) copy
85       */
86      public MessageDelivery(MessageDelivery md) {
87          this.id = md.id;
88          this.delivererTypeName = md.delivererTypeName;
89          this.deliveryStatus = md.deliveryStatus;
90          this.delivererSystemId = md.delivererSystemId;
91          this.message = md.message;
92          this.lockVerNbr = md.lockVerNbr;
93      }
94  
95      /**
96       * Gets the id attribute. 
97       * @return Returns the id.
98       */
99      public Long getId() {
100         return id;
101     }
102 
103     /**
104      * Sets the id attribute value.
105      * @param id The id to set.
106      */
107     public void setId(Long id) {
108         this.id = id;
109     }
110 
111 
112     /**
113      * Return value of lock column for OJB optimistic locking
114      * @return value of lock column for OJB optimistic locking
115      */
116     public Integer getLockVerNbr() {
117         return lockVerNbr;
118     }
119 
120     /**
121      * Set value of lock column for OJB optimistic locking
122      * @param lockVerNbr value of lock column for OJB optimistic locking
123      */
124     public void setLockVerNbr(Integer lockVerNbr) {
125         this.lockVerNbr = lockVerNbr;
126     }
127 
128     /**
129      * Gets the deliveryStatus attribute. 
130      * @return Returns the deliveryStatus.
131      */
132     public String getDeliveryStatus() {
133         return deliveryStatus;
134     }
135 
136     /**
137      * Convenience method that sets the delivery status in a typesafe manner.
138      * This method is preferred to {@link #setDeliveryStatus(String)}
139      * @param deliveryStatus the MessageDeliveryStatus enum constant
140      */
141     public void setDeliveryStatus(MessageDeliveryStatus deliveryStatus) {
142         this.deliveryStatus = deliveryStatus.name();
143     }
144 
145     /**
146      * Sets the deliveryStatus attribute value.
147      * @param deliveryStatus The deliveryStatus to set.
148      */
149     public void setDeliveryStatus(String deliveryStatus) {
150         // Enums will throw an IllegalArgumentException from valueOf if there
151         // is no matching enum
152         MessageDeliveryStatus.valueOf(deliveryStatus);
153         this.deliveryStatus = deliveryStatus;
154     }
155 
156     /**
157      * @return the number of times processing has been attempted for this message
158      */
159     public Integer getProcessCount() {
160         return this.processCount;
161     }
162 
163     /**
164      * Sets the number of times processing has been attempted for this message
165      * @param processCount the number of times processing has been attempted for this message
166      */
167     public void setProcessCount(Integer processCount) {
168         this.processCount = processCount;
169     }
170 
171     /**
172      * Gets the delivererTypeName attribute. 
173      * @return Returns the delivererTypeName.
174      */
175     public String getDelivererTypeName() {
176         return delivererTypeName;
177     }
178 
179     /**
180      * Sets the delivererTypeName attribute value.
181      * @param delivererTypeName The delivererTypeName to set.
182      */
183     public void setDelivererTypeName(String delivererTypeName) {
184         this.delivererTypeName = delivererTypeName;
185     }
186 
187     /**
188      * Gets the delivererSystemId attribute. 
189      * @return Returns the delivererSystemId.
190      */
191     public String getDelivererSystemId() {
192         return delivererSystemId;
193     }
194 
195     /**
196      * Sets the delivererSystemId attribute value.
197      * @param delivererSystemId The delivererSystemId to set.
198      */
199     public void setDelivererSystemId(String delivererSystemId) {
200         this.delivererSystemId = delivererSystemId;
201     }
202 
203     /**
204      * @return this delivery's message
205      */
206     public Message getMessage() {
207         return this.message;
208     }
209 
210     /**
211      * Sets this delivery's message
212      * @param message the message to set
213      */
214     public void setMessage(Message message) {
215         this.message = message;
216     }
217 
218     /**
219      * @see java.lang.Object#toString()
220      */
221     @Override
222     public String toString() {
223         return new ToStringBuilder(this)
224                        .append("id", id)
225                        .append("deliveryStatus", deliveryStatus)
226                        .append("processCount", processCount)
227                        .append("delivererTypename", delivererTypeName)
228                        .append("delivererSystemId", delivererSystemId)
229                        .append("message", message == null ? null : message.getId())
230                        .toString();
231     }
232 }