001    /**
002     * Copyright 2005-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.kew.routemodule.service.impl;
017    
018    import org.kuali.rice.kew.engine.simulation.SimulationCriteria;
019    import org.kuali.rice.kew.engine.simulation.SimulationResults;
020    import org.kuali.rice.kew.engine.simulation.SimulationWorkflowEngine;
021    import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
022    import org.kuali.rice.kew.routemodule.service.RoutingReportService;
023    import org.kuali.rice.kew.service.KEWServiceLocator;
024    
025    
026    public class RoutingReportServiceImpl implements RoutingReportService {
027    
028        public DocumentRouteHeaderValue report(SimulationCriteria criteria) {
029            try {
030                    SimulationWorkflowEngine simulationEngine = KEWServiceLocator.getSimulationEngine();
031                    SimulationResults results = simulationEngine.runSimulation(criteria);
032                    return materializeDocument(results);
033            } catch (Exception e) {
034                    if (e instanceof RuntimeException) {
035                            throw (RuntimeException)e;
036                    }
037                throw new IllegalStateException("Problem running report: " + e.getMessage(), e);
038            }
039        }
040    
041        /**
042         * The document returned does not have any of the simulated action requests set on it, we'll want to set them.
043         */
044        private DocumentRouteHeaderValue materializeDocument(SimulationResults results) {
045            DocumentRouteHeaderValue document = results.getDocument();
046                    //document.getActionRequests().addAll(results.getSimulatedActionRequests());
047            document.getSimulatedActionRequests().addAll(results.getSimulatedActionRequests());
048            return document;
049    
050        }
051    }