Coverage Report - org.kuali.rice.kew.engine.node.RouteNode
 
Classes in this File Line Coverage Branch Coverage Complexity
RouteNode
0%
0/98
0%
0/24
1.292
 
 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.engine.node;
 18  
 
 19  
 import java.io.Serializable;
 20  
 import java.util.ArrayList;
 21  
 import java.util.List;
 22  
 import java.util.Map;
 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.JoinTable;
 31  
 import javax.persistence.ManyToMany;
 32  
 import javax.persistence.ManyToOne;
 33  
 import javax.persistence.NamedQueries;
 34  
 import javax.persistence.NamedQuery;
 35  
 import javax.persistence.OneToMany;
 36  
 import javax.persistence.OneToOne;
 37  
 import javax.persistence.PrePersist;
 38  
 import javax.persistence.Table;
 39  
 import javax.persistence.Transient;
 40  
 import javax.persistence.Version;
 41  
 
 42  
 import org.apache.commons.lang.StringUtils;
 43  
 import org.apache.log4j.Logger;
 44  
 import org.hibernate.annotations.Fetch;
 45  
 import org.hibernate.annotations.FetchMode;
 46  
 import org.kuali.rice.core.jpa.annotations.Sequence;
 47  
 import org.kuali.rice.core.util.OrmUtils;
 48  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 49  
 import org.kuali.rice.kew.exception.ResourceUnavailableException;
 50  
 import org.kuali.rice.kew.rule.bo.RuleTemplate;
 51  
 import org.kuali.rice.kew.rule.service.RuleTemplateService;
 52  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 53  
 import org.kuali.rice.kew.util.KEWConstants;
 54  
 import org.kuali.rice.kew.util.Utilities;
 55  
 import org.kuali.rice.kim.bo.Group;
 56  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 57  
 
 58  
 /**
 59  
  * Represents the prototype definition of a node in the route path of {@link DocumentType}.
 60  
  *
 61  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 62  
  */
 63  
 @Entity
 64  
 @Table(name="KREW_RTE_NODE_T")
 65  
 @Sequence(name="KREW_RTE_NODE_S", property="routeNodeId")
 66  
 @NamedQueries({
 67  
         @NamedQuery(name="RouteNode.FindByRouteNodeId",query="select r from RouteNode as r where r.routeNodeId = :routeNodeId"),
 68  
         @NamedQuery(name="RouteNode.FindRouteNodeByName", query="select r from RouteNode as r where r.routeNodeName = :routeNodeName and r.documentTypeId = :documentTypeId"),
 69  
         @NamedQuery(name="RouteNode.FindApprovalRouteNodes", query="select r from RouteNode as r where r.documentTypeId = :documentTypeId and r.finalApprovalInd = :finalApprovalInd")
 70  
 })
 71  0
 public class RouteNode implements Serializable {    
 72  
 
 73  
     private static final long serialVersionUID = 4891233177051752726L;
 74  
 
 75  
     public static final String CONTENT_FRAGMENT_CFG_KEY = "contentFragment";
 76  
     public static final String RULE_SELECTOR_CFG_KEY = "ruleSelector";
 77  
 
 78  
     @Id
 79  
         @Column(name="RTE_NODE_ID")
 80  
         private Long routeNodeId;
 81  
     @Column(name="DOC_TYP_ID",insertable=false, updatable=false)
 82  
         private Long documentTypeId;
 83  
     @Column(name="NM")
 84  
         private String routeNodeName;
 85  
     @Column(name="RTE_MTHD_NM")
 86  
         private String routeMethodName;
 87  
     @Column(name="FNL_APRVR_IND")
 88  
         private Boolean finalApprovalInd;
 89  
     @Column(name="MNDTRY_RTE_IND")
 90  
         private Boolean mandatoryRouteInd;
 91  
     @Column(name="GRP_ID")
 92  
         private String exceptionWorkgroupId;
 93  
     @Column(name="RTE_MTHD_CD")
 94  
         private String routeMethodCode;
 95  0
     @Column(name="ACTVN_TYP")
 96  
     private String activationType = ActivationTypeEnum.PARALLEL.getCode();
 97  
     
 98  
     /**
 99  
      * The nextDocStatus property represents the value of the ApplicationDocumentStatus to be set 
 100  
      * in the RouteHeader upon transitioning from this node.
 101  
      */
 102  
     @Column(name="NEXT_DOC_STAT")
 103  
         private String nextDocStatus;
 104  
 
 105  
     @Version
 106  
         @Column(name="VER_NBR")
 107  
         private Integer lockVerNbr;
 108  
     @ManyToOne(fetch=FetchType.EAGER)
 109  
         @JoinColumn(name="DOC_TYP_ID")
 110  
         private DocumentType documentType;
 111  
     @Transient
 112  
     private String exceptionWorkgroupName;
 113  
 
 114  
     @Transient
 115  
     private RuleTemplate ruleTemplate;
 116  0
     @Column(name="TYP")
 117  
     private String nodeType = RequestsNode.class.getName();
 118  
     
 119  0
     @ManyToMany(fetch = FetchType.EAGER,mappedBy="nextNodes")
 120  
     @Fetch(value = FetchMode.SUBSELECT)
 121  
     @JoinTable(name = "KREW_RTE_NODE_LNK_T", joinColumns = @JoinColumn(name = "TO_RTE_NODE_ID"), inverseJoinColumns = @JoinColumn(name = "FROM_RTE_NODE_ID"))
 122  
     private List<RouteNode> previousNodes = new ArrayList<RouteNode>();
 123  0
     @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
 124  
     @Fetch(value = FetchMode.SUBSELECT)
 125  
     @JoinTable(name = "KREW_RTE_NODE_LNK_T", joinColumns = @JoinColumn(name = "FROM_RTE_NODE_ID"), inverseJoinColumns = @JoinColumn(name = "TO_RTE_NODE_ID"))
 126  
     private List<RouteNode> nextNodes = new ArrayList<RouteNode>();
 127  
     @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.MERGE})
 128  
         @JoinColumn(name="BRCH_PROTO_ID")
 129  
         private BranchPrototype branch;
 130  0
     @OneToMany(fetch=FetchType.EAGER,mappedBy="routeNode",cascade = {CascadeType.PERSIST, CascadeType.MERGE})
 131  
     @Fetch(value = FetchMode.SUBSELECT)
 132  
     private List<RouteNodeConfigParam> configParams  = new ArrayList<RouteNodeConfigParam>(0);
 133  
 
 134  
     /**
 135  
      * Looks up a config parameter for this route node definition
 136  
      * @param key the config param key 
 137  
      * @return the RouteNodeConfigParam if present
 138  
      */
 139  
     protected RouteNodeConfigParam getConfigParam(String key) {
 140  0
         Map<String, RouteNodeConfigParam> configParamMap = Utilities.getKeyValueCollectionAsLookupTable(configParams);
 141  0
         return configParamMap.get(key);
 142  
     }
 143  
 
 144  
     /**
 145  
      * Sets a config parameter for this route node definition.  If the key already exists
 146  
      * the existing RouteNodeConfigParam is modified, otherwise a new one is created
 147  
      * @param key the key of the parameter to set
 148  
      * @param value the value to set
 149  
      */
 150  
     protected void setConfigParam(String key, String value) {
 151  0
         Map<String, RouteNodeConfigParam> configParamMap = Utilities.getKeyValueCollectionAsLookupTable(configParams);
 152  0
         RouteNodeConfigParam cfCfgParam = configParamMap.get(key);
 153  0
         if (cfCfgParam == null) {
 154  0
             cfCfgParam = new RouteNodeConfigParam(this, key, value);
 155  0
             configParams.add(cfCfgParam);
 156  
         } else {
 157  0
             cfCfgParam.setValue(value);
 158  
         }
 159  0
     }
 160  
 
 161  
     public List<RouteNodeConfigParam> getConfigParams() {
 162  0
         return configParams;
 163  
     }
 164  
 
 165  
     public void setConfigParams(List<RouteNodeConfigParam> configParams) {
 166  0
         this.configParams = configParams;
 167  0
     }
 168  
 
 169  
     /**
 170  
      * @return the RouteNodeConfigParam value under the 'contentFragment'  key
 171  
      */
 172  
     public String getContentFragment() {
 173  0
         RouteNodeConfigParam cfCfgParam = getConfigParam(CONTENT_FRAGMENT_CFG_KEY);
 174  0
         if (cfCfgParam == null) return null;
 175  0
         return cfCfgParam.getValue();
 176  
     }
 177  
 
 178  
     /**
 179  
      * @param contentFragment the content fragment of the node, which will be set as a RouteNodeConfigParam under the 'contentFragment' key
 180  
      */
 181  
     public void setContentFragment(String contentFragment) {
 182  0
         setConfigParam(CONTENT_FRAGMENT_CFG_KEY, contentFragment);
 183  0
     }
 184  
 
 185  
     public String getActivationType() {
 186  0
         return activationType;
 187  
     }
 188  
 
 189  
     public void setActivationType(String activationType) {
 190  
         /* Cleanse the input.
 191  
          * This is surely not the best way to validate the activation types;
 192  
          * it would probably be better to use typesafe enums accross the board
 193  
          * but that would probably entail refactoring large swaths of code, not
 194  
          * to mention reconfiguring OJB (can typesafe enums be used?) and dealing
 195  
          * with serialization compatibility issues (if any).
 196  
          * So instead, let's just be sure to fail-fast.
 197  
          */
 198  0
         ActivationTypeEnum at = ActivationTypeEnum.lookupCode(activationType);
 199  0
         this.activationType = at.getCode();
 200  0
     }
 201  
 
 202  
     public Group getExceptionWorkgroup() {
 203  0
             if (!StringUtils.isBlank(exceptionWorkgroupId)) {
 204  0
                     return KIMServiceLocator.getIdentityManagementService().getGroup(exceptionWorkgroupId);
 205  
             }
 206  0
             return null;
 207  
     }
 208  
     
 209  
     public boolean isExceptionGroupDefined() {
 210  0
             return getExceptionWorkgroupId() != null;
 211  
     }
 212  
 
 213  
     public String getExceptionWorkgroupId() {
 214  0
         return exceptionWorkgroupId;
 215  
     }
 216  
 
 217  
     public void setExceptionWorkgroupId(String workgroupId) {
 218  0
         this.exceptionWorkgroupId = workgroupId;
 219  0
     }
 220  
 
 221  
     public void setFinalApprovalInd(Boolean finalApprovalInd) {
 222  0
         this.finalApprovalInd = finalApprovalInd;
 223  0
     }
 224  
 
 225  
     public void setMandatoryRouteInd(Boolean mandatoryRouteInd) {
 226  0
         this.mandatoryRouteInd = mandatoryRouteInd;
 227  0
     }
 228  
 
 229  
     public String getRouteMethodName() {
 230  0
         return routeMethodName;
 231  
     }
 232  
 
 233  
     public void setRouteMethodName(String routeMethodName) {
 234  0
         this.routeMethodName = routeMethodName;
 235  0
     }
 236  
 
 237  
     public Long getDocumentTypeId() {
 238  0
         return documentTypeId;
 239  
     }
 240  
 
 241  
     public void setDocumentTypeId(Long documentTypeId) {
 242  0
         this.documentTypeId = documentTypeId;
 243  0
     }
 244  
 
 245  
     public Long getRouteNodeId() {
 246  0
         return routeNodeId;
 247  
     }
 248  
 
 249  
     public void setRouteNodeId(Long routeNodeId) {
 250  0
         this.routeNodeId = routeNodeId;
 251  0
     }
 252  
 
 253  
     public String getRouteNodeName() {
 254  0
         return routeNodeName;
 255  
     }
 256  
 
 257  
     public void setRouteNodeName(String routeLevelName) {
 258  0
         this.routeNodeName = routeLevelName;
 259  0
     }
 260  
 
 261  
     public DocumentType getDocumentType() {
 262  0
         return documentType;
 263  
     }
 264  
 
 265  
     public void setDocumentType(DocumentType documentType) {
 266  0
         this.documentType = documentType;
 267  0
     }
 268  
 
 269  
     public String getRouteMethodCode() {
 270  0
         return routeMethodCode;
 271  
     }
 272  
 
 273  
     public void setRouteMethodCode(String routeMethodCode) {
 274  0
         this.routeMethodCode = routeMethodCode;
 275  0
     }
 276  
 
 277  
         /**
 278  
          * @param nextDocStatus the nextDocStatus to set
 279  
          */
 280  
         public void setNextDocStatus(String nextDocStatus) {
 281  0
                 this.nextDocStatus = nextDocStatus;
 282  0
         }
 283  
 
 284  
         /**
 285  
          * @return the nextDocStatus
 286  
          */
 287  
         public String getNextDocStatus() {
 288  0
                 return nextDocStatus;
 289  
         }
 290  
         
 291  
     public String getExceptionWorkgroupName() {
 292  0
             Group exceptionGroup = getExceptionWorkgroup();
 293  0
         if (exceptionWorkgroupName == null || exceptionWorkgroupName.equals("")) {
 294  0
             if (exceptionGroup != null) {
 295  0
                 return exceptionGroup.getGroupName();
 296  
             }
 297  
         }
 298  0
         return exceptionWorkgroupName;
 299  
     }
 300  
 
 301  
     public void setExceptionWorkgroupName(String exceptionWorkgroupName) {
 302  0
         this.exceptionWorkgroupName = exceptionWorkgroupName;
 303  0
     }
 304  
 
 305  
     public Integer getLockVerNbr() {
 306  0
         return lockVerNbr;
 307  
     }
 308  
 
 309  
     public void setLockVerNbr(Integer lockVerNbr) {
 310  0
         this.lockVerNbr = lockVerNbr;
 311  0
     }
 312  
 
 313  
     public boolean isFlexRM() {
 314  0
         return routeMethodCode != null && routeMethodCode.equals(KEWConstants.ROUTE_LEVEL_FLEX_RM);
 315  
     }
 316  
     
 317  
     public boolean isRoleNode() {
 318  
             try {
 319  0
                     return nodeType != null && NodeType.fromNode(this).isTypeOf(NodeType.ROLE);
 320  0
             } catch( ResourceUnavailableException ex ) {
 321  0
                     Logger.getLogger( RouteNode.class ).info( "isRoleNode(): Unable to determine node type: " + ex.getMessage() );
 322  0
                     return false;
 323  
             }
 324  
     }
 325  
 
 326  
     public Boolean getFinalApprovalInd() {
 327  0
         return finalApprovalInd;
 328  
     }
 329  
 
 330  
     public Boolean getMandatoryRouteInd() {
 331  0
         return mandatoryRouteInd;
 332  
     }
 333  
 
 334  
     public void addNextNode(RouteNode nextNode) {
 335  0
         getNextNodes().add(nextNode);
 336  0
         nextNode.getPreviousNodes().add(this);
 337  0
     }
 338  
 
 339  
     public List<RouteNode> getNextNodes() {
 340  0
         return nextNodes;
 341  
     }
 342  
 
 343  
     public void setNextNodes(List<RouteNode> nextNodes) {
 344  0
         this.nextNodes = nextNodes;
 345  0
     }
 346  
 
 347  
     public List<RouteNode> getPreviousNodes() {
 348  0
         return previousNodes;
 349  
     }
 350  
 
 351  
     public void setPreviousNodes(List<RouteNode> parentNodes) {
 352  0
         this.previousNodes = parentNodes;
 353  0
     }
 354  
 
 355  
     public RuleTemplate getRuleTemplate() {
 356  0
         if (ruleTemplate == null) {
 357  0
             RuleTemplateService ruleTemplateService = (RuleTemplateService) KEWServiceLocator.getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE);
 358  0
             ruleTemplate = ruleTemplateService.findByRuleTemplateName(getRouteMethodName());
 359  
         }
 360  0
         return ruleTemplate;
 361  
     }
 362  
 
 363  
     public String getNodeType() {
 364  0
         return nodeType;
 365  
     }
 366  
 
 367  
     public void setNodeType(String nodeType) {
 368  0
         this.nodeType = nodeType;
 369  0
     }
 370  
 
 371  
     public BranchPrototype getBranch() {
 372  0
         return branch;
 373  
     }
 374  
 
 375  
     public void setBranch(BranchPrototype branch) {
 376  0
         this.branch = branch;
 377  0
     }
 378  
 
 379  
         @PrePersist
 380  
         public void beforeInsert(){
 381  0
                 OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());                
 382  0
         }
 383  
         
 384  
         /**
 385  
          * This overridden method ...
 386  
          * 
 387  
          * @see java.lang.Object#toString()
 388  
          */
 389  
         @Override
 390  
         public String toString() {
 391  0
                 return "RouteNode[routeNodeName="+routeNodeName+", nodeType="+nodeType+", activationType="+activationType+"]";
 392  
         }
 393  
 
 394  
 }