View Javadoc

1   /*
2    * Copyright 2005-2007 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.routemanager;
18  
19  import java.util.List;
20  
21  import org.kuali.rice.kew.postprocessor.ActionTakenEvent;
22  import org.kuali.rice.kew.postprocessor.AfterProcessEvent;
23  import org.kuali.rice.kew.postprocessor.BeforeProcessEvent;
24  import org.kuali.rice.kew.postprocessor.DeleteEvent;
25  import org.kuali.rice.kew.postprocessor.DocumentLockingEvent;
26  import org.kuali.rice.kew.postprocessor.DocumentRouteLevelChange;
27  import org.kuali.rice.kew.postprocessor.DocumentRouteStatusChange;
28  import org.kuali.rice.kew.postprocessor.PostProcessor;
29  import org.kuali.rice.kew.postprocessor.ProcessDocReport;
30  import org.kuali.rice.kew.util.KEWConstants;
31  
32  
33  public class ExceptionRoutingTestPostProcessor implements PostProcessor {
34  	
35  	public static boolean THROW_ROUTE_STATUS_CHANGE_EXCEPTION;
36  	public static boolean THROW_ROUTE_STATUS_LEVEL_EXCEPTION;
37  	public static boolean THROW_ROUTE_DELETE_ROUTE_HEADER_EXCEPTION;
38      public static boolean THROW_DO_ACTION_TAKEN_EXCEPTION;
39      public static boolean THROW_BEFORE_PROCESS_EXCEPTION;
40      public static boolean THROW_AFTER_PROCESS_EXCEPTION;
41      public static boolean THROW_DOCUMENT_LOCKING_EXCEPTION;
42  	public static boolean TRANSITIONED_OUT_OF_EXCEPTION_ROUTING = false;
43  	public static boolean BLOW_UP_ON_TRANSITION_INTO_EXCEPTION = false;
44  	
45  	public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) throws Exception {
46  	        // 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!
47  	        // 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
48  	        // which will result in the document never actually transitioning into exception state
49  	        boolean transitioningIntoException = !KEWConstants.ROUTE_HEADER_EXCEPTION_CD.equals(statusChangeEvent.getOldRouteStatus()) &&
50                                                        KEWConstants.ROUTE_HEADER_EXCEPTION_CD.equals(statusChangeEvent.getNewRouteStatus()); 
51  		if (THROW_ROUTE_STATUS_CHANGE_EXCEPTION && !transitioningIntoException) {
52  			throw new RuntimeException("I am the doRouteStatusChange exploder");
53  		}
54  		if (BLOW_UP_ON_TRANSITION_INTO_EXCEPTION && transitioningIntoException) {
55  			throw new RuntimeException("Throwing an exception when transitioning into exception status.");
56  		}
57  		if (KEWConstants.ROUTE_HEADER_EXCEPTION_CD.equals(statusChangeEvent.getOldRouteStatus())) {
58  			TRANSITIONED_OUT_OF_EXCEPTION_ROUTING = true;
59  		}
60  		return new ProcessDocReport(true, "");
61  	}
62  
63  	public ProcessDocReport doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent) throws Exception {
64  		if (THROW_ROUTE_STATUS_LEVEL_EXCEPTION) {
65  			throw new RuntimeException("I am the doRouteLevelChange exploder");
66  		}
67  		return new ProcessDocReport(true, "");
68  	}
69  
70  	public ProcessDocReport doDeleteRouteHeader(DeleteEvent event) throws Exception {
71  		if (THROW_ROUTE_DELETE_ROUTE_HEADER_EXCEPTION) {
72  			throw new RuntimeException("I am the doDeleteRouteHeader exploder");
73  		}
74  		return new ProcessDocReport(true, "");
75  	}
76  
77  	public ProcessDocReport doActionTaken(ActionTakenEvent event) throws Exception {
78  		if (THROW_DO_ACTION_TAKEN_EXCEPTION) {
79  			throw new RuntimeException("I am the doActionTaken exploder");
80  		}
81  		return new ProcessDocReport(true, "");
82  	}
83  
84      public ProcessDocReport beforeProcess(BeforeProcessEvent event) throws Exception {
85          if (THROW_BEFORE_PROCESS_EXCEPTION) {
86              throw new RuntimeException("I am the beforeProcess exploder");
87          }
88          return new ProcessDocReport(true, "");
89      }
90  
91      public ProcessDocReport afterProcess(AfterProcessEvent event) throws Exception {
92          if (THROW_AFTER_PROCESS_EXCEPTION) {
93              throw new RuntimeException("I am the afterProcess exploder");
94          }
95          return new ProcessDocReport(true, "");
96      }
97  
98  	public List<String> getDocumentIdsToLock(DocumentLockingEvent lockingEvent)
99  			throws Exception {
100 		if (THROW_DOCUMENT_LOCKING_EXCEPTION) {
101 			throw new RuntimeException("I am the getDocumentIdsToLock exploder");
102 		}
103 		return null;
104 	}
105     
106     
107 
108 }