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.rule;
017    
018    import org.kuali.rice.kew.framework.postprocessor.DeleteEvent;
019    import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange;
020    import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
021    import org.kuali.rice.kew.framework.postprocessor.ProcessDocReport;
022    import org.kuali.rice.kew.postprocessor.DefaultPostProcessor;
023    import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
024    import org.kuali.rice.kew.routeheader.service.RouteHeaderService;
025    import org.kuali.rice.kew.rule.service.RuleServiceInternal;
026    import org.kuali.rice.kew.service.KEWServiceLocator;
027    import org.kuali.rice.kew.api.KewApiConstants;
028    
029    
030    /**
031     * The {@link org.kuali.rice.kew.framework.postprocessor.PostProcessor} implementation for rules.  Delegates to the
032     * {@link org.kuali.rice.kew.rule.service.RuleServiceInternal#makeCurrent(Long)} method.
033     *
034     * @see org.kuali.rice.kew.rule.service.RuleServiceInternal#makeCurrent(Long)
035     *
036     * @author Kuali Rice Team (rice.collab@kuali.org)
037     */
038    public class RulePostProcessor extends DefaultPostProcessor {
039    
040        public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) throws Exception {
041            DocumentRouteHeaderValue routeHeader = getRouteHeaderService().getRouteHeader(statusChangeEvent.getDocumentId());
042            
043            if (KewApiConstants.ROUTE_HEADER_PROCESSED_CD.equals(routeHeader.getDocRouteStatus())) {
044                getRuleService().makeCurrent(routeHeader.getDocumentId());
045            }
046            return new ProcessDocReport(true, "");
047        }    
048        
049        public ProcessDocReport doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent) throws Exception {
050            return new ProcessDocReport(true, "");
051        }
052    
053        public ProcessDocReport doDeleteRouteHeader(DeleteEvent event) throws Exception {
054            return new ProcessDocReport(true, "");
055        }
056    
057        public String getVersion() throws Exception {
058            return "";
059        }
060    
061        private RouteHeaderService getRouteHeaderService() {
062            return (RouteHeaderService) KEWServiceLocator.getService(KEWServiceLocator.DOC_ROUTE_HEADER_SRV);
063        }
064    
065        private RuleServiceInternal getRuleService() {
066            return (RuleServiceInternal) KEWServiceLocator.getService(KEWServiceLocator.RULE_SERVICE);
067        }
068    
069    }