From 01cd9ab37e8041038910798ba217b7e4d19c5503 Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Thu, 2 Jun 2016 09:13:37 +0000
Subject: [PATCH] SSDM-3092 : Export functionality, working prototype with all
 entity types

SVN: 36617
---
 .../eln-lims/html/js/server/ServerFacade.js   |  4 ++--
 .../js/views/DataSetForm/DataSetFormView.js   | 14 ++++++++++++++
 .../ExperimentForm/ExperimentFormView.js      | 14 ++++++++++++++
 .../js/views/ProjectForm/ProjectFormView.js   | 14 ++++++++++++++
 .../js/views/SampleForm/SampleFormView.js     | 14 ++++++++++++++
 .../html/js/views/SpaceForm/SpaceFormView.js  |  2 +-
 .../exports-api/exports-api.py                | 19 +++++++++++--------
 7 files changed, 70 insertions(+), 11 deletions(-)

diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js
index 54a8a5a38f0..63a23f6a915 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js
@@ -185,7 +185,7 @@ function ServerFacade(openbisServer) {
 	//
 	//
 	//
-	this.exportAll = function(entity, userId, callbackFunction) {
+	this.exportAll = function(entities, userId, callbackFunction) {
 		var _this = this;
 		this.openbisServer.listPersons(function(data) {
 			var userEmail = null;
@@ -204,7 +204,7 @@ function ServerFacade(openbisServer) {
 			} else {
 				_this.customELNApi({
 					"method" : "exportAll",
-					"entity" : entity,
+					"entities" : entities,
 					"userEmail" : userEmail
 				}, callbackFunction, "exports-api");
 			}
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormView.js
index c9cb539e9f9..7900a2edff0 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormView.js
@@ -83,6 +83,20 @@ function DataSetFormView(dataSetFormController, dataSetFormModel) {
 				_this._dataSetFormController.deleteDataSet(reason);
 			}, true);
 			toolbarModel.push({ component : $deleteBtn, tooltip: "Delete" });
+			
+			//Export
+			var $export = FormUtil.getButtonWithIcon("glyphicon-export", function() {
+				Util.blockUI();
+				var facade = mainController.serverFacade;
+				facade.exportAll([{ type: "DATASET", permId : _this._dataSetFormModel.dataSet.code, expand : true }], facade.getUserId(), function(error, result) {
+					if(error) {
+						Util.showError(error);
+					} else {
+						Util.showSuccess("Export is being processed, you will receibe an email when is ready.", function() { Util.unblockUI(); });
+					}
+				});
+			});
+			toolbarModel.push({ component : $export, tooltip: "Export" });
 		}
 		
 		if(!this._dataSetFormModel.isMini) {
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ExperimentForm/ExperimentFormView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ExperimentForm/ExperimentFormView.js
index d60c1b22626..acdaba7da20 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ExperimentForm/ExperimentFormView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ExperimentForm/ExperimentFormView.js
@@ -95,6 +95,20 @@ function ExperimentFormView(experimentFormController, experimentFormModel) {
 				_this._experimentFormController.deleteExperiment(reason);
 			}, true);
 			toolbarModel.push({ component : $deleteBtn, tooltip: "Delete" });
+			
+			//Export
+			var $export = FormUtil.getButtonWithIcon("glyphicon-export", function() {
+				Util.blockUI();
+				var facade = mainController.serverFacade;
+				facade.exportAll([{ type: "EXPERIMENT", permId : _this._experimentFormModel.experiment.permId, expand : true }], facade.getUserId(), function(error, result) {
+					if(error) {
+						Util.showError(error);
+					} else {
+						Util.showSuccess("Export is being processed, you will receibe an email when is ready.", function() { Util.unblockUI(); });
+					}
+				});
+			});
+			toolbarModel.push({ component : $export, tooltip: "Export" });
 		}
 		
 		$formColumn.append(FormUtil.getToolbar(toolbarModel));
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ProjectForm/ProjectFormView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ProjectForm/ProjectFormView.js
index b5fe15002ef..4545a3f2382 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ProjectForm/ProjectFormView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ProjectForm/ProjectFormView.js
@@ -101,6 +101,20 @@ function ProjectFormView(projectFormController, projectFormModel) {
 			}, true);
 			toolbarModel.push({ component : $deleteBtn, tooltip: "Delete" });
 			
+			//Export
+			var $export = FormUtil.getButtonWithIcon("glyphicon-export", function() {
+				Util.blockUI();
+				var facade = mainController.serverFacade;
+				facade.exportAll([{ type: "PROJECT", permId : _this._projectFormModel.project.permId, expand : true }], facade.getUserId(), function(error, result) {
+					if(error) {
+						Util.showError(error);
+					} else {
+						Util.showSuccess("Export is being processed, you will receibe an email when is ready.", function() { Util.unblockUI(); });
+					}
+				});
+			});
+			toolbarModel.push({ component : $export, tooltip: "Export" });
+			
 			//Operations
 			var $operationsMenu = FormUtil.getOperationsMenu([{ label: "Create Experiment", event: function() {
 				showSelectExperimentType();
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormView.js
index ba5d68cfa44..78329a2dded 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormView.js
@@ -203,6 +203,20 @@ function SampleFormView(sampleFormController, sampleFormModel) {
 				mainController.changeView('showCreateDataSetPageFromPermId',_this._sampleFormModel.sample.permId);
 			});
 			toolbarModel.push({ component : $uploadBtn, tooltip: "Upload Dataset" });
+			
+			//Export
+			var $export = FormUtil.getButtonWithIcon("glyphicon-export", function() {
+				Util.blockUI();
+				var facade = mainController.serverFacade;
+				facade.exportAll([{ type: "SAMPLE", permId : _this._sampleFormModel.sample.permId, expand : true }], facade.getUserId(), function(error, result) {
+					if(error) {
+						Util.showError(error);
+					} else {
+						Util.showSuccess("Export is being processed, you will receibe an email when is ready.", function() { Util.unblockUI(); });
+					}
+				});
+			});
+			toolbarModel.push({ component : $export, tooltip: "Export" });
 		}
 		
 		$formColumn.append($formTitle);
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SpaceForm/SpaceFormView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SpaceForm/SpaceFormView.js
index 8f251dc9462..0676f3e493e 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SpaceForm/SpaceFormView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SpaceForm/SpaceFormView.js
@@ -40,7 +40,7 @@ function SpaceFormView(spaceFormController, spaceFormModel) {
 		var $export = FormUtil.getButtonWithIcon("glyphicon-export", function() {
 			Util.blockUI();
 			var facade = mainController.serverFacade;
-			facade.exportAll({ type: "SPACE", permId : _this._spaceFormModel.space.code, expand : true }, facade.getUserId(), function(error, result) {
+			facade.exportAll([{ type: "SPACE", permId : _this._spaceFormModel.space.code, expand : true }], facade.getUserId(), function(error, result) {
 				if(error) {
 					Util.showError(error);
 				} else {
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/exports-api/exports-api.py b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/exports-api/exports-api.py
index 0adc64267c5..f5f78613746 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/exports-api/exports-api.py
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/exports-api/exports-api.py
@@ -74,7 +74,7 @@ def process(tr, params, tableBuilder):
 	# Set user using the Dropbox
 	tr.setUserId(userId);
 	if method == "exportAll":
-		isOk = exportAll(tr, params);
+		isOk = expandAndexport(tr, params);
 
 	if isOk:
 		tableBuilder.addHeader("STATUS");
@@ -92,7 +92,7 @@ def process(tr, params, tableBuilder):
 		row.setCell("MESSAGE", "Operation Failed");
 		
 
-def exportAll(tr, params):
+def expandAndexport(tr, params):
 	#Services used during the export process
 	# TO-DO Login on the services as ETL server but on behalf of the user that makes the call
 	sessionToken = params.get("sessionToken");
@@ -100,13 +100,16 @@ def exportAll(tr, params):
 	v3d = ServiceProvider.getApplicationContext().getBean(V3_DSS_BEAN);
 	mailClient = tr.getGlobalState().getMailClient();
 	
-	entity = params.get("entity");
-	userEmail = params.get("userEmail");
-	entityAsPythonMap = { "type" : entity.get("type"), "permId" : entity.get("permId"), "expand" : entity.get("expand") };
-	entitiesToExport = [entityAsPythonMap];
+	entitiesToExport = [];
 	entitiesToExpand = deque([]);
-	if entity.get("expand"):
-		entitiesToExpand.append(entityAsPythonMap);
+		
+	entities = params.get("entities");
+	userEmail = params.get("userEmail");
+	for entity in entities:
+		entityAsPythonMap = { "type" : entity.get("type"), "permId" : entity.get("permId"), "expand" : entity.get("expand") };
+		entitiesToExport.append(entityAsPythonMap);
+		if entity.get("expand"):
+			entitiesToExpand.append(entityAsPythonMap);
 	
 	while entitiesToExpand:
 		entityToExpand = entitiesToExpand.popleft();
-- 
GitLab