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