Coverage Report - org.kuali.rice.kew.engine.node.service.impl.RouteNodeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RouteNodeServiceImpl
0%
0/246
0%
0/118
2.756
RouteNodeServiceImpl$1
N/A
N/A
2.756
RouteNodeServiceImpl$NodeInstanceIdSorter
0%
0/4
N/A
2.756
RouteNodeServiceImpl$RouteNodeSorter
0%
0/4
N/A
2.756
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.engine.node.service.impl;
 18  
 
 19  
 import org.apache.commons.collections.ComparatorUtils;
 20  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 21  
 import org.kuali.rice.kew.engine.RouteHelper;
 22  
 import org.kuali.rice.kew.engine.node.*;
 23  
 import org.kuali.rice.kew.engine.node.Process;
 24  
 import org.kuali.rice.kew.engine.node.dao.RouteNodeDAO;
 25  
 import org.kuali.rice.kew.engine.node.service.RouteNodeService;
 26  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 27  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 28  
 
 29  
 import java.util.*;
 30  
 
 31  
 
 32  
 
 33  0
 public class RouteNodeServiceImpl implements RouteNodeService {
 34  
 
 35  0
         protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass());
 36  
         
 37  
         public static final String REVOKED_NODE_INSTANCES_STATE_KEY = "NodeInstances.Revoked";
 38  
 
 39  0
         private static final Comparator NODE_INSTANCE_FORWARD_SORT = new NodeInstanceIdSorter();
 40  0
         private static final Comparator NODE_INSTANCE_BACKWARD_SORT = 
 41  
                 ComparatorUtils.reversedComparator(NODE_INSTANCE_FORWARD_SORT);
 42  0
     private RouteHelper helper = new RouteHelper();
 43  
         private RouteNodeDAO routeNodeDAO;
 44  
         
 45  
     public void save(RouteNode node) {
 46  0
             routeNodeDAO.save(node);
 47  0
     }
 48  
     
 49  
     public void save(RouteNodeInstance nodeInstance) {
 50  0
             routeNodeDAO.save(nodeInstance);
 51  0
     }
 52  
     
 53  
     public void save(NodeState nodeState) {
 54  0
         routeNodeDAO.save(nodeState);
 55  0
     }
 56  
     
 57  
     public void save(Branch branch) {
 58  0
         routeNodeDAO.save(branch);
 59  0
     }
 60  
 
 61  
     public RouteNode findRouteNodeById(String nodeId) {
 62  0
             return routeNodeDAO.findRouteNodeById(nodeId);
 63  
     }
 64  
     
 65  
     public RouteNodeInstance findRouteNodeInstanceById(String nodeInstanceId) {
 66  0
             return routeNodeDAO.findRouteNodeInstanceById(nodeInstanceId);
 67  
     }
 68  
 
 69  
     public RouteNodeInstance findRouteNodeInstanceById(String nodeInstanceId, DocumentRouteHeaderValue document) {
 70  0
             return RouteNodeUtils.findRouteNodeInstanceById(nodeInstanceId, document);
 71  
     }
 72  
     
 73  
     public List<RouteNodeInstance> getCurrentNodeInstances(String documentId) {
 74  0
         List<RouteNodeInstance> currentNodeInstances = getActiveNodeInstances(documentId);
 75  0
         if (currentNodeInstances.isEmpty()) {
 76  0
             currentNodeInstances = getTerminalNodeInstances(documentId);
 77  
         }
 78  0
         return currentNodeInstances;
 79  
     }
 80  
     
 81  
     public List<RouteNodeInstance> getActiveNodeInstances(String documentId) {
 82  0
             return routeNodeDAO.getActiveNodeInstances(documentId);
 83  
     }
 84  
     
 85  
     public List<RouteNodeInstance> getActiveNodeInstances(DocumentRouteHeaderValue document) {
 86  0
        List<RouteNodeInstance> flattenedNodeInstances = getFlattenedNodeInstances(document, true);
 87  0
         List<RouteNodeInstance> activeNodeInstances = new ArrayList<RouteNodeInstance>();
 88  0
         for (RouteNodeInstance nodeInstance : flattenedNodeInstances) {
 89  0
             if (nodeInstance.isActive()) {
 90  0
                 activeNodeInstances.add(nodeInstance);
 91  
             }
 92  
         }
 93  0
         return activeNodeInstances;
 94  
     }
 95  
     
 96  
     public List<RouteNodeInstance> getTerminalNodeInstances(String documentId) {
 97  0
         return routeNodeDAO.getTerminalNodeInstances(documentId);
 98  
     }
 99  
     
 100  
     public List getInitialNodeInstances(String documentId) {
 101  0
             return routeNodeDAO.getInitialNodeInstances(documentId);
 102  
     }
 103  
     
 104  
     public NodeState findNodeState(Long nodeInstanceId, String key) {
 105  0
         return routeNodeDAO.findNodeState(nodeInstanceId, key);
 106  
     }
 107  
     
 108  
     public RouteNode findRouteNodeByName(String documentTypeId, String name) {
 109  0
         return routeNodeDAO.findRouteNodeByName(documentTypeId, name);
 110  
     }
 111  
     
 112  
     public List findFinalApprovalRouteNodes(String documentTypeId) {
 113  0
         DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findById(documentTypeId);
 114  0
         documentType = documentType.getRouteDefiningDocumentType();
 115  0
         return routeNodeDAO.findFinalApprovalRouteNodes(documentType.getDocumentTypeId());
 116  
     }
 117  
     
 118  
     public List findNextRouteNodesInPath(RouteNodeInstance nodeInstance, String nodeName) {
 119  0
         List<RouteNode> nodesInPath = new ArrayList<RouteNode>();
 120  0
         for (Iterator<RouteNode> iterator = nodeInstance.getRouteNode().getNextNodes().iterator(); iterator.hasNext();) {
 121  0
             RouteNode nextNode = iterator.next();
 122  0
             nodesInPath.addAll(findNextRouteNodesInPath(nodeName, nextNode, new HashSet<String>()));
 123  0
         }
 124  0
         return nodesInPath;
 125  
     }
 126  
     
 127  
     private List<RouteNode> findNextRouteNodesInPath(String nodeName, RouteNode node, Set<String> inspected) {
 128  0
         List<RouteNode> nextNodesInPath = new ArrayList<RouteNode>();
 129  0
         if (inspected.contains(node.getRouteNodeId())) {
 130  0
             return nextNodesInPath;
 131  
         }
 132  0
         inspected.add(node.getRouteNodeId());
 133  0
         if (node.getRouteNodeName().equals(nodeName)) {
 134  0
             nextNodesInPath.add(node);
 135  
         } else {
 136  0
             if (helper.isSubProcessNode(node)) {
 137  0
                 Process subProcess = node.getDocumentType().getNamedProcess(node.getRouteNodeName());
 138  0
                 RouteNode subNode = subProcess.getInitialRouteNode();
 139  0
                 nextNodesInPath.addAll(findNextRouteNodesInPath(nodeName, subNode, inspected));
 140  
             }
 141  0
             for (Iterator<RouteNode> iterator = node.getNextNodes().iterator(); iterator.hasNext();) {
 142  0
                 RouteNode nextNode = iterator.next();
 143  0
                 nextNodesInPath.addAll(findNextRouteNodesInPath(nodeName, nextNode, inspected));
 144  0
             }
 145  
         }
 146  0
         return nextNodesInPath;
 147  
     }
 148  
     
 149  
     public boolean isNodeInPath(DocumentRouteHeaderValue document, String nodeName) {
 150  0
         boolean isInPath = false;
 151  0
         Collection<RouteNodeInstance> activeNodes = getActiveNodeInstances(document.getDocumentId());
 152  0
         for (Iterator<RouteNodeInstance> iterator = activeNodes.iterator(); iterator.hasNext();) {
 153  0
             RouteNodeInstance nodeInstance = iterator.next();
 154  0
             List nextNodesInPath = findNextRouteNodesInPath(nodeInstance, nodeName);
 155  0
             isInPath = isInPath || !nextNodesInPath.isEmpty();
 156  0
         }
 157  0
         return isInPath;
 158  
     }
 159  
     
 160  
     public List findRouteNodeInstances(String documentId) {
 161  0
         return this.routeNodeDAO.findRouteNodeInstances(documentId);
 162  
     }
 163  
     
 164  
         public void setRouteNodeDAO(RouteNodeDAO dao) {
 165  0
                 this.routeNodeDAO = dao;
 166  0
         }
 167  
     
 168  
     public List findProcessNodeInstances(RouteNodeInstance process) {
 169  0
        return this.routeNodeDAO.findProcessNodeInstances(process);
 170  
     }
 171  
     
 172  
     public Set findPreviousNodeNames(String documentId) {
 173  0
         List currentNodeInstances = KEWServiceLocator.getRouteNodeService().getCurrentNodeInstances(documentId);
 174  0
         List<RouteNodeInstance> nodeInstances = new ArrayList<RouteNodeInstance>();
 175  0
         for (Iterator iterator = currentNodeInstances.iterator(); iterator.hasNext();) {
 176  0
             RouteNodeInstance nodeInstance = (RouteNodeInstance) iterator.next();
 177  0
             nodeInstances.addAll(nodeInstance.getPreviousNodeInstances());
 178  0
         }
 179  0
         Set<String> nodeNames = new HashSet<String>();
 180  0
         while (!nodeInstances.isEmpty()) {
 181  0
             RouteNodeInstance nodeInstance = nodeInstances.remove(0);
 182  0
             nodeNames.add(nodeInstance.getName());
 183  0
             nodeInstances.addAll(nodeInstance.getPreviousNodeInstances());
 184  0
         }
 185  0
         return nodeNames;
 186  
     }
 187  
     
 188  
     public List<String> findFutureNodeNames(String documentId) {
 189  0
         List currentNodeInstances = KEWServiceLocator.getRouteNodeService().getCurrentNodeInstances(documentId);
 190  0
         List<RouteNode> nodes = new ArrayList<RouteNode>();
 191  0
         for (Iterator iterator = currentNodeInstances.iterator(); iterator.hasNext();) {
 192  0
             RouteNodeInstance nodeInstance = (RouteNodeInstance) iterator.next();
 193  0
             nodes.addAll(nodeInstance.getRouteNode().getNextNodes());
 194  0
         }
 195  0
         List<String> nodeNames = new ArrayList<String>();
 196  0
         while (!nodes.isEmpty()) {
 197  0
             RouteNode node = nodes.remove(0);
 198  0
             if (!nodeNames.contains(node.getRouteNodeName())) {
 199  0
                 nodeNames.add(node.getRouteNodeName());
 200  
             }
 201  0
             nodes.addAll(node.getNextNodes());
 202  0
         }
 203  0
         return nodeNames;
 204  
     }
 205  
     
 206  
     public List<RouteNode> getFlattenedNodes(DocumentType documentType, boolean climbHierarchy) {
 207  0
         List<RouteNode> nodes = new ArrayList<RouteNode>();
 208  0
         if (!documentType.isRouteInherited() || climbHierarchy) {
 209  0
             for (Iterator iterator = documentType.getProcesses().iterator(); iterator.hasNext();) {
 210  0
                 Process process = (Process) iterator.next();
 211  0
                 nodes.addAll(getFlattenedNodes(process));
 212  0
             }
 213  
         }
 214  0
         Collections.sort(nodes, new RouteNodeSorter());
 215  0
         return nodes;
 216  
     }
 217  
     
 218  
     public List<RouteNode> getFlattenedNodes(Process process) {
 219  0
         Map<String, RouteNode> nodesMap = new HashMap<String, RouteNode>();
 220  0
         if (process.getInitialRouteNode() != null) {
 221  0
             flattenNodeGraph(nodesMap, process.getInitialRouteNode());
 222  0
             List<RouteNode> nodes = new ArrayList<RouteNode>(nodesMap.values());
 223  0
             Collections.sort(nodes, new RouteNodeSorter());
 224  0
             return nodes;
 225  
         } else {
 226  0
             List<RouteNode> nodes = new ArrayList<RouteNode>();
 227  0
             nodes.add(new RouteNode());
 228  0
             return nodes;
 229  
         }
 230  
 
 231  
     }
 232  
     
 233  
     /**
 234  
      * Recursively walks the node graph and builds up the map.  Uses a map because we will
 235  
      * end up walking through duplicates, as is the case with Join nodes.
 236  
      */
 237  
     private void flattenNodeGraph(Map<String, RouteNode> nodes, RouteNode node) {
 238  0
         if (node != null) {
 239  0
             if (nodes.containsKey(node.getRouteNodeName())) {
 240  0
                 return;
 241  
             }
 242  0
             nodes.put(node.getRouteNodeName(), node);
 243  0
             for (Iterator<RouteNode> iterator = node.getNextNodes().iterator(); iterator.hasNext();) {
 244  0
                 RouteNode nextNode = iterator.next();
 245  0
                 flattenNodeGraph(nodes, nextNode);
 246  0
             }
 247  
         } else {
 248  0
             return;
 249  
         }
 250  0
     }        
 251  
     
 252  
     public List<RouteNodeInstance> getFlattenedNodeInstances(DocumentRouteHeaderValue document, boolean includeProcesses) {
 253  0
         List<RouteNodeInstance> nodeInstances = new ArrayList<RouteNodeInstance>();
 254  0
         Set<String> visitedNodeInstanceIds = new HashSet<String>();
 255  0
         for (Iterator<RouteNodeInstance> iterator = document.getInitialRouteNodeInstances().iterator(); iterator.hasNext();) {
 256  0
             RouteNodeInstance initialNodeInstance = iterator.next();
 257  0
             flattenNodeInstanceGraph(nodeInstances, visitedNodeInstanceIds, initialNodeInstance, includeProcesses);    
 258  0
         }
 259  0
         return nodeInstances;
 260  
     }
 261  
     
 262  
         private void flattenNodeInstanceGraph(List<RouteNodeInstance> nodeInstances, Set<String> visitedNodeInstanceIds, RouteNodeInstance nodeInstance, boolean includeProcesses) {
 263  
 
 264  0
                 if (nodeInstance != null) {
 265  0
                         if (visitedNodeInstanceIds.contains(nodeInstance.getRouteNodeInstanceId())) {
 266  0
                                 return;
 267  
                         }
 268  0
                         if (includeProcesses && nodeInstance.getProcess() != null) {
 269  0
                                 flattenNodeInstanceGraph(nodeInstances, visitedNodeInstanceIds, nodeInstance.getProcess(), includeProcesses);
 270  
                         }
 271  0
                         visitedNodeInstanceIds.add(nodeInstance.getRouteNodeInstanceId());
 272  0
                         nodeInstances.add(nodeInstance);
 273  0
                         for (Iterator<RouteNodeInstance> iterator = nodeInstance.getNextNodeInstances().iterator(); iterator.hasNext();) {
 274  0
                                 RouteNodeInstance nextNodeInstance = iterator.next();
 275  0
                                 flattenNodeInstanceGraph(nodeInstances, visitedNodeInstanceIds, nextNodeInstance, includeProcesses);
 276  0
                         }
 277  
 
 278  
                 }
 279  
 
 280  0
     }      
 281  
     
 282  
     public NodeGraphSearchResult searchNodeGraph(NodeGraphSearchCriteria criteria) {
 283  0
             NodeGraphContext context = new NodeGraphContext();
 284  0
             if (criteria.getSearchDirection() == NodeGraphSearchCriteria.SEARCH_DIRECTION_BACKWARD) {
 285  0
                 searchNodeGraphBackward(context, criteria.getMatcher(), null, criteria.getStartingNodeInstances());
 286  
             } else {
 287  0
                     throw new UnsupportedOperationException("Search feature can only search backward currently.");
 288  
             }
 289  0
             List exactPath = determineExactPath(context, criteria.getSearchDirection(), criteria.getStartingNodeInstances());
 290  0
         return new NodeGraphSearchResult(context.getCurrentNodeInstance(), exactPath);
 291  
     }
 292  
     
 293  
     private void searchNodeGraphBackward(NodeGraphContext context, NodeMatcher matcher, RouteNodeInstance previousNodeInstance, Collection nodeInstances) {
 294  0
         if (nodeInstances == null) {
 295  0
             return;
 296  
         }
 297  0
             for (Iterator iterator = nodeInstances.iterator(); iterator.hasNext();) {
 298  0
             RouteNodeInstance nodeInstance = (RouteNodeInstance) iterator.next();
 299  0
             context.setPreviousNodeInstance(previousNodeInstance);
 300  0
             context.setCurrentNodeInstance(nodeInstance);
 301  0
             searchNodeGraphBackward(context, matcher);
 302  0
             if (context.getResultNodeInstance() != null) {
 303  
                     // we've located the node instance we're searching for, we're done
 304  0
                     break;
 305  
             }
 306  0
         }
 307  0
     }
 308  
     
 309  
     private void searchNodeGraphBackward(NodeGraphContext context, NodeMatcher matcher) {
 310  0
         RouteNodeInstance current = context.getCurrentNodeInstance();
 311  0
         int numBranches = current.getNextNodeInstances().size();
 312  
         // if this is a split node, we want to wait here, until all branches join back to us
 313  0
         if (numBranches > 1) {
 314  
                 // determine the number of branches that have joined back to the split thus far
 315  0
             Integer joinCount = (Integer)context.getSplitState().get(current.getRouteNodeInstanceId());
 316  0
             if (joinCount == null) {
 317  0
                 joinCount = new Integer(0);
 318  
             }
 319  
             // if this split is not a leaf node we increment the count
 320  0
             if (context.getPreviousNodeInstance() != null) {
 321  0
                 joinCount = new Integer(joinCount.intValue()+1);
 322  
             }
 323  0
             context.getSplitState().put(current.getRouteNodeInstanceId(), joinCount);
 324  
             // if not all branches have joined, stop and wait for other branches to join
 325  0
             if (joinCount.intValue() != numBranches) {
 326  0
                 return;
 327  
             }
 328  
         }
 329  0
         if (matcher.isMatch(context)) {
 330  0
             context.setResultNodeInstance(current);
 331  
         } else {
 332  0
             context.getVisited().put(current.getRouteNodeInstanceId(), current);
 333  0
             searchNodeGraphBackward(context, matcher, current, current.getPreviousNodeInstances());
 334  
         }
 335  0
     }
 336  
     
 337  
     public List<RouteNodeInstance> getActiveNodeInstances(DocumentRouteHeaderValue document, String nodeName) {
 338  0
                 Collection<RouteNodeInstance> activeNodes = getActiveNodeInstances(document.getDocumentId());
 339  0
                 List<RouteNodeInstance> foundNodes = new ArrayList<RouteNodeInstance>();
 340  0
         for (Iterator<RouteNodeInstance> iterator = activeNodes.iterator(); iterator.hasNext();) {
 341  0
             RouteNodeInstance nodeInstance = iterator.next();
 342  0
             if (nodeInstance.getName().equals(nodeName)) {
 343  0
                     foundNodes.add(nodeInstance);
 344  
             }
 345  0
         }
 346  0
         return foundNodes;
 347  
     }
 348  
     
 349  
     private List determineExactPath(NodeGraphContext context, int searchDirection, Collection<RouteNodeInstance> startingNodeInstances) {
 350  0
             List<RouteNodeInstance> exactPath = new ArrayList<RouteNodeInstance>();
 351  0
             if (context.getResultNodeInstance() == null) {
 352  0
                     exactPath.addAll(context.getVisited().values());
 353  
             } else {
 354  0
                     determineExactPath(exactPath, new HashMap<String, RouteNodeInstance>(), startingNodeInstances, context.getResultNodeInstance());
 355  
             }
 356  0
             if (NodeGraphSearchCriteria.SEARCH_DIRECTION_FORWARD == searchDirection) {
 357  0
                     Collections.sort(exactPath, NODE_INSTANCE_BACKWARD_SORT);
 358  
             } else {
 359  0
                     Collections.sort(exactPath, NODE_INSTANCE_FORWARD_SORT);
 360  
             }
 361  0
             return exactPath;
 362  
     }
 363  
     
 364  
     private void determineExactPath(List<RouteNodeInstance> exactPath, Map<String, RouteNodeInstance> visited, Collection<RouteNodeInstance> startingNodeInstances, RouteNodeInstance nodeInstance) {
 365  0
             if (nodeInstance == null) {
 366  0
                     return;
 367  
             }
 368  0
             if (visited.containsKey(nodeInstance.getRouteNodeInstanceId())) {
 369  0
                     return;
 370  
             }
 371  0
             visited.put(nodeInstance.getRouteNodeInstanceId(), nodeInstance);
 372  0
             exactPath.add(nodeInstance);
 373  0
             for (RouteNodeInstance startingNode : startingNodeInstances) {
 374  0
                         if (startingNode.getRouteNodeInstanceId().equals(nodeInstance.getRouteNodeInstanceId())) {
 375  0
                                 return;
 376  
                         }
 377  
                 }
 378  0
             for (Iterator<RouteNodeInstance> iterator = nodeInstance.getNextNodeInstances().iterator(); iterator.hasNext(); ) {
 379  0
                         RouteNodeInstance nextNodeInstance = iterator.next();
 380  0
                         determineExactPath(exactPath, visited, startingNodeInstances, nextNodeInstance);
 381  0
                 }
 382  0
     }
 383  
     
 384  
        
 385  
     /**
 386  
      * Sorts by RouteNodeId or the order the nodes will be evaluated in *roughly*.  This is 
 387  
      * for display purposes when rendering a flattened list of nodes.
 388  
      * 
 389  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 390  
      */
 391  0
     private static class RouteNodeSorter implements Comparator {
 392  
         public int compare(Object arg0, Object arg1) {
 393  0
             RouteNode rn1 = (RouteNode)arg0;
 394  0
             RouteNode rn2 = (RouteNode)arg1;
 395  0
             return rn1.getRouteNodeId().compareTo(rn2.getRouteNodeId());
 396  
         }
 397  
     }
 398  
     
 399  0
     private static class NodeInstanceIdSorter implements Comparator {
 400  
         public int compare(Object arg0, Object arg1) {
 401  0
             RouteNodeInstance nodeInstance1 = (RouteNodeInstance)arg0;
 402  0
             RouteNodeInstance nodeInstance2 = (RouteNodeInstance)arg1;
 403  0
             return nodeInstance1.getRouteNodeInstanceId().compareTo(nodeInstance2.getRouteNodeInstanceId());
 404  
         }
 405  
     }
 406  
     
 407  
     
 408  
     public void deleteByRouteNodeInstance(RouteNodeInstance routeNodeInstance){
 409  
             //update the route node instance link table to cancel the relationship between the to-be-deleted instance and the previous node instances
 410  0
             routeNodeDAO.deleteLinksToPreNodeInstances(routeNodeInstance);
 411  
             //delete the routeNodeInstance and its next node instances
 412  0
             routeNodeDAO.deleteRouteNodeInstancesHereAfter(routeNodeInstance);
 413  0
     }
 414  
     
 415  
     public void deleteNodeStateById(Long nodeStateId){
 416  0
             routeNodeDAO.deleteNodeStateById(nodeStateId);
 417  0
     }
 418  
     
 419  
     public void deleteNodeStates(List statesToBeDeleted){
 420  0
             routeNodeDAO.deleteNodeStates(statesToBeDeleted);
 421  0
     }
 422  
     
 423  
     /**
 424  
      * Records the revocation in the root BranchState of the document.
 425  
      */
 426  
     public void revokeNodeInstance(DocumentRouteHeaderValue document, RouteNodeInstance nodeInstance) {
 427  0
             if (document == null) {
 428  0
                     throw new IllegalArgumentException("Document must not be null.");
 429  
             }
 430  0
                 if (nodeInstance == null || nodeInstance.getRouteNodeInstanceId() == null) {
 431  0
                         throw new IllegalArgumentException("In order to revoke a final approval node the node instance must be persisent and have an id.");
 432  
                 }
 433  
                 // get the initial node instance, the root branch is where we will store the state
 434  0
             Branch rootBranch = document.getRootBranch();
 435  0
             BranchState state = null;
 436  0
             if (rootBranch != null) {
 437  0
                 state = rootBranch.getBranchState(REVOKED_NODE_INSTANCES_STATE_KEY);
 438  
             }
 439  0
             if (state == null) {
 440  0
                     state = new BranchState();
 441  0
                     state.setKey(REVOKED_NODE_INSTANCES_STATE_KEY);
 442  0
                     state.setValue("");
 443  0
                     rootBranch.addBranchState(state);
 444  
             }
 445  0
             if (state.getValue() == null) {
 446  0
                     state.setValue("");
 447  
             }
 448  0
             state.setValue(state.getValue() + nodeInstance.getRouteNodeInstanceId() + ",");
 449  0
             save(rootBranch);
 450  0
         }
 451  
 
 452  
     /**
 453  
      * Queries the list of revoked node instances from the root BranchState of the Document
 454  
      * and returns a List of revoked RouteNodeInstances.
 455  
      */
 456  
         public List getRevokedNodeInstances(DocumentRouteHeaderValue document) {
 457  0
                 if (document == null) {
 458  0
                     throw new IllegalArgumentException("Document must not be null.");
 459  
             }
 460  0
                 List<RouteNodeInstance> revokedNodeInstances = new ArrayList<RouteNodeInstance>();
 461  
             
 462  0
             Branch rootBranch = document.getRootBranch();
 463  0
             BranchState state = null;
 464  0
             if (rootBranch != null) {
 465  0
                 state = rootBranch.getBranchState(REVOKED_NODE_INSTANCES_STATE_KEY);
 466  
             }
 467  0
             if (state == null || org.apache.commons.lang.StringUtils.isEmpty(state.getValue())) {
 468  0
                     return revokedNodeInstances;
 469  
             }
 470  0
             String[] revokedNodes = state.getValue().split(",");
 471  0
             for (int index = 0; index < revokedNodes.length; index++) {
 472  0
                         String revokedNodeInstanceId = revokedNodes[index];
 473  0
                         RouteNodeInstance revokedNodeInstance = findRouteNodeInstanceById(revokedNodeInstanceId);
 474  0
                         if (revokedNodeInstance == null) {
 475  0
                                 LOG.warn("Could not locate revoked RouteNodeInstance with the given id: " + revokedNodeInstanceId);
 476  
                         } else {
 477  0
                                 revokedNodeInstances.add(revokedNodeInstance);
 478  
                         }
 479  
                 }
 480  0
             return revokedNodeInstances;
 481  
         }
 482  
     
 483  
     
 484  
 }