| 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 org.apache.commons.lang.StringUtils; |
| 19 |
|
import org.kuali.rice.core.api.exception.RiceRuntimeException; |
| 20 |
|
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 21 |
|
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
| 22 |
|
import org.kuali.rice.kew.rule.xmlrouting.XPathHelper; |
| 23 |
|
import org.w3c.dom.Document; |
| 24 |
|
import org.xml.sax.InputSource; |
| 25 |
|
|
| 26 |
|
import javax.xml.parsers.DocumentBuilder; |
| 27 |
|
import javax.xml.parsers.DocumentBuilderFactory; |
| 28 |
|
import java.io.StringReader; |
| 29 |
|
import java.util.*; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
@author |
| 36 |
|
|
| 37 |
|
|
|
|
|
| 0% |
Uncovered Elements: 86 (86) |
Complexity: 21 |
Complexity Density: 0.36 |
|
| 38 |
|
public final class RouteNodeUtils { |
| 39 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 40 |
0
|
private RouteNodeUtils() {... |
| 41 |
0
|
throw new UnsupportedOperationException("do not call"); |
| 42 |
|
} |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
@param |
| 59 |
|
@param |
| 60 |
|
|
| 61 |
|
@return |
| 62 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 63 |
0
|
public static String getValueOfCustomProperty(RouteNode routeNode, String propertyName) {... |
| 64 |
0
|
String contentFragment = routeNode.getContentFragment(); |
| 65 |
0
|
String elementValue = null; |
| 66 |
0
|
if (!StringUtils.isBlank(contentFragment)) { |
| 67 |
0
|
try { |
| 68 |
0
|
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
| 69 |
0
|
Document document = db.parse(new InputSource(new StringReader(contentFragment))); |
| 70 |
0
|
elementValue = XPathHelper.newXPath().evaluate("//" + propertyName, document); |
| 71 |
|
} catch (Exception e) { |
| 72 |
0
|
throw new RiceRuntimeException("Error when attempting to parse Document Type content fragment for property name: " + propertyName, e); |
| 73 |
|
} |
| 74 |
|
} |
| 75 |
0
|
return elementValue; |
| 76 |
|
} |
| 77 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 78 |
0
|
public static List<RouteNodeInstance> getFlattenedNodeInstances(DocumentRouteHeaderValue document, boolean includeProcesses) {... |
| 79 |
0
|
List<RouteNodeInstance> nodeInstances = new ArrayList<RouteNodeInstance>(); |
| 80 |
0
|
Set<Long> visitedNodeInstanceIds = new HashSet<Long>(); |
| 81 |
0
|
for (RouteNodeInstance initialNodeInstance : document.getInitialRouteNodeInstances()) |
| 82 |
|
{ |
| 83 |
0
|
flattenNodeInstanceGraph(nodeInstances, visitedNodeInstanceIds, initialNodeInstance, includeProcesses); |
| 84 |
|
} |
| 85 |
0
|
return nodeInstances; |
| 86 |
|
} |
| 87 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 88 |
0
|
private static void flattenNodeInstanceGraph(List<RouteNodeInstance> nodeInstances, Set<Long> visitedNodeInstanceIds, RouteNodeInstance nodeInstance, boolean includeProcesses) {... |
| 89 |
0
|
if (visitedNodeInstanceIds.contains(nodeInstance.getRouteNodeInstanceId())) { |
| 90 |
0
|
return; |
| 91 |
|
} |
| 92 |
0
|
if (includeProcesses && nodeInstance.getProcess() != null) { |
| 93 |
0
|
flattenNodeInstanceGraph(nodeInstances, visitedNodeInstanceIds, nodeInstance.getProcess(), includeProcesses); |
| 94 |
|
} |
| 95 |
0
|
visitedNodeInstanceIds.add(nodeInstance.getRouteNodeInstanceId()); |
| 96 |
0
|
nodeInstances.add(nodeInstance); |
| 97 |
0
|
for (RouteNodeInstance nextNodeInstance : nodeInstance.getNextNodeInstances()) |
| 98 |
|
{ |
| 99 |
0
|
flattenNodeInstanceGraph(nodeInstances, visitedNodeInstanceIds, nextNodeInstance, includeProcesses); |
| 100 |
|
} |
| 101 |
|
} |
| 102 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 103 |
0
|
public static List<RouteNode> getFlattenedNodes(DocumentType documentType, boolean climbHierarchy) {... |
| 104 |
0
|
List<RouteNode> nodes = new ArrayList<RouteNode>(); |
| 105 |
0
|
if (!documentType.isRouteInherited() || climbHierarchy) { |
| 106 |
0
|
for (Object o : documentType.getProcesses()) |
| 107 |
|
{ |
| 108 |
0
|
Process process = (Process) o; |
| 109 |
0
|
nodes.addAll(getFlattenedNodes(process)); |
| 110 |
|
} |
| 111 |
|
} |
| 112 |
0
|
Collections.sort(nodes, new RouteNodeSorter()); |
| 113 |
0
|
return nodes; |
| 114 |
|
} |
| 115 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 116 |
0
|
public static List<RouteNode> getFlattenedNodes(Process process) {... |
| 117 |
0
|
Map<String, RouteNode> nodesMap = new HashMap<String, RouteNode>(); |
| 118 |
0
|
if (process.getInitialRouteNode() != null) { |
| 119 |
0
|
flattenNodeGraph(nodesMap, process.getInitialRouteNode()); |
| 120 |
0
|
List<RouteNode> nodes = new ArrayList<RouteNode>(nodesMap.values()); |
| 121 |
0
|
Collections.sort(nodes, new RouteNodeSorter()); |
| 122 |
0
|
return nodes; |
| 123 |
|
} else { |
| 124 |
0
|
List<RouteNode> nodes = new ArrayList<RouteNode>(); |
| 125 |
0
|
nodes.add(new RouteNode()); |
| 126 |
0
|
return nodes; |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
@param |
| 135 |
|
@param |
| 136 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 137 |
0
|
private static void flattenNodeGraph(Map<String, RouteNode> nodes, RouteNode node) {... |
| 138 |
0
|
if (node != null) { |
| 139 |
0
|
if (nodes.containsKey(node.getRouteNodeName())) { |
| 140 |
0
|
return; |
| 141 |
|
} |
| 142 |
0
|
nodes.put(node.getRouteNodeName(), node); |
| 143 |
0
|
for (RouteNode nextNode : node.getNextNodes()) |
| 144 |
|
{ |
| 145 |
0
|
flattenNodeGraph(nodes, nextNode); |
| 146 |
|
} |
| 147 |
|
} else { |
| 148 |
0
|
return; |
| 149 |
|
} |
| 150 |
|
} |
| 151 |
|
|
| 152 |
|
|
| 153 |
|
|
| 154 |
|
|
| 155 |
|
|
| 156 |
|
@author |
| 157 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 158 |
|
private static class RouteNodeSorter implements Comparator { |
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 159 |
0
|
public int compare(Object arg0, Object arg1) {... |
| 160 |
0
|
RouteNode rn1 = (RouteNode)arg0; |
| 161 |
0
|
RouteNode rn2 = (RouteNode)arg1; |
| 162 |
0
|
return rn1.getRouteNodeId().compareTo(rn2.getRouteNodeId()); |
| 163 |
|
} |
| 164 |
|
} |
| 165 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 166 |
0
|
public static List<RouteNodeInstance> getActiveNodeInstances(DocumentRouteHeaderValue document) {... |
| 167 |
0
|
List<RouteNodeInstance> flattenedNodeInstances = getFlattenedNodeInstances(document, true); |
| 168 |
0
|
List<RouteNodeInstance> activeNodeInstances = new ArrayList<RouteNodeInstance>(); |
| 169 |
0
|
for (RouteNodeInstance nodeInstance : flattenedNodeInstances) |
| 170 |
|
{ |
| 171 |
0
|
if (nodeInstance.isActive()) |
| 172 |
|
{ |
| 173 |
0
|
activeNodeInstances.add(nodeInstance); |
| 174 |
|
} |
| 175 |
|
} |
| 176 |
0
|
return activeNodeInstances; |
| 177 |
|
} |
| 178 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 179 |
0
|
public static RouteNodeInstance findRouteNodeInstanceById(Long nodeInstanceId, DocumentRouteHeaderValue document) {... |
| 180 |
0
|
List<RouteNodeInstance> flattenedNodeInstances = getFlattenedNodeInstances(document, true); |
| 181 |
0
|
RouteNodeInstance niRet = null; |
| 182 |
0
|
for (RouteNodeInstance nodeInstance : flattenedNodeInstances) |
| 183 |
|
{ |
| 184 |
0
|
if (nodeInstanceId.equals(nodeInstance.getRouteNodeInstanceId())) |
| 185 |
|
{ |
| 186 |
0
|
niRet = nodeInstance; |
| 187 |
0
|
break; |
| 188 |
|
} |
| 189 |
|
} |
| 190 |
0
|
return niRet; |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
} |