Skip to content

Commit

Permalink
Wrap up tasks of loading local and remote nomadhelper.html
Browse files Browse the repository at this point in the history
alongside comparision into Proxy (reference #57)
  • Loading branch information
piotrzarzycki21 committed May 29, 2024
1 parent 584bf88 commit 8af10c7
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ package controller.startup.pepareController
import controller.CommandAuthenticationTest;
import controller.CommandCleanUrlParameters;
import controller.CommandGetLTPAToken;
import controller.CommandLaunchNomadLink;
import controller.CommandLogoutCleanUp;
import controller.CommandNavigationItemsEnabled;
import controller.CommandNavigationRefreshInstalledApps;
import controller.CommandProxyManager;
import controller.CommandRefreshNavigationBookmarks;
import controller.CommandRemoveRegisterMainContentView;
import controller.CommandShowBrowserWarning;
import controller.CommandShowPopup;
import controller.startup.prepareView.CommandSwitchTheme;
import controller.startup.start.CommandPostLogin;
import controller.startup.start.CommandStartNewRegistration;
import controller.startup.start.CommandStartPasswordReset;

import org.puremvc.as3.multicore.interfaces.INotification;
import org.puremvc.as3.multicore.patterns.command.SimpleCommand;
import controller.startup.prepareView.CommandSwitchTheme;
import controller.CommandLaunchNomadLink;
import controller.CommandShowBrowserWarning;

public class CommandPrepareController extends SimpleCommand
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package controller.startup.prepareModel

import org.puremvc.as3.multicore.interfaces.INotification;
import org.puremvc.as3.multicore.patterns.command.SimpleCommand;
import model.proxy.ProxyNomadHelperComparer;

public class CommandPrepareModel extends SimpleCommand
{
Expand All @@ -32,6 +33,7 @@ package controller.startup.prepareModel
facade.registerProxy(new ProxyVersion());

facade.registerProxy(new ProxyUrlParameters());
facade.registerProxy(new ProxyNomadHelperComparer());
facade.registerProxy(new ProxyLogin());
facade.registerProxy(new ProxyNewRegistration());
facade.registerProxy(new ProxySessionCheck());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package model.proxy
{
import model.proxy.login.ProxyLogin;

import org.apache.royale.utils.async.PromiseTask;
import org.apache.royale.utils.async.SequentialAsyncTask;
import org.puremvc.as3.multicore.patterns.proxy.Proxy;

import utils.NomadHelperLoaderTasks;
import utils.UtilsCore;

public class ProxyNomadHelperComparer extends Proxy
{
public static const NAME:String = "ProxyNomadHelperComparer";
public static const NOTE_COMPARE_RESULTS:String = NAME + "NoteCompareResults";

public function ProxyNomadHelperComparer()
{
super(NAME);

setData(false);
}

public function isNomadHelpersEqual():Boolean
{
return Boolean(getData());
}

public function compareNomadHelpers():void
{
var loginProxy:ProxyLogin = facade.retrieveProxy(ProxyLogin.NAME) as ProxyLogin;
if (loginProxy.isNomadHelperUrlExists())
{
var nomadHelperUrlTasks:NomadHelperLoaderTasks = new NomadHelperLoaderTasks();
nomadHelperUrlTasks.done(function(task:PromiseTask):void {
if (nomadHelperUrlTasks.failed)
{
setData(false);
sendNotification(NOTE_COMPARE_RESULTS, getData());
}
else if (nomadHelperUrlTasks.completed)
{
compareNomadHelperUrl(nomadHelperUrlTasks.completedTasks[0], nomadHelperUrlTasks.completedTasks[1]);
}
});
nomadHelperUrlTasks.run(loginProxy.config.config.nomad_helper_url);
}
}

private function compareNomadHelperUrl(nomadHelperUrlTask:PromiseTask, nomadHelperUrlTask2:PromiseTask):void
{
var nomadHelperUrlHash:PromiseTask = UtilsCore.computeHash(nomadHelperUrlTask.result.target.element.responseText);
var nomadHelperUrlHash2:PromiseTask = UtilsCore.computeHash(nomadHelperUrlTask2.result.target.element.responseText);

var sequentialHashTask:SequentialAsyncTask = new SequentialAsyncTask([
nomadHelperUrlHash,
nomadHelperUrlHash2
]);

sequentialHashTask.done(function(task:PromiseTask) {
if (sequentialHashTask.failed)
{
setData(false);
}
else if (sequentialHashTask.completed)
{
var hash1:String = sequentialHashTask.completedTasks[0].data;
var hash2:String = sequentialHashTask.completedTasks[1].data;

var isNomadHelpersEqual:Boolean = hash1 == hash2;
setData(isNomadHelpersEqual);
}

sendNotification(NOTE_COMPARE_RESULTS, getData());
})
sequentialHashTask.run();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ package model.proxy.login
import org.apache.royale.net.events.FaultEvent;
import org.puremvc.as3.multicore.patterns.proxy.Proxy;

import services.NomadHelperUrlDelegate;
import services.login.LoginServiceDelegate;

import utils.UtilsCore;
import org.apache.royale.utils.async.PromiseTask;
import utils.NomadHelperUrlTasks;
import org.apache.royale.utils.async.SequentialAsyncTask;
import model.proxy.ProxyNomadHelperComparer;

public class ProxyLogin extends Proxy
{
Expand All @@ -33,7 +28,6 @@ package model.proxy.login
public static const NOTE_ACCOUNTS_LOAD_FAILED:String = NAME + "NoteAccountsLoadFailed";

protected var loginServiceDelegate:LoginServiceDelegate;
private var nomadHelperUrlDelegate:NomadHelperUrlDelegate;

private var username:String;
private var proxyUrlParams:ProxyUrlParameters;
Expand All @@ -44,7 +38,6 @@ package model.proxy.login
super(NAME);

loginServiceDelegate = new LoginServiceDelegate();
nomadHelperUrlDelegate = new NomadHelperUrlDelegate();
}

override public function onRegister():void
Expand Down Expand Up @@ -173,39 +166,14 @@ package model.proxy.login
if (!config) return;

_config = config;

if (this.isNomadHelperUrlExists())
{
var nomadHelperUrlTasks:NomadHelperUrlTasks = new NomadHelperUrlTasks();
nomadHelperUrlTasks.done(function(task:PromiseTask):void {
if (nomadHelperUrlTasks.failed)
{
sendNotification(ProxyLogin.NOTE_LOGIN_SUCCESS, getData() as UserVO);
}
else if (nomadHelperUrlTasks.completed)
{
compareNomadHelperUrl(nomadHelperUrlTasks.completedTasks[0], nomadHelperUrlTasks.completedTasks[1]);
}
});
nomadHelperUrlTasks.run(config.config.nomad_helper_url);
}
else
{
sendNotification(ProxyLogin.NOTE_LOGIN_SUCCESS, this.getData() as UserVO);
}

var nomadHelperCompare:ProxyNomadHelperComparer = facade.retrieveProxy(ProxyNomadHelperComparer.NAME) as ProxyNomadHelperComparer;
nomadHelperCompare.compareNomadHelpers();

sendNotification(ProxyLogin.NOTE_LOGIN_SUCCESS, this.getData() as UserVO);
//ParseCentral.parseAppConfig(new XML(event.target["data"]));
}

private function onNomadHelperLoadSuccess(event:Event):void
{
nomadHelperUrlDelegate.getLocalNomadHelper(function onNomadHelperLocalSuccess(event:Event):void {
sendNotification(ProxyLogin.NOTE_LOGIN_SUCCESS, this.getData() as UserVO);
},
function onFault(event:FaultEvent):void{
sendNotification(ProxyLogin.NOTE_LOGIN_SUCCESS, this.getData() as UserVO);
});
}

private function onAccountsLoadSuccess(event:Event):void
{
ParseCentral.parseAccounts(new XML(event.target["data"]));
Expand Down Expand Up @@ -233,35 +201,6 @@ package model.proxy.login
this.testAuthenticationWithoutBusyIndicator();
}

private function compareNomadHelperUrl(nomadHelperUrlTask:PromiseTask, nomadHelperUrlTask2:PromiseTask):void
{
var nomadHelperUrlHash:PromiseTask = UtilsCore.computeHash(nomadHelperUrlTask.result.target.responseText);
var nomadHelperUrlHash2:PromiseTask = UtilsCore.computeHash(nomadHelperUrlTask2.result.target.responseText);

var sequentialHashTask:SequentialAsyncTask = new SequentialAsyncTask([
nomadHelperUrlHash,
nomadHelperUrlHash2
]);

sequentialHashTask.done(function(task:PromiseTask) {
if (sequentialHashTask.failed)
{
sendNotification(ProxyLogin.NOTE_LOGIN_SUCCESS, getData() as UserVO);
}
else
{
if (sequentialHashTask.completed)
{
var hash1:String = sequentialHashTask.completedTasks[0].data;
var hash2:String = sequentialHashTask.completedTasks[1].data;

sendNotification(ProxyLogin.NOTE_LOGIN_SUCCESS, getData() as UserVO);
}
}
})
sequentialHashTask.run();
}

private function failOnServer(data:Object):void
{
var eventData:String = String(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package services
import org.apache.royale.net.beads.CORSCredentialsBead;
import org.apache.royale.net.events.FaultEvent;

public class NomadHelperUrlDelegate
public class NomadHelperDelegate
{
public function getNomadHelper(nomadHelperUrl:String, resultCallback:Function, faultCallback:Function=null):void
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package utils
{
import org.apache.royale.utils.async.SequentialAsyncTask;
import services.NomadHelperUrlDelegate;
import services.NomadHelperDelegate;
import org.apache.royale.utils.async.AsyncTask;
import org.apache.royale.utils.async.PromiseTask;
import org.apache.royale.net.events.FaultEvent;

public class NomadHelperUrlTasks extends SequentialAsyncTask
/**
* Class load local resources/nomadhelper.html and deployed nomadhelper.html
**/
public class NomadHelperLoaderTasks extends SequentialAsyncTask
{
public function NomadHelperUrlTasks(tasks:Array=null)
public function NomadHelperLoaderTasks(tasks:Array=null)
{
super(tasks);


}

override public function run(data:Object=null):void
Expand All @@ -24,7 +25,7 @@ package utils
}

var localNomadHelperTask:PromiseTask = new PromiseTask(new Promise(function(resolve:Function, reject:Function){
var localNomadHelper:NomadHelperUrlDelegate = new NomadHelperUrlDelegate();
var localNomadHelper:NomadHelperDelegate = new NomadHelperDelegate();
localNomadHelper.getLocalNomadHelper(function(event:Event):void{
resolve(event);
}, function onFault(fault:FaultEvent):void{
Expand All @@ -34,7 +35,7 @@ package utils
this.addTask(localNomadHelperTask);

var remoteNomadHelperTask:PromiseTask = new PromiseTask(new Promise(function(resolve:Function, reject:Function){
var localNomadHelper:NomadHelperUrlDelegate = new NomadHelperUrlDelegate();
var localNomadHelper:NomadHelperDelegate = new NomadHelperDelegate();
localNomadHelper.getNomadHelper(String(data), function(event:Event):void{
resolve(event);
}, function onFault(fault:FaultEvent):void{
Expand Down

0 comments on commit 8af10c7

Please sign in to comment.