View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.actionrequest;
18  
19  import java.sql.Timestamp;
20  import java.util.ArrayList;
21  import java.util.Iterator;
22  import java.util.List;
23  
24  import javax.persistence.CascadeType;
25  import javax.persistence.Column;
26  import javax.persistence.Entity;
27  import javax.persistence.FetchType;
28  import javax.persistence.Id;
29  import javax.persistence.JoinColumn;
30  import javax.persistence.ManyToMany;
31  import javax.persistence.ManyToOne;
32  import javax.persistence.NamedQueries;
33  import javax.persistence.NamedQuery;
34  import javax.persistence.OneToMany;
35  import javax.persistence.PrePersist;
36  import javax.persistence.Table;
37  import javax.persistence.Transient;
38  
39  import org.apache.commons.beanutils.BeanUtils;
40  import org.apache.commons.lang.StringUtils;
41  import org.apache.commons.lang.builder.ToStringBuilder;
42  import org.apache.commons.lang.builder.ToStringStyle;
43  import org.hibernate.annotations.Fetch;
44  import org.hibernate.annotations.FetchMode;
45  import org.kuali.rice.core.jpa.annotations.Sequence;
46  import org.kuali.rice.core.util.OrmUtils;
47  import org.kuali.rice.core.util.RiceConstants;
48  import org.kuali.rice.kew.actionitem.ActionItem;
49  import org.kuali.rice.kew.actiontaken.ActionTakenValue;
50  import org.kuali.rice.kew.bo.WorkflowPersistable;
51  import org.kuali.rice.kew.engine.CompatUtils;
52  import org.kuali.rice.kew.engine.node.RouteNode;
53  import org.kuali.rice.kew.engine.node.RouteNodeInstance;
54  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
55  import org.kuali.rice.kew.rule.RuleBaseValues;
56  import org.kuali.rice.kew.rule.service.RuleService;
57  import org.kuali.rice.kew.service.KEWServiceLocator;
58  import org.kuali.rice.kew.user.RoleRecipient;
59  import org.kuali.rice.kew.util.CodeTranslator;
60  import org.kuali.rice.kew.util.KEWConstants;
61  import org.kuali.rice.kim.bo.Group;
62  import org.kuali.rice.kim.bo.Person;
63  import org.kuali.rice.kim.bo.entity.KimPrincipal;
64  import org.kuali.rice.kim.service.KIMServiceLocator;
65  
66  
67  /**
68   * Bean mapped to DB. Represents ActionRequest to a workgroup, user or role.  Contains
69   * references to children/parent if a member of a graph
70   *
71   * @author Kuali Rice Team (rice.collab@kuali.org)
72   */
73  @Entity
74  @Table(name="KREW_ACTN_RQST_T")
75  @Sequence(name="KREW_ACTN_RQST_S", property="actionRequestId")
76  @NamedQueries({
77    @NamedQuery(name="ActionRequestValue.FindByRouteHeaderId", query="select arv from ActionRequestValue arv where arv.routeHeaderId = :routeHeaderId"),
78    @NamedQuery(name="ActionRequestValue.GetUserRequestCount", query="select count(arv) from ActionRequestValue arv where arv.routeHeaderId = :routeHeaderId and arv.recipientTypeCd = :recipientTypeCd and arv.principalId = :principalId and arv.currentIndicator = :currentIndicator"),
79    @NamedQuery(name="ActionRequestValue.FindActivatedByGroup", query="select count(arv) from ActionRequestValue arv where arv.groupId = :groupId and arv.currentIndicator = :currentIndicator and arv.status = :status"),
80    @NamedQuery(name="ActionRequestValue.FindAllByDocId", query="select arv from ActionRequestValue arv where arv.routeHeaderId = :routeHeaderId and arv.currentIndicator = :currentIndicator"),
81    @NamedQuery(name="ActionRequestValue.FindAllPendingByDocId", query="select arv from ActionRequestValue arv where arv.routeHeaderId = :routeHeaderId and arv.currentIndicator = :currentIndicator and (arv.status = '" + KEWConstants.ACTION_REQUEST_INITIALIZED + "' or arv.status = '" + KEWConstants.ACTION_REQUEST_ACTIVATED + "')"),
82    @NamedQuery(name="ActionRequestValue.FindAllRootByDocId", query="select arv from ActionRequestValue arv where arv.routeHeaderId = :routeHeaderId and arv.currentIndicator = :currentIndicator and arv.parentActionRequest is null"),
83    @NamedQuery(name="ActionRequestValue.FindByStatusAndDocId", query="select arv from ActionRequestValue arv where arv.routeHeaderId = :routeHeaderId and arv.currentIndicator = :currentIndicator and arv.status = :status"),
84    @NamedQuery(name="ActionRequestValue.FindPendingByActionRequestedAndDocId", query="select arv from ActionRequestValue arv where arv.routeHeaderId = :routeHeaderId and arv.currentIndicator = :currentIndicator and arv.actionRequested = :actionRequested and (arv.status = '" + KEWConstants.ACTION_REQUEST_INITIALIZED + "' or arv.status = '" + KEWConstants.ACTION_REQUEST_ACTIVATED + "')"),
85    @NamedQuery(name="ActionRequestValue.FindPendingByDocIdAtOrBelowRouteLevel", query="select arv from ActionRequestValue arv where arv.routeHeaderId = :routeHeaderId and arv.currentIndicator = :currentIndicator and arv.status <> :status and arv.routeLevel <= :routeLevel"),
86    @NamedQuery(name="ActionRequestValue.FindPendingByResponsibilityIds", query="select arv from ActionRequestValue arv where arv.responsibilityId in (:responsibilityIds) and (arv.status = '" + KEWConstants.ACTION_REQUEST_INITIALIZED + "' or arv.status = '" + KEWConstants.ACTION_REQUEST_ACTIVATED + "')"),
87    @NamedQuery(name="ActionRequestValue.FindPendingRootRequestsByDocIdAtOrBelowRouteLevel", query="select arv from ActionRequestValue arv where arv.routeHeaderId = :routeHeaderId and arv.currentIndicator = :currentIndicator and arv.parentActionRequest is null and arv.status <> :status and routeLevel <= :routeLevel"),
88    @NamedQuery(name="ActionRequestValue.FindPendingRootRequestsByDocIdAtRouteLevel", query="select arv from ActionRequestValue arv where arv.routeHeaderId = :routeHeaderId and arv.currentIndicator = :currentIndicator and arv.parentActionRequest is null and arv.status <> :status and routeLevel = :routeLevel"),
89    @NamedQuery(name="ActionRequestValue.FindPendingRootRequestsByDocIdAtRouteNode", query="select arv from ActionRequestValue arv where arv.routeHeaderId = :routeHeaderId and arv.currentIndicator = :currentIndicator and arv.parentActionRequest is null and arv.nodeInstance.routeNodeInstanceId = :routeNodeInstanceId and (arv.status = '" + KEWConstants.ACTION_REQUEST_INITIALIZED + "' or arv.status = '" + KEWConstants.ACTION_REQUEST_ACTIVATED + "')"),
90    @NamedQuery(name="ActionRequestValue.FindPendingRootRequestsByDocumentType", query="select arv from ActionRequestValue arv where arv.routeHeader.documentTypeId = :documentTypeId and arv.currentIndicator = :currentIndicator and arv.parentActionRequest is null and (arv.status = '" + KEWConstants.ACTION_REQUEST_INITIALIZED + "' or arv.status = '" + KEWConstants.ACTION_REQUEST_ACTIVATED + "')"),
91    @NamedQuery(name="ActionRequestValue.FindRootRequestsByDocIdAtRouteNode", query="select arv from ActionRequestValue arv where arv.routeHeaderId = :routeHeaderId and arv.currentIndicator = :currentIndicator and arv.parentActionRequest is null and arv.nodeInstance.routeNodeInstanceId = :routeNodeInstanceId"),
92    @NamedQuery(name="ActionRequestValue.GetRequestGroupIds", query="select arv.groupId from ActionRequestValue arv where arv.routeHeaderId = :routeHeaderId and arv.currentIndicator = :currentIndicator and arv.recipientTypeCd = :recipientTypeCd"),
93    @NamedQuery(name="ActionRequestValue.FindByStatusAndGroupId", query="select arv from ActionRequestValue arv where arv.groupId = :groupId and arv.currentIndicator = :currentIndicator and arv.status = :status")
94  })
95  public class ActionRequestValue implements WorkflowPersistable {
96  
97  	private static final long serialVersionUID = 8781414791855848385L;
98  
99  	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionRequestValue.class);
100 
101     private static final String ACTION_CODE_RANK = "FKACB";//B is a hack for allowing blanket approves to count for approve and complete requests in findPreviousAction in ActionTakenService this is a hack and accounts for the -3 on compareActionCode
102     private static final String RECIPIENT_TYPE_RANK = "RWU";
103     private static final String DELEGATION_TYPE_RANK = "SPN";
104 
105     @Id
106 	@Column(name="ACTN_RQST_ID")
107 	private Long actionRequestId;
108     @Column(name="ACTN_RQST_CD")
109 	private String actionRequested;
110     @Column(name="DOC_HDR_ID", insertable=false, updatable=false)
111 	private Long routeHeaderId;
112     @Column(name="STAT_CD")
113 	private String status;
114     @Column(name="RSP_ID")
115 	private Long responsibilityId;
116     @Column(name="GRP_ID")
117 	private String groupId;
118     @Column(name="RECIP_TYP_CD")
119 	private String recipientTypeCd;
120     @Column(name="PRIO_NBR")
121 	private Integer priority;
122     @Column(name="RTE_LVL_NBR")
123 	private Integer routeLevel;
124     @Column(name="ACTN_TKN_ID", insertable=false, updatable=false)
125 	private Long actionTakenId;
126     @Column(name="DOC_VER_NBR")
127     private Integer docVersion = 1;
128 	@Column(name="CRTE_DT")
129 	private java.sql.Timestamp createDate;
130     @Column(name="RSP_DESC_TXT")
131 	private String responsibilityDesc;
132     @Column(name="ACTN_RQST_ANNOTN_TXT")
133 	private String annotation;
134     @Column(name="VER_NBR")
135 	private Integer jrfVerNbr;
136     @Column(name="PRNCPL_ID")
137 	private String principalId;
138     @Column(name="FRC_ACTN")
139 	private Boolean forceAction;
140     @Column(name="PARNT_ID", insertable=false, updatable=false)
141 	private Long parentActionRequestId;
142     @Column(name="QUAL_ROLE_NM")
143 	private String qualifiedRoleName;
144     @Column(name="ROLE_NM")
145 	private String roleName;
146     @Column(name="QUAL_ROLE_NM_LBL_TXT")
147 	private String qualifiedRoleNameLabel;
148     @Transient
149     private String displayStatus;
150     @Column(name="RULE_ID")
151 	private Long ruleBaseValuesId;
152 
153     @Column(name="DLGN_TYP")
154     private String delegationType = KEWConstants.DELEGATION_NONE;
155     @Column(name="APPR_PLCY")
156 	private String approvePolicy;
157 
158     @ManyToOne(fetch=FetchType.EAGER)
159 	@JoinColumn(name="PARNT_ID")
160 	private ActionRequestValue parentActionRequest;
161     @Fetch(value = FetchMode.SUBSELECT)
162     @ManyToMany(mappedBy="parentActionRequest",cascade={CascadeType.PERSIST, CascadeType.MERGE},fetch=FetchType.EAGER)
163     private List<ActionRequestValue> childrenRequests = new ArrayList<ActionRequestValue>();
164     @ManyToOne(fetch=FetchType.EAGER)
165 	@JoinColumn(name="ACTN_TKN_ID")
166 	private ActionTakenValue actionTaken;
167     @ManyToOne(fetch=FetchType.EAGER)
168 	@JoinColumn(name="DOC_HDR_ID")
169 	private DocumentRouteHeaderValue routeHeader;
170     @Fetch(value = FetchMode.SUBSELECT)
171     @OneToMany(fetch=FetchType.EAGER,mappedBy="actionRequestId")
172     private List<ActionItem> actionItems = new ArrayList<ActionItem>();
173     @Column(name="CUR_IND")
174     private Boolean currentIndicator = true;
175     @Transient
176     private String createDateString;
177     @Transient
178     private String groupName;
179 
180     /* New Workflow 2.1 Field */
181     // The node instance at which this request was generated
182     @ManyToOne(fetch=FetchType.EAGER/*, cascade={CascadeType.PERSIST}*/)
183 	@JoinColumn(name="RTE_NODE_INSTN_ID")
184 	private RouteNodeInstance nodeInstance;
185 
186     @Column(name="RQST_LBL")
187     private String requestLabel;
188     
189     @Transient
190     private boolean resolveResponsibility = true;
191     
192     public ActionRequestValue() {
193         createDate = new Timestamp(System.currentTimeMillis());
194     }
195     
196     @PrePersist
197     public void beforeInsert(){
198     	OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
199     }
200    
201     public Group getGroup() {
202         if (getGroupId() == null) {
203             LOG.error("Attempting to get a group with a blank group id");
204             return null;
205         }
206         return KIMServiceLocator.getIdentityManagementService().getGroup(getGroupId());
207     }
208 
209     public String getRouteLevelName() {
210         // this is for backward compatibility of requests which have not been converted
211         if (CompatUtils.isRouteLevelRequest(this)) {
212             int routeLevelInt = getRouteLevel();
213             if (routeLevelInt == KEWConstants.EXCEPTION_ROUTE_LEVEL) {
214                 return "Exception";
215             }
216 
217             List routeLevelNodes = CompatUtils.getRouteLevelCompatibleNodeList(routeHeader.getDocumentType());
218             if (!(routeLevelInt < routeLevelNodes.size())) {
219                 return "Not Found";
220             }
221             return ((RouteNode)routeLevelNodes.get(routeLevelInt)).getRouteNodeName();
222         } else {
223             return (nodeInstance == null ? "Exception" : nodeInstance.getName());
224         }
225     }
226 
227     public boolean isUserRequest() {
228         return principalId != null;
229     }
230 
231     public KimPrincipal getPrincipal() {
232     	if (getPrincipalId() == null) {
233     		return null;
234     	}
235     	return KEWServiceLocator.getIdentityHelperService().getPrincipal(getPrincipalId());
236     }
237     
238     public Person getPerson() {
239     	if (getPrincipalId() == null) {
240     		return null;
241     	}
242     	return KIMServiceLocator.getPersonService().getPerson(getPrincipalId());
243     }
244 
245     public String getDisplayName() {
246     	if (isUserRequest()) {
247     	    return getPerson().getName();
248     	} else if (isGroupRequest()) {
249     		return getGroup().getGroupName();
250     	} else if (isRoleRequest()) {
251     		return getRoleName();
252     	}
253     	return "";
254     }
255 
256     public Recipient getRecipient() {
257         if (getPrincipalId() != null) {
258             return new KimPrincipalRecipient(getPrincipal());
259         } else if (getGroupId() != null){
260             return new KimGroupRecipient(getGroup());
261         } else {
262         	return new RoleRecipient(this.getRoleName());
263         }
264     }
265 
266     public boolean isPending() {
267         return KEWConstants.ACTION_REQUEST_INITIALIZED.equals(getStatus()) || KEWConstants.ACTION_REQUEST_ACTIVATED.equals(getStatus());
268     }
269 
270     public DocumentRouteHeaderValue getRouteHeader() {
271         return routeHeader;
272     }
273 
274     public String getStatusLabel() {
275         return CodeTranslator.getActionRequestStatusLabel(getStatus());
276     }
277 
278     public String getActionRequestedLabel() {
279     	if (StringUtils.isNotBlank(getRequestLabel())) {
280     		return getRequestLabel();
281     	}
282     	return CodeTranslator.getActionRequestLabel(getActionRequested());
283     }
284 
285     /**
286      * @param routeHeader
287      *            The routeHeader to set.
288      */
289     public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
290         this.routeHeader = routeHeader;
291     }
292 
293     /**
294      * @return Returns the actionTaken.
295      */
296     public ActionTakenValue getActionTaken() {
297         return actionTaken;
298     }
299 
300     /**
301      * @param actionTaken
302      *            The actionTaken to set.
303      */
304     public void setActionTaken(ActionTakenValue actionTaken) {
305         this.actionTaken = actionTaken;
306     }
307 
308     /**
309      * @return Returns the actionRequested.
310      */
311     public String getActionRequested() {
312         return actionRequested;
313     }
314 
315     /**
316      * @param actionRequested
317      *            The actionRequested to set.
318      */
319     public void setActionRequested(String actionRequested) {
320         this.actionRequested = actionRequested;
321     }
322 
323     /**
324      * @return Returns the actionRequestId.
325      */
326     public Long getActionRequestId() {
327         return actionRequestId;
328     }
329 
330     /**
331      * @param actionRequestId
332      *            The actionRequestId to set.
333      */
334     public void setActionRequestId(Long actionRequestId) {
335         this.actionRequestId = actionRequestId;
336     }
337 
338     /**
339      * @return Returns the actionTakenId.
340      */
341     public Long getActionTakenId() {
342         return actionTakenId;
343     }
344 
345     /**
346      * @param actionTakenId
347      *            The actionTakenId to set.
348      */
349     public void setActionTakenId(Long actionTakenId) {
350         this.actionTakenId = actionTakenId;
351     }
352 
353     /**
354      * @return Returns the annotation.
355      */
356     public String getAnnotation() {
357         return annotation;
358     }
359 
360     /**
361      * @param annotation
362      *            The annotation to set.
363      */
364     public void setAnnotation(String annotation) {
365         this.annotation = annotation;
366     }
367 
368     /**
369      * @return Returns the createDate.
370      */
371     public java.sql.Timestamp getCreateDate() {
372         return createDate;
373     }
374 
375     /**
376      * @param createDate
377      *            The createDate to set.
378      */
379     public void setCreateDate(java.sql.Timestamp createDate) {
380         this.createDate = createDate;
381     }
382 
383     /**
384      * @return Returns the docVersion.
385      */
386     public Integer getDocVersion() {
387         return docVersion;
388     }
389 
390     /**
391      * @param docVersion
392      *            The docVersion to set.
393      */
394     public void setDocVersion(Integer docVersion) {
395         this.docVersion = docVersion;
396     }
397 
398     public String getPrincipalId() {
399         return principalId;
400     }
401 
402     public void setPrincipalId(String principalId) {
403         this.principalId = principalId;
404     }
405     
406     /**
407      * @return Returns the forceAction.
408      */
409     public Boolean getForceAction() {
410         return forceAction;
411     }
412 
413     /**
414      * @param forceAction
415      *            The forceAction to set.
416      */
417     public void setForceAction(Boolean forceAction) {
418         this.forceAction = forceAction;
419     }
420 
421     /**
422      * @return Returns the jrfVerNbr.
423      */
424     public Integer getJrfVerNbr() {
425         return jrfVerNbr;
426     }
427 
428     /**
429      * @param jrfVerNbr
430      *            The jrfVerNbr to set.
431      */
432     public void setJrfVerNbr(Integer jrfVerNbr) {
433         this.jrfVerNbr = jrfVerNbr;
434     }
435 
436     /**
437      * @return Returns the priority.
438      */
439     public Integer getPriority() {
440         return priority;
441     }
442 
443     /**
444      * @param priority
445      *            The priority to set.
446      */
447     public void setPriority(Integer priority) {
448         this.priority = priority;
449     }
450 
451     /**
452      * @return Returns the recipientTypeCd.
453      */
454     public String getRecipientTypeCd() {
455         return recipientTypeCd;
456     }
457 
458     /**
459      * @param recipientTypeCd
460      *            The recipientTypeCd to set.
461      */
462     public void setRecipientTypeCd(String recipientTypeCd) {
463         this.recipientTypeCd = recipientTypeCd;
464     }
465 
466     /**
467      * @return Returns the responsibilityDesc.
468      */
469     public String getResponsibilityDesc() {
470         return responsibilityDesc;
471     }
472 
473     /**
474      * @param responsibilityDesc
475      *            The responsibilityDesc to set.
476      */
477     public void setResponsibilityDesc(String responsibilityDesc) {
478         this.responsibilityDesc = responsibilityDesc;
479     }
480 
481     /**
482      * @return Returns the responsibilityId.
483      */
484     public Long getResponsibilityId() {
485         return responsibilityId;
486     }
487 
488     /**
489      * @param responsibilityId
490      *            The responsibilityId to set.
491      */
492     public void setResponsibilityId(Long responsibilityId) {
493         this.responsibilityId = responsibilityId;
494     }
495 
496     /**
497      * @return Returns the routeHeaderId.
498      */
499     public Long getRouteHeaderId() {
500         return routeHeaderId;
501     }
502 
503     public void setRouteHeaderId(Long routeHeaderId) {
504         this.routeHeaderId = routeHeaderId;
505     }
506 
507     public Integer getRouteLevel() {
508         return routeLevel;
509     }
510 
511     public void setRouteLevel(Integer routeLevel) {
512         this.routeLevel = routeLevel;
513     }
514 
515     public String getStatus() {
516         return status;
517     }
518 
519     public void setStatus(String status) {
520         this.status = status;
521     }
522 
523     public String getGroupId() {
524         return groupId;
525     }
526 
527     public void setGroupId(String groupId) {
528         this.groupId = groupId;
529     }
530 
531     public Object copy(boolean preserveKeys) {
532         ActionRequestValue clone = new ActionRequestValue();
533         try {
534             BeanUtils.copyProperties(clone, this);
535         } catch (Exception e) {
536             throw new RuntimeException(e);
537         }
538         if (!preserveKeys) {
539             clone.setActionRequestId(null);
540         }
541         ActionTakenValue actionTakenClone = (ActionTakenValue) getActionTaken().copy(preserveKeys);
542         clone.setActionTaken(actionTakenClone);
543         return clone;
544     }
545 
546     public boolean isInitialized() {
547         return KEWConstants.ACTION_REQUEST_INITIALIZED.equals(getStatus());
548     }
549 
550     public boolean isActive() {
551         return KEWConstants.ACTION_REQUEST_ACTIVATED.equals(getStatus());
552     }
553 
554     public boolean isApproveOrCompleteRequest() {
555         return KEWConstants.ACTION_REQUEST_APPROVE_REQ.equals(getActionRequested()) || KEWConstants.ACTION_REQUEST_COMPLETE_REQ.equals(getActionRequested());
556     }
557 
558     public boolean isDone() {
559         return KEWConstants.ACTION_REQUEST_DONE_STATE.equals(getStatus());
560     }
561 
562     public boolean isReviewerUser() {
563         return KEWConstants.ACTION_REQUEST_USER_RECIPIENT_CD.equals(getRecipientTypeCd());
564     }
565 
566     public boolean isRecipientRoutedRequest(String principalId) {
567     	//before altering this method it is used in checkRouteLogAuthentication
568     	//don't break that method
569     	if (principalId == null || "".equals(principalId)) {
570     		return false;
571     	}
572 
573     	boolean isRecipientInGraph = false;
574     	if (isReviewerUser()) {
575     			isRecipientInGraph = getPrincipalId().equals(principalId);
576     	} else if (isGroupRequest()) {
577     		Group group = getGroup();
578 			if (group == null){
579 				LOG.error("Was unable to retrieve workgroup " + getGroupId());
580 			}
581     		isRecipientInGraph = KIMServiceLocator.getIdentityManagementService().isMemberOfGroup(principalId, group.getGroupId());
582     	}
583 
584 
585         for (ActionRequestValue childRequest : getChildrenRequests())
586         {
587             isRecipientInGraph = isRecipientInGraph || childRequest.isRecipientRoutedRequest(principalId);
588         }
589 
590     	return isRecipientInGraph;
591     }
592 
593     public boolean isRecipientRoutedRequest(Recipient recipient) {
594     	//before altering this method it is used in checkRouteLogAuthentication
595     	//don't break that method
596     	if (recipient == null) {
597     		return false;
598     	}
599 
600     	boolean isRecipientInGraph = false;
601     	if (isReviewerUser()) {
602     		if (recipient instanceof KimPrincipalRecipient) {
603     			isRecipientInGraph = getPrincipalId().equals(((KimPrincipalRecipient) recipient).getPrincipalId());
604     		} else if (recipient instanceof KimGroupRecipient){
605     			isRecipientInGraph = KIMServiceLocator.getIdentityManagementService().isMemberOfGroup(getPrincipalId(), ((KimGroupRecipient)recipient).getGroup().getGroupId());
606     		}
607 
608     	} else if (isGroupRequest()) {
609     		Group group = getGroup();
610 			if (group == null){
611 				LOG.error("Was unable to retrieve workgroup " + getGroupId());
612 			}
613     		if (recipient instanceof KimPrincipalRecipient) {
614     			KimPrincipalRecipient principalRecipient = (KimPrincipalRecipient)recipient;
615     			isRecipientInGraph = KIMServiceLocator.getIdentityManagementService().isMemberOfGroup(principalRecipient.getPrincipalId(), group.getGroupId());
616     		} else if (recipient instanceof KimGroupRecipient) {
617     			isRecipientInGraph = ((KimGroupRecipient) recipient).getGroup().getGroupId().equals(group.getGroupId());
618     		}
619     	}
620 
621 
622         for (ActionRequestValue childRequest : getChildrenRequests())
623         {
624             isRecipientInGraph = isRecipientInGraph || childRequest.isRecipientRoutedRequest(recipient);
625         }
626 
627     	return isRecipientInGraph;
628     }
629 
630     public boolean isGroupRequest(){
631     	return KEWConstants.ACTION_REQUEST_GROUP_RECIPIENT_CD.equals(getRecipientTypeCd());
632     }
633 
634     public boolean isRoleRequest() {
635         return KEWConstants.ACTION_REQUEST_ROLE_RECIPIENT_CD.equals(getRecipientTypeCd());
636     }
637 
638     public boolean isAcknowledgeRequest() {
639         return KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ.equals(getActionRequested());
640     }
641 
642     public boolean isApproveRequest() {
643         return KEWConstants.ACTION_REQUEST_APPROVE_REQ.equals(getActionRequested());
644     }
645 
646     public boolean isCompleteRequst() {
647         return KEWConstants.ACTION_REQUEST_COMPLETE_REQ.equals(getActionRequested());
648     }
649 
650     public boolean isFYIRequest() {
651         return KEWConstants.ACTION_REQUEST_FYI_REQ.equals(getActionRequested());
652     }
653 
654     /**
655      * Allows comparison of action requests to see which is greater responsibility. -1 : indicates code 1 is lesser responsibility than code 2 0 : indicates the same responsibility 1 : indicates code1 is greater responsibility than code 2 The priority of action requests is as follows: fyi < acknowledge < (approve == complete)
656      *
657      * @param code1
658      * @param code2
659      * @param completeAndApproveTheSame
660      * @return -1 if less than, 0 if equal, 1 if greater than
661      */
662     public static int compareActionCode(String code1, String code2, boolean completeAndApproveTheSame) {
663     	int cutoff = Integer.MAX_VALUE;
664     	if (completeAndApproveTheSame) {
665     		// hacked so that APPROVE and COMPLETE are equal
666     		cutoff = ACTION_CODE_RANK.length() - 3;
667     	}
668         Integer code1Index = Math.min(ACTION_CODE_RANK.indexOf(code1), cutoff);
669         Integer code2Index = Math.min(ACTION_CODE_RANK.indexOf(code2), cutoff);
670         return code1Index.compareTo(code2Index);
671     }
672 
673     /**
674      * Allows comparison of action requests to see which is greater responsibility. -1 : indicates type 1 is lesser responsibility than type 2 0 : indicates the same responsibility 1 : indicates type1 is greater responsibility than type 2
675      *
676      * @param type1
677      * @param type2
678      * @return -1 if less than, 0 if equal, 1 if greater than
679      */
680     public static int compareRecipientType(String type1, String type2) {
681         Integer type1Index = RECIPIENT_TYPE_RANK.indexOf(type1);
682         Integer type2Index = RECIPIENT_TYPE_RANK.indexOf(type2);
683         return type1Index.compareTo(type2Index);
684     }
685 
686     public static int compareDelegationType(String type1, String type2) {
687     	if (StringUtils.isEmpty(type1)) {
688     		type1 = "N";
689     	}
690     	if (StringUtils.isEmpty(type2)) {
691     		type2 = "N";
692     	}
693     	Integer type1Index = DELEGATION_TYPE_RANK.indexOf(type1);
694         Integer type2Index = DELEGATION_TYPE_RANK.indexOf(type2);
695         return type1Index.compareTo(type2Index);
696     }
697 
698     public List<ActionItem> getActionItems() {
699         return actionItems;
700     }
701 
702     public void setActionItems(List<ActionItem> actionItems) {
703         this.actionItems = actionItems;
704     }
705 
706     public Boolean getCurrentIndicator() {
707         return currentIndicator;
708     }
709 
710     public void setCurrentIndicator(Boolean currentIndicator) {
711         this.currentIndicator = currentIndicator;
712     }
713 
714     public Long getParentActionRequestId() {
715         return parentActionRequestId;
716     }
717 
718     public void setParentActionRequestId(Long parentActionRequestId) {
719         this.parentActionRequestId = parentActionRequestId;
720     }
721 
722     public ActionRequestValue getParentActionRequest() {
723         return parentActionRequest;
724     }
725 
726     public void setParentActionRequest(ActionRequestValue parentActionRequest) {
727         this.parentActionRequest = parentActionRequest;
728     }
729 
730     public List<ActionRequestValue> getChildrenRequests() {
731         return childrenRequests;
732     }
733 
734     public void setChildrenRequests(List<ActionRequestValue> childrenRequests) {
735         this.childrenRequests = childrenRequests;
736     }
737 
738     public String getQualifiedRoleName() {
739         return qualifiedRoleName;
740     }
741 
742     public void setQualifiedRoleName(String roleName) {
743         this.qualifiedRoleName = roleName;
744     }
745 
746     public String getDelegationType() {
747         return delegationType;
748     }
749 
750     public void setDelegationType(String delegatePolicy) {
751         this.delegationType = delegatePolicy;
752     }
753 
754     public String getRoleName() {
755         return roleName;
756     }
757 
758     public void setRoleName(String roleName) {
759         this.roleName = roleName;
760     }
761 
762     public String getApprovePolicy() {
763         return approvePolicy;
764     }
765 
766     public void setApprovePolicy(String requestType) {
767         this.approvePolicy = requestType;
768     }
769 
770     public boolean getHasApprovePolicy() {
771         return getApprovePolicy() != null;
772     }
773 
774     public boolean isDeactivated() {
775         return KEWConstants.ACTION_REQUEST_DONE_STATE.equals(getStatus());
776     }
777 
778     public boolean hasParent() {
779         return getParentActionRequest() != null;
780     }
781 
782     public boolean hasChild(ActionRequestValue actionRequest) {
783         if (actionRequest == null)
784             return false;
785         Long actionRequestId = actionRequest.getActionRequestId();
786         for (Iterator<ActionRequestValue> iter = getChildrenRequests().iterator(); iter.hasNext();) {
787             ActionRequestValue childRequest = iter.next();
788             if (childRequest.equals(actionRequest) || (actionRequestId != null && actionRequestId.equals(childRequest.getActionRequestId()))) {
789                 return true;
790             }
791         }
792         return false;
793     }
794 
795     public String getDisplayStatus() {
796         return displayStatus;
797     }
798 
799     public void setDisplayStatus(String displayStatus) {
800         this.displayStatus = displayStatus;
801     }
802 
803     public String getQualifiedRoleNameLabel() {
804         return qualifiedRoleNameLabel;
805     }
806 
807     public void setQualifiedRoleNameLabel(String qualifiedRoleNameLabel) {
808         this.qualifiedRoleNameLabel = qualifiedRoleNameLabel;
809     }
810 
811     public String getCreateDateString() {
812         if (createDateString == null || createDateString.trim().equals("")) {
813             return RiceConstants.getDefaultDateFormat().format(getCreateDate());
814         } else {
815             return createDateString;
816         }
817     }
818 
819     public void setCreateDateString(String createDateString) {
820         this.createDateString = createDateString;
821     }
822 
823     public RouteNodeInstance getNodeInstance() {
824 		return nodeInstance;
825 	}
826 
827     public String getPotentialNodeName() {
828         return (getNodeInstance() == null ? "" : getNodeInstance().getName());
829     }
830 
831 	public void setNodeInstance(RouteNodeInstance nodeInstance) {
832 		this.nodeInstance = nodeInstance;
833 	}
834 
835 	public String getRecipientTypeLabel() {
836         return (String) KEWConstants.ACTION_REQUEST_RECIPIENT_TYPE.get(getRecipientTypeCd());
837     }
838 
839     public RuleBaseValues getRuleBaseValues(){
840         if(ruleBaseValuesId != null){
841             return getRuleService().findRuleBaseValuesById(ruleBaseValuesId);
842         }
843         return null;
844     }
845     public Long getRuleBaseValuesId() {
846         return ruleBaseValuesId;
847     }
848 
849     public void setRuleBaseValuesId(Long ruleBaseValuesId) {
850         this.ruleBaseValuesId = ruleBaseValuesId;
851     }
852     
853 	private RuleService getRuleService() {
854         return (RuleService) KEWServiceLocator.getService(KEWServiceLocator.RULE_SERVICE);
855     }
856 
857     public boolean isPrimaryDelegator() {
858         boolean primaryDelegator = false;
859         for (Iterator<ActionRequestValue> iter = childrenRequests.iterator(); iter.hasNext();) {
860             ActionRequestValue childRequest = iter.next();
861             primaryDelegator = KEWConstants.DELEGATION_PRIMARY.equals(childRequest.getDelegationType()) || primaryDelegator;
862         }
863         return primaryDelegator;
864     }
865 
866     /**
867      * Used to get primary delegate names on route log in the 'Requested Of' section so primary delegate requests
868      * list the delegate and not the delegator as having the request 'IN ACTION LIST'.  This method doesn't recurse
869      * and therefore assume an AR structure.
870      *
871      * @return primary delgate requests
872      */
873     public List<ActionRequestValue> getPrimaryDelegateRequests() {
874         List<ActionRequestValue> primaryDelegateRequests = new ArrayList<ActionRequestValue>();
875         for (ActionRequestValue childRequest : childrenRequests)
876         {
877             if (KEWConstants.DELEGATION_PRIMARY.equals(childRequest.getDelegationType()))
878             {
879                 if (childRequest.isRoleRequest())
880                 {
881                     for (ActionRequestValue actionRequestValue : childRequest.getChildrenRequests())
882                     {
883                         primaryDelegateRequests.add(actionRequestValue);
884                     }
885                 } else
886                 {
887                 	primaryDelegateRequests.add(childRequest);
888                 }
889             }
890         }
891         return primaryDelegateRequests;
892     }
893 
894     public boolean isAdHocRequest() {                                          
895     	return KEWConstants.ADHOC_REQUEST_RESPONSIBILITY_ID.equals(getResponsibilityId());
896     }
897 
898     public boolean isGeneratedRequest() {
899     	return KEWConstants.MACHINE_GENERATED_RESPONSIBILITY_ID.equals(getResponsibilityId());
900     }
901 
902     public boolean isExceptionRequest() {
903     	return KEWConstants.EXCEPTION_REQUEST_RESPONSIBILITY_ID.equals(getResponsibilityId());
904     }
905 
906     public boolean isRouteModuleRequest() {
907     	return getResponsibilityId() > 0;
908     }
909 
910     public String toString() {
911         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
912             .append("actionRequestId", actionRequestId)
913             .append("actionRequested", actionRequested)
914             .append("routeHeaderId", routeHeaderId)
915             .append("status", status)
916             .append("responsibilityId", responsibilityId)
917             .append("groupId", groupId)
918             .append("recipientTypeCd", recipientTypeCd)
919             .append("priority", priority)
920             .append("routeLevel", routeLevel)
921             .append("actionTakenId", actionTakenId)
922             .append("docVersion", docVersion)
923             .append("createDate", createDate)
924             .append("responsibilityDesc", responsibilityDesc)
925             .append("annotation", annotation)
926             .append("jrfVerNbr", jrfVerNbr)
927             .append("principalId", principalId)
928             .append("forceAction", forceAction)
929             .append("parentActionRequestId", parentActionRequestId)
930             .append("qualifiedRoleName", qualifiedRoleName)
931             .append("roleName", roleName)
932             .append("qualifiedRoleNameLabel", qualifiedRoleNameLabel)
933             .append("displayStatus", displayStatus)
934             .append("ruleBaseValuesId", ruleBaseValuesId)
935             .append("delegationType", delegationType)
936             .append("approvePolicy", approvePolicy)
937             .append("childrenRequests", childrenRequests == null ? null : childrenRequests.size())
938             .append("actionTaken", actionTaken)
939             .append("routeHeader", routeHeader)
940             .append("actionItems", actionItems == null ? null : actionItems.size())
941             .append("currentIndicator", currentIndicator)
942             .append("createDateString", createDateString)
943             .append("nodeInstance", nodeInstance).toString();
944     }
945 
946 	public String getRequestLabel() {
947 		return this.requestLabel;
948 	}
949 
950 	public void setRequestLabel(String requestLabel) {
951 		this.requestLabel = requestLabel;
952 	}
953 
954     public String getGroupName() {
955         return KIMServiceLocator.getIdentityManagementService().getGroup(this.groupId).getGroupName();
956     }
957 
958 	/**
959 	 * @return the resolveResponsibility
960 	 */
961 	public boolean getResolveResponsibility() {
962 		return this.resolveResponsibility;
963 	}
964 
965 	/**
966 	 * @param resolveResponsibility the resolveResponsibility to set
967 	 */
968 	public void setResolveResponsibility(boolean resolveResponsibility) {
969 		this.resolveResponsibility = resolveResponsibility;
970 	}
971     
972 }