[1227] | 1 | package gov.va.med.edp.command
|
---|
| 2 | {
|
---|
| 3 | import flash.system.System;
|
---|
| 4 | import flash.utils.getQualifiedClassName;
|
---|
| 5 | import flash.net.URLRequest;
|
---|
| 6 | import flash.net.navigateToURL;
|
---|
| 7 |
|
---|
| 8 | import gov.va.med.edp.control.ClearUnsavedViewsModelEvent;
|
---|
| 9 | import gov.va.med.edp.control.SwitchAppViewEvent
|
---|
| 10 | import gov.va.med.edp.model.TrackingModelLocator;
|
---|
| 11 | import gov.va.med.edp.view.ErrorDialog;
|
---|
| 12 |
|
---|
| 13 | import mx.core.Application;
|
---|
| 14 | import mx.events.CloseEvent;
|
---|
| 15 | import mx.rpc.IResponder;
|
---|
| 16 | import mx.rpc.events.FaultEvent;
|
---|
| 17 | import mx.rpc.http.HTTPService;
|
---|
| 18 |
|
---|
| 19 | public class AbstractResponderCommand implements IResponder
|
---|
| 20 | {
|
---|
| 21 | public function result(data:Object):void {
|
---|
| 22 | // NOOP: must override
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | public function fault(info:Object):void {
|
---|
| 26 | var f:FaultEvent = info as FaultEvent;
|
---|
| 27 | if (f.fault.faultCode == "Client.Error.RequestTimeout" || f.fault.faultCode == "Server.Error.Request") {
|
---|
| 28 | handleServerUnavailable(f);
|
---|
| 29 | } else if (f.fault.faultCode == HTTPService.ERROR_DECODING) { // XML parser choking on HTML error page
|
---|
| 30 | if (isLoginPage(String(f.fault.rootCause))) {
|
---|
| 31 | ErrorDialog.show("Your session appears to be invalid.\nYou will be now be asked to log in.\nUnsaved changes will be lost.", createFaultDetail(f), "Invalid Session", attemptLogin, "Login");
|
---|
| 32 | } else {
|
---|
| 33 | handleServerError(f);
|
---|
| 34 | }
|
---|
| 35 | } else {
|
---|
| 36 | handleUnknownError(f);
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | protected function getFaultMessage(faultEvent:FaultEvent) : String {
|
---|
| 41 | return faultEvent.fault.faultString;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | protected function createFaultDetail(faultEvent:FaultEvent) : Object {
|
---|
| 45 | var detail:Object = {};
|
---|
| 46 | detail.command = getQualifiedClassName(this);
|
---|
| 47 | detail.fault = faultEvent.fault;
|
---|
| 48 | detail.totalMemory = System.totalMemory;
|
---|
| 49 | detail.currentTarget = faultEvent.currentTarget;
|
---|
| 50 | return detail;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | protected function handleServerUnavailable(f:FaultEvent) : void {
|
---|
| 54 | TrackingModelLocator.getInstance().disconnectionFault = f.fault;
|
---|
| 55 | TrackingModelLocator.getInstance().disconnected = true;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | protected function handleServerError(f:FaultEvent) : void {
|
---|
| 59 | if (TrackingModelLocator.getInstance().appName == TrackingModelLocator.APP_NAME_BIGBOARD) {
|
---|
| 60 | reloadBoard();
|
---|
| 61 | } else {
|
---|
| 62 | ErrorDialog.fatal(getFaultMessage(f), createFaultDetail(f)); // sign of a unknown server-side error
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | protected function handleUnknownError(f:FaultEvent) : void {
|
---|
| 67 | if (TrackingModelLocator.getInstance().appName == TrackingModelLocator.APP_NAME_BIGBOARD) {
|
---|
| 68 | reloadBoard();
|
---|
| 69 | } else {
|
---|
| 70 | ErrorDialog.show(getFaultMessage(f), createFaultDetail(f)); // default is non-fatal
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | private function isLoginPage(result:String):Boolean {
|
---|
| 75 | return result.indexOf("<TITLE>Login Page</TITLE>") != -1;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | private function attemptLogin():void {
|
---|
| 79 | ClearUnsavedViewsModelEvent.dispatchClearUnsavedViews();
|
---|
| 80 | var request: URLRequest = new URLRequest(TrackingModelLocator.getInstance().rootURL);
|
---|
| 81 | navigateToURL(request, "_top");
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | private function reloadBoard():void {
|
---|
| 85 | if (TrackingModelLocator.getInstance().reloadFunction)
|
---|
| 86 | TrackingModelLocator.getInstance().reloadFunction.call(null);
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | }
|
---|