| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kew.engine.node; |
| 18 | |
|
| 19 | |
import java.io.Serializable; |
| 20 | |
import java.util.ArrayList; |
| 21 | |
import java.util.Iterator; |
| 22 | |
import java.util.List; |
| 23 | |
|
| 24 | |
import javax.persistence.CascadeType; |
| 25 | |
import javax.persistence.Column; |
| 26 | |
import javax.persistence.Entity; |
| 27 | |
import javax.persistence.FetchType; |
| 28 | |
import javax.persistence.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.Version; |
| 40 | |
|
| 41 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 42 | |
import org.hibernate.annotations.Fetch; |
| 43 | |
import org.hibernate.annotations.FetchMode; |
| 44 | |
import org.hibernate.annotations.GenericGenerator; |
| 45 | |
import org.hibernate.annotations.Parameter; |
| 46 | |
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
| 47 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 48 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
| 49 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
@Entity |
| 60 | |
@Table(name="KREW_RTE_NODE_INSTN_T") |
| 61 | |
|
| 62 | |
@NamedQueries({ |
| 63 | |
@NamedQuery(name="RouteNodeInstance.FindByRouteNodeInstanceId",query="select r from RouteNodeInstance r where r.routeNodeInstanceId = :routeNodeInstanceId"), |
| 64 | |
@NamedQuery(name="RouteNodeInstance.FindActiveNodeInstances",query="select r from RouteNodeInstance r where r.documentId = :documentId and r.active = true"), |
| 65 | |
@NamedQuery(name="RouteNodeInstance.FindTerminalNodeInstances",query="select r from RouteNodeInstance r where r.documentId = :documentId and r.active = false and r.complete = true"), |
| 66 | |
@NamedQuery(name="RouteNodeInstance.FindInitialNodeInstances",query="select d.initialRouteNodeInstances from DocumentRouteHeaderValue d where d.routeHeaderId = :routeHeaderId"), |
| 67 | |
@NamedQuery(name="RouteNodeInstance.FindProcessNodeInstances", query="select r from RouteNodeInstance r where r.process.routeNodeInstanceId = :processId"), |
| 68 | |
@NamedQuery(name="RouteNodeInstance.FindRouteNodeInstances", query="select r from RouteNodeInstance r where r.documentId = :documentId") |
| 69 | |
}) |
| 70 | 0 | public class RouteNodeInstance implements Serializable { |
| 71 | |
|
| 72 | |
private static final long serialVersionUID = 7183670062805580420L; |
| 73 | |
|
| 74 | |
@Id |
| 75 | |
@GeneratedValue(generator="KREW_RTE_NODE_S") |
| 76 | |
@GenericGenerator(name="KREW_RTE_NODE_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ |
| 77 | |
@Parameter(name="sequence_name",value="KREW_RTE_NODE_S"), |
| 78 | |
@Parameter(name="value_column",value="id") |
| 79 | |
}) |
| 80 | |
@Column(name="RTE_NODE_INSTN_ID") |
| 81 | |
private Long routeNodeInstanceId; |
| 82 | |
@Column(name="DOC_HDR_ID") |
| 83 | |
private Long documentId; |
| 84 | |
@ManyToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE}) |
| 85 | |
@JoinColumn(name="BRCH_ID") |
| 86 | |
private Branch branch; |
| 87 | |
@OneToOne(fetch=FetchType.EAGER) |
| 88 | |
@JoinColumn(name="RTE_NODE_ID") |
| 89 | |
private RouteNode routeNode; |
| 90 | 0 | @Column(name="ACTV_IND") |
| 91 | |
private boolean active = false; |
| 92 | 0 | @Column(name="CMPLT_IND") |
| 93 | |
private boolean complete = false; |
| 94 | 0 | @Column(name="INIT_IND") |
| 95 | |
private boolean initial = true; |
| 96 | |
@OneToOne(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST, CascadeType.MERGE}) |
| 97 | |
@JoinColumn(name="PROC_RTE_NODE_INSTN_ID") |
| 98 | |
private RouteNodeInstance process; |
| 99 | |
|
| 100 | 0 | @ManyToMany(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}) |
| 101 | |
@JoinTable(name = "KREW_RTE_NODE_INSTN_LNK_T", joinColumns = @JoinColumn(name = "FROM_RTE_NODE_INSTN_ID"), inverseJoinColumns = @JoinColumn(name = "TO_RTE_NODE_INSTN_ID")) |
| 102 | |
@Fetch(value = FetchMode.SELECT) |
| 103 | |
private List<RouteNodeInstance> nextNodeInstances = new ArrayList<RouteNodeInstance>(); |
| 104 | |
|
| 105 | 0 | @ManyToMany(fetch=FetchType.EAGER, mappedBy="nextNodeInstances") |
| 106 | |
@Fetch(value = FetchMode.SELECT) |
| 107 | |
|
| 108 | |
private List<RouteNodeInstance> previousNodeInstances = new ArrayList<RouteNodeInstance>(); |
| 109 | |
|
| 110 | 0 | @OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE}, mappedBy="nodeInstance", orphanRemoval=true) |
| 111 | |
@Fetch(value = FetchMode.SELECT) |
| 112 | |
private List<NodeState> state = new ArrayList<NodeState>(); |
| 113 | |
|
| 114 | |
@Version |
| 115 | |
@Column(name="VER_NBR") |
| 116 | |
private Integer lockVerNbr; |
| 117 | |
|
| 118 | |
public boolean isActive() { |
| 119 | 0 | return active; |
| 120 | |
} |
| 121 | |
public void setActive(boolean active) { |
| 122 | 0 | this.active = active; |
| 123 | 0 | } |
| 124 | |
|
| 125 | |
public boolean isComplete() { |
| 126 | 0 | return complete; |
| 127 | |
} |
| 128 | |
public void setComplete(boolean complete) { |
| 129 | 0 | this.complete = complete; |
| 130 | 0 | } |
| 131 | |
public Branch getBranch() { |
| 132 | 0 | return branch; |
| 133 | |
} |
| 134 | |
public void setBranch(Branch branch) { |
| 135 | 0 | this.branch = branch; |
| 136 | 0 | } |
| 137 | |
public RouteNode getRouteNode() { |
| 138 | 0 | return routeNode; |
| 139 | |
} |
| 140 | |
public void setRouteNode(RouteNode node) { |
| 141 | 0 | this.routeNode = node; |
| 142 | 0 | } |
| 143 | |
public Long getRouteNodeInstanceId() { |
| 144 | 0 | return routeNodeInstanceId; |
| 145 | |
} |
| 146 | |
public void setRouteNodeInstanceId(Long routeNodeInstanceId) { |
| 147 | 0 | this.routeNodeInstanceId = routeNodeInstanceId; |
| 148 | 0 | } |
| 149 | |
public Long getDocumentId() { |
| 150 | 0 | return documentId; |
| 151 | |
} |
| 152 | |
public void setDocumentId(Long routeHeaderId) { |
| 153 | 0 | this.documentId = routeHeaderId; |
| 154 | 0 | } |
| 155 | |
public List<RouteNodeInstance> getNextNodeInstances() { |
| 156 | 0 | return nextNodeInstances; |
| 157 | |
} |
| 158 | |
public RouteNodeInstance getNextNodeInstance(int index) { |
| 159 | 0 | while (getNextNodeInstances().size() <= index) { |
| 160 | 0 | nextNodeInstances.add(new RouteNodeInstance()); |
| 161 | |
} |
| 162 | 0 | return (RouteNodeInstance) getNextNodeInstances().get(index); |
| 163 | |
} |
| 164 | |
public void setNextNodeInstances(List<RouteNodeInstance> nextNodeInstances) { |
| 165 | 0 | this.nextNodeInstances = nextNodeInstances; |
| 166 | 0 | } |
| 167 | |
public List<RouteNodeInstance> getPreviousNodeInstances() { |
| 168 | 0 | return previousNodeInstances; |
| 169 | |
} |
| 170 | |
public RouteNodeInstance getPreviousNodeInstance(int index) { |
| 171 | 0 | while (previousNodeInstances.size() <= index) { |
| 172 | 0 | previousNodeInstances.add(new RouteNodeInstance()); |
| 173 | |
} |
| 174 | 0 | return (RouteNodeInstance) getPreviousNodeInstances().get(index); |
| 175 | |
} |
| 176 | |
public void setPreviousNodeInstances(List<RouteNodeInstance> previousNodeInstances) { |
| 177 | 0 | this.previousNodeInstances = previousNodeInstances; |
| 178 | 0 | } |
| 179 | |
public boolean isInitial() { |
| 180 | 0 | return initial; |
| 181 | |
} |
| 182 | |
public void setInitial(boolean initial) { |
| 183 | 0 | this.initial = initial; |
| 184 | 0 | } |
| 185 | |
public List getState() { |
| 186 | 0 | return state; |
| 187 | |
} |
| 188 | |
public void setState(List<NodeState> state) { |
| 189 | 0 | this.state.clear(); |
| 190 | 0 | this.state.addAll(state); |
| 191 | |
|
| 192 | 0 | } |
| 193 | |
public RouteNodeInstance getProcess() { |
| 194 | 0 | return process; |
| 195 | |
} |
| 196 | |
public void setProcess(RouteNodeInstance process) { |
| 197 | 0 | this.process = process; |
| 198 | 0 | } |
| 199 | |
public Integer getLockVerNbr() { |
| 200 | 0 | return lockVerNbr; |
| 201 | |
} |
| 202 | |
public void setLockVerNbr(Integer lockVerNbr) { |
| 203 | 0 | this.lockVerNbr = lockVerNbr; |
| 204 | 0 | } |
| 205 | |
|
| 206 | |
public NodeState getNodeState(String key) { |
| 207 | 0 | for (Iterator iter = getState().iterator(); iter.hasNext();) { |
| 208 | 0 | NodeState nodeState = (NodeState) iter.next(); |
| 209 | 0 | if (nodeState.getKey().equals(key)) { |
| 210 | 0 | return nodeState; |
| 211 | |
} |
| 212 | 0 | } |
| 213 | 0 | return null; |
| 214 | |
} |
| 215 | |
|
| 216 | |
public void addNodeState(NodeState state) { |
| 217 | 0 | this.state.add(state); |
| 218 | 0 | state.setNodeInstance(this); |
| 219 | 0 | } |
| 220 | |
|
| 221 | |
public void removeNodeState(String key) { |
| 222 | 0 | for (Iterator iter = getState().iterator(); iter.hasNext();) { |
| 223 | 0 | NodeState nodeState = (NodeState) iter.next(); |
| 224 | 0 | if (nodeState.getKey().equals(key)) { |
| 225 | 0 | iter.remove(); |
| 226 | 0 | break; |
| 227 | |
} |
| 228 | 0 | } |
| 229 | 0 | } |
| 230 | |
|
| 231 | |
public void addNextNodeInstance(RouteNodeInstance nextNodeInstance) { |
| 232 | 0 | nextNodeInstances.add(nextNodeInstance); |
| 233 | 0 | nextNodeInstance.getPreviousNodeInstances().add(this); |
| 234 | 0 | } |
| 235 | |
|
| 236 | |
public void removeNextNodeInstance(RouteNodeInstance nextNodeInstance) { |
| 237 | 0 | nextNodeInstances.remove(nextNodeInstance); |
| 238 | 0 | nextNodeInstance.getPreviousNodeInstances().remove(this); |
| 239 | 0 | } |
| 240 | |
|
| 241 | |
public void clearNextNodeInstances() { |
| 242 | 0 | for (Iterator iterator = nextNodeInstances.iterator(); iterator.hasNext();) { |
| 243 | 0 | RouteNodeInstance nextNodeInstance = (RouteNodeInstance) iterator.next(); |
| 244 | 0 | iterator.remove(); |
| 245 | 0 | nextNodeInstance.getPreviousNodeInstances().remove(this); |
| 246 | 0 | } |
| 247 | 0 | } |
| 248 | |
|
| 249 | |
public String getName() { |
| 250 | 0 | return (getRouteNode() == null ? null : getRouteNode().getRouteNodeName()); |
| 251 | |
} |
| 252 | |
|
| 253 | |
public boolean isInProcess() { |
| 254 | 0 | return getProcess() != null; |
| 255 | |
} |
| 256 | |
|
| 257 | |
public DocumentType getDocumentType() { |
| 258 | 0 | return KEWServiceLocator.getDocumentTypeService().findByDocumentId(getDocumentId()); |
| 259 | |
} |
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
public NodeState getNodeStateByIndex(int index){ |
| 266 | 0 | while (state.size() <= index) { |
| 267 | 0 | state.add(new NodeState()); |
| 268 | |
} |
| 269 | 0 | return (NodeState) getState().get(index); |
| 270 | |
} |
| 271 | |
|
| 272 | |
public void populateState(List<NodeState> state) { |
| 273 | 0 | this.state.addAll(state); |
| 274 | 0 | } |
| 275 | |
|
| 276 | |
public String toString() { |
| 277 | 0 | return new ToStringBuilder(this) |
| 278 | |
.append("routeNodeInstanceId", routeNodeInstanceId) |
| 279 | |
.append("documentId", documentId) |
| 280 | |
.append("branch", branch == null ? null : branch.getBranchId()) |
| 281 | |
.append("routeNode", routeNode == null ? null : routeNode.getRouteNodeName()) |
| 282 | |
.append("active", active) |
| 283 | |
.append("complete", complete) |
| 284 | |
.append("initial", initial) |
| 285 | |
.append("process", process) |
| 286 | |
.append("nextNodeInstances", nextNodeInstances == null ? null : nextNodeInstances.size()) |
| 287 | |
.append("previousNodeInstances", previousNodeInstances == null ? null : previousNodeInstances.size()) |
| 288 | |
.append("state", state == null ? null : state.size()) |
| 289 | |
.toString(); |
| 290 | |
} |
| 291 | |
|
| 292 | |
|
| 293 | |
public void beforeInsert(){ |
| 294 | 0 | OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager()); |
| 295 | 0 | } |
| 296 | |
|
| 297 | |
} |
| 298 | |
|