View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.routemodule.service.impl;
17  
18  import org.kuali.rice.kew.engine.simulation.SimulationCriteria;
19  import org.kuali.rice.kew.engine.simulation.SimulationResults;
20  import org.kuali.rice.kew.engine.simulation.SimulationWorkflowEngine;
21  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
22  import org.kuali.rice.kew.routemodule.service.RoutingReportService;
23  import org.kuali.rice.kew.service.KEWServiceLocator;
24  
25  
26  public class RoutingReportServiceImpl implements RoutingReportService {
27  
28      public DocumentRouteHeaderValue report(SimulationCriteria criteria) {
29      	try {
30      		SimulationWorkflowEngine simulationEngine = KEWServiceLocator.getSimulationEngine();
31      		SimulationResults results = simulationEngine.runSimulation(criteria);
32      		return materializeDocument(results);
33          } catch (Exception e) {
34          	if (e instanceof RuntimeException) {
35          		throw (RuntimeException)e;
36          	}
37              throw new IllegalStateException("Problem running report: " + e.getMessage(), e);
38          }
39      }
40  
41      /**
42       * The document returned does not have any of the simulated action requests set on it, we'll want to set them.
43       */
44      private DocumentRouteHeaderValue materializeDocument(SimulationResults results) {
45      	DocumentRouteHeaderValue document = results.getDocument();
46  		//document.getActionRequests().addAll(results.getSimulatedActionRequests());
47      	document.getSimulatedActionRequests().addAll(results.getSimulatedActionRequests());
48          return document;
49  
50      }
51  }