1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.engine; |
18 | |
|
19 | |
import java.util.ArrayList; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
23 | |
import org.kuali.rice.kew.api.KewApiConstants; |
24 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
25 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
26 | |
import org.kuali.rice.kew.engine.node.Process; |
27 | |
import org.kuali.rice.kew.engine.node.RouteNode; |
28 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
29 | |
import org.kuali.rice.kew.util.KEWConstants; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public final class CompatUtils { |
41 | |
|
42 | 0 | private static RouteHelper helper = new RouteHelper(); |
43 | |
|
44 | 0 | private CompatUtils() { |
45 | 0 | throw new UnsupportedOperationException("do not call"); |
46 | |
} |
47 | |
|
48 | |
public static Integer getLevelForNode(DocumentType documentType, String nodeName) { |
49 | 0 | if (isRouteLevelCompatible(documentType)) { |
50 | 0 | return getLevelForNode(documentType.getPrimaryProcess().getInitialRouteNode(), nodeName, new Integer(0)); |
51 | |
} |
52 | 0 | return new Integer(KEWConstants.INVALID_ROUTE_LEVEL); |
53 | |
} |
54 | |
|
55 | |
private static Integer getLevelForNode(RouteNode node, String nodeName, Integer currentLevel) { |
56 | |
|
57 | |
|
58 | 0 | if (node.getRouteNodeName().equals(nodeName)) { |
59 | 0 | return currentLevel; |
60 | |
} |
61 | 0 | List<RouteNode> nextNodes = node.getNextNodes(); |
62 | 0 | if (nextNodes.isEmpty()) { |
63 | 0 | throw new WorkflowRuntimeException("Could not locate node with name '"+nodeName+"'"); |
64 | |
} |
65 | 0 | if (nextNodes.size() > 1) { |
66 | 0 | throw new WorkflowRuntimeException("Can only determine route level for document types with no splitting"); |
67 | |
} |
68 | 0 | RouteNode nextNode = (RouteNode)nextNodes.get(0); |
69 | 0 | return getLevelForNode(nextNode, nodeName, new Integer(currentLevel.intValue()+1)); |
70 | |
} |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
public static RouteNode getNodeForLevel(DocumentType documentType, Integer routeLevel) { |
78 | 0 | Object[] node = getNodeForLevel(documentType.getPrimaryProcess().getInitialRouteNode(), routeLevel, new Integer(0)); |
79 | 0 | return (RouteNode)node[0]; |
80 | |
} |
81 | |
|
82 | |
private static Object[] getNodeForLevel(RouteNode node, Integer routeLevel, Integer currentLevel) { |
83 | 0 | if (helper.isSubProcessNode(node)) { |
84 | 0 | Object[] result = getNodeForLevel(node.getDocumentType().getNamedProcess(node.getRouteNodeName()).getInitialRouteNode(), routeLevel, currentLevel); |
85 | 0 | if (result[0] != null) { |
86 | 0 | node = (RouteNode)result[0]; |
87 | |
} |
88 | 0 | currentLevel = (Integer)result[1]; |
89 | |
} |
90 | 0 | if (currentLevel.equals(routeLevel)) { |
91 | 0 | return new Object[] { node, currentLevel }; |
92 | |
} |
93 | 0 | List<RouteNode> nextNodes = node.getNextNodes(); |
94 | 0 | if (nextNodes.isEmpty()) { |
95 | 0 | return new Object[] { null, currentLevel }; |
96 | |
} |
97 | 0 | if (nextNodes.size() > 1) { |
98 | 0 | throw new WorkflowRuntimeException("Cannot determine a route level number for documents with splitting."); |
99 | |
} |
100 | 0 | currentLevel = new Integer(currentLevel.intValue()+1); |
101 | 0 | return getNodeForLevel((RouteNode)nextNodes.get(0), routeLevel, currentLevel); |
102 | |
} |
103 | |
|
104 | |
public static boolean isRouteLevelCompatible(DocumentType documentType) { |
105 | 0 | return KEWConstants.ROUTING_VERSION_ROUTE_LEVEL.equals(documentType.getRoutingVersion()); |
106 | |
} |
107 | |
|
108 | |
public static boolean isRouteLevelCompatible(DocumentRouteHeaderValue document) { |
109 | 0 | return isRouteLevelCompatible(document.getDocumentType()); |
110 | |
} |
111 | |
|
112 | |
public static boolean isNodalDocument(DocumentRouteHeaderValue document) { |
113 | 0 | return KewApiConstants.DocumentContentVersions.NODAL == document.getDocVersion().intValue(); |
114 | |
} |
115 | |
|
116 | |
public static boolean isNodalRequest(ActionRequestValue request) { |
117 | 0 | return KewApiConstants.DocumentContentVersions.NODAL == request.getDocVersion().intValue(); |
118 | |
} |
119 | |
|
120 | |
public static boolean isRouteLevelDocument(DocumentRouteHeaderValue document) { |
121 | 0 | return KewApiConstants.DocumentContentVersions.ROUTE_LEVEL == document.getDocVersion().intValue(); |
122 | |
} |
123 | |
|
124 | |
public static boolean isRouteLevelRequest(ActionRequestValue request) { |
125 | 0 | return KewApiConstants.DocumentContentVersions.ROUTE_LEVEL == request.getDocVersion().intValue(); |
126 | |
} |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
public static List<RouteNode> getRouteLevelCompatibleNodeList(DocumentType documentType) { |
133 | 0 | if (!isRouteLevelCompatible(documentType)) { |
134 | 0 | throw new WorkflowRuntimeException("Attempting to invoke a 'route level' operation on a document which is not route level compatible."); |
135 | |
} |
136 | 0 | Process primaryProcess = documentType.getPrimaryProcess(); |
137 | 0 | RouteNode routeNode = primaryProcess.getInitialRouteNode(); |
138 | 0 | List<RouteNode> nodes = new ArrayList<RouteNode>(); |
139 | 0 | int count = 0; |
140 | 0 | int maxCount = 100; |
141 | |
while (true) { |
142 | 0 | nodes.add(routeNode); |
143 | 0 | List<RouteNode> nextNodes = routeNode.getNextNodes(); |
144 | 0 | if (nextNodes.size() == 0) { |
145 | 0 | break; |
146 | |
} |
147 | 0 | if (nextNodes.size() > 1) { |
148 | 0 | throw new RuntimeException("Node has more than one next node! It is not route level compatible!" + routeNode.getRouteNodeName()); |
149 | |
} |
150 | 0 | if (count >= maxCount) { |
151 | 0 | throw new RuntimeException("A runaway loop was detected when attempting to create route level compatible node graph. documentType=" + documentType.getDocumentTypeId()+","+documentType.getName()); |
152 | |
} |
153 | 0 | routeNode = nextNodes.iterator().next(); |
154 | 0 | } |
155 | 0 | return nodes; |
156 | |
} |
157 | |
|
158 | |
public static int getMaxRouteLevel(DocumentType documentType) { |
159 | 0 | return getRouteLevelCompatibleNodeList(documentType).size(); |
160 | |
} |
161 | |
} |