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