Coverage Report - org.kuali.student.common.ui.client.application.KSAsyncCallback
 
Classes in this File Line Coverage Branch Coverage Complexity
KSAsyncCallback
0%
0/22
0%
0/8
1.8
 
 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  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotification;
 23  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;
 24  
 import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator;
 25  
 
 26  
 import com.google.gwt.core.client.GWT;
 27  
 import com.google.gwt.user.client.Window;
 28  
 import com.google.gwt.user.client.rpc.AsyncCallback;
 29  
 
 30  
 /**
 31  
  * This extends the AysncCallback to handle uncaught RPC exceptions and
 32  
  * handle authentication.
 33  
  * 
 34  
  * @author Kuali Student Team
 35  
  *
 36  
  */
 37  0
 public abstract class KSAsyncCallback<T> implements AsyncCallback<T>{
 38  
        
 39  0
         private static final SessionTimeoutHandler handler = GWT.create(SpringSecurityLoginDialogHandler.class);
 40  
         
 41  
         /**
 42  
          * It is recommended that this method not be overrided, as it provides session timeout handling. 
 43  
          * Instead the handleFailure method should be overriden to handle rpc call error.
 44  
          *  
 45  
          */
 46  
         public void onFailure(Throwable caught) {  
 47  0
             if (isSessionTimeout(caught)){
 48  0
                 handleTimeout(caught);
 49  0
                 handler.handleSessionTimeout();
 50  0
         } else if (caught instanceof VersionMismatchClientException){
 51  0
             handleVersionMismatch(caught);
 52  
         }else {        
 53  0
                 handleFailure(caught);
 54  
         }
 55  0
     }
 56  
 
 57  
     /**
 58  
      * Override this method to process any exceptions you wish to handle. The default implementation displays 
 59  
      * an error dialog with the message and logs the exception.
 60  
      * 
 61  
      * @param caught
 62  
      */
 63  
     public void handleFailure(Throwable caught){
 64  0
             if (!isSessionTimeout(caught)){
 65  0
                     KSErrorDialog.show(caught);
 66  
             }
 67  0
         GWT.log("Exception:", caught);
 68  0
     }
 69  
     
 70  
     /**
 71  
      * By default this defers to handleFailure. Override this handle a rpc failure due to timeout differently
 72  
      * from other exceptions.
 73  
      * 
 74  
      * @param caught
 75  
      */
 76  
     public void handleTimeout(Throwable caught){
 77  0
             handleFailure(caught);
 78  0
     }
 79  
     
 80  
     private boolean isSessionTimeout(Throwable caught){
 81  
         //TODO: Better detection of session timeout
 82  0
             return caught.toString().contains("Login");
 83  
     }
 84  
     
 85  
     public void handleVersionMismatch(Throwable caught){
 86  0
         String message = null;
 87  0
         if (caught.getMessage() != null){
 88  0
             message = "Version Error: " + caught.getMessage() + "\n\n";
 89  
         }
 90  0
         message += "This page has been updated by another user since you loaded it. Please refresh and re-apply changes before saving.";
 91  0
         Window.alert(message);
 92  0
     }
 93  
 }