Coverage Report - org.kuali.rice.kew.actionrequest.ActionRequestValue
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionRequestValue
0%
0/338
0%
0/176
1.826
 
 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 org.apache.commons.lang.StringUtils;
 20  
 import org.apache.commons.lang.builder.ToStringBuilder;
 21  
 import org.apache.commons.lang.builder.ToStringStyle;
 22  
 import org.hibernate.annotations.Fetch;
 23  
 import org.hibernate.annotations.FetchMode;
 24  
 import org.hibernate.annotations.GenericGenerator;
 25  
 import org.hibernate.annotations.Parameter;
 26  
 import org.joda.time.DateTime;
 27  
 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
 28  
 import org.kuali.rice.core.util.RiceConstants;
 29  
 import org.kuali.rice.kew.actionitem.ActionItem;
 30  
 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
 31  
 import org.kuali.rice.kew.api.action.ActionRequest;
 32  
 import org.kuali.rice.kew.api.action.ActionRequestPolicy;
 33  
 import org.kuali.rice.kew.api.action.ActionRequestStatus;
 34  
 import org.kuali.rice.kew.api.action.ActionRequestType;
 35  
 import org.kuali.rice.kew.api.action.ActionTaken;
 36  
 import org.kuali.rice.kew.api.action.DelegationType;
 37  
 import org.kuali.rice.kew.api.action.RecipientType;
 38  
 import org.kuali.rice.kew.dto.DTOConverter.RouteNodeInstanceLoader;
 39  
 import org.kuali.rice.kew.engine.CompatUtils;
 40  
 import org.kuali.rice.kew.engine.node.RouteNode;
 41  
 import org.kuali.rice.kew.engine.node.RouteNodeInstance;
 42  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 43  
 import org.kuali.rice.kew.rule.RuleBaseValues;
 44  
 import org.kuali.rice.kew.rule.service.RuleService;
 45  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 46  
 import org.kuali.rice.kew.user.RoleRecipient;
 47  
 import org.kuali.rice.kew.util.CodeTranslator;
 48  
 import org.kuali.rice.kew.util.KEWConstants;
 49  
 import org.kuali.rice.kim.api.group.Group;
 50  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 51  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 52  
 import org.kuali.rice.kim.bo.Person;
 53  
 
 54  
 import javax.persistence.CascadeType;
 55  
 import javax.persistence.Column;
 56  
 import javax.persistence.Entity;
 57  
 import javax.persistence.FetchType;
 58  
 import javax.persistence.GeneratedValue;
 59  
 import javax.persistence.Id;
 60  
 import javax.persistence.JoinColumn;
 61  
 import javax.persistence.ManyToOne;
 62  
 import javax.persistence.NamedQueries;
 63  
 import javax.persistence.NamedQuery;
 64  
 import javax.persistence.OneToMany;
 65  
 import javax.persistence.Table;
 66  
 import javax.persistence.Transient;
 67  
 import java.io.Serializable;
 68  
 import java.sql.Timestamp;
 69  
 import java.util.ArrayList;
 70  
 import java.util.Iterator;
 71  
 import java.util.List;
 72  
 /**
 73  
  * Bean mapped to DB. Represents ActionRequest to a workgroup, user or role.  Contains
 74  
  * references to children/parent if a member of a graph
 75  
  *
 76  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 77  
  */
 78  
 @Entity
 79  
 @Table(name="KREW_ACTN_RQST_T")
 80  
 //@Sequence(name="KREW_ACTN_RQST_S", property="actionRequestId")
 81  
 @NamedQueries({
 82  
   @NamedQuery(name="ActionRequestValue.FindByDocumentId", query="select arv from ActionRequestValue arv where arv.documentId = :documentId"),
 83  
   @NamedQuery(name="ActionRequestValue.GetUserRequestCount", query="select count(arv) from ActionRequestValue arv where arv.documentId = :documentId and arv.recipientTypeCd = :recipientTypeCd and arv.principalId = :principalId and arv.currentIndicator = :currentIndicator"),
 84  
   @NamedQuery(name="ActionRequestValue.FindActivatedByGroup", query="select count(arv) from ActionRequestValue arv where arv.groupId = :groupId and arv.currentIndicator = :currentIndicator and arv.status = :status"),
 85  
   @NamedQuery(name="ActionRequestValue.FindAllByDocId", query="select arv from ActionRequestValue arv where arv.documentId = :documentId and arv.currentIndicator = :currentIndicator"),
 86  
   @NamedQuery(name="ActionRequestValue.FindAllPendingByDocId", query="select arv from ActionRequestValue arv where arv.documentId = :documentId and arv.currentIndicator = :currentIndicator and (arv.status = :actionRequestStatus1 or arv.status = :actionRequestStatus2)"),
 87  
   @NamedQuery(name="ActionRequestValue.FindAllRootByDocId", query="select arv from ActionRequestValue arv where arv.documentId = :documentId and arv.currentIndicator = :currentIndicator and arv.parentActionRequest is null"),
 88  
   @NamedQuery(name="ActionRequestValue.FindByStatusAndDocId", query="select arv from ActionRequestValue arv where arv.documentId = :documentId and arv.currentIndicator = :currentIndicator and arv.status = :status"),
 89  
   @NamedQuery(name="ActionRequestValue.FindPendingByActionRequestedAndDocId", query="select arv from ActionRequestValue arv where arv.documentId = :documentId and arv.currentIndicator = :currentIndicator and arv.actionRequested = :actionRequested and (arv.status = :actionRequestStatus1 or arv.status = :actionRequestStatus2)"),
 90  
   @NamedQuery(name="ActionRequestValue.FindPendingByDocIdAtOrBelowRouteLevel", query="select arv from ActionRequestValue arv where arv.documentId = :documentId and arv.currentIndicator = :currentIndicator and arv.status <> :status and arv.routeLevel <= :routeLevel"),
 91  
   @NamedQuery(name="ActionRequestValue.FindPendingRootRequestsByDocIdAtOrBelowRouteLevel", query="select arv from ActionRequestValue arv where arv.documentId = :documentId and arv.currentIndicator = :currentIndicator and arv.parentActionRequest is null and arv.status <> :status and routeLevel <= :routeLevel"),
 92  
   @NamedQuery(name="ActionRequestValue.FindPendingRootRequestsByDocIdAtRouteLevel", query="select arv from ActionRequestValue arv where arv.documentId = :documentId and arv.currentIndicator = :currentIndicator and arv.parentActionRequest is null and arv.status <> :status and routeLevel = :routeLevel"),
 93  
   @NamedQuery(name="ActionRequestValue.FindPendingRootRequestsByDocIdAtRouteNode", query="select arv from ActionRequestValue arv where arv.documentId = :documentId and arv.currentIndicator = :currentIndicator and arv.parentActionRequest is null and arv.nodeInstance.routeNodeInstanceId = :routeNodeInstanceId and (arv.status = :actionRequestStatus1 or arv.status = :actionRequestStatus2)"),
 94  
   @NamedQuery(name="ActionRequestValue.FindPendingRootRequestsByDocumentType", query="select arv from ActionRequestValue arv where arv.documentId in (select drhv.documentId from DocumentRouteHeaderValue drhv where drhv.documentTypeId = :documentTypeId) and arv.currentIndicator = :currentIndicator and arv.parentActionRequest is null and (arv.status = :actionRequestStatus1 or arv.status = :actionRequestStatus2)"),
 95  
   @NamedQuery(name="ActionRequestValue.FindRootRequestsByDocIdAtRouteNode", query="select arv from ActionRequestValue arv where arv.documentId = :documentId and arv.currentIndicator = :currentIndicator and arv.parentActionRequest is null and arv.nodeInstance.routeNodeInstanceId = :routeNodeInstanceId"),
 96  
   @NamedQuery(name="ActionRequestValue.GetRequestGroupIds", query="select arv.groupId from ActionRequestValue arv where arv.documentId = :documentId and arv.currentIndicator = :currentIndicator and arv.recipientTypeCd = :recipientTypeCd"),
 97  
   @NamedQuery(name="ActionRequestValue.FindByStatusAndGroupId", query="select arv from ActionRequestValue arv where arv.groupId = :groupId and arv.currentIndicator = :currentIndicator and arv.status = :status")
 98  
 })
 99  
 public class ActionRequestValue implements Serializable {
 100  
 
 101  
         private static final long serialVersionUID = 8781414791855848385L;
 102  
 
 103  0
         private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionRequestValue.class);
 104  
 
 105  
     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
 106  
     private static final String RECIPIENT_TYPE_RANK = "RWU";
 107  
     private static final String DELEGATION_TYPE_RANK = "SPN";
 108  
 
 109  
     @Id
 110  
     @GeneratedValue(generator="KREW_ACTN_RQST_S")
 111  
         @GenericGenerator(name="KREW_ACTN_RQST_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
 112  
                         @Parameter(name="sequence_name",value="KREW_ACTN_RQST_S"),
 113  
                         @Parameter(name="value_column",value="id")
 114  
         })
 115  
         @Column(name="ACTN_RQST_ID")
 116  
         private String actionRequestId;
 117  
     @Column(name="ACTN_RQST_CD")
 118  
         private String actionRequested;
 119  
     @Column(name="DOC_HDR_ID")
 120  
         private String documentId;
 121  
     @Column(name="STAT_CD")
 122  
         private String status;
 123  
     @Column(name="RSP_ID")
 124  
         private String responsibilityId;
 125  
     @Column(name="GRP_ID")
 126  
         private String groupId;
 127  
     @Column(name="RECIP_TYP_CD")
 128  
         private String recipientTypeCd;
 129  
     @Column(name="PRIO_NBR")
 130  
         private Integer priority;
 131  
     @Column(name="RTE_LVL_NBR")
 132  
         private Integer routeLevel;
 133  
     @Column(name="ACTN_TKN_ID", insertable=false, updatable=false)
 134  
         private String actionTakenId;
 135  0
     @Column(name="DOC_VER_NBR")
 136  
     private Integer docVersion = 1;
 137  
         @Column(name="CRTE_DT")
 138  
         private java.sql.Timestamp createDate;
 139  
     @Column(name="RSP_DESC_TXT")
 140  
         private String responsibilityDesc;
 141  
     @Column(name="ACTN_RQST_ANNOTN_TXT")
 142  
         private String annotation;
 143  
     @Column(name="VER_NBR")
 144  
         private Integer jrfVerNbr;
 145  
     @Column(name="PRNCPL_ID")
 146  
         private String principalId;
 147  
     @Column(name="FRC_ACTN")
 148  
         private Boolean forceAction;
 149  
     @Column(name="PARNT_ID", insertable=false, updatable=false)
 150  
         private String parentActionRequestId;
 151  
     @Column(name="QUAL_ROLE_NM")
 152  
         private String qualifiedRoleName;
 153  
     @Column(name="ROLE_NM")
 154  
         private String roleName;
 155  
     @Column(name="QUAL_ROLE_NM_LBL_TXT")
 156  
         private String qualifiedRoleNameLabel;
 157  
     @Transient
 158  
     private String displayStatus;
 159  
     @Column(name="RULE_ID")
 160  
         private String ruleBaseValuesId;
 161  
 
 162  
     @Column(name="DLGN_TYP")
 163  
     private String delegationType;
 164  
     @Column(name="APPR_PLCY")
 165  
         private String approvePolicy;
 166  
 
 167  
     @ManyToOne(fetch=FetchType.EAGER)
 168  
         @JoinColumn(name="PARNT_ID")
 169  
         private ActionRequestValue parentActionRequest;
 170  0
     @Fetch(value = FetchMode.SELECT)
 171  
     @OneToMany(mappedBy="parentActionRequest",cascade={CascadeType.PERSIST, CascadeType.MERGE},fetch=FetchType.EAGER)
 172  
     private List<ActionRequestValue> childrenRequests = new ArrayList<ActionRequestValue>();
 173  
     @ManyToOne(fetch=FetchType.EAGER)
 174  
         @JoinColumn(name="ACTN_TKN_ID")
 175  
         private ActionTakenValue actionTaken;
 176  
     //@OneToMany(fetch=FetchType.LAZY,mappedBy="actionRequestId")
 177  
     //private List<ActionItem> actionItems = new ArrayList<ActionItem>();
 178  0
     @Column(name="CUR_IND")
 179  
     private Boolean currentIndicator = true;
 180  
     @Transient
 181  
     private String createDateString;
 182  
 
 183  
     /* New Workflow 2.1 Field */
 184  
     // The node instance at which this request was generated
 185  
     @ManyToOne(fetch=FetchType.EAGER)
 186  
         @JoinColumn(name="RTE_NODE_INSTN_ID")
 187  
         private RouteNodeInstance nodeInstance;
 188  
 
 189  
     @Column(name="RQST_LBL")
 190  
     private String requestLabel;
 191  
     
 192  0
     @Transient
 193  
     private boolean resolveResponsibility = true;
 194  
     @Transient
 195  
     private DocumentRouteHeaderValue routeHeader;
 196  
     @Transient
 197  
     private List<ActionItem> simulatedActionItems;
 198  
     
 199  0
     public ActionRequestValue() {
 200  0
         createDate = new Timestamp(System.currentTimeMillis());
 201  0
     }
 202  
     
 203  
     //@PrePersist
 204  
     public void beforeInsert(){
 205  0
             OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
 206  0
     }
 207  
    
 208  
     public Group getGroup() {
 209  0
         if (getGroupId() == null) {
 210  0
             LOG.error("Attempting to get a group with a blank group id");
 211  0
             return null;
 212  
         }
 213  0
         return KimApiServiceLocator.getGroupService().getGroup(getGroupId());
 214  
     }
 215  
 
 216  
     public String getRouteLevelName() {
 217  
         // this is for backward compatibility of requests which have not been converted
 218  0
         if (CompatUtils.isRouteLevelRequest(this)) {
 219  0
             int routeLevelInt = getRouteLevel();
 220  0
             if (routeLevelInt == KEWConstants.EXCEPTION_ROUTE_LEVEL) {
 221  0
                 return "Exception";
 222  
             }
 223  
 
 224  0
             List<RouteNode> routeLevelNodes = CompatUtils.getRouteLevelCompatibleNodeList(KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId).getDocumentType());
 225  0
             if (!(routeLevelInt < routeLevelNodes.size())) {
 226  0
                 return "Not Found";
 227  
             }
 228  0
             return ((RouteNode)routeLevelNodes.get(routeLevelInt)).getRouteNodeName();
 229  
         } else {
 230  0
             return (nodeInstance == null ? "Exception" : nodeInstance.getName());
 231  
         }
 232  
     }
 233  
 
 234  
     public boolean isUserRequest() {
 235  0
         return principalId != null;
 236  
     }
 237  
 
 238  
     public Principal getPrincipal() {
 239  0
             if (getPrincipalId() == null) {
 240  0
                     return null;
 241  
             }
 242  0
             return KEWServiceLocator.getIdentityHelperService().getPrincipal(getPrincipalId());
 243  
     }
 244  
     
 245  
     public Person getPerson() {
 246  0
             if (getPrincipalId() == null) {
 247  0
                     return null;
 248  
             }
 249  0
             return KimApiServiceLocator.getPersonService().getPerson(getPrincipalId());
 250  
     }
 251  
 
 252  
     public String getDisplayName() {
 253  0
             if (isUserRequest()) {
 254  0
                 return getPerson().getName();
 255  0
             } else if (isGroupRequest()) {
 256  0
                     return getGroup().getName();
 257  0
             } else if (isRoleRequest()) {
 258  0
                     return getRoleName();
 259  
             }
 260  0
             return "";
 261  
     }
 262  
 
 263  
     public Recipient getRecipient() {
 264  0
         if (getPrincipalId() != null) {
 265  0
             return new KimPrincipalRecipient(getPrincipal());
 266  0
         } else if (getGroupId() != null){
 267  0
             return new KimGroupRecipient(getGroup());
 268  
         } else {
 269  0
                 return new RoleRecipient(this.getRoleName());
 270  
         }
 271  
     }
 272  
 
 273  
     public boolean isPending() {
 274  0
         return ActionRequestStatus.INITIALIZED.getCode().equals(getStatus()) || ActionRequestStatus.ACTIVATED.getCode().equals(getStatus());
 275  
     }
 276  
 
 277  
     public String getStatusLabel() {
 278  0
         return CodeTranslator.getActionRequestStatusLabel(getStatus());
 279  
     }
 280  
 
 281  
     public String getActionRequestedLabel() {
 282  0
             if (StringUtils.isNotBlank(getRequestLabel())) {
 283  0
                     return getRequestLabel();
 284  
             }
 285  0
             return CodeTranslator.getActionRequestLabel(getActionRequested());
 286  
     }
 287  
 
 288  
     /**
 289  
      * @return Returns the actionTaken.
 290  
      */
 291  
     public ActionTakenValue getActionTaken() {
 292  0
         return actionTaken;
 293  
     }
 294  
 
 295  
     /**
 296  
      * @param actionTaken
 297  
      *            The actionTaken to set.
 298  
      */
 299  
     public void setActionTaken(ActionTakenValue actionTaken) {
 300  0
         this.actionTaken = actionTaken;
 301  0
     }
 302  
 
 303  
     /**
 304  
      * @return Returns the actionRequested.
 305  
      */
 306  
     public String getActionRequested() {
 307  0
         return actionRequested;
 308  
     }
 309  
 
 310  
     /**
 311  
      * @param actionRequested
 312  
      *            The actionRequested to set.
 313  
      */
 314  
     public void setActionRequested(String actionRequested) {
 315  0
         this.actionRequested = actionRequested;
 316  0
     }
 317  
 
 318  
     /**
 319  
      * @return Returns the actionRequestId.
 320  
      */
 321  
     public String getActionRequestId() {
 322  0
         return actionRequestId;
 323  
     }
 324  
 
 325  
     /**
 326  
      * @param actionRequestId
 327  
      *            The actionRequestId to set.
 328  
      */
 329  
     public void setActionRequestId(String actionRequestId) {
 330  0
         this.actionRequestId = actionRequestId;
 331  0
     }
 332  
 
 333  
     /**
 334  
      * @return Returns the actionTakenId.
 335  
      */
 336  
     public String getActionTakenId() {
 337  0
         return actionTakenId;
 338  
     }
 339  
 
 340  
     /**
 341  
      * @param actionTakenId
 342  
      *            The actionTakenId to set.
 343  
      */
 344  
     public void setActionTakenId(String actionTakenId) {
 345  0
         this.actionTakenId = actionTakenId;
 346  0
     }
 347  
 
 348  
     /**
 349  
      * @return Returns the annotation.
 350  
      */
 351  
     public String getAnnotation() {
 352  0
         return annotation;
 353  
     }
 354  
 
 355  
     /**
 356  
      * @param annotation
 357  
      *            The annotation to set.
 358  
      */
 359  
     public void setAnnotation(String annotation) {
 360  0
         this.annotation = annotation;
 361  0
     }
 362  
 
 363  
     /**
 364  
      * @return Returns the createDate.
 365  
      */
 366  
     public java.sql.Timestamp getCreateDate() {
 367  0
         return createDate;
 368  
     }
 369  
 
 370  
     /**
 371  
      * @param createDate
 372  
      *            The createDate to set.
 373  
      */
 374  
     public void setCreateDate(java.sql.Timestamp createDate) {
 375  0
         this.createDate = createDate;
 376  0
     }
 377  
 
 378  
     /**
 379  
      * @return Returns the docVersion.
 380  
      */
 381  
     public Integer getDocVersion() {
 382  0
         return docVersion;
 383  
     }
 384  
 
 385  
     /**
 386  
      * @param docVersion
 387  
      *            The docVersion to set.
 388  
      */
 389  
     public void setDocVersion(Integer docVersion) {
 390  0
         this.docVersion = docVersion;
 391  0
     }
 392  
 
 393  
     public String getPrincipalId() {
 394  0
         return principalId;
 395  
     }
 396  
 
 397  
     public void setPrincipalId(String principalId) {
 398  0
         this.principalId = principalId;
 399  0
     }
 400  
     
 401  
     /**
 402  
      * @return Returns the forceAction.
 403  
      */
 404  
     public Boolean getForceAction() {
 405  0
         return forceAction;
 406  
     }
 407  
 
 408  
     /**
 409  
      * @param forceAction
 410  
      *            The forceAction to set.
 411  
      */
 412  
     public void setForceAction(Boolean forceAction) {
 413  0
         this.forceAction = forceAction;
 414  0
     }
 415  
 
 416  
     /**
 417  
      * @return Returns the jrfVerNbr.
 418  
      */
 419  
     public Integer getJrfVerNbr() {
 420  0
         return jrfVerNbr;
 421  
     }
 422  
 
 423  
     /**
 424  
      * @param jrfVerNbr
 425  
      *            The jrfVerNbr to set.
 426  
      */
 427  
     public void setJrfVerNbr(Integer jrfVerNbr) {
 428  0
         this.jrfVerNbr = jrfVerNbr;
 429  0
     }
 430  
 
 431  
     /**
 432  
      * @return Returns the priority.
 433  
      */
 434  
     public Integer getPriority() {
 435  0
         return priority;
 436  
     }
 437  
 
 438  
     /**
 439  
      * @param priority
 440  
      *            The priority to set.
 441  
      */
 442  
     public void setPriority(Integer priority) {
 443  0
         this.priority = priority;
 444  0
     }
 445  
 
 446  
     /**
 447  
      * @return Returns the recipientTypeCd.
 448  
      */
 449  
     public String getRecipientTypeCd() {
 450  0
         return recipientTypeCd;
 451  
     }
 452  
 
 453  
     /**
 454  
      * @param recipientTypeCd
 455  
      *            The recipientTypeCd to set.
 456  
      */
 457  
     public void setRecipientTypeCd(String recipientTypeCd) {
 458  0
         this.recipientTypeCd = recipientTypeCd;
 459  0
     }
 460  
 
 461  
     /**
 462  
      * @return Returns the responsibilityDesc.
 463  
      */
 464  
     public String getResponsibilityDesc() {
 465  0
         return responsibilityDesc;
 466  
     }
 467  
 
 468  
     /**
 469  
      * @param responsibilityDesc
 470  
      *            The responsibilityDesc to set.
 471  
      */
 472  
     public void setResponsibilityDesc(String responsibilityDesc) {
 473  0
         this.responsibilityDesc = responsibilityDesc;
 474  0
     }
 475  
 
 476  
     /**
 477  
      * @return Returns the responsibilityId.
 478  
      */
 479  
     public String getResponsibilityId() {
 480  0
         return responsibilityId;
 481  
     }
 482  
 
 483  
     /**
 484  
      * @param responsibilityId
 485  
      *            The responsibilityId to set.
 486  
      */
 487  
     public void setResponsibilityId(String responsibilityId) {
 488  0
         this.responsibilityId = responsibilityId;
 489  0
     }
 490  
 
 491  
     /**
 492  
      * @return Returns the documentId.
 493  
      */
 494  
     public String getDocumentId() {
 495  0
         return documentId;
 496  
     }
 497  
 
 498  
     public void setDocumentId(String documentId) {
 499  0
         this.documentId = documentId;
 500  0
     }
 501  
 
 502  
     public Integer getRouteLevel() {
 503  0
         return routeLevel;
 504  
     }
 505  
 
 506  
     public void setRouteLevel(Integer routeLevel) {
 507  0
         this.routeLevel = routeLevel;
 508  0
     }
 509  
 
 510  
     public String getStatus() {
 511  0
         return status;
 512  
     }
 513  
 
 514  
     public void setStatus(String status) {
 515  0
         this.status = status;
 516  0
     }
 517  
 
 518  
     public String getGroupId() {
 519  0
         return groupId;
 520  
     }
 521  
 
 522  
     public void setGroupId(String groupId) {
 523  0
         this.groupId = groupId;
 524  0
     }
 525  
 
 526  
     public boolean isInitialized() {
 527  0
         return ActionRequestStatus.INITIALIZED.getCode().equals(getStatus());
 528  
     }
 529  
 
 530  
     public boolean isActive() {
 531  0
         return ActionRequestStatus.ACTIVATED.getCode().equals(getStatus());
 532  
     }
 533  
 
 534  
     public boolean isApproveOrCompleteRequest() {
 535  0
         return KEWConstants.ACTION_REQUEST_APPROVE_REQ.equals(getActionRequested()) || KEWConstants.ACTION_REQUEST_COMPLETE_REQ.equals(getActionRequested());
 536  
     }
 537  
 
 538  
     public boolean isDone() {
 539  0
         return ActionRequestStatus.DONE.getCode().equals(getStatus());
 540  
     }
 541  
 
 542  
     public boolean isReviewerUser() {
 543  0
         return RecipientType.PRINCIPAL.getCode().equals(getRecipientTypeCd());
 544  
     }
 545  
 
 546  
     public boolean isRecipientRoutedRequest(String principalId) {
 547  
             //before altering this method it is used in checkRouteLogAuthentication
 548  
             //don't break that method
 549  0
             if (principalId == null || "".equals(principalId)) {
 550  0
                     return false;
 551  
             }
 552  
 
 553  0
             boolean isRecipientInGraph = false;
 554  0
             if (isReviewerUser()) {
 555  0
                             isRecipientInGraph = getPrincipalId().equals(principalId);
 556  0
             } else if (isGroupRequest()) {
 557  0
                     Group group = getGroup();
 558  0
                         if (group == null){
 559  0
                                 LOG.error("Was unable to retrieve workgroup " + getGroupId());
 560  
                         }
 561  0
                     isRecipientInGraph = KimApiServiceLocator.getGroupService().isMemberOfGroup(principalId, group.getId());
 562  
             }
 563  
 
 564  
 
 565  0
         for (ActionRequestValue childRequest : getChildrenRequests())
 566  
         {
 567  0
             isRecipientInGraph = isRecipientInGraph || childRequest.isRecipientRoutedRequest(principalId);
 568  
         }
 569  
 
 570  0
             return isRecipientInGraph;
 571  
     }
 572  
 
 573  
     public boolean isRecipientRoutedRequest(Recipient recipient) {
 574  
             //before altering this method it is used in checkRouteLogAuthentication
 575  
             //don't break that method
 576  0
             if (recipient == null) {
 577  0
                     return false;
 578  
             }
 579  
 
 580  0
             boolean isRecipientInGraph = false;
 581  0
             if (isReviewerUser()) {
 582  0
                     if (recipient instanceof KimPrincipalRecipient) {
 583  0
                             isRecipientInGraph = getPrincipalId().equals(((KimPrincipalRecipient) recipient).getPrincipalId());
 584  0
                     } else if (recipient instanceof KimGroupRecipient){
 585  0
                             isRecipientInGraph = KimApiServiceLocator.getGroupService().isMemberOfGroup(getPrincipalId(), ((KimGroupRecipient)recipient).getGroup().getId());
 586  
                     }
 587  
 
 588  0
             } else if (isGroupRequest()) {
 589  0
                     Group group = getGroup();
 590  0
                         if (group == null){
 591  0
                                 LOG.error("Was unable to retrieve workgroup " + getGroupId());
 592  
                         }
 593  0
                     if (recipient instanceof KimPrincipalRecipient) {
 594  0
                             KimPrincipalRecipient principalRecipient = (KimPrincipalRecipient)recipient;
 595  0
                             isRecipientInGraph = KimApiServiceLocator.getGroupService().isMemberOfGroup(principalRecipient.getPrincipalId(), group.getId());
 596  0
                     } else if (recipient instanceof KimGroupRecipient) {
 597  0
                             isRecipientInGraph = ((KimGroupRecipient) recipient).getGroup().getId().equals(group.getId());
 598  
                     }
 599  
             }
 600  
 
 601  
 
 602  0
         for (ActionRequestValue childRequest : getChildrenRequests())
 603  
         {
 604  0
             isRecipientInGraph = isRecipientInGraph || childRequest.isRecipientRoutedRequest(recipient);
 605  
         }
 606  
 
 607  0
             return isRecipientInGraph;
 608  
     }
 609  
 
 610  
     public boolean isGroupRequest(){
 611  0
             return RecipientType.GROUP.getCode().equals(getRecipientTypeCd());
 612  
     }
 613  
 
 614  
     public boolean isRoleRequest() {
 615  0
         return RecipientType.ROLE.getCode().equals(getRecipientTypeCd());
 616  
     }
 617  
 
 618  
     public boolean isAcknowledgeRequest() {
 619  0
         return KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ.equals(getActionRequested());
 620  
     }
 621  
 
 622  
     public boolean isApproveRequest() {
 623  0
         return KEWConstants.ACTION_REQUEST_APPROVE_REQ.equals(getActionRequested());
 624  
     }
 625  
 
 626  
     public boolean isCompleteRequst() {
 627  0
         return KEWConstants.ACTION_REQUEST_COMPLETE_REQ.equals(getActionRequested());
 628  
     }
 629  
 
 630  
     public boolean isFYIRequest() {
 631  0
         return KEWConstants.ACTION_REQUEST_FYI_REQ.equals(getActionRequested());
 632  
     }
 633  
 
 634  
     /**
 635  
      * 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)
 636  
      *
 637  
      * @param code1
 638  
      * @param code2
 639  
      * @param completeAndApproveTheSame
 640  
      * @return -1 if less than, 0 if equal, 1 if greater than
 641  
      */
 642  
     public static int compareActionCode(String code1, String code2, boolean completeAndApproveTheSame) {
 643  0
             int cutoff = Integer.MAX_VALUE;
 644  0
             if (completeAndApproveTheSame) {
 645  
                     // hacked so that APPROVE and COMPLETE are equal
 646  0
                     cutoff = ACTION_CODE_RANK.length() - 3;
 647  
             }
 648  0
         Integer code1Index = Math.min(ACTION_CODE_RANK.indexOf(code1), cutoff);
 649  0
         Integer code2Index = Math.min(ACTION_CODE_RANK.indexOf(code2), cutoff);
 650  0
         return code1Index.compareTo(code2Index);
 651  
     }
 652  
 
 653  
     /**
 654  
      * 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
 655  
      *
 656  
      * @param type1
 657  
      * @param type2
 658  
      * @return -1 if less than, 0 if equal, 1 if greater than
 659  
      */
 660  
     public static int compareRecipientType(String type1, String type2) {
 661  0
         Integer type1Index = RECIPIENT_TYPE_RANK.indexOf(type1);
 662  0
         Integer type2Index = RECIPIENT_TYPE_RANK.indexOf(type2);
 663  0
         return type1Index.compareTo(type2Index);
 664  
     }
 665  
 
 666  
     public static int compareDelegationType(String type1, String type2) {
 667  0
             if (StringUtils.isEmpty(type1)) {
 668  0
                     type1 = "N";
 669  
             }
 670  0
             if (StringUtils.isEmpty(type2)) {
 671  0
                     type2 = "N";
 672  
             }
 673  0
             Integer type1Index = DELEGATION_TYPE_RANK.indexOf(type1);
 674  0
         Integer type2Index = DELEGATION_TYPE_RANK.indexOf(type2);
 675  0
         return type1Index.compareTo(type2Index);
 676  
     }
 677  
 
 678  
     public List<ActionItem> getActionItems() {
 679  0
             if (this.simulatedActionItems == null || this.simulatedActionItems.isEmpty()) {
 680  0
                     return (List<ActionItem>) KEWServiceLocator.getActionListService().findByActionRequestId(actionRequestId);
 681  
             } else {
 682  0
                     return this.simulatedActionItems;
 683  
             }
 684  
     }
 685  
 
 686  
     public List<ActionItem> getSimulatedActionItems() {
 687  0
             if (this.simulatedActionItems == null) {
 688  0
                     this.simulatedActionItems = new ArrayList<ActionItem>();
 689  
             }
 690  0
                 return this.simulatedActionItems;
 691  
         }
 692  
 
 693  
         public void setSimulatedActionItems(List<ActionItem> simulatedActionItems) {
 694  0
                 this.simulatedActionItems = simulatedActionItems;
 695  0
         }
 696  
 
 697  
         public Boolean getCurrentIndicator() {
 698  0
         return currentIndicator;
 699  
     }
 700  
 
 701  
     public void setCurrentIndicator(Boolean currentIndicator) {
 702  0
         this.currentIndicator = currentIndicator;
 703  0
     }
 704  
 
 705  
     public String getParentActionRequestId() {
 706  0
         return parentActionRequestId;
 707  
     }
 708  
 
 709  
     public void setParentActionRequestId(String parentActionRequestId) {
 710  0
         this.parentActionRequestId = parentActionRequestId;
 711  0
     }
 712  
 
 713  
     public ActionRequestValue getParentActionRequest() {
 714  0
         return parentActionRequest;
 715  
     }
 716  
 
 717  
     public void setParentActionRequest(ActionRequestValue parentActionRequest) {
 718  0
         this.parentActionRequest = parentActionRequest;
 719  0
     }
 720  
 
 721  
     public List<ActionRequestValue> getChildrenRequests() {
 722  0
         return childrenRequests;
 723  
     }
 724  
 
 725  
     public void setChildrenRequests(List<ActionRequestValue> childrenRequests) {
 726  0
         this.childrenRequests = childrenRequests;
 727  0
     }
 728  
 
 729  
     public String getQualifiedRoleName() {
 730  0
         return qualifiedRoleName;
 731  
     }
 732  
 
 733  
     public void setQualifiedRoleName(String roleName) {
 734  0
         this.qualifiedRoleName = roleName;
 735  0
     }
 736  
 
 737  
     public String getDelegationType() {
 738  0
         return delegationType;
 739  
     }
 740  
 
 741  
     public void setDelegationType(String delegatePolicy) {
 742  0
         this.delegationType = delegatePolicy;
 743  0
     }
 744  
 
 745  
     public String getRoleName() {
 746  0
         return roleName;
 747  
     }
 748  
 
 749  
     public void setRoleName(String roleName) {
 750  0
         this.roleName = roleName;
 751  0
     }
 752  
 
 753  
     public String getApprovePolicy() {
 754  0
         return approvePolicy;
 755  
     }
 756  
 
 757  
     public void setApprovePolicy(String requestType) {
 758  0
         this.approvePolicy = requestType;
 759  0
     }
 760  
 
 761  
     public boolean getHasApprovePolicy() {
 762  0
         return getApprovePolicy() != null;
 763  
     }
 764  
 
 765  
     public boolean isDeactivated() {
 766  0
         return ActionRequestStatus.DONE.getCode().equals(getStatus());
 767  
     }
 768  
 
 769  
     public boolean hasParent() {
 770  0
         return getParentActionRequest() != null;
 771  
     }
 772  
 
 773  
     public boolean hasChild(ActionRequestValue actionRequest) {
 774  0
         if (actionRequest == null)
 775  0
             return false;
 776  0
         String actionRequestId = actionRequest.getActionRequestId();
 777  0
         for (Iterator<ActionRequestValue> iter = getChildrenRequests().iterator(); iter.hasNext();) {
 778  0
             ActionRequestValue childRequest = iter.next();
 779  0
             if (childRequest.equals(actionRequest) || (actionRequestId != null && actionRequestId.equals(childRequest.getActionRequestId()))) {
 780  0
                 return true;
 781  
             }
 782  0
         }
 783  0
         return false;
 784  
     }
 785  
 
 786  
     public String getDisplayStatus() {
 787  0
         return displayStatus;
 788  
     }
 789  
 
 790  
     public void setDisplayStatus(String displayStatus) {
 791  0
         this.displayStatus = displayStatus;
 792  0
     }
 793  
 
 794  
     public String getQualifiedRoleNameLabel() {
 795  0
         return qualifiedRoleNameLabel;
 796  
     }
 797  
 
 798  
     public void setQualifiedRoleNameLabel(String qualifiedRoleNameLabel) {
 799  0
         this.qualifiedRoleNameLabel = qualifiedRoleNameLabel;
 800  0
     }
 801  
 
 802  
     public String getCreateDateString() {
 803  0
         if (createDateString == null || createDateString.trim().equals("")) {
 804  0
             return RiceConstants.getDefaultDateFormat().format(getCreateDate());
 805  
         } else {
 806  0
             return createDateString;
 807  
         }
 808  
     }
 809  
 
 810  
     public void setCreateDateString(String createDateString) {
 811  0
         this.createDateString = createDateString;
 812  0
     }
 813  
 
 814  
     public RouteNodeInstance getNodeInstance() {
 815  0
                 return nodeInstance;
 816  
         }
 817  
 
 818  
     public String getPotentialNodeName() {
 819  0
         return (getNodeInstance() == null ? "" : getNodeInstance().getName());
 820  
     }
 821  
 
 822  
         public void setNodeInstance(RouteNodeInstance nodeInstance) {
 823  0
                 this.nodeInstance = nodeInstance;
 824  0
         }
 825  
 
 826  
         public String getRecipientTypeLabel() {
 827  0
                 return RecipientType.fromCode(getRecipientTypeCd()).getLabel();
 828  
     }
 829  
 
 830  
     public RuleBaseValues getRuleBaseValues(){
 831  0
         if(ruleBaseValuesId != null){
 832  0
             return getRuleService().findRuleBaseValuesById(ruleBaseValuesId);
 833  
         }
 834  0
         return null;
 835  
     }
 836  
     public String getRuleBaseValuesId() {
 837  0
         return ruleBaseValuesId;
 838  
     }
 839  
 
 840  
     public void setRuleBaseValuesId(String ruleBaseValuesId) {
 841  0
         this.ruleBaseValuesId = ruleBaseValuesId;
 842  0
     }
 843  
     
 844  
         private RuleService getRuleService() {
 845  0
         return (RuleService) KEWServiceLocator.getService(KEWServiceLocator.RULE_SERVICE);
 846  
     }
 847  
 
 848  
     public boolean isPrimaryDelegator() {
 849  0
         boolean primaryDelegator = false;
 850  0
         for (Iterator<ActionRequestValue> iter = childrenRequests.iterator(); iter.hasNext();) {
 851  0
             ActionRequestValue childRequest = iter.next();
 852  0
             primaryDelegator = DelegationType.PRIMARY.getCode().equals(childRequest.getDelegationType()) || primaryDelegator;
 853  0
         }
 854  0
         return primaryDelegator;
 855  
     }
 856  
 
 857  
     /**
 858  
      * Used to get primary delegate names on route log in the 'Requested Of' section so primary delegate requests
 859  
      * list the delegate and not the delegator as having the request 'IN ACTION LIST'.  This method doesn't recurse
 860  
      * and therefore assume an AR structure.
 861  
      *
 862  
      * @return primary delgate requests
 863  
      */
 864  
     public List<ActionRequestValue> getPrimaryDelegateRequests() {
 865  0
         List<ActionRequestValue> primaryDelegateRequests = new ArrayList<ActionRequestValue>();
 866  0
         for (ActionRequestValue childRequest : childrenRequests)
 867  
         {
 868  0
             if (DelegationType.PRIMARY.getCode().equals(childRequest.getDelegationType()))
 869  
             {
 870  0
                 if (childRequest.isRoleRequest())
 871  
                 {
 872  0
                     for (ActionRequestValue actionRequestValue : childRequest.getChildrenRequests())
 873  
                     {
 874  0
                         primaryDelegateRequests.add(actionRequestValue);
 875  
                     }
 876  
                 } else
 877  
                 {
 878  0
                         primaryDelegateRequests.add(childRequest);
 879  
                 }
 880  
             }
 881  
         }
 882  0
         return primaryDelegateRequests;
 883  
     }
 884  
 
 885  
     public boolean isAdHocRequest() {                                          
 886  0
             return KEWConstants.ADHOC_REQUEST_RESPONSIBILITY_ID.equals(getResponsibilityId());
 887  
     }
 888  
 
 889  
     public boolean isGeneratedRequest() {
 890  0
             return KEWConstants.MACHINE_GENERATED_RESPONSIBILITY_ID.equals(getResponsibilityId());
 891  
     }
 892  
 
 893  
     public boolean isExceptionRequest() {
 894  0
             return KEWConstants.EXCEPTION_REQUEST_RESPONSIBILITY_ID.equals(getResponsibilityId());
 895  
     }
 896  
 
 897  
     public boolean isRouteModuleRequest() {
 898  
             // FIXME: KULRICE-5201 switched rsp_id to a varchar, so the comparison below is no longer valid
 899  
 //            return getResponsibilityId() > 0;
 900  
             // TODO: KULRICE-5329 Verify that this code below makes sense 
 901  0
             return getResponsibilityId() != null && !KEWConstants.SPECIAL_RESPONSIBILITY_ID_SET.contains(getResponsibilityId());
 902  
     }
 903  
 
 904  
     public String toString() {
 905  0
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
 906  
             .append("actionRequestId", actionRequestId)
 907  
             .append("actionRequested", actionRequested)
 908  
             .append("documentId", documentId)
 909  
             .append("status", status)
 910  
             .append("responsibilityId", responsibilityId)
 911  
             .append("groupId", groupId)
 912  
             .append("recipientTypeCd", recipientTypeCd)
 913  
             .append("priority", priority)
 914  
             .append("routeLevel", routeLevel)
 915  
             .append("actionTakenId", actionTakenId)
 916  
             .append("docVersion", docVersion)
 917  
             .append("createDate", createDate)
 918  
             .append("responsibilityDesc", responsibilityDesc)
 919  
             .append("annotation", annotation)
 920  
             .append("jrfVerNbr", jrfVerNbr)
 921  
             .append("principalId", principalId)
 922  
             .append("forceAction", forceAction)
 923  
             .append("parentActionRequestId", parentActionRequestId)
 924  
             .append("qualifiedRoleName", qualifiedRoleName)
 925  
             .append("roleName", roleName)
 926  
             .append("qualifiedRoleNameLabel", qualifiedRoleNameLabel)
 927  
             .append("displayStatus", displayStatus)
 928  
             .append("ruleBaseValuesId", ruleBaseValuesId)
 929  
             .append("delegationType", delegationType)
 930  
             .append("approvePolicy", approvePolicy)
 931  
             .append("childrenRequests", childrenRequests == null ? null : childrenRequests.size())
 932  
             .append("actionTaken", actionTaken)
 933  
             .append("currentIndicator", currentIndicator)
 934  
             .append("createDateString", createDateString)
 935  
             .append("nodeInstance", nodeInstance).toString();
 936  
     }
 937  
 
 938  
         public String getRequestLabel() {
 939  0
                 return this.requestLabel;
 940  
         }
 941  
 
 942  
         public void setRequestLabel(String requestLabel) {
 943  0
                 this.requestLabel = requestLabel;
 944  0
         }
 945  
 
 946  
     public String getGroupName() {
 947  0
         return KimApiServiceLocator.getGroupService().getGroup(this.groupId).getName();
 948  
     }
 949  
 
 950  
         /**
 951  
          * @return the resolveResponsibility
 952  
          */
 953  
         public boolean getResolveResponsibility() {
 954  0
                 return this.resolveResponsibility;
 955  
         }
 956  
 
 957  
         /**
 958  
          * @param resolveResponsibility the resolveResponsibility to set
 959  
          */
 960  
         public void setResolveResponsibility(boolean resolveResponsibility) {
 961  0
                 this.resolveResponsibility = resolveResponsibility;
 962  0
         }
 963  
 
 964  
         public DocumentRouteHeaderValue getRouteHeader() {
 965  0
                 if (this.routeHeader == null && this.documentId != null) {
 966  0
                         this.routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(this.documentId);
 967  
                 }
 968  0
                 return this.routeHeader;
 969  
         }
 970  
 
 971  
         public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
 972  0
                 this.routeHeader = routeHeader;
 973  0
         }
 974  
         
 975  
         public static ActionRequest to(ActionRequestValue actionRequestBo) {
 976  0
                 if (actionRequestBo == null) {
 977  0
                         return null;
 978  
                 }
 979  0
                 return createActionRequestBuilder(actionRequestBo).build();
 980  
         }
 981  
         
 982  
         private static ActionRequest.Builder createActionRequestBuilder(ActionRequestValue actionRequestBo) {
 983  0
                 ActionRequest.Builder builder = ActionRequest.Builder.create(actionRequestBo.getActionRequestId().toString(),
 984  
                                 ActionRequestType.fromCode(actionRequestBo.getActionRequested()),
 985  
                                 ActionRequestStatus.fromCode(actionRequestBo.getStatus()),
 986  
                                 actionRequestBo.getResponsibilityId().toString(),
 987  
                                 actionRequestBo.getDocumentId(),
 988  
                                 RecipientType.fromCode(actionRequestBo.getRecipientTypeCd()));
 989  0
                 if (actionRequestBo.getActionTaken() != null) {
 990  0
                         builder.setActionTaken(ActionTaken.Builder.create(ActionTakenValue.to(actionRequestBo.getActionTaken())));
 991  
                 }
 992  0
                 builder.setAnnotation(actionRequestBo.getAnnotation());
 993  0
                 builder.setCurrent(actionRequestBo.getCurrentIndicator().booleanValue());
 994  0
                 builder.setDateCreated(new DateTime(actionRequestBo.getCreateDate().getTime()));
 995  0
                 if (!StringUtils.isBlank(actionRequestBo.getDelegationType())) {
 996  0
                         builder.setDelegationType(DelegationType.fromCode(actionRequestBo.getDelegationType()));
 997  
                 }
 998  0
                 builder.setForceAction(actionRequestBo.getForceAction().booleanValue());
 999  0
                 builder.setGroupId(actionRequestBo.getGroupId());
 1000  0
                 builder.setNodeName(actionRequestBo.getPotentialNodeName());
 1001  0
                 if (actionRequestBo.getParentActionRequestId() != null) {
 1002  0
                         builder.setParentActionRequestId(actionRequestBo.getParentActionRequestId().toString());
 1003  
                 }
 1004  0
                 builder.setPrincipalId(actionRequestBo.getPrincipalId());
 1005  0
                 if (actionRequestBo.getPriority() == null) {
 1006  0
                         builder.setPriority(KEWConstants.ACTION_REQUEST_DEFAULT_PRIORITY);
 1007  
                 }
 1008  0
                 builder.setQualifiedRoleName(actionRequestBo.getQualifiedRoleName());
 1009  0
                 builder.setQualifiedRoleNameLabel(actionRequestBo.getQualifiedRoleNameLabel());
 1010  0
                 builder.setRequestLabel(actionRequestBo.getRequestLabel());
 1011  0
                 if (!StringUtils.isBlank(actionRequestBo.getApprovePolicy())) {
 1012  0
                         builder.setRequestPolicy(ActionRequestPolicy.fromCode(actionRequestBo.getApprovePolicy()));
 1013  
                 }
 1014  0
                 builder.setResponsibilityDescription(actionRequestBo.getResponsibilityDesc());
 1015  0
                 builder.setRoleName(actionRequestBo.getRoleName());
 1016  0
                 if (actionRequestBo.getNodeInstance() != null) {
 1017  0
                         builder.setRouteNodeInstanceId(actionRequestBo.getNodeInstance().getRouteNodeInstanceId().toString());
 1018  
                 }
 1019  
                 
 1020  0
                 List<ActionRequest.Builder> childRequests = new ArrayList<ActionRequest.Builder>();
 1021  0
                 if (actionRequestBo.getChildrenRequests() != null) {
 1022  0
                         for (ActionRequestValue childActionRequestBo : actionRequestBo.getChildrenRequests()) {
 1023  0
                                 childRequests.add(createActionRequestBuilder(childActionRequestBo));
 1024  
                         }
 1025  
                 }
 1026  0
                 builder.setChildRequests(childRequests);
 1027  0
                 return builder;
 1028  
         }
 1029  
         
 1030  
     /**
 1031  
      * TODO - this javadoc copied from DTOConverter, needs to be updated!
 1032  
      * 
 1033  
      * Converts an ActionRequestVO to an ActionRequest. The ActionRequestDTO passed in must be the root action request in the
 1034  
      * graph, otherwise an IllegalArgumentException is thrown. This is to avoid potentially sticky issues with circular
 1035  
      * references in the conversion. NOTE: This method's primary purpose is to convert ActionRequestVOs returned from a
 1036  
      * RouteModule. Incidentally, the DTO's returned from the route module will be lacking some information (like the node
 1037  
      * instance) so no attempts are made to convert this data since further initialization is handled by a higher level
 1038  
      * component (namely ActionRequestService.initializeActionRequestGraph).
 1039  
      */
 1040  
     public static ActionRequestValue from(ActionRequest actionRequest) {
 1041  0
         return ActionRequestValue.from(actionRequest, null);
 1042  
     }
 1043  
     
 1044  
     /**
 1045  
      * Converts an ActionRequestVO to an ActionRequest. The ActionRequestDTO passed in must be the root action request in the
 1046  
      * graph, otherwise an IllegalArgumentException is thrown. This is to avoid potentially sticky issues with circular
 1047  
      * references in the conversion. 
 1048  
      * @param routeNodeInstanceLoader a service that will provide routeNodeInstanceS based on their IDs.
 1049  
      */
 1050  
     public static ActionRequestValue from(ActionRequest actionRequest, 
 1051  
             RouteNodeInstanceLoader routeNodeInstanceLoader) {
 1052  0
         return convertActionRequest(actionRequest, null, routeNodeInstanceLoader);
 1053  
     }
 1054  
 
 1055  
     private static ActionRequestValue convertActionRequest(ActionRequest actionRequest, ActionRequestValue parentActionRequestBo,
 1056  
             RouteNodeInstanceLoader routeNodeInstanceLoader) {
 1057  0
         if (actionRequest == null) {
 1058  0
             return null;
 1059  
         }
 1060  0
         ActionRequestValue actionRequestBo = new ActionRequestFactory().createBlankActionRequest();
 1061  0
         populateActionRequest(actionRequestBo, actionRequest, routeNodeInstanceLoader);
 1062  0
         if (parentActionRequestBo != null) {
 1063  0
             actionRequestBo.setParentActionRequest(parentActionRequestBo);
 1064  0
             actionRequestBo.setParentActionRequestId(parentActionRequestBo.getActionRequestId());
 1065  
         }
 1066  0
         if (actionRequest.getChildRequests() != null) {
 1067  0
             for (ActionRequest childRequest : actionRequest.getChildRequests()) {
 1068  0
                 actionRequestBo.getChildrenRequests().add(ActionRequestValue.convertActionRequest(childRequest, actionRequestBo, routeNodeInstanceLoader));
 1069  
             }
 1070  
         }
 1071  0
         return actionRequestBo;
 1072  
     }
 1073  
 
 1074  
     /**
 1075  
      * This method converts everything except for the parent and child requests
 1076  
      */
 1077  
     private static void populateActionRequest(ActionRequestValue actionRequestBo, ActionRequest actionRequest, 
 1078  
             RouteNodeInstanceLoader routeNodeInstanceLoader) {
 1079  
 
 1080  0
         actionRequestBo.setActionRequested(actionRequest.getActionRequested().getCode());
 1081  0
         if (!StringUtils.isBlank(actionRequest.getId())) {
 1082  0
             actionRequestBo.setActionRequestId(actionRequest.getId());
 1083  
         }
 1084  
         
 1085  0
         if (actionRequest.getActionTaken() != null) {
 1086  
             // actionRequestBo.setActionTaken(ActionTakenValue.from(actionRequest.getActionTaken()));
 1087  0
             if (!StringUtils.isBlank(actionRequest.getActionTaken().getId())) {
 1088  0
                 actionRequestBo.setActionTakenId(actionRequest.getActionTaken().getId());
 1089  
             }
 1090  
         }
 1091  0
         actionRequestBo.setAnnotation(actionRequest.getAnnotation());
 1092  0
         if (actionRequest.getRequestPolicy() != null) {
 1093  0
             actionRequestBo.setApprovePolicy(actionRequest.getRequestPolicy().getCode());
 1094  
         }
 1095  0
         actionRequestBo.setCreateDate(new Timestamp(actionRequest.getDateCreated().getMillis()));
 1096  0
         actionRequestBo.setCurrentIndicator(actionRequest.isCurrent());
 1097  0
         if (actionRequest.getDelegationType() != null) {
 1098  0
             actionRequestBo.setDelegationType(actionRequest.getDelegationType().getCode());
 1099  
         }
 1100  
         //actionRequestBo.setDocVersion(actionRequest.?);
 1101  0
         actionRequestBo.setForceAction(actionRequest.isForceAction());
 1102  0
         actionRequestBo.setPriority(actionRequest.getPriority());
 1103  0
         actionRequestBo.setQualifiedRoleName(actionRequest.getQualifiedRoleName());
 1104  0
         actionRequestBo.setQualifiedRoleNameLabel(actionRequest.getQualifiedRoleNameLabel());
 1105  0
         actionRequestBo.setRecipientTypeCd(actionRequest.getRecipientType().getCode());
 1106  0
         actionRequestBo.setResponsibilityDesc(actionRequest.getResponsibilityDescription());
 1107  0
         if (!StringUtils.isBlank(actionRequest.getResponsibilityId())) {
 1108  0
             actionRequestBo.setResponsibilityId(actionRequest.getResponsibilityId());
 1109  
         }
 1110  0
         actionRequestBo.setRoleName(actionRequest.getRoleName());
 1111  0
         String documentId = actionRequest.getDocumentId();
 1112  0
         if (documentId != null) {
 1113  0
             actionRequestBo.setDocumentId(documentId);
 1114  0
             actionRequestBo.setRouteHeader(KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId));
 1115  
         }
 1116  
 
 1117  0
         actionRequestBo.setStatus(actionRequest.getStatus().getCode());
 1118  0
         actionRequestBo.setPrincipalId(actionRequest.getPrincipalId());
 1119  0
         actionRequestBo.setGroupId(actionRequest.getGroupId());
 1120  
         
 1121  0
         if (routeNodeInstanceLoader != null && !StringUtils.isBlank(actionRequest.getRouteNodeInstanceId())) {
 1122  0
             actionRequestBo.setNodeInstance(routeNodeInstanceLoader.load(actionRequest.getRouteNodeInstanceId()));
 1123  
         }
 1124  0
     }
 1125  
     
 1126  
 }