Coverage Report - org.kuali.rice.kew.engine.node.RouteNodeInstance
 
Classes in this File Line Coverage Branch Coverage Complexity
RouteNodeInstance
0%
0/89
0%
0/30
1.385
 
 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 org.apache.commons.lang.builder.ToStringBuilder;
 20  
 import org.hibernate.annotations.Cascade;
 21  
 import org.hibernate.annotations.Fetch;
 22  
 import org.hibernate.annotations.FetchMode;
 23  
 import org.kuali.rice.core.jpa.annotations.Sequence;
 24  
 import org.kuali.rice.core.util.OrmUtils;
 25  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 26  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 27  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 28  
 
 29  
 import javax.persistence.*;
 30  
 import java.io.Serializable;
 31  
 import java.util.ArrayList;
 32  
 import java.util.Iterator;
 33  
 import java.util.List;
 34  
 
 35  
 
 36  
 /**
 37  
  * Represents a materialized instance of a {@link RouteNode} definition on a {@link DocumentRouteHeaderValue}.  Node instances
 38  
  * are generated by the engine using the {@link RouteNode} as a prototype and connected as a 
 39  
  * Directed Acyclic Graph.
 40  
  *
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 42  
  */
 43  
 @Entity
 44  
 @Table(name="KREW_RTE_NODE_INSTN_T")
 45  
 @Sequence(name="KREW_RTE_NODE_S",property="routeNodeInstanceId")
 46  
 @NamedQueries({
 47  
         @NamedQuery(name="RouteNodeInstance.FindByRouteNodeInstanceId",query="select r from RouteNodeInstance r where r.routeNodeInstanceId = :routeNodeInstanceId"),
 48  
         @NamedQuery(name="RouteNodeInstance.FindActiveNodeInstances",query="select r from RouteNodeInstance r where r.documentId = :documentId and r.active = true"),
 49  
         @NamedQuery(name="RouteNodeInstance.FindTerminalNodeInstances",query="select r from RouteNodeInstance r where r.documentId = :documentId and r.active = false and r.complete = true"),
 50  
         @NamedQuery(name="RouteNodeInstance.FindInitialNodeInstances",query="select d.initialRouteNodeInstances from DocumentRouteHeaderValue d where d.routeHeaderId = :routeHeaderId"),
 51  
         @NamedQuery(name="RouteNodeInstance.FindProcessNodeInstances", query="select r from RouteNodeInstance r where r.process.routeNodeInstanceId = :processId"),
 52  
         @NamedQuery(name="RouteNodeInstance.FindRouteNodeInstances", query="select r from RouteNodeInstance r where r.documentId = :documentId")
 53  
 })
 54  0
 public class RouteNodeInstance implements Serializable {
 55  
     
 56  
         private static final long serialVersionUID = 7183670062805580420L;
 57  
         
 58  
         @Id
 59  
         @Column(name="RTE_NODE_INSTN_ID")
 60  
         private Long routeNodeInstanceId;
 61  
     @Column(name="DOC_HDR_ID")
 62  
         private Long documentId;
 63  
     @OneToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE})
 64  
         @JoinColumn(name="BRCH_ID")
 65  
         private Branch branch;
 66  
     @OneToOne(fetch=FetchType.EAGER)
 67  
         @JoinColumn(name="RTE_NODE_ID")
 68  
     private RouteNode routeNode;
 69  0
     @Column(name="ACTV_IND")
 70  
     private boolean active = false;
 71  0
     @Column(name="CMPLT_IND")
 72  
     private boolean complete = false;
 73  0
     @Column(name="INIT_IND")
 74  
     private boolean initial = true;
 75  
     @OneToOne(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST, CascadeType.MERGE})
 76  
         @JoinColumn(name="PROC_RTE_NODE_INSTN_ID")
 77  
         private RouteNodeInstance process;
 78  
     
 79  0
     @ManyToMany(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
 80  
     @JoinTable(name = "KREW_RTE_NODE_INSTN_LNK_T", joinColumns = @JoinColumn(name = "FROM_RTE_NODE_INSTN_ID"), inverseJoinColumns = @JoinColumn(name = "TO_RTE_NODE_INSTN_ID"))        
 81  
     @Fetch(value = FetchMode.SUBSELECT)
 82  
     private List<RouteNodeInstance> nextNodeInstances = new ArrayList<RouteNodeInstance>();
 83  
     
 84  0
     @ManyToMany(fetch=FetchType.EAGER, mappedBy="nextNodeInstances")
 85  
     @Fetch(value = FetchMode.SUBSELECT)
 86  
     @JoinTable(name = "KREW_RTE_NODE_INSTN_LNK_T", joinColumns = @JoinColumn(name = "TO_RTE_NODE_INSTN_ID"), inverseJoinColumns = @JoinColumn(name = "FROM_RTE_NODE_INSTN_ID"))    
 87  
     private List<RouteNodeInstance> previousNodeInstances = new ArrayList<RouteNodeInstance>();
 88  
 
 89  0
     @OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE}, mappedBy="nodeInstance")    
 90  
     @Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
 91  
     @Fetch(value = FetchMode.SUBSELECT)
 92  
     private List<NodeState> state = new ArrayList<NodeState>();
 93  
             
 94  
     @Version
 95  
         @Column(name="VER_NBR")
 96  
         private Integer lockVerNbr;
 97  
     
 98  
     public boolean isActive() {
 99  0
         return active;
 100  
     }
 101  
     public void setActive(boolean active) {
 102  0
         this.active = active;
 103  0
     }
 104  
     
 105  
     public boolean isComplete() {
 106  0
         return complete;
 107  
     }
 108  
     public void setComplete(boolean complete) {
 109  0
         this.complete = complete;
 110  0
     }
 111  
     public Branch getBranch() {
 112  0
         return branch;
 113  
     }
 114  
     public void setBranch(Branch branch) {
 115  0
         this.branch = branch;
 116  0
     }
 117  
     public RouteNode getRouteNode() {
 118  0
         return routeNode;
 119  
     }
 120  
     public void setRouteNode(RouteNode node) {
 121  0
         this.routeNode = node;
 122  0
     }
 123  
     public Long getRouteNodeInstanceId() {
 124  0
         return routeNodeInstanceId;
 125  
     }
 126  
     public void setRouteNodeInstanceId(Long routeNodeInstanceId) {
 127  0
         this.routeNodeInstanceId = routeNodeInstanceId;
 128  0
     }
 129  
     public Long getDocumentId() {
 130  0
         return documentId;
 131  
     }
 132  
     public void setDocumentId(Long routeHeaderId) {
 133  0
         this.documentId = routeHeaderId;
 134  0
     }
 135  
     public List<RouteNodeInstance> getNextNodeInstances() {
 136  0
         return nextNodeInstances;
 137  
     }
 138  
     public RouteNodeInstance getNextNodeInstance(int index) {
 139  0
             while (getNextNodeInstances().size() <= index) {
 140  0
                     nextNodeInstances.add(new RouteNodeInstance());
 141  
             }
 142  0
             return (RouteNodeInstance) getNextNodeInstances().get(index);
 143  
     }
 144  
     public void setNextNodeInstances(List<RouteNodeInstance> nextNodeInstances) {
 145  0
         this.nextNodeInstances = nextNodeInstances;
 146  0
     }
 147  
     public List<RouteNodeInstance> getPreviousNodeInstances() {
 148  0
         return previousNodeInstances;
 149  
     }
 150  
     public RouteNodeInstance getPreviousNodeInstance(int index) {
 151  0
             while (previousNodeInstances.size() <= index) {
 152  0
                     previousNodeInstances.add(new RouteNodeInstance());
 153  
             }
 154  0
             return (RouteNodeInstance) getPreviousNodeInstances().get(index);
 155  
     }
 156  
     public void setPreviousNodeInstances(List<RouteNodeInstance> previousNodeInstances) {
 157  0
         this.previousNodeInstances = previousNodeInstances;
 158  0
     }
 159  
     public boolean isInitial() {
 160  0
         return initial;
 161  
     }
 162  
     public void setInitial(boolean initial) {
 163  0
         this.initial = initial;
 164  0
     }
 165  
     public List getState() {
 166  0
         return state;
 167  
     }
 168  
     public void setState(List<NodeState> state) {
 169  0
         this.state.clear();
 170  0
             this.state.addAll(state);
 171  
         //this.state = state;
 172  0
     }
 173  
     public RouteNodeInstance getProcess() {
 174  0
                 return process;
 175  
         }
 176  
         public void setProcess(RouteNodeInstance process) {
 177  0
                 this.process = process;
 178  0
         }
 179  
         public Integer getLockVerNbr() {
 180  0
         return lockVerNbr;
 181  
     }
 182  
     public void setLockVerNbr(Integer lockVerNbr) {
 183  0
         this.lockVerNbr = lockVerNbr;
 184  0
     }
 185  
     
 186  
     public NodeState getNodeState(String key) {
 187  0
         for (Iterator iter = getState().iterator(); iter.hasNext();) {
 188  0
             NodeState nodeState = (NodeState) iter.next();
 189  0
             if (nodeState.getKey().equals(key)) {
 190  0
                 return nodeState;
 191  
             }
 192  0
         }
 193  0
         return null;
 194  
     }
 195  
     
 196  
     public void addNodeState(NodeState state) {
 197  0
         this.state.add(state);
 198  0
         state.setNodeInstance(this);
 199  0
     }
 200  
     
 201  
     public void removeNodeState(String key) {
 202  0
         for (Iterator iter = getState().iterator(); iter.hasNext();) {
 203  0
             NodeState nodeState = (NodeState) iter.next();
 204  0
             if (nodeState.getKey().equals(key)) {
 205  0
                 iter.remove();
 206  0
                 break;
 207  
             }
 208  0
         }
 209  0
     }
 210  
     
 211  
     public void addNextNodeInstance(RouteNodeInstance nextNodeInstance) {
 212  0
         nextNodeInstances.add(nextNodeInstance);
 213  0
         nextNodeInstance.getPreviousNodeInstances().add(this);
 214  0
     }
 215  
     
 216  
     public void removeNextNodeInstance(RouteNodeInstance nextNodeInstance) {
 217  0
         nextNodeInstances.remove(nextNodeInstance);
 218  0
         nextNodeInstance.getPreviousNodeInstances().remove(this);
 219  0
     }
 220  
     
 221  
     public void clearNextNodeInstances() {
 222  0
         for (Iterator iterator = nextNodeInstances.iterator(); iterator.hasNext();) {
 223  0
             RouteNodeInstance nextNodeInstance = (RouteNodeInstance) iterator.next();
 224  0
             iterator.remove();
 225  0
             nextNodeInstance.getPreviousNodeInstances().remove(this);
 226  0
         }
 227  0
     }
 228  
     
 229  
     public String getName() {
 230  0
         return (getRouteNode() == null ? null : getRouteNode().getRouteNodeName());
 231  
     }
 232  
     
 233  
     public boolean isInProcess() {
 234  0
         return getProcess() != null;
 235  
     }
 236  
     
 237  
     public DocumentType getDocumentType() {
 238  0
         return KEWServiceLocator.getDocumentTypeService().findByDocumentId(getDocumentId());
 239  
     }
 240  
     
 241  
     /*
 242  
      * methods used to display route node instances' data on documentoperation.jsp
 243  
      */
 244  
     
 245  
     public NodeState getNodeStateByIndex(int index){
 246  0
             while (state.size() <= index) {
 247  0
             state.add(new NodeState());
 248  
         }
 249  0
         return (NodeState) getState().get(index);
 250  
     }   
 251  
 
 252  
     public void populateState(List<NodeState> state) {
 253  0
         this.state.addAll(state);
 254  0
      }
 255  
 
 256  
     public String toString() {
 257  0
         return new ToStringBuilder(this)
 258  
             .append("routeNodeInstanceId", routeNodeInstanceId)
 259  
             .append("documentId", documentId)
 260  
             .append("branch", branch == null ? null : branch.getBranchId())
 261  
             .append("routeNode", routeNode == null ? null : routeNode.getRouteNodeName())
 262  
             .append("active", active)
 263  
             .append("complete", complete)
 264  
             .append("initial", initial)
 265  
             .append("process", process)
 266  
             .append("nextNodeInstances", nextNodeInstances == null ? null : nextNodeInstances.size())
 267  
             .append("previousNodeInstances", previousNodeInstances == null ? null : previousNodeInstances.size())
 268  
             .append("state", state == null ? null : state.size())
 269  
             .toString();
 270  
     }
 271  
     
 272  
         @PrePersist
 273  
         public void beforeInsert(){
 274  0
                 OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());                
 275  0
         }
 276  
     
 277  
 }
 278