Coverage Report - org.kuali.student.common.ui.client.application.KSAsyncCallback
 
Classes in this File Line Coverage Branch Coverage Complexity
KSAsyncCallback
0%
0/21
0%
0/8
2
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.student.common.ui.client.application;
 17  
 
 18  
 import org.kuali.student.common.ui.client.security.SessionTimeoutHandler;
 19  
 import org.kuali.student.common.ui.client.security.SpringSecurityLoginDialogHandler;
 20  
 import org.kuali.student.common.ui.client.service.exceptions.VersionMismatchClientException;
 21  
 import org.kuali.student.common.ui.client.widgets.KSErrorDialog;
 22  
 
 23  
 import com.google.gwt.core.client.GWT;
 24  
 import com.google.gwt.user.client.Window;
 25  
 import com.google.gwt.user.client.rpc.AsyncCallback;
 26  
 
 27  
 /**
 28  
  * This extends the AysncCallback to handle uncaught RPC exceptions and
 29  
  * handle authentication.
 30  
  * 
 31  
  * @author Kuali Student Team
 32  
  *
 33  
  */
 34  0
 public abstract class KSAsyncCallback<T> implements AsyncCallback<T>{
 35  
        
 36  0
         private static final SessionTimeoutHandler sessionTimeoutHandler = GWT.create(SpringSecurityLoginDialogHandler.class);
 37  
         
 38  
         /**
 39  
          * It is recommended that this method not be overrided, as it provides session timeout handling. 
 40  
          * Instead the handleFailure method should be overriden to handle rpc call error.
 41  
          *  
 42  
          */
 43  
         public void onFailure(Throwable caught) {  
 44  0
             if (sessionTimeoutHandler.isSessionTimeout(caught)){
 45  0
                 handleTimeout(caught);
 46  0
                 sessionTimeoutHandler.handleSessionTimeout();
 47  0
         } else if (caught instanceof VersionMismatchClientException){
 48  0
             handleVersionMismatch(caught);
 49  
         }else {        
 50  0
                 handleFailure(caught);
 51  
         }
 52  0
     }
 53  
 
 54  
     /**
 55  
      * Override this method to process any exceptions you wish to handle. The default implementation displays 
 56  
      * an error dialog with the message and logs the exception.
 57  
      * 
 58  
      * @param caught
 59  
      */
 60  
     public void handleFailure(Throwable caught){
 61  0
             if (!sessionTimeoutHandler.isSessionTimeout(caught)){
 62  0
                     KSErrorDialog.show(caught);
 63  
             }
 64  0
         GWT.log("Exception:", caught);
 65  0
     }
 66  
     
 67  
     /**
 68  
      * By default this defers to handleFailure. Override this handle a rpc failure due to timeout differently
 69  
      * from other exceptions.
 70  
      * 
 71  
      * @param caught
 72  
      */
 73  
     public void handleTimeout(Throwable caught){
 74  0
             handleFailure(caught);
 75  0
     }
 76  
         
 77  
     public void handleVersionMismatch(Throwable caught){
 78  0
         String message = null;
 79  0
         if (caught.getMessage() != null){
 80  0
             message = "Version Error: " + caught.getMessage() + "\n\n";
 81  
         }
 82  0
         message += "This page has been updated by another user since you loaded it. Please refresh and re-apply changes before saving.";
 83  0
         Window.alert(message);
 84  0
     }
 85  
 }