diff --git a/AABrowserAPI/TeamSetup.js b/AABrowserAPI/TeamSetup.js
new file mode 100644
index 000000000..a65abc607
--- /dev/null
+++ b/AABrowserAPI/TeamSetup.js
@@ -0,0 +1,148 @@
+exports.newTeamSetup = function newTeamSetup() {
+
+ CONSOLE_LOG = true;
+ LOG_FILE_CONTENT = false;
+
+ let thisObject = {
+ newTeam: newTeam,
+ initialize: initialize
+ }
+
+ let storage;
+
+ return thisObject;
+
+ function initialize(pServerConfig) {
+
+ const STORAGE = require('../Server/Storage');
+ storage = STORAGE.newStorage();
+
+ storage.initialize(undefined, pServerConfig);
+
+ }
+
+ function newTeam(pTeamCodeName, pTeamDisplayName, pUserName, pBotName, callBackFunction) {
+
+ try {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] TeamSetup -> newTeam -> Entering function."); }
+
+ /*
+
+ Procedure to create a new Team, User and Bot:
+
+ 1. Add it to the Ecosystem.
+ 2. Agregarlo al archivo de sessiones. --> copiar la session local a Develop
+ 3. Crear el container del nuevo devTeam.
+ 4. Crear el folder del nuevo devTeam en el container aaplatform.
+ 5. Copiar el bot a devTeam/bots --> Cambiarle el nombre al folder
+ 6. Modificar la configuracion del bot reemplazando el devTeam y el Nombre.
+ 7. Modificar la configuracion del bot en sus status dependecies y data depedencies. // solo si el bot va a usar otros productos.
+ 8. Asegurarse de que tenga la data dependency de Bruce para poder obtener el precio del mercado en backtest.
+ 9. Copiar el bot al directorio del usuario.
+ 10. Copiar la configuracion del cloud al folder del nuevo team.
+ 11. Modificarla configuracion de AACloud para detallar el proceso que tiene que correr.
+
+ */
+
+ addToEcosystem();
+
+ function addToEcosystem() {
+
+ try {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] TeamSetup -> newTeam -> addToEcosystem -> Entering function."); }
+
+ storage.readData("AdvancedAlgos", "AAPlatform", "ecosystem.json", false, onDataRead);
+
+ function onDataRead(err, pFileContent) {
+
+ try {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] TeamSetup -> newTeam -> addToEcosystem -> onDataRead -> Entering function."); }
+
+ if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
+
+ console.log("[ERROR] TeamSetup -> newTeam -> addToEcosystem -> onDataRead -> Could not read a file. ");
+ console.log("[ERROR] TeamSetup -> newTeam -> addToEcosystem -> onDataRead -> err.message = " + err.message);
+
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ return;
+ }
+
+ let ecosystem = JSON.parse(pFileContent);
+
+ let newTeam = {
+ codeName: pTeamCodeName,
+ displayName: pTeamDisplayName,
+ bots: [
+ {
+ "repo": pBotName + "-Trading-Bot",
+ "configFile": "this.bot.config.json"
+ }
+ ],
+ "plotters": []
+ };
+
+ ecosystem.devTeams.push(newTeam);
+
+ let fileContent = JSON.stringify(ecosystem);
+
+ storage.writeData("AdvancedAlgos", "AAPlatform", "ecosystem.json", fileContent, onDataWritten);
+
+ function onDataWritten(err) {
+
+ try {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] TeamSetup -> newTeam -> addToEcosystem -> onDataRead -> onDataWritten -> Entering function."); }
+
+ if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
+
+ console.log("[ERROR] TeamSetup -> newTeam -> addToEcosystem -> onDataRead -> onDataWritten -> Could not write a file. ");
+ console.log("[ERROR] TeamSetup -> newTeam -> addToEcosystem -> onDataRead -> onDataWritten -> err.message = " + err.message);
+
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ return;
+ }
+
+ addToSessions();
+
+ } catch (err) {
+
+ console.log("[ERROR] TeamSetup -> newTeam -> addToEcosystem -> onDataRead -> onDataWritten -> err.message = " + err.message);
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+
+ }
+ }
+
+ } catch (err) {
+
+ console.log("[ERROR] TeamSetup -> newTeam -> addToEcosystem -> onDataRead -> err.message = " + err.message);
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+
+ }
+ }
+
+ } catch (err) {
+
+ console.log("[ERROR] TeamSetup -> newTeam -> addToEcosystem -> err.message = " + err.message);
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+
+ }
+ }
+
+ function addToSessions() {
+
+
+ }
+
+ callBackFunction(global.DEFAULT_OK_RESPONSE);
+
+ } catch (err) {
+
+ console.log("[ERROR] TeamSetup -> newTeam -> err.message = " + err.message);
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/Project.njsproj b/Project.njsproj
index 7f6f10c7f..48d374bb1 100644
--- a/Project.njsproj
+++ b/Project.njsproj
@@ -32,6 +32,9 @@
Code
+
+ Code
+
Code
diff --git a/Server/Storage.js b/Server/Storage.js
index 1f8164b14..9df403947 100644
--- a/Server/Storage.js
+++ b/Server/Storage.js
@@ -18,31 +18,31 @@
}
- function readData(pOrg, pRepo, pPath, saveAtCache, callBackFunction) {
+ function readData(pOrg, pPath, pFile, saveAtCache, callBackFunction) {
try {
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> Entering function."); }
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> pOrg = " + pOrg); }
- if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> pRepo = " + pRepo); }
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> pPath = " + pPath); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> pFile = " + pFile); }
let cacheVersion;
if (storageData !== undefined) {
- cacheVersion = storageData.get(pOrg + '.' + pRepo + '.' + pPath);
+ cacheVersion = storageData.get(pOrg + '.' + pPath + '.' + pFile);
}
if (cacheVersion !== undefined) {
- if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> " + pOrg + '.' + pRepo + '.' + pPath + " found at cache."); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> " + pOrg + '.' + pPath + '.' + pFile + " found at cache."); }
callBackFunction(cacheVersion);
} else {
- if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> " + pOrg + '.' + pRepo + '.' + pPath + " NOT found at cache."); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> " + pOrg + '.' + pPath + '.' + pFile + " NOT found at cache."); }
let storage = require('azure-storage');
let connectionString;
@@ -64,7 +64,7 @@
let blobService = storage.createBlobService(connectionString);
- blobService.getBlobToText('aaplatform', pOrg + "/" + pRepo + "/" + pPath, onFileReceived);
+ blobService.getBlobToText('aaplatform', pOrg + "/" + pPath + "/" + pFile, onFileReceived);
function onFileReceived(err, text, response) {
@@ -75,12 +75,12 @@
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> err = " + JSON.stringify(err)); }
if (LOG_FILE_CONTENT === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> response = " + JSON.stringify(response)); }
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> pOrg = " + pOrg); }
- if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> pRepo = " + pRepo); }
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> pPath = " + pPath); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> pFile = " + pFile); }
if (saveAtCache === true) {
- storageData.set(pOrg + '.' + pRepo + '.' + pPath, text);
+ storageData.set(pOrg + '.' + pPath + '.' + pFile, text);
}
@@ -110,16 +110,16 @@
}
}
- function writeData(pOrg, pRepo, pPath, pFileContent, callBackFunction) {
+ function writeData(pOrg, pPath, pFile, pFileContent, callBackFunction) {
try {
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> Entering function."); }
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> pOrg = " + pOrg); }
- if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> pRepo = " + pRepo); }
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> pPath = " + pPath); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> pFile = " + pFile); }
- if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> " + pOrg + '.' + pRepo + '.' + pPath + " NOT found at cache."); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> " + pOrg + '.' + pPath + '.' + pFile + " NOT found at cache."); }
let storage = require('azure-storage');
let connectionString;
@@ -140,7 +140,7 @@
}
let blobService = storage.createBlobService(connectionString);
- let blobPath = pOrg + "/" + pRepo + "/" + pPath;
+ let blobPath = pOrg + "/" + pPath + "/" + pFile;
let blobText = pFileContent.toString();
blobService.createBlockBlobFromText('aaplatform', blobPath, blobText, onFileCreated);
@@ -153,8 +153,8 @@
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
if (LOG_FILE_CONTENT === true) { console.log("[INFO] API -> writeData -> onFileCreated -> response = " + JSON.stringify(response)); }
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> pOrg = " + pOrg); }
- if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> pRepo = " + pRepo); }
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> pPath = " + pPath); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> pFile = " + pFile); }
if (err !== null || text === null) {
diff --git a/server.js b/server.js
index 6bc1840d2..78722cb8d 100644
--- a/server.js
+++ b/server.js
@@ -467,8 +467,8 @@ function onBrowserRequest(request, response) {
case "saveBotCode": {
- const AABROSER_API_BOT_CODE = require('./AABrowserAPI/' + 'BotCode');
- let botCode = AABROSER_API_BOT_CODE.newBotCode();
+ const AABROWSER_API_BOT_CODE = require('./AABrowserAPI/' + 'BotCode');
+ let botCode = AABROWSER_API_BOT_CODE.newBotCode();
botCode.initialize(serverConfig);
@@ -499,8 +499,8 @@ function onBrowserRequest(request, response) {
case "authenticateUser": {
- const AABROSER_API_USER_AUTHENTICATION = require('./AABrowserAPI/' + 'UserAuthentication');
- let userAuthentication = AABROSER_API_USER_AUTHENTICATION.newUserAuthentication();
+ const AABROWSER_API_USER_AUTHENTICATION = require('./AABrowserAPI/' + 'UserAuthentication');
+ let userAuthentication = AABROWSER_API_USER_AUTHENTICATION.newUserAuthentication();
userAuthentication.initialize(sessionManager, storageAccessManager);
userAuthentication.authenticateUser(requestParameters[3], onFinish);
@@ -517,6 +517,27 @@ function onBrowserRequest(request, response) {
break;
}
+
+ case "teamSetup": {
+
+ const AABROWSER_API_TEAM_SETUP = require('./AABrowserAPI/' + 'TeamSetup');
+ let teamSetup = AABROWSER_API_TEAM_SETUP.newTeamSetup();
+
+ teamSetup.initialize(serverConfig);
+
+ let devTeamCodeName = requestParameters[3];
+ let devTeamDisplayName = requestParameters[4].replace("%20", " ");
+ let userName = requestParameters[5];
+ let botName = requestParameters[6];
+
+ teamSetup.newTeam(devTeamCodeName, devTeamDisplayName, userName, botName, onSetupFinished);
+
+ function onSetupFinished(err) {
+
+ respondWithContent(JSON.stringify(err), response);
+ }
+ break;
+ }
}
}
break;