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.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.api.doctype.RouteNodeConfigurationParameterContract; |
50 | |
import org.kuali.rice.kew.api.doctype.RouteNodeContract; |
51 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
52 | |
import org.kuali.rice.kew.exception.ResourceUnavailableException; |
53 | |
import org.kuali.rice.kew.rule.bo.RuleTemplate; |
54 | |
import org.kuali.rice.kew.rule.service.RuleTemplateService; |
55 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
56 | |
import org.kuali.rice.kew.util.KEWConstants; |
57 | |
import org.kuali.rice.kew.util.Utilities; |
58 | |
import org.kuali.rice.kim.api.group.Group; |
59 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
@Entity |
67 | |
@Table(name="KREW_RTE_NODE_T") |
68 | |
|
69 | |
@NamedQueries({ |
70 | |
@NamedQuery(name="RouteNode.FindByRouteNodeId",query="select r from RouteNode as r where r.routeNodeId = :routeNodeId"), |
71 | |
@NamedQuery(name="RouteNode.FindRouteNodeByName", query="select r from RouteNode as r where r.routeNodeName = :routeNodeName and r.documentTypeId = :documentTypeId"), |
72 | |
@NamedQuery(name="RouteNode.FindApprovalRouteNodes", query="select r from RouteNode as r where r.documentTypeId = :documentTypeId and r.finalApprovalInd = :finalApprovalInd") |
73 | |
}) |
74 | 0 | public class RouteNode implements Serializable, RouteNodeContract { |
75 | |
|
76 | |
private static final long serialVersionUID = 4891233177051752726L; |
77 | |
|
78 | |
public static final String CONTENT_FRAGMENT_CFG_KEY = "contentFragment"; |
79 | |
public static final String RULE_SELECTOR_CFG_KEY = "ruleSelector"; |
80 | |
|
81 | |
@Id |
82 | |
@GeneratedValue(generator="KREW_RTE_NODE_S") |
83 | |
@GenericGenerator(name="KREW_RTE_NODE_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ |
84 | |
@Parameter(name="sequence_name",value="KREW_RTE_NODE_S"), |
85 | |
@Parameter(name="value_column",value="id") |
86 | |
}) |
87 | |
@Column(name="RTE_NODE_ID") |
88 | |
private String routeNodeId; |
89 | |
@Column(name="DOC_TYP_ID",insertable=false, updatable=false) |
90 | |
private String documentTypeId; |
91 | |
@Column(name="NM") |
92 | |
private String routeNodeName; |
93 | |
@Column(name="RTE_MTHD_NM") |
94 | |
private String routeMethodName; |
95 | |
@Column(name="FNL_APRVR_IND") |
96 | |
private Boolean finalApprovalInd; |
97 | |
@Column(name="MNDTRY_RTE_IND") |
98 | |
private Boolean mandatoryRouteInd; |
99 | |
@Column(name="GRP_ID") |
100 | |
private String exceptionWorkgroupId; |
101 | |
@Column(name="RTE_MTHD_CD") |
102 | |
private String routeMethodCode; |
103 | 0 | @Column(name="ACTVN_TYP") |
104 | |
private String activationType = ActivationTypeEnum.PARALLEL.getCode(); |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
@Column(name="NEXT_DOC_STAT") |
111 | |
private String nextDocStatus; |
112 | |
|
113 | |
@Version |
114 | |
@Column(name="VER_NBR") |
115 | |
private Integer lockVerNbr; |
116 | |
@ManyToOne(fetch=FetchType.EAGER) |
117 | |
@JoinColumn(name="DOC_TYP_ID") |
118 | |
private DocumentType documentType; |
119 | |
@Transient |
120 | |
private String exceptionWorkgroupName; |
121 | |
|
122 | |
@Transient |
123 | |
private RuleTemplate ruleTemplate; |
124 | 0 | @Column(name="TYP") |
125 | |
private String nodeType = RequestsNode.class.getName(); |
126 | |
|
127 | |
|
128 | 0 | @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST}, mappedBy="nextNodes") |
129 | |
@Fetch(value = FetchMode.SELECT) |
130 | |
|
131 | |
private List<RouteNode> previousNodes = new ArrayList<RouteNode>(); |
132 | |
|
133 | 0 | @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST}) |
134 | |
@Fetch(value = FetchMode.SELECT) |
135 | |
@JoinTable(name = "KREW_RTE_NODE_LNK_T", joinColumns = @JoinColumn(name = "FROM_RTE_NODE_ID"), inverseJoinColumns = @JoinColumn(name = "TO_RTE_NODE_ID")) |
136 | |
private List<RouteNode> nextNodes = new ArrayList<RouteNode>(); |
137 | |
@OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.MERGE}) |
138 | |
@JoinColumn(name="BRCH_PROTO_ID") |
139 | |
private BranchPrototype branch; |
140 | 0 | @OneToMany(fetch=FetchType.EAGER,mappedBy="routeNode",cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}) |
141 | |
@Fetch(value = FetchMode.SELECT) |
142 | |
private List<RouteNodeConfigParam> configParams = new ArrayList<RouteNodeConfigParam>(0); |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
protected RouteNodeConfigParam getConfigParam(String key) { |
150 | 0 | Map<String, RouteNodeConfigParam> configParamMap = Utilities.getKeyValueCollectionAsLookupTable(configParams); |
151 | 0 | return configParamMap.get(key); |
152 | |
} |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
protected void setConfigParam(String key, String value) { |
161 | 0 | Map<String, RouteNodeConfigParam> configParamMap = Utilities.getKeyValueCollectionAsLookupTable(configParams); |
162 | 0 | RouteNodeConfigParam cfCfgParam = configParamMap.get(key); |
163 | 0 | if (cfCfgParam == null) { |
164 | 0 | cfCfgParam = new RouteNodeConfigParam(this, key, value); |
165 | 0 | configParams.add(cfCfgParam); |
166 | |
} else { |
167 | 0 | cfCfgParam.setValue(value); |
168 | |
} |
169 | 0 | } |
170 | |
|
171 | |
public List<RouteNodeConfigParam> getConfigParams() { |
172 | 0 | return configParams; |
173 | |
} |
174 | |
|
175 | |
public void setConfigParams(List<RouteNodeConfigParam> configParams) { |
176 | 0 | this.configParams = configParams; |
177 | 0 | } |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
public String getContentFragment() { |
183 | 0 | RouteNodeConfigParam cfCfgParam = getConfigParam(CONTENT_FRAGMENT_CFG_KEY); |
184 | 0 | if (cfCfgParam == null) return null; |
185 | 0 | return cfCfgParam.getValue(); |
186 | |
} |
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
public void setContentFragment(String contentFragment) { |
192 | 0 | setConfigParam(CONTENT_FRAGMENT_CFG_KEY, contentFragment); |
193 | 0 | } |
194 | |
|
195 | |
public String getActivationType() { |
196 | 0 | return activationType; |
197 | |
} |
198 | |
|
199 | |
public void setActivationType(String activationType) { |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | 0 | ActivationTypeEnum at = ActivationTypeEnum.lookupCode(activationType); |
209 | 0 | this.activationType = at.getCode(); |
210 | 0 | } |
211 | |
|
212 | |
public Group getExceptionWorkgroup() { |
213 | 0 | if (!StringUtils.isBlank(exceptionWorkgroupId)) { |
214 | 0 | return KimApiServiceLocator.getGroupService().getGroup(exceptionWorkgroupId); |
215 | |
} |
216 | 0 | return null; |
217 | |
} |
218 | |
|
219 | |
public boolean isExceptionGroupDefined() { |
220 | 0 | return getExceptionWorkgroupId() != null; |
221 | |
} |
222 | |
|
223 | |
public String getExceptionWorkgroupId() { |
224 | 0 | return exceptionWorkgroupId; |
225 | |
} |
226 | |
|
227 | |
public void setExceptionWorkgroupId(String workgroupId) { |
228 | 0 | this.exceptionWorkgroupId = workgroupId; |
229 | 0 | } |
230 | |
|
231 | |
public void setFinalApprovalInd(Boolean finalApprovalInd) { |
232 | 0 | this.finalApprovalInd = finalApprovalInd; |
233 | 0 | } |
234 | |
|
235 | |
public void setMandatoryRouteInd(Boolean mandatoryRouteInd) { |
236 | 0 | this.mandatoryRouteInd = mandatoryRouteInd; |
237 | 0 | } |
238 | |
|
239 | |
public String getRouteMethodName() { |
240 | 0 | return routeMethodName; |
241 | |
} |
242 | |
|
243 | |
public void setRouteMethodName(String routeMethodName) { |
244 | 0 | this.routeMethodName = routeMethodName; |
245 | 0 | } |
246 | |
|
247 | |
public String getDocumentTypeId() { |
248 | 0 | return documentTypeId; |
249 | |
} |
250 | |
|
251 | |
public void setDocumentTypeId(String documentTypeId) { |
252 | 0 | this.documentTypeId = documentTypeId; |
253 | 0 | } |
254 | |
|
255 | |
public String getRouteNodeId() { |
256 | 0 | return routeNodeId; |
257 | |
} |
258 | |
|
259 | |
public void setRouteNodeId(String routeNodeId) { |
260 | 0 | this.routeNodeId = routeNodeId; |
261 | 0 | } |
262 | |
|
263 | |
public String getRouteNodeName() { |
264 | 0 | return routeNodeName; |
265 | |
} |
266 | |
|
267 | |
public void setRouteNodeName(String routeLevelName) { |
268 | 0 | this.routeNodeName = routeLevelName; |
269 | 0 | } |
270 | |
|
271 | |
public DocumentType getDocumentType() { |
272 | 0 | return documentType; |
273 | |
} |
274 | |
|
275 | |
public void setDocumentType(DocumentType documentType) { |
276 | 0 | this.documentType = documentType; |
277 | 0 | } |
278 | |
|
279 | |
public String getRouteMethodCode() { |
280 | 0 | return routeMethodCode; |
281 | |
} |
282 | |
|
283 | |
public void setRouteMethodCode(String routeMethodCode) { |
284 | 0 | this.routeMethodCode = routeMethodCode; |
285 | 0 | } |
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
public void setNextDocStatus(String nextDocStatus) { |
291 | 0 | this.nextDocStatus = nextDocStatus; |
292 | 0 | } |
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
public String getNextDocStatus() { |
298 | 0 | return nextDocStatus; |
299 | |
} |
300 | |
|
301 | |
public String getExceptionWorkgroupName() { |
302 | 0 | Group exceptionGroup = getExceptionWorkgroup(); |
303 | 0 | if (exceptionWorkgroupName == null || exceptionWorkgroupName.equals("")) { |
304 | 0 | if (exceptionGroup != null) { |
305 | 0 | return exceptionGroup.getName(); |
306 | |
} |
307 | |
} |
308 | 0 | return exceptionWorkgroupName; |
309 | |
} |
310 | |
|
311 | |
public void setExceptionWorkgroupName(String exceptionWorkgroupName) { |
312 | 0 | this.exceptionWorkgroupName = exceptionWorkgroupName; |
313 | 0 | } |
314 | |
|
315 | |
public Integer getLockVerNbr() { |
316 | 0 | return lockVerNbr; |
317 | |
} |
318 | |
|
319 | |
public void setLockVerNbr(Integer lockVerNbr) { |
320 | 0 | this.lockVerNbr = lockVerNbr; |
321 | 0 | } |
322 | |
|
323 | |
public boolean isFlexRM() { |
324 | 0 | return routeMethodCode != null && routeMethodCode.equals(KEWConstants.ROUTE_LEVEL_FLEX_RM); |
325 | |
} |
326 | |
|
327 | |
public boolean isRoleNode() { |
328 | |
try { |
329 | 0 | return nodeType != null && NodeType.fromNode(this).isTypeOf(NodeType.ROLE); |
330 | 0 | } catch( ResourceUnavailableException ex ) { |
331 | 0 | Logger.getLogger( RouteNode.class ).info( "isRoleNode(): Unable to determine node type: " + ex.getMessage() ); |
332 | 0 | return false; |
333 | |
} |
334 | |
} |
335 | |
|
336 | |
public Boolean getFinalApprovalInd() { |
337 | 0 | return finalApprovalInd; |
338 | |
} |
339 | |
|
340 | |
public Boolean getMandatoryRouteInd() { |
341 | 0 | return mandatoryRouteInd; |
342 | |
} |
343 | |
|
344 | |
public void addNextNode(RouteNode nextNode) { |
345 | 0 | getNextNodes().add(nextNode); |
346 | 0 | nextNode.getPreviousNodes().add(this); |
347 | 0 | } |
348 | |
|
349 | |
public List<RouteNode> getNextNodes() { |
350 | 0 | return nextNodes; |
351 | |
} |
352 | |
|
353 | |
public void setNextNodes(List<RouteNode> nextNodes) { |
354 | 0 | this.nextNodes = nextNodes; |
355 | 0 | } |
356 | |
|
357 | |
public List<RouteNode> getPreviousNodes() { |
358 | 0 | return previousNodes; |
359 | |
} |
360 | |
|
361 | |
public void setPreviousNodes(List<RouteNode> parentNodes) { |
362 | 0 | this.previousNodes = parentNodes; |
363 | 0 | } |
364 | |
|
365 | |
public RuleTemplate getRuleTemplate() { |
366 | 0 | if (ruleTemplate == null) { |
367 | 0 | RuleTemplateService ruleTemplateService = (RuleTemplateService) KEWServiceLocator.getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE); |
368 | 0 | ruleTemplate = ruleTemplateService.findByRuleTemplateName(getRouteMethodName()); |
369 | |
} |
370 | 0 | return ruleTemplate; |
371 | |
} |
372 | |
|
373 | |
public String getNodeType() { |
374 | 0 | return nodeType; |
375 | |
} |
376 | |
|
377 | |
public void setNodeType(String nodeType) { |
378 | 0 | this.nodeType = nodeType; |
379 | 0 | } |
380 | |
|
381 | |
public BranchPrototype getBranch() { |
382 | 0 | return branch; |
383 | |
} |
384 | |
|
385 | |
public void setBranch(BranchPrototype branch) { |
386 | 0 | this.branch = branch; |
387 | 0 | } |
388 | |
|
389 | |
|
390 | |
public void beforeInsert(){ |
391 | 0 | OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager()); |
392 | 0 | } |
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
@Override |
400 | |
public String toString() { |
401 | 0 | return "RouteNode[routeNodeName="+routeNodeName+", nodeType="+nodeType+", activationType="+activationType+"]"; |
402 | |
} |
403 | |
|
404 | |
@Override |
405 | |
public Long getVersionNumber() { |
406 | 0 | if (lockVerNbr == null) { |
407 | 0 | return null; |
408 | |
} |
409 | 0 | return Long.valueOf(lockVerNbr.longValue()); |
410 | |
} |
411 | |
|
412 | |
@Override |
413 | |
public String getId() { |
414 | 0 | if (routeNodeId == null) { |
415 | 0 | return null; |
416 | |
} |
417 | 0 | return routeNodeId.toString(); |
418 | |
} |
419 | |
|
420 | |
@Override |
421 | |
public String getName() { |
422 | 0 | return getRouteNodeName(); |
423 | |
} |
424 | |
|
425 | |
@Override |
426 | |
public boolean isFinalApproval() { |
427 | 0 | if (finalApprovalInd == null) { |
428 | 0 | return false; |
429 | |
} |
430 | 0 | return finalApprovalInd.booleanValue(); |
431 | |
} |
432 | |
|
433 | |
@Override |
434 | |
public boolean isMandatory() { |
435 | 0 | if (mandatoryRouteInd == null) { |
436 | 0 | return false; |
437 | |
} |
438 | 0 | return mandatoryRouteInd.booleanValue(); |
439 | |
} |
440 | |
|
441 | |
@Override |
442 | |
public String getExceptionGroupId() { |
443 | 0 | return exceptionWorkgroupId; |
444 | |
} |
445 | |
|
446 | |
@Override |
447 | |
public String getType() { |
448 | 0 | return nodeType; |
449 | |
} |
450 | |
|
451 | |
@Override |
452 | |
public String getBranchName() { |
453 | 0 | if (branch == null) { |
454 | 0 | return null; |
455 | |
} |
456 | 0 | return branch.getName(); |
457 | |
} |
458 | |
|
459 | |
@Override |
460 | |
public String getNextDocumentStatus() { |
461 | 0 | return nextDocStatus; |
462 | |
} |
463 | |
|
464 | |
@Override |
465 | |
public List<? extends RouteNodeConfigurationParameterContract> getConfigurationParameters() { |
466 | 0 | return configParams; |
467 | |
} |
468 | |
|
469 | |
@Override |
470 | |
public List<String> getPreviousNodeIds() { |
471 | 0 | List<String> previousNodeIds = new ArrayList<String>(); |
472 | 0 | if (previousNodes != null) { |
473 | 0 | for (RouteNode previousNode : previousNodes) { |
474 | 0 | previousNodeIds.add(previousNode.getRouteNodeId().toString()); |
475 | |
} |
476 | |
} |
477 | 0 | return previousNodeIds; |
478 | |
} |
479 | |
|
480 | |
@Override |
481 | |
public List<String> getNextNodeIds() { |
482 | 0 | List<String> nextNodeIds = new ArrayList<String>(); |
483 | 0 | if (nextNodeIds != null) { |
484 | 0 | for (RouteNode nextNode : nextNodes) { |
485 | 0 | nextNodeIds.add(nextNode.getRouteNodeId().toString()); |
486 | |
} |
487 | |
} |
488 | 0 | return nextNodeIds; |
489 | |
} |
490 | |
|
491 | |
|
492 | |
|
493 | |
} |