View Javadoc

1   /*
2    * Copyright 2005-2008 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.routemodule.service.impl;
18  
19  import org.kuali.rice.kew.engine.simulation.SimulationCriteria;
20  import org.kuali.rice.kew.engine.simulation.SimulationEngine;
21  import org.kuali.rice.kew.engine.simulation.SimulationResults;
22  import org.kuali.rice.kew.exception.WorkflowException;
23  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
24  import org.kuali.rice.kew.routemodule.service.RoutingReportService;
25  
26  
27  public class RoutingReportServiceImpl implements RoutingReportService {
28  
29      public DocumentRouteHeaderValue report(SimulationCriteria criteria) throws WorkflowException {
30      	try {
31      		SimulationEngine simulationEngine = new SimulationEngine();
32      		SimulationResults results = simulationEngine.runSimulation(criteria);
33      		return materializeDocument(results);
34          } catch (Exception e) {
35          	if (e instanceof RuntimeException) {
36          		throw (RuntimeException)e;
37          	}
38              throw new WorkflowException("Problem running report: " + e.getMessage(), e);
39          }
40      }
41  
42      /**
43       * The document returned does not have any of the simulated action requests set on it, we'll want to set them.
44       */
45      private DocumentRouteHeaderValue materializeDocument(SimulationResults results) {
46      	DocumentRouteHeaderValue document = results.getDocument();
47  		document.getActionRequests().addAll(results.getSimulatedActionRequests());
48          return document;
49  
50      }
51  }