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