1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.engine.node; |
17 | |
|
18 | |
import java.io.Serializable; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Iterator; |
21 | |
import java.util.List; |
22 | |
|
23 | |
import javax.persistence.CascadeType; |
24 | |
import javax.persistence.Column; |
25 | |
import javax.persistence.Entity; |
26 | |
import javax.persistence.FetchType; |
27 | |
import javax.persistence.GeneratedValue; |
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.Table; |
38 | |
import javax.persistence.Version; |
39 | |
|
40 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
41 | |
import org.hibernate.annotations.Fetch; |
42 | |
import org.hibernate.annotations.FetchMode; |
43 | |
import org.hibernate.annotations.GenericGenerator; |
44 | |
import org.hibernate.annotations.Parameter; |
45 | |
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
46 | |
import org.kuali.rice.kew.api.document.node.RouteNodeInstanceState; |
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.documentId = :documentId"), |
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 String routeNodeInstanceId; |
82 | |
@Column(name="DOC_HDR_ID") |
83 | |
private String 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 String getRouteNodeInstanceId() { |
144 | 0 | return routeNodeInstanceId; |
145 | |
} |
146 | |
public void setRouteNodeInstanceId(String routeNodeInstanceId) { |
147 | 0 | this.routeNodeInstanceId = routeNodeInstanceId; |
148 | 0 | } |
149 | |
public String getDocumentId() { |
150 | 0 | return documentId; |
151 | |
} |
152 | |
public void setDocumentId(String documentId) { |
153 | 0 | this.documentId = documentId; |
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<NodeState> 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 | |
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()); |
306 | 0 | builder.setComplete(routeNodeInstance.isComplete()); |
307 | 0 | builder.setDocumentId(routeNodeInstance.getDocumentId()); |
308 | 0 | builder.setId(routeNodeInstance.getRouteNodeInstanceId()); |
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()); |
313 | |
} |
314 | 0 | builder.setRouteNodeId(routeNodeInstance.getRouteNode().getRouteNodeId()); |
315 | 0 | List<RouteNodeInstanceState.Builder> states = new ArrayList<RouteNodeInstanceState.Builder>(); |
316 | 0 | for (NodeState stateBo : routeNodeInstance.getState()) { |
317 | 0 | RouteNodeInstanceState.Builder stateBuilder = RouteNodeInstanceState.Builder.create(); |
318 | 0 | stateBuilder.setId(stateBo.getStateId()); |
319 | 0 | stateBuilder.setKey(stateBo.getKey()); |
320 | 0 | stateBuilder.setValue(stateBo.getValue()); |
321 | 0 | states.add(stateBuilder); |
322 | 0 | } |
323 | 0 | builder.setState(states); |
324 | |
|
325 | 0 | List<org.kuali.rice.kew.api.document.node.RouteNodeInstance.Builder> nextNodes = new ArrayList<org.kuali.rice.kew.api.document.node.RouteNodeInstance.Builder>(); |
326 | 0 | if (routeNodeInstance.getNextNodeInstances() != null) { |
327 | 0 | for (RouteNodeInstance next : routeNodeInstance.getNextNodeInstances()) { |
328 | |
|
329 | 0 | nextNodes.add(org.kuali.rice.kew.api.document.node.RouteNodeInstance.Builder.create(RouteNodeInstance.to(next))); |
330 | |
} |
331 | |
} |
332 | 0 | builder.setNextNodeInstances(nextNodes); |
333 | |
|
334 | 0 | return builder.build(); |
335 | |
|
336 | |
|
337 | |
|
338 | |
} |
339 | |
|
340 | |
} |
341 | |
|