1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actionitem;
17
18 import java.io.Serializable;
19 import java.sql.Timestamp;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.Id;
30 import javax.persistence.Inheritance;
31 import javax.persistence.InheritanceType;
32 import javax.persistence.NamedQueries;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.Table;
35 import javax.persistence.Transient;
36 import javax.persistence.Version;
37
38 import org.apache.commons.lang.StringUtils;
39 import org.apache.commons.lang.builder.ToStringBuilder;
40 import org.hibernate.annotations.GenericGenerator;
41 import org.hibernate.annotations.Parameter;
42 import org.joda.time.DateTime;
43 import org.kuali.rice.core.api.delegation.DelegationType;
44 import org.kuali.rice.core.api.util.RiceConstants;
45 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
46 import org.kuali.rice.kew.api.action.ActionItemContract;
47 import org.kuali.rice.kew.api.action.RecipientType;
48 import org.kuali.rice.kew.api.util.CodeTranslator;
49 import org.kuali.rice.kew.service.KEWServiceLocator;
50 import org.kuali.rice.kew.web.RowStyleable;
51 import org.kuali.rice.kim.api.group.Group;
52 import org.kuali.rice.kim.api.identity.Person;
53 import org.kuali.rice.kim.api.identity.principal.Principal;
54 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
55
56
57
58
59
60
61
62
63
64
65
66
67 @Entity
68 @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
69 @Table(name="KREW_ACTN_ITM_T")
70
71 @NamedQueries({
72 @NamedQuery(name="ActionItem.QuickLinks.FindActionListStatsByPrincipalId", query="SELECT docName, COUNT(*) FROM ActionItem WHERE principalId = :principalId " +
73 "AND (delegationType IS null OR delegationType != :delegationType) GROUP BY docName")
74 })
75 public class ActionItem implements ActionItemContract, RowStyleable, Serializable {
76
77 private static final long serialVersionUID = -1079562205125660151L;
78
79 @Id
80 @GeneratedValue(generator="KREW_ACTN_ITM_S")
81 @GenericGenerator(name="KREW_ACTN_ITM_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
82 @Parameter(name="sequence_name",value="KREW_ACTN_ITM_S"),
83 @Parameter(name="value_column",value="id")
84 })
85 @Column(name="ACTN_ITM_ID")
86 private String id;
87 @Column(name="PRNCPL_ID")
88 private String principalId;
89 @Column(name="ASND_DT")
90 private Timestamp dateAssigned;
91 @Column(name="RQST_CD")
92 private String actionRequestCd;
93 @Column(name="ACTN_RQST_ID", nullable=false)
94 private String actionRequestId;
95 @Column(name="DOC_HDR_ID")
96 private String documentId;
97 @Column(name="GRP_ID")
98 private String groupId;
99 @Column(name="DOC_HDR_TTL")
100 private String docTitle;
101 @Column(name="DOC_TYP_LBL")
102 private String docLabel;
103 @Column(name="DOC_HDLR_URL")
104 private String docHandlerURL;
105 @Version
106 @Column(name="VER_NBR")
107 private Integer lockVerNbr;
108 @Column(name="DOC_TYP_NM")
109 private String docName;
110 @Column(name="RSP_ID")
111 private String responsibilityId = "1";
112 @Column(name="ROLE_NM")
113 private String roleName;
114 @Column(name="DLGN_PRNCPL_ID")
115 private String delegatorPrincipalId;
116 @Column(name="DLGN_GRP_ID")
117 private String delegatorGroupId;
118 @Column(name="DLGN_TYP")
119 private String delegationType;
120 @Column(name="RQST_LBL")
121 private String requestLabel;
122
123
124
125
126
127 @Transient
128 private Timestamp lastApprovedDate;
129 @Transient
130 private Integer actionItemIndex;
131 @Transient
132 private Map customActions = new HashMap();
133 @Transient
134 private String dateAssignedString;
135 @Transient
136 private String actionToTake;
137 @Transient
138 private String rowStyleClass;
139
140
141
142 public void beforeInsert(){
143 OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
144 }
145
146 public String getId() {
147 return id;
148 }
149
150 public String getPrincipalId() {
151 return principalId;
152 }
153
154 public Timestamp getDateAssigned() {
155 return dateAssigned;
156 }
157
158 public DateTime getDateTimeAssigned() {
159 return new DateTime(dateAssigned);
160 }
161
162 public String getActionRequestCd() {
163 return actionRequestCd;
164 }
165
166 public String getActionRequestId() {
167 return actionRequestId;
168 }
169
170 public String getDocumentId() {
171 return documentId;
172 }
173
174 public String getGroupId() {
175 return groupId;
176 }
177
178 public String getDocTitle() {
179 return docTitle;
180 }
181
182 public String getDocLabel() {
183 return docLabel;
184 }
185
186 public String getDocHandlerURL() {
187 return docHandlerURL;
188 }
189
190 public Integer getLockVerNbr() {
191 return lockVerNbr;
192 }
193
194 public String getDocName() {
195 return docName;
196 }
197
198 public String getResponsibilityId() {
199 return responsibilityId;
200 }
201
202 public String getRoleName() {
203 return roleName;
204 }
205
206 public String getDelegatorPrincipalId() {
207 return delegatorPrincipalId;
208 }
209
210 public String getDelegatorGroupId() {
211 return delegatorGroupId;
212 }
213
214 public DelegationType getDelegationType() {
215 return DelegationType.fromCode(delegationType);
216 }
217
218 public String getRequestLabel() {
219 return this.requestLabel;
220 }
221
222 public Timestamp getLastApprovedDate() {
223 return this.lastApprovedDate;
224 }
225
226 public Integer getActionItemIndex() {
227 return actionItemIndex;
228 }
229
230 public Map getCustomActions() {
231 return customActions;
232 }
233
234 public String getDateAssignedString() {
235 if (dateAssignedString == null || dateAssignedString.trim().equals("")){
236 return RiceConstants.getDefaultDateFormat().format(getDateAssigned());
237 } else {
238 return dateAssignedString;
239 }
240 }
241
242 public String getActionToTake() {
243 return actionToTake;
244 }
245
246 public String getRowStyleClass() {
247 return rowStyleClass;
248 }
249
250 private Group getGroup(String groupId) {
251 if (StringUtils.isBlank(groupId)) {
252 return null;
253 }
254 return KimApiServiceLocator.getGroupService().getGroup(groupId);
255 }
256
257 public Group getGroup(){
258 return getGroup(groupId);
259 }
260
261 private Person getPerson(String workflowId) {
262 if (StringUtils.isBlank(workflowId)) {
263 return null;
264 }
265 return KimApiServiceLocator.getPersonService().getPerson(workflowId);
266 }
267
268 public Person getPerson() {
269 return getPerson(principalId);
270 }
271
272 public Person getDelegatorPerson() {
273 return getPerson(delegatorPrincipalId);
274 }
275
276 public String getRecipientTypeCode() {
277 String recipientTypeCode = RecipientType.PRINCIPAL.getCode();
278 if (getRoleName() != null) {
279 recipientTypeCode = RecipientType.ROLE.getCode();
280 }
281 if (getGroupId() != null) {
282 recipientTypeCode = RecipientType.GROUP.getCode();
283 }
284 return recipientTypeCode;
285 }
286
287 public String getActionRequestLabel() {
288 if (StringUtils.isNotBlank(getRequestLabel())) {
289 return getRequestLabel();
290 }
291 return CodeTranslator.getActionRequestLabel(getActionRequestCd());
292 }
293
294 public boolean isWorkgroupItem() {
295 return getGroupId() != null;
296 }
297
298 public Principal getPrincipal(){
299 return KimApiServiceLocator.getIdentityService().getPrincipal(principalId);
300 }
301
302 public void setRowStyleClass(String rowStyleClass) {
303 this.rowStyleClass = rowStyleClass;
304 }
305
306 public void setResponsibilityId(String responsibilityId) {
307 this.responsibilityId = responsibilityId;
308 }
309
310 public void setDocName(String docName) {
311 this.docName = docName;
312 }
313
314 public void setActionRequestCd(String actionRequestCd) {
315 this.actionRequestCd = actionRequestCd;
316 }
317
318 public void setDateAssigned(Timestamp dateAssigned) {
319 this.dateAssigned = dateAssigned;
320 }
321
322 public void setPrincipalId(String principalId) {
323 this.principalId = principalId;
324 }
325
326 public void setLockVerNbr(Integer lockVerNbr) {
327 this.lockVerNbr = lockVerNbr;
328 }
329
330 public void setDocumentId(String documentId) {
331 this.documentId = documentId;
332 }
333
334 public void setId(String id) {
335 this.id = id;
336 }
337
338 public void setActionRequestId(String actionRequestId) {
339 this.actionRequestId = actionRequestId;
340 }
341
342 public void setDocHandlerURL(String docHandlerURL) {
343 this.docHandlerURL = docHandlerURL;
344 }
345
346 public void setGroupId(String groupId) {
347 this.groupId = groupId;
348 }
349
350 public void setDocLabel(String docLabel) {
351 this.docLabel = docLabel;
352 }
353
354 public void setDocTitle(String docTitle) {
355 this.docTitle = docTitle;
356 }
357
358 public void setRoleName(String roleName) {
359 this.roleName = roleName;
360 }
361
362 public void setDelegatorPrincipalId(String delegatorPrincipalId) {
363 this.delegatorPrincipalId = delegatorPrincipalId;
364 }
365
366 public void setDelegatorGroupId(String delegatorGroupId) {
367 this.delegatorGroupId = delegatorGroupId;
368 }
369
370 public void setDateAssignedString(String dateAssignedString) {
371 this.dateAssignedString = dateAssignedString;
372 }
373
374 public void setActionToTake(String actionToTake) {
375 this.actionToTake = actionToTake;
376 }
377
378 public void setActionItemIndex(Integer actionItemIndex) {
379 this.actionItemIndex = actionItemIndex;
380 }
381
382 public void setCustomActions(Map customActions) {
383 this.customActions = customActions;
384 }
385
386 public void setDelegationType(DelegationType delegationType) {
387 this.delegationType = delegationType == null ? null : delegationType.getCode();
388 }
389
390
391 public void setLastApprovedDate(Timestamp lastApprovedDate) {
392 this.lastApprovedDate = lastApprovedDate;
393 }
394
395 public void setRequestLabel(String requestLabel) {
396 this.requestLabel = requestLabel;
397 }
398
399 public String toString() {
400 return new ToStringBuilder(this).append("id", id)
401 .append("workflowId", principalId)
402 .append("id", id)
403 .append("workflowId", principalId)
404 .append("dateAssigned", dateAssigned)
405 .append("actionRequestCd", actionRequestCd)
406 .append("actionRequestId", actionRequestId)
407 .append("documentId", documentId)
408 .append("groupId", groupId)
409 .append("docTitle", docTitle)
410 .append("docLabel", docLabel)
411 .append("docHandlerURL", docHandlerURL)
412 .append("lockVerNbr", lockVerNbr)
413 .append("docName", docName)
414 .append("responsibilityId", responsibilityId)
415 .append("rowStyleClass", rowStyleClass)
416 .append("roleName", roleName)
417 .append("delegatorPrincipalId", delegatorPrincipalId)
418 .append("delegatorGroupId", delegatorGroupId)
419 .append("dateAssignedString", dateAssignedString)
420 .append("actionToTake", actionToTake)
421 .append("delegationType", delegationType)
422 .append("actionItemIndex", actionItemIndex)
423 .append("customActions", customActions)
424 .append("lastApprovedDate", lastApprovedDate)
425 .toString();
426 }
427
428 public static org.kuali.rice.kew.api.action.ActionItem to(ActionItem bo) {
429 if (bo == null) {
430 return null;
431 }
432 return org.kuali.rice.kew.api.action.ActionItem.Builder.create(bo).build();
433 }
434
435 public static List<org.kuali.rice.kew.api.action.ActionItem> to(Collection<ActionItem> bos) {
436 if (bos == null)
437 return null;
438 if (bos.isEmpty())
439 return new ArrayList<org.kuali.rice.kew.api.action.ActionItem>();
440
441 List<org.kuali.rice.kew.api.action.ActionItem> dtos = new ArrayList<org.kuali.rice.kew.api.action.ActionItem>(bos.size());
442 for (ActionItem bo : bos) {
443 dtos.add(ActionItem.to(bo));
444 }
445 return dtos;
446 }
447 }