From e08735743eb786530dd661e1e7a215e985f95deb Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Wed, 24 Jan 2018 12:59:45 +0000
Subject: [PATCH] SSDM-6001 : Microservice server, openBIS UI integration

SVN: 39137
---
 .../eln-lims/html/js/config/Profile.js        | 10 +++---
 .../js/views/DataSetForm/DataSetFormView.js   | 10 +++---
 .../widgets/DatasetViewerController.js        | 27 +++++++++++++---
 .../DataSetForm/widgets/DatasetViewerModel.js | 31 ++++++++++++++++++-
 4 files changed, 62 insertions(+), 16 deletions(-)

diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/Profile.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/Profile.js
index a8d7d05f64b..f6e8b7f63ba 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/Profile.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/Profile.js
@@ -116,12 +116,10 @@ $.extend(DefaultProfile.prototype, {
 		
 		this.isAdmin = false;
 
-//		TO-DO Delete Jupyter developer initialization notes
-//		source ~/.bash_profile
-//		pyenv local miniconda3-latest
-//		/home/osboxes/installation
-//		python pybis/src/python/ELNJupyter/elnjupyter/server.py --port 8123 --cert cert.pem --key key.pem --openbis http://10.0.2.2:8888
-//		jupyterhub -f jupyterhub_config.py --no-ssl
+//		obis integration config
+		this.EDMSs = {
+				"JUANF-BS-MBPR28.D.ETHZ.CH-E96954A7" : "http://localhost:8080/download"
+		}
 		
 //		Jupyter integration config
 //		this.jupyterOpenbisEndpoint = "http://10.0.2.2:8888"; //Should not end with slash
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 8eeca2f9540..ac938eb6f73 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
@@ -224,11 +224,11 @@ function DataSetFormView(dataSetFormController, dataSetFormModel) {
 				
 				if(cc) {
 					var $cc = FormUtil.getFieldForLabelWithText("Content Copy " + (cIdx+1) , 
-							"- <u>External DMS</u>: " + externalDmsCode + "</br>" + 
-							"- <u>Host</u>: " + host + "</br>" +
-							"- <u>Directory</u>: " + cc.path + "</br>" +
-							"- <u>Commit Hash</u>: " + cc.gitCommitHash + "</br>" + 
-							"- <u>Repository Id</u>: " + cc.gitRepositoryId + "</br>" +
+							"- <u>External DMS</u>: " + externalDmsCode + "<br>" + 
+							"- <u>Host</u>: " + host + "<br>" +
+							"- <u>Directory</u>: " + cc.path + "<br>" +
+							"- <u>Commit Hash</u>: " + cc.gitCommitHash + "<br>" + 
+							"- <u>Repository Id</u>: " + cc.gitRepositoryId + "<br>" +
 							"- <u>Connect cmd</u>: " +  "ssh -t " + host + " \"cd " + cc.path + "; bash\""
 							);
 					$dataSetTypeFieldSet.append($cc);
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerController.js
index 190ad1ead48..17a3c054a91 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerController.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerController.js
@@ -37,7 +37,6 @@ function DataSetViewerController(containerId, profile, entity, serverFacade, dat
 		if(this._datasetViewerModel.datasets) {
 			if(this._datasetViewerModel.datasets.length > 0) {
 				this.updateDatasets(this._datasetViewerModel.datasets);
-				this._datasetViewerView.repaintDatasets();
 			}
 		} else {
 			var _this = this;
@@ -59,16 +58,13 @@ function DataSetViewerController(containerId, profile, entity, serverFacade, dat
 						
 						if(results.length > 0) {
 							_this.updateDatasets(results);
-							_this._datasetViewerView.repaintDatasets();
 						}
-						
 					});
 				});
 			} else {
 				serverFacade.listDataSetsForSample(this._datasetViewerModel.entity, true, function(datasets) {
 					if(datasets.result.length > 0) {
 						_this.updateDatasets(datasets.result);
-						_this._datasetViewerView.repaintDatasets();
 					}
 				});
 			}
@@ -76,10 +72,33 @@ function DataSetViewerController(containerId, profile, entity, serverFacade, dat
 	}
 	
 	this.updateDatasets = function(datasets) {
+		var _this = this;
+		var datasetPermIds = [];
+		
 		for(var i = 0; i < datasets.length; i++) { //DataSets for entity
 			var dataset = datasets[i];
 			this._datasetViewerModel.entityDataSets[dataset.code] = dataset;
+			datasetPermIds.push(dataset.code);
 		}
+		
+		require([ "as/dto/dataset/id/DataSetPermId", "as/dto/dataset/fetchoptions/DataSetFetchOptions" ],
+				function(DataSetPermId, DataSetFetchOptions) {
+					var ids = [];
+					for(var dIdx = 0; dIdx < datasetPermIds.length; dIdx++) {
+						var id = new DataSetPermId(datasetPermIds[dIdx]);
+						ids.push(id);
+					}
+		            var fetchOptions = new DataSetFetchOptions();
+		            fetchOptions.withLinkedData().withExternalDms();
+		            mainController.openbisV3.getDataSets(ids, fetchOptions).done(function(map) {
+		            	for(var dIdx = 0; dIdx < datasetPermIds.length; dIdx++) {
+							_this._datasetViewerModel.v3Datasets.push(map[datasetPermIds[dIdx]]);
+						}
+		            	_this._datasetViewerView.repaintDatasets();
+		            });
+		});
+		
+		
 	}
 	
 }
\ No newline at end of file
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerModel.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerModel.js
index eb59fc47773..e30400c621f 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerModel.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerModel.js
@@ -29,6 +29,7 @@ function DataSetViewerModel(containerId, profile, entity, serverFacade, datastor
 	}
 	
 	this.datasets = datasets;
+	this.v3Datasets = [];
 	
 	this.enableUpload = enableUpload;
 	this.enableDeepUnfolding = enableDeepUnfolding;
@@ -36,7 +37,19 @@ function DataSetViewerModel(containerId, profile, entity, serverFacade, datastor
 	this.datastoreDownloadURL = datastoreDownloadURL;
 	
 	this.getDownloadLink = function(datasetCode, datasetFile, isShowSize) {
-		var downloadUrl = this.datastoreDownloadURL + '/' + datasetCode + "/" + encodeURIComponent(datasetFile.pathInDataSet) + "?sessionID=" + mainController.serverFacade.getSession();
+		
+		var downloadUrl = null;
+		
+		if(this.isLinkDataset(datasetCode)) {
+			var cc = this.getDownloadableContentCopy(datasetCode);
+			downloadUrl = profile.EDMSs[cc.externalDms.code] 	+ "?sessionToken=" + encodeURIComponent(mainController.serverFacade.getSession())
+													+ "&datasetPermId=" + encodeURIComponent(datasetCode)
+													+ "&externalDMSCode=" + encodeURIComponent(cc.externalDms.code)
+													+ "&contentCopyPath=" + encodeURIComponent(cc.path)
+													+ "&datasetPathToFile=" + encodeURIComponent(datasetFile.pathInDataSet);
+		} else {
+			downloadUrl = this.datastoreDownloadURL + '/' + datasetCode + "/" + encodeURIComponent(datasetFile.pathInDataSet) + "?sessionID=" + mainController.serverFacade.getSession();
+		}
 		
 		var size = null;
 		if(parseInt(datasetFile.fileSize) / 1024 > 1024) {
@@ -89,6 +102,22 @@ function DataSetViewerModel(containerId, profile, entity, serverFacade, datastor
 		return false;
 	}
 	
+	this.getDownloadableContentCopy = function(datasetCode) {
+		for(var idx = 0; idx < this.datasets.length; idx++) {
+			var dataset = this.v3Datasets[idx];
+			if(dataset.code === datasetCode && dataset.linkedData) {
+				var contentCopies = dataset.linkedData.contentCopies;
+				for(var ccIdx = 0; ccIdx < contentCopies.length; ccIdx++) {
+					var contentCopy = contentCopies[ccIdx];
+					if(profile.EDMSs[contentCopy.externalDms.code]) {
+						return contentCopy;
+					}
+				}
+			}
+		}
+		return null;
+	}
+	
 	this.getDirectDirectoryLink = function(datasetCode, pathInDataSet) {
 		var directLinkComponent = null;
 		if(this.isLinkDataset(datasetCode)) {
-- 
GitLab