1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.engine.transition;
18
19 import org.kuali.rice.kew.engine.RouteContext;
20 import org.kuali.rice.kew.engine.node.Process;
21 import org.kuali.rice.kew.engine.node.*;
22 import org.kuali.rice.kew.exception.WorkflowException;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27
28
29
30
31
32
33
34
35 public class SubProcessTransitionEngine extends TransitionEngine {
36
37 public RouteNodeInstance transitionTo(RouteNodeInstance nextNodeInstance, RouteContext context) throws Exception {
38 String processName = nextNodeInstance.getRouteNode().getRouteNodeName();
39 Process process = context.getDocument().getDocumentType().getNamedProcess(processName);
40 if (process == null) {
41 throw new WorkflowException("Could not locate named sub process: " + processName);
42 }
43 RouteNodeInstance subProcessNodeInstance = nextNodeInstance;
44 subProcessNodeInstance.setInitial(false);
45 subProcessNodeInstance.setActive(false);
46 nextNodeInstance = getRouteHelper().getNodeFactory().createRouteNodeInstance(subProcessNodeInstance.getDocumentId(), process.getInitialRouteNode());
47 nextNodeInstance.setBranch(subProcessNodeInstance.getBranch());
48 nextNodeInstance.setProcess(subProcessNodeInstance);
49 return nextNodeInstance;
50 }
51
52 public ProcessResult isComplete(RouteContext context) throws Exception {
53 throw new UnsupportedOperationException("isComplete() should not be invoked on a SubProcess!");
54 }
55
56 public Transition transitionFrom(RouteContext context, ProcessResult processResult) throws Exception {
57 RouteNodeInstance processInstance = context.getNodeInstance().getProcess();
58 processInstance.setComplete(true);
59 SubProcessNode node = (SubProcessNode)getNode(processInstance.getRouteNode(), SubProcessNode.class);
60 SubProcessResult result = node.process(context);
61 List<RouteNodeInstance> nextNodeInstances = new ArrayList<RouteNodeInstance>();
62 if (result.isComplete()) {
63 List<RouteNode> nextNodes = processInstance.getRouteNode().getNextNodes();
64 for (RouteNode nextNode : nextNodes)
65 {
66 RouteNodeInstance nextNodeInstance = getRouteHelper().getNodeFactory().createRouteNodeInstance(processInstance.getDocumentId(), nextNode);
67 nextNodeInstance.setBranch(processInstance.getBranch());
68 nextNodeInstance.setProcess(processInstance.getProcess());
69 nextNodeInstances.add(nextNodeInstance);
70 }
71 }
72 return new Transition(nextNodeInstances);
73 }
74
75 }