View Javadoc

1   /**
2    * Copyright 2005-2013 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.kew.actionitem;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.commons.lang.builder.ToStringBuilder;
20  import org.hibernate.annotations.GenericGenerator;
21  import org.hibernate.annotations.Parameter;
22  import org.joda.time.DateTime;
23  import org.kuali.rice.core.api.delegation.DelegationType;
24  import org.kuali.rice.core.api.util.RiceConstants;
25  import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
26  import org.kuali.rice.kew.api.action.ActionItemContract;
27  import org.kuali.rice.kew.api.action.RecipientType;
28  import org.kuali.rice.kew.api.util.CodeTranslator;
29  import org.kuali.rice.kew.service.KEWServiceLocator;
30  import org.kuali.rice.kew.web.RowStyleable;
31  import org.kuali.rice.kim.api.group.Group;
32  import org.kuali.rice.kim.api.identity.principal.Principal;
33  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
34  
35  import javax.persistence.Column;
36  import javax.persistence.Entity;
37  import javax.persistence.GeneratedValue;
38  import javax.persistence.Id;
39  import javax.persistence.Inheritance;
40  import javax.persistence.InheritanceType;
41  import javax.persistence.NamedQueries;
42  import javax.persistence.NamedQuery;
43  import javax.persistence.Table;
44  import javax.persistence.Transient;
45  import javax.persistence.Version;
46  import java.io.Serializable;
47  import java.sql.Timestamp;
48  import java.util.ArrayList;
49  import java.util.Collection;
50  import java.util.HashMap;
51  import java.util.List;
52  import java.util.Map;
53  
54  /**
55   * This is the model for action items. These are displayed as the action list as well.  Mapped to ActionItemService.
56   * NOTE: This object contains denormalized fields that have been copied from related ActionRequestValue and DocumentRouteHeaderValue
57   * objects for performance reasons.  These should be preserved and their related objects should not be added to the OJB
58   * mapping as we do not want them loaded for each ActionItem object.
59   *
60   * @author Kuali Rice Team (rice.collab@kuali.org)
61   *
62   */
63  
64  
65  @Entity
66  @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
67  @Table(name="KREW_ACTN_ITM_T")
68  //@Sequence(name="KREW_ACTN_ITM_S",property="id")
69  @NamedQueries({
70      @NamedQuery(name="ActionItem.QuickLinks.FindActionListStatsByPrincipalId", query="SELECT docName, COUNT(*) FROM ActionItem WHERE principalId = :principalId " +
71          "AND (delegationType IS null OR delegationType != :delegationType) GROUP BY docName")
72  })
73  public class ActionItem implements ActionItemContract, Serializable {
74  
75      private static final long serialVersionUID = -1079562205125660151L;
76  
77      @Id
78      @GeneratedValue(generator="KREW_ACTN_ITM_S")
79  	@GenericGenerator(name="KREW_ACTN_ITM_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
80  			@Parameter(name="sequence_name",value="KREW_ACTN_ITM_S"),
81  			@Parameter(name="value_column",value="id")
82  	})
83      @Column(name="ACTN_ITM_ID")
84  	private String id;
85      @Column(name="PRNCPL_ID")
86  	private String principalId;
87  	@Column(name="ASND_DT")
88  	private Timestamp dateAssigned;
89      @Column(name="RQST_CD")
90  	private String actionRequestCd;
91      @Column(name="ACTN_RQST_ID", nullable=false)
92  	private String actionRequestId;
93      @Column(name="DOC_HDR_ID")//, insertable=false, updatable=false)
94  	private String documentId;
95      @Column(name="GRP_ID")
96  	private String groupId;
97      @Column(name="DOC_HDR_TTL")
98  	private String docTitle;
99      @Column(name="DOC_TYP_LBL")
100 	private String docLabel;
101     @Column(name="DOC_HDLR_URL")
102 	private String docHandlerURL;
103     @Column(name="DOC_TYP_NM")
104 	private String docName;
105     @Column(name="RSP_ID")
106     private String responsibilityId = "1";
107     @Column(name="ROLE_NM")
108 	private String roleName;
109     @Column(name="DLGN_PRNCPL_ID")
110 	private String delegatorPrincipalId;
111     @Column(name="DLGN_GRP_ID")
112 	private String delegatorGroupId;
113     @Column(name="DLGN_TYP")
114 	private String delegationType;
115     @Column(name="RQST_LBL")
116     private String requestLabel;
117 
118     // used by Document Operations screen
119     @Transient
120     private String dateAssignedStringValue;
121 
122 
123     //@PrePersist
124     public void beforeInsert(){
125         OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
126     }
127 
128     @Deprecated
129     @Override
130     public String getActionToTake() {
131         // deprecated, always return null (see the contract javadoc for more details)
132         return null;
133     }
134 
135     @Deprecated
136     @Override
137     public String getDateAssignedString() {
138         // deprecated, always return null (see the contract javadoc for more details)
139         return null;
140     }
141 
142     public String getDateAssignedStringValue() {
143         if (StringUtils.isBlank(dateAssignedStringValue)) {
144             return RiceConstants.getDefaultDateFormat().format(getDateAssigned());
145         }
146         return dateAssignedStringValue;
147     }
148 
149     public void setDateAssignedStringValue(String dateAssignedStringValue) {
150         this.dateAssignedStringValue = dateAssignedStringValue;
151     }
152     
153     public String getId() {
154         return id;
155     }
156     
157     public String getPrincipalId() {
158         return principalId;
159     }
160     
161     public Timestamp getDateAssigned() {
162         return dateAssigned;
163     }
164 
165     public DateTime getDateTimeAssigned() {
166         return new DateTime(dateAssigned);
167     }
168     
169     public String getActionRequestCd() {
170         return actionRequestCd;
171     }
172     
173     public String getActionRequestId() {
174         return actionRequestId;
175     }
176     
177     public String getDocumentId() {
178         return documentId;
179     }
180     
181     public String getGroupId() {
182         return groupId;
183     }
184 
185     public String getDocTitle() {
186         return docTitle;
187     }
188     
189     public String getDocLabel() {
190         return docLabel;
191     }
192     
193     public String getDocHandlerURL() {
194         return docHandlerURL;
195     }
196     
197     public String getDocName() {
198         return docName;
199     }
200 
201     public String getResponsibilityId() {
202         return responsibilityId;
203     }
204 
205     public String getRoleName() {
206         return roleName;
207     }
208 
209     public String getDelegatorPrincipalId() {
210         return delegatorPrincipalId;
211     }
212 
213     public String getDelegatorGroupId() {
214         return delegatorGroupId;
215     }
216 
217     public DelegationType getDelegationType() {
218         return DelegationType.fromCode(delegationType);
219     }
220 
221     public String getRequestLabel() {
222         return this.requestLabel;
223     }
224 
225     private Group getGroup(String groupId) {
226     	if (StringUtils.isBlank(groupId)) {
227     		return null;
228     	}
229     	return KimApiServiceLocator.getGroupService().getGroup(groupId);
230     }
231 
232     public Group getGroup(){
233     	return getGroup(groupId);
234     }
235 
236     public String getRecipientTypeCode() {
237         String recipientTypeCode = RecipientType.PRINCIPAL.getCode();
238         if (getRoleName() != null) {
239             recipientTypeCode = RecipientType.ROLE.getCode();
240         }
241         if (getGroupId() != null) {
242             recipientTypeCode = RecipientType.GROUP.getCode();
243         }
244         return recipientTypeCode;
245     }
246     
247     public String getActionRequestLabel() {
248     	if (StringUtils.isNotBlank(getRequestLabel())) {
249     		return getRequestLabel();
250     	}
251     	return CodeTranslator.getActionRequestLabel(getActionRequestCd());
252     }
253 
254     public boolean isWorkgroupItem() {
255         return getGroupId() != null;
256     }
257     
258     public Principal getPrincipal(){
259         return KimApiServiceLocator.getIdentityService().getPrincipal(principalId);
260     }
261 
262     public void setResponsibilityId(String responsibilityId) {
263         this.responsibilityId = responsibilityId;
264     }
265     
266     public void setDocName(String docName) {
267         this.docName = docName;
268     }
269 
270     public void setActionRequestCd(String actionRequestCd) {
271         this.actionRequestCd = actionRequestCd;
272     }
273 
274     public void setDateAssigned(Timestamp dateAssigned) {
275         this.dateAssigned = dateAssigned;
276     }
277 
278     public void setPrincipalId(String principalId) {
279         this.principalId = principalId;
280     }
281     
282     public void setDocumentId(String documentId) {
283         this.documentId = documentId;
284     }
285 
286     public void setId(String id) {
287         this.id = id;
288     }
289 
290     public void setActionRequestId(String actionRequestId) {
291         this.actionRequestId = actionRequestId;
292     }
293 
294     public void setDocHandlerURL(String docHandlerURL) {
295         this.docHandlerURL = docHandlerURL;
296     }
297 
298     public void setGroupId(String groupId) {
299         this.groupId = groupId;
300     }
301 
302     public void setDocLabel(String docLabel) {
303         this.docLabel = docLabel;
304     }
305 
306     public void setDocTitle(String docTitle) {
307         this.docTitle = docTitle;
308     }
309     
310     public void setRoleName(String roleName) {
311         this.roleName = roleName;
312     }
313     
314     public void setDelegatorPrincipalId(String delegatorPrincipalId) {
315         this.delegatorPrincipalId = delegatorPrincipalId;
316     }
317     
318     public void setDelegatorGroupId(String delegatorGroupId) {
319         this.delegatorGroupId = delegatorGroupId;
320     }
321 
322     public void setDelegationType(DelegationType delegationType) {
323         this.delegationType = delegationType == null ? null : delegationType.getCode();
324     }
325     
326     public void setRequestLabel(String requestLabel) {
327         this.requestLabel = requestLabel;
328     }
329 
330     @Deprecated
331     @Override
332     public Integer getActionItemIndex() {
333         // deprecated, always return null (see the contract javadoc for more details)
334         return null;
335     }
336 
337     public String toString() {
338         return new ToStringBuilder(this).append("id", id)
339                                         .append("principalId", principalId)
340                                         .append("dateAssigned", dateAssigned)
341                                         .append("actionRequestCd", actionRequestCd)
342                                         .append("actionRequestId", actionRequestId)
343                                         .append("documentId", documentId)
344                                         .append("groupId", groupId)
345                                         .append("docTitle", docTitle)
346                                         .append("docLabel", docLabel)
347                                         .append("docHandlerURL", docHandlerURL)
348                                         .append("docName", docName)
349                                         .append("responsibilityId", responsibilityId)
350                                         .append("roleName", roleName)
351                                         .append("delegatorPrincipalId", delegatorPrincipalId)
352                                         .append("delegatorGroupId", delegatorGroupId)
353                                         .append("delegationType", delegationType)
354                                         .toString();
355     }
356 
357     public static org.kuali.rice.kew.api.action.ActionItem to(ActionItem bo) {
358         if (bo == null) {
359             return null;
360         }
361         return org.kuali.rice.kew.api.action.ActionItem.Builder.create(bo).build();
362     }
363     
364     public static List<org.kuali.rice.kew.api.action.ActionItem> to(Collection<ActionItem> bos) {
365         if (bos == null)
366             return null;
367         if (bos.isEmpty()) 
368             return new ArrayList<org.kuali.rice.kew.api.action.ActionItem>();
369         
370         List<org.kuali.rice.kew.api.action.ActionItem> dtos = new ArrayList<org.kuali.rice.kew.api.action.ActionItem>(bos.size());
371         for (ActionItem bo : bos) {
372             dtos.add(ActionItem.to(bo));
373         }
374         return dtos;
375     }
376 }