RequestsNode extends RequestActivationNode { public List<ActionRequestValue> getNewActionRequests(RouteContext context) throws Exception { RouteNodeInstance nodeInstance = context.getNodeInstance(); String routeMethodName = nodeInstance.getRouteNode().getRouteMethodName(); if ( LOG.isDebugEnabled() ) { LOG.debug( "Looking for action requests in " + routeMethodName + " : " + nodeInstance.getRouteNode().getRouteNodeName() ); } List<ActionRequestValue> newRequests = new ArrayList<ActionRequestValue>(); try { RouteModule routeModule = getRouteModule( context ); List<ActionRequestValue> requests = routeModule.findActionRequests( context ); requests = KEWServiceLocator.getActionRequestService().getRootRequests(requests); List<ActionRequestValue> uniqueRequests = new ArrayList<ActionRequestValue>(); for ( ActionRequestValue actionRequest : requests ) { boolean duplicateFound = false; for (ActionRequestValue uniqueRequest: uniqueRequests ) { if (isDuplicateActionRequestDetected(uniqueRequest, actionRequest)) { duplicateFound = true; break; } } if (!duplicateFound) { uniqueRequests.add(actionRequest); } } for ( ActionRequestValue actionRequest : uniqueRequests ) { if ( LOG.isDebugEnabled() ) { LOG.debug( "Request generated by RouteModule '" + routeModule + "' for node " + nodeInstance + ":" + actionRequest ); } actionRequest = KEWServiceLocator.getActionRequestService() .initializeActionRequestGraph( actionRequest, context.getDocument(), nodeInstance ); actionRequest = saveActionRequest( context, actionRequest ); newRequests.add( actionRequest ); } } catch ( WorkflowException ex ) { LOG.warn( "Caught WorkflowException during routing", ex ); throw new RouteManagerException( ex, context ); } return newRequests; }  final SimpleResult process(RouteContext routeContext, RouteHelper routeHelper); List<ActionRequestValue> getNewActionRequests(RouteContext context); static boolean isSuppressingPolicyErrors(RouteContext routeContext); @SuppressWarnings("unchecked") static void setSuppressPolicyErrors(RouteContext routeContext);  }
@Test public void testIdenticalActionRequestValuesWithNoChildrenAreDuplicates() throws Exception { List<ActionRequestValue> actionRequestValues = new ArrayList<ActionRequestValue>(); actionRequestValues.add(getActionRequest()); actionRequestValues.add(getActionRequest()); when(routeModule.findActionRequests(routeContext)).thenReturn(actionRequestValues); List<ActionRequestValue> deduplicatedActionRequestValues = requestsNode.getNewActionRequests(routeContext); assertEquals(1, deduplicatedActionRequestValues.size()); }
@Test public void testActionRequestsWithDifferentNumbersOfChildrenAreNotDuplicates() throws Exception { List<ActionRequestValue> actionRequestValues = new ArrayList<ActionRequestValue>(); ActionRequestValue firstActionRequest = getActionRequest(); List<ActionRequestValue> children = new ArrayList<ActionRequestValue>(); children.add(getActionRequest()); firstActionRequest.setChildrenRequests(children); actionRequestValues.add(firstActionRequest); ActionRequestValue secondActionRequest = getActionRequest(); secondActionRequest.setChildrenRequests(Collections.<ActionRequestValue>emptyList()); actionRequestValues.add(secondActionRequest); when(routeModule.findActionRequests(routeContext)).thenReturn(actionRequestValues); List<ActionRequestValue> deduplicatedActionRequestValues = requestsNode.getNewActionRequests(routeContext); assertEquals(2, deduplicatedActionRequestValues.size()); }
@Test public void testActionRequestsWithIdenticalChildrenAreDuplicates() throws Exception { List<ActionRequestValue> actionRequestValues = new ArrayList<ActionRequestValue>(); List<ActionRequestValue> children = new ArrayList<ActionRequestValue>(); children.add(getActionRequest()); ActionRequestValue firstActionRequest = getActionRequest(); firstActionRequest.setChildrenRequests(children); actionRequestValues.add(firstActionRequest); ActionRequestValue secondActionRequest = getActionRequest(); secondActionRequest.setChildrenRequests(children); actionRequestValues.add(secondActionRequest); when(routeModule.findActionRequests(routeContext)).thenReturn(actionRequestValues); List<ActionRequestValue> deduplicatedActionRequestValues = requestsNode.getNewActionRequests(routeContext); assertEquals(1, deduplicatedActionRequestValues.size()); }
@Test public void testActionRequestsWithDifferingChildrenAreDuplicates() throws Exception { List<ActionRequestValue> actionRequestValues = new ArrayList<ActionRequestValue>(); List<ActionRequestValue> firstChildren = new ArrayList<ActionRequestValue>(); firstChildren.add(getActionRequest()); ActionRequestValue firstActionRequest = getActionRequest(); firstActionRequest.setChildrenRequests(firstChildren); actionRequestValues.add(firstActionRequest); ActionRequestValue secondActionRequest = getActionRequest(); List<ActionRequestValue> secondChildren = new ArrayList<ActionRequestValue>(); ActionRequestValue differingActionRequest = getActionRequest(); differingActionRequest.setPrincipalId("otherPrincipal"); secondChildren.add(differingActionRequest); secondActionRequest.setChildrenRequests(secondChildren); actionRequestValues.add(secondActionRequest); when(routeModule.findActionRequests(routeContext)).thenReturn(actionRequestValues); List<ActionRequestValue> deduplicatedActionRequestValues = requestsNode.getNewActionRequests(routeContext); assertEquals(2, deduplicatedActionRequestValues.size()); }