View Javadoc

1   package org.kuali.student.common.ui.client.security;
2   
3   import org.kuali.student.common.ui.client.service.exceptions.VersionMismatchClientException;
4   import org.kuali.student.common.ui.client.widgets.KSErrorDialog;
5   
6   import com.google.gwt.core.client.GWT;
7   import com.google.gwt.user.client.Window;
8   
9   /**
10   * Default KS implementation of failure handling.
11   * <p>
12   * Implementing institution should override this class to 
13   * custom handle failures.
14   */
15  public class AsyncCallbackFailureHandler {
16    
17      /**
18       * Attempt to provide default session timeout handling.
19       */
20      protected static final SessionTimeoutHandler sessionTimeoutHandler = GWT.create(SpringSecurityLoginDialogHandler.class);
21      
22      public void onFailure(Throwable caught) {
23          // This code attempts to handle session timeouts
24          // it appears to be half finished.  The implementing
25          // institution may wish to override the method to
26          // to properly detect session timeout
27          
28          // The idea with the if/else below is to attempt to detect
29          // the type of error and handle it appropriately. It was
30          // not finished, so only these two errors are detected.  
31          // There is also inconsistent handling of errors in the 
32          // individual widgets as well. 
33          if (sessionTimeoutHandler.isSessionTimeout(caught)){
34               handleTimeout(caught);
35               sessionTimeoutHandler.handleSessionTimeout();
36          } else if (caught instanceof VersionMismatchClientException){
37               handleVersionMismatch(caught);
38           }else {        
39               handleFailure(caught);
40           } 
41      }
42       
43      /**
44       * Override this method to process any exceptions you wish to handle. The default implementation displays 
45       * an error dialog with the message and logs the exception.
46       * 
47       * @param caught
48       */
49      public void handleFailure(Throwable caught){
50          if (!sessionTimeoutHandler.isSessionTimeout(caught)){
51              KSErrorDialog.show(caught);
52          }
53          GWT.log("Exception:", caught);
54      }
55  
56      /**
57       * By default this defers to handleFailure. Override this handle a rpc failure due to timeout differently
58       * from other exceptions.
59       * 
60       * @param caught
61       */
62      public void handleTimeout(Throwable caught){
63          handleFailure(caught);
64      }
65          
66      public void handleVersionMismatch(Throwable caught){
67          String message = null;
68          if (caught.getMessage() != null){
69              message = "Version Error: " + caught.getMessage() + "\n\n";
70          }
71          message += "This page has been updated by another user since you loaded it. Please refresh and re-apply changes before saving.";
72          Window.alert(message);
73      }
74      
75  }