From 190852741fa48c9112f935ac7579b1cf8e7a3d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Carretero?= <frederic.carretero@veremes.com> Date: Wed, 21 Nov 2018 15:54:41 +0100 Subject: [PATCH] Chargement de la liste des fichiers d'un projet sur S3 --- .../directives/projectDirectoryDrtv.js | 7 + module/lang/lang-en.json | 2 + module/lang/lang-fr.json | 2 + web_service/ws/Workspaces.class.inc | 150 ++++++++++++++++-- 4 files changed, 151 insertions(+), 10 deletions(-) diff --git a/module/javascript/directives/projectDirectoryDrtv.js b/module/javascript/directives/projectDirectoryDrtv.js index 68385c5a..89be6a4a 100755 --- a/module/javascript/directives/projectDirectoryDrtv.js +++ b/module/javascript/directives/projectDirectoryDrtv.js @@ -91,6 +91,13 @@ vitisApp.appProjectDirectoryTreeviewDrtv = function(propertiesSrvc, envSrvc) { "data": scope["aTreeviewLogs"]["data"] }); } + else if (response["data"]["status"] == 0) { + var oOptions = { + "className": "modal-danger", + "message": response["data"]["errorMessage"] + }; + scope["modalWindow"]("dialog", "REQUEST_ERROR", oOptions); + } } }); }; diff --git a/module/lang/lang-en.json b/module/lang/lang-en.json index 5825ce57..c1006ff2 100644 --- a/module/lang/lang-en.json +++ b/module/lang/lang-en.json @@ -67,6 +67,7 @@ "ERROR_STOP_ORDER_PROCESS_NO_SELECTION_SUPERVISION_ORDER" : "Please select a running order to stop it", "ERROR_STOP_ORDER_PROCESS_ONE_ORDER_ONLY_SUPERVISION_ORDER" : "You can only stop one running order at a time", "ERROR_STOP_ORDER_PROCESS_NO_RUNNING_ORDER_SUPERVISION_ORDER" : "The selected order is not running", + "STOPPED_BOX_TITLE_SUPERVISION_ORDER" : "Stopped", "" : "", "STATUS_TITLE_SUPERVISION_SUBSCRIPTION" : "Subscriptions", "ENABLED_SUBSCRIPTION_BOX_TITLE_SUPERVISION_SUBSCRIPTION" : "Enabled", @@ -219,6 +220,7 @@ "ERROR_FMW_FILE_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY" : "The selected file is not a valid fmw file", "ERROR_ADDITIONAL_RESOURCES_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY" : "The selected file type is not allowed", "ERROR_FILE_SIZE_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY" : "The file size exceeds the maximum allowed size.", + "ERROR_FILE_TREE_LOADING_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY" : "Error while loading the project file list", "" : "", "DESCRIPTION_TOOLTIP_TITLE_PUBLICATION_WORKSPACE" : "Description", "" : "", diff --git a/module/lang/lang-fr.json b/module/lang/lang-fr.json index 95e05117..691f41d6 100644 --- a/module/lang/lang-fr.json +++ b/module/lang/lang-fr.json @@ -67,6 +67,7 @@ "ERROR_STOP_ORDER_PROCESS_NO_SELECTION_SUPERVISION_ORDER" : "Veuillez sélectioner une demande en cours pour la stopper.", "ERROR_STOP_ORDER_PROCESS_ONE_ORDER_ONLY_SUPERVISION_ORDER" : "Vous ne pouvez stopper qu'une seule demande en cours à la fois.", "ERROR_STOP_ORDER_PROCESS_NO_RUNNING_ORDER_SUPERVISION_ORDER" : "La demande sélectionnée n'est pas en cours d'exécution.", + "STOPPED_BOX_TITLE_SUPERVISION_ORDER" : "Stoppé", "" : "", "STATUS_TITLE_SUPERVISION_SUBSCRIPTION" : "Abonnements", "ENABLED_SUBSCRIPTION_BOX_TITLE_SUPERVISION_SUBSCRIPTION" : "Actif", @@ -219,6 +220,7 @@ "ERROR_FMW_FILE_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY" : "Le fichier sélectionné n'est pas un fichier fmw valide.", "ERROR_ADDITIONAL_RESOURCES_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY" : "Le type de fichier sélectionné n'est pas autorisé.", "ERROR_FILE_SIZE_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY" : "La taille du fichier est supérieure à la taille maximale autorisée.", + "ERROR_FILE_TREE_LOADING_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY" : "Erreur pendant le chargement de la liste des fichiers du projet.", "" : "", "DESCRIPTION_TOOLTIP_TITLE_PUBLICATION_WORKSPACE" : "Description", "" : "", diff --git a/web_service/ws/Workspaces.class.inc b/web_service/ws/Workspaces.class.inc index a9f9942d..64d06e54 100755 --- a/web_service/ws/Workspaces.class.inc +++ b/web_service/ws/Workspaces.class.inc @@ -1100,17 +1100,33 @@ class Workspaces extends GTF { */ function getWorkspaceDirectoryTree() { $aReturn = array('status' => 1, 'message' => ''); - $sWorkspaceDir = $this->aProperties['workspace_dir'] . '/' . $this->aValues["my_vitis_id"] . '/fme'; - $sTreeName = 'fme'; - if (is_dir($sWorkspaceDir)) { - $aDirStructure = $this->getDirStructure($sWorkspaceDir, $sTreeName); - $aTreeviewLogs["data"][] = $aDirStructure["data"]; - foreach ($aDirStructure["files"] as $aFiles) { - $aTreeviewLogs["files"][] = $aFiles; + if ($this->aProperties['fileS3Uploader'] === true) { + $aWorkspaceDirectoryTree = $this->getS3FolderInfos('ws_data/gtf/workspace/' . $this->aValues["my_vitis_id"] . '/fme'); + if ($aWorkspaceDirectoryTree === false) { + $aReturn['status'] = 0; + $aReturn['error_code'] = 13; + $aReturn['message'] = 'ERROR_FILE_TREE_LOADING_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY'; } - $this->aFields['tree'] = $aTreeviewLogs; - } else - writeToErrorLog('scandir(' . $sWorkspaceDir . '): failed to open dir'); + else + $this->aFields['tree'] = $aWorkspaceDirectoryTree; + } + else { + $sWorkspaceDir = $this->aProperties['workspace_dir'] . '/' . $this->aValues["my_vitis_id"] . '/fme'; + $sTreeName = 'fme'; + if (is_dir($sWorkspaceDir)) { + $aDirStructure = $this->getDirStructure($sWorkspaceDir, $sTreeName); + $aTreeviewLogs["data"][] = $aDirStructure["data"]; + foreach ($aDirStructure["files"] as $aFiles) + $aTreeviewLogs["files"][] = $aFiles; + $this->aFields['tree'] = $aTreeviewLogs; + } + else { + writeToErrorLog('scandir(' . $sWorkspaceDir . '): failed to open dir'); + $aReturn['status'] = 0; + $aReturn['error_code'] = 13; + $aReturn['message'] = 'ERROR_FILE_TREE_LOADING_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY'; + } + } return $aReturn; } @@ -1272,6 +1288,120 @@ class Workspaces extends GTF { return $aReturn; } + /** + *This method scan a path to get metrics of an object (S3). + *@file vmlib/phpUtil.inc + *@param $sDirectoryPath path/prefix to scan. + *@return $aArray file structure from S3. + */ + function getS3FolderInfos ($sDirectoryPath){ + global $properties; + require_once ("aws_sdk/aws-autoloader.php"); + + // traitement du bucket et de ses sous-dossiers + $sBucket = $properties['fileS3UploaderBucket']; + $sPrefix = ""; + if (strpos($sBucket, "/") > -1){ + $aBucket = explode("/", $sBucket ); + $sBucket = $aBucket[0]; + $sPrefix = implode("/", array_slice($aBucket, 1)); + } + // Création du client S3 + $s3 = new Aws\S3\S3Client(array( + 'version'=>'latest', + 'region'=> $properties['fileS3UploaderRegion'], + 'profile'=> $properties['fileS3UploaderProfil'], + 'debug' => false + )); + $sListPrefix = str_replace($properties['ws_data_dir'], $sPrefix . "/ws_data" , $sDirectoryPath); + try { + // Liste des objets. + $aList = $s3->listObjectsV2(array( + 'Bucket' => $sBucket, + 'Prefix' => $sListPrefix + )); + $date = new DateTime(); + $sDataUrl = $properties['web_server_name'] . "/rest/vitis/file_downloader?key=[KEY]&eTag=[ETAG]&d=" . $date->getTimestamp(); + $aPath = explode("/", $sDirectoryPath); + $aReturn = array(); + $aTree = array( + "filename"=> end($aPath), + "text"=> end($aPath), + 'selectable' => false, + "nodes" => array() + ); + if ($aList["KeyCount"] > 0){ + $aFiles = array(); + foreach ($aList["Contents"] as $aObject) { + $aFiles[] = array('path' => $aObject['Key']); + $sObjectPath = str_replace($sListPrefix, "", $aObject["Key"]); + $aObjectPath = explode("/", $sObjectPath); + // Libellé du fichier avec la taille. + $iFileSizeLabel = $aObject["Size"]; + $aFileSizeUnity = array('o', 'Ko', 'Mo', 'Go', 'To'); + $i = 0; + while ($iFileSizeLabel > 1024) { + $iFileSizeLabel /= 1024; + $i++; + } + $sDate = $aObject["LastModified"]->__toString(); + $aTree = $this->s3TreeBuilder($aTree, $sObjectPath, array( + "filename"=> end($aObjectPath), + "text"=> end($aObjectPath) . ' (' . round($iFileSizeLabel) . ' ' . $aFileSizeUnity[$i] . ')', + "size" => $aObject["Size"], + 'icon' => 'glyphicon glyphicon-file', + 'tags' => array(date ("d/m/Y H:i:s", strtotime($sDate))), + "path" => $aObject["Key"] + )); + } + $aReturn['files'] = $aFiles; + $aReturn['data'] = array($aTree); + } + else + $aReturn = false; + return $aReturn; + + }catch(Aws\S3\Exception\S3Exception $e){ + writeToErrorLog($e->getMessage()); + return false; + } + } + + /** + *This method scan an object key to generate a tree struct (S3). + *@file vmlib/phpUtil.inc + *@param $aTree an existing tree. + *@param $sPath Path to scan. + *@param $FileStructure object metrics structure. + *@return $aArray file structure from S3. + */ + function s3TreeBuilder ($aTree, $sPath, $FileStructure) { + $aTreeTmp = &$aTree["nodes"]; + $aPath = explode("/", $sPath); + foreach ($aPath as $sFragment){ + if(!empty($sFragment)){ + if($sFragment !== $FileStructure["filename"]){ + $key = array_search($sFragment, array_column($aTreeTmp, 'filename')); + if ($key !== false) + $aTreeTmp = &$aTreeTmp[$key]["nodes"]; + else { + $aFolder = array( + "filename"=> $sFragment, + "text"=> $sFragment, + 'selectable' => false, + "nodes" => array() + ); + array_push($aTreeTmp, $aFolder); + $key = array_search($sFragment, array_column($aTreeTmp, 'filename')); + $aTreeTmp = &$aTreeTmp[$key]["nodes"]; + } + } + else + array_push($aTreeTmp, $FileStructure); + } + } + return $aTree; + } } ?> \ No newline at end of file -- GitLab