1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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 | |
|
32 | |
|
33 | |
|
34 | |
|
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 | |
|
43 | |
|
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 | |
|
59 | |
|
60 | |
|
61 | |
|
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 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public void handleTimeout(Throwable caught){ |
77 | 0 | handleFailure(caught); |
78 | 0 | } |
79 | |
|
80 | |
private boolean isSessionTimeout(Throwable caught){ |
81 | |
|
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 | |
} |