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