001/**
002 * Copyright 2005-2014 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 */
016package org.kuali.rice.kew.routemanager;
017
018import java.util.List;
019
020import org.kuali.rice.kew.api.action.ActionType;
021import org.kuali.rice.kew.framework.postprocessor.ActionTakenEvent;
022import org.kuali.rice.kew.framework.postprocessor.AfterProcessEvent;
023import org.kuali.rice.kew.framework.postprocessor.BeforeProcessEvent;
024import org.kuali.rice.kew.framework.postprocessor.DeleteEvent;
025import org.kuali.rice.kew.framework.postprocessor.DocumentLockingEvent;
026import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange;
027import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
028import org.kuali.rice.kew.framework.postprocessor.PostProcessor;
029import org.kuali.rice.kew.framework.postprocessor.ProcessDocReport;
030import org.kuali.rice.kew.api.KewApiConstants;
031
032
033public class ExceptionRoutingTestPostProcessor implements PostProcessor {
034        
035        public static boolean THROW_ROUTE_STATUS_CHANGE_EXCEPTION;
036        public static boolean THROW_ROUTE_STATUS_LEVEL_EXCEPTION;
037        public static boolean THROW_ROUTE_DELETE_ROUTE_HEADER_EXCEPTION;
038    public static boolean THROW_DO_ACTION_TAKEN_EXCEPTION;
039    public static boolean THROW_BEFORE_PROCESS_EXCEPTION;
040    public static boolean THROW_AFTER_PROCESS_EXCEPTION;
041    public static boolean THROW_DOCUMENT_LOCKING_EXCEPTION;
042        public static boolean TRANSITIONED_OUT_OF_EXCEPTION_ROUTING = false;
043        public static boolean BLOW_UP_ON_TRANSITION_INTO_EXCEPTION = false;
044        
045        public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) throws Exception {
046                // defend against re-entrancy by only throwing the route status change exception if the status change we are undergoing is not a transition into exception state!
047                // if we don't do this, this postprocessor will blow up when it is subsequently notified about the transition into exception state that it previously caused
048                // which will result in the document never actually transitioning into exception state
049                boolean transitioningIntoException = !KewApiConstants.ROUTE_HEADER_EXCEPTION_CD.equals(statusChangeEvent.getOldRouteStatus()) &&
050                                                      KewApiConstants.ROUTE_HEADER_EXCEPTION_CD.equals(statusChangeEvent.getNewRouteStatus());
051                if (THROW_ROUTE_STATUS_CHANGE_EXCEPTION && !transitioningIntoException) {
052                        throw new RuntimeException("I am the doRouteStatusChange exploder");
053                }
054                if (BLOW_UP_ON_TRANSITION_INTO_EXCEPTION && transitioningIntoException) {
055                        throw new RuntimeException("Throwing an exception when transitioning into exception status.");
056                }
057                if (KewApiConstants.ROUTE_HEADER_EXCEPTION_CD.equals(statusChangeEvent.getOldRouteStatus())) {
058                        TRANSITIONED_OUT_OF_EXCEPTION_ROUTING = true;
059                }
060                return new ProcessDocReport(true, "");
061        }
062
063        public ProcessDocReport doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent) throws Exception {
064                if (THROW_ROUTE_STATUS_LEVEL_EXCEPTION) {
065                        throw new RuntimeException("I am the doRouteLevelChange exploder");
066                }
067                return new ProcessDocReport(true, "");
068        }
069
070        public ProcessDocReport doDeleteRouteHeader(DeleteEvent event) throws Exception {
071                if (THROW_ROUTE_DELETE_ROUTE_HEADER_EXCEPTION) {
072                        throw new RuntimeException("I am the doDeleteRouteHeader exploder");
073                }
074                return new ProcessDocReport(true, "");
075        }
076
077        public ProcessDocReport doActionTaken(ActionTakenEvent event) throws Exception {
078                if (THROW_DO_ACTION_TAKEN_EXCEPTION) {
079                        throw new RuntimeException("I am the doActionTaken exploder");
080                }
081                return new ProcessDocReport(true, "");
082        }
083
084    public ProcessDocReport afterActionTaken(ActionType performed, ActionTakenEvent event) throws Exception {
085        if (THROW_DO_ACTION_TAKEN_EXCEPTION) {
086            throw new RuntimeException("I am the afterActionTaken exploder");
087        }
088        return new ProcessDocReport(true, "");
089    }
090
091    public ProcessDocReport beforeProcess(BeforeProcessEvent event) throws Exception {
092        if (THROW_BEFORE_PROCESS_EXCEPTION) {
093            throw new RuntimeException("I am the beforeProcess exploder");
094        }
095        return new ProcessDocReport(true, "");
096    }
097
098    public ProcessDocReport afterProcess(AfterProcessEvent event) throws Exception {
099        if (THROW_AFTER_PROCESS_EXCEPTION) {
100            throw new RuntimeException("I am the afterProcess exploder");
101        }
102        return new ProcessDocReport(true, "");
103    }
104
105        public List<String> getDocumentIdsToLock(DocumentLockingEvent lockingEvent)
106                        throws Exception {
107                if (THROW_DOCUMENT_LOCKING_EXCEPTION) {
108                        throw new RuntimeException("I am the getDocumentIdsToLock exploder");
109                }
110                return null;
111        }
112    
113    
114
115}