From c1ba891f642f8d28bb5317485edf3c3546d9f033 Mon Sep 17 00:00:00 2001 From: Viktor Kovtun <viktor.kovtun@id.ethz.ch> Date: Tue, 13 Aug 2019 11:14:41 +0200 Subject: [PATCH] SSDM-8405 Created basic UI for Zenodo export. --- .../1/as/webapps/eln-lims/html/index.html | 4 + .../html/js/controllers/MainController.js | 7 ++ .../ResearchCollectionExportController.js | 2 +- .../ResearchCollectionExportView.js | 2 - .../js/views/SideMenu/SideMenuWidgetView.js | 6 + .../ZenodoExport/ZenodoExportController.js | 109 ++++++++++++++++++ .../views/ZenodoExport/ZenodoExportModel.js | 18 +++ .../js/views/ZenodoExport/ZenodoExportView.js | 49 ++++++++ .../zenodo-exports-api/plugin.properties | 4 + .../zenodo-exports-api/zenodoExports.py | 34 ++++++ 10 files changed, 232 insertions(+), 3 deletions(-) create mode 100644 openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ZenodoExport/ZenodoExportController.js create mode 100644 openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ZenodoExport/ZenodoExportModel.js create mode 100644 openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ZenodoExport/ZenodoExportView.js create mode 100644 openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/zenodo-exports-api/plugin.properties create mode 100644 openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/zenodo-exports-api/zenodoExports.py diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html index d72ffce44d8..91f80febfa3 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html @@ -259,6 +259,10 @@ <script type="text/javascript" src="./js/views/ResearchCollectionExport/ResearchCollectionExportModel.js"></script> <script type="text/javascript" src="./js/views/ResearchCollectionExport/ResearchCollectionExportView.js"></script> + <script type="text/javascript" src="./js/views/ZenodoExport/ZenodoExportController.js"></script> + <script type="text/javascript" src="./js/views/ZenodoExport/ZenodoExportModel.js"></script> + <script type="text/javascript" src="./js/views/ZenodoExport/ZenodoExportView.js"></script> + <script type="text/javascript" src="./js/views/DrawingBoards/DrawingBoardsController.js"></script> <script type="text/javascript" src="./js/views/DrawingBoards/DrawingBoardsModel.js"></script> <script type="text/javascript" src="./js/views/DrawingBoards/DrawingBoardsView.js"></script> diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js index 142198f6bab..1294aec2ba7 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js @@ -389,6 +389,13 @@ function MainController(profile) { newResearchCollectionExportView.init(researchCollectionExportViews); this.currentView = newResearchCollectionExportView; break; + case "showZenodoExportPage": + document.title = "Zenodo Export Builder"; + var newZenodoExportView = new ZenodoExportController(this); + var zenodoExportViews = this._getNewViewModel(true, true, false); + newZenodoExportView.init(zenodoExportViews); + this.currentView = newZenodoExportView; + break; case "showLabNotebookPage": document.title = "Lab Notebook"; var newView = new LabNotebookController(this); diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ResearchCollectionExport/ResearchCollectionExportController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ResearchCollectionExport/ResearchCollectionExportController.js index 514b6a15d2d..3e0e4e18b8e 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ResearchCollectionExport/ResearchCollectionExportController.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ResearchCollectionExport/ResearchCollectionExportController.js @@ -22,7 +22,7 @@ function ResearchCollectionExportController(parentController) { researchCollectionExportView.repaint(views); }; - this.initialiseSubmissionTypesDropdown = function(callback) { + this.initialiseSubmissionTypesDropdown = function() { Util.blockUI(); mainController.serverFacade.listSubmissionTypes(function(error, result) { Util.unblockUI(); diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ResearchCollectionExport/ResearchCollectionExportView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ResearchCollectionExport/ResearchCollectionExportView.js index 7945f200cb3..45d54e05ae5 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ResearchCollectionExport/ResearchCollectionExportView.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ResearchCollectionExport/ResearchCollectionExportView.js @@ -15,8 +15,6 @@ */ function ResearchCollectionExportView(researchCollectionExportController, researchCollectionExportModel) { - var exportTreeView = new ExportTreeView(researchCollectionExportController, researchCollectionExportModel); - this.repaint = function(views) { researchCollectionExportController.initialiseSubmissionTypesDropdown(); diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetView.js index 03d1f8e2c95..222da7d5edb 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetView.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetView.js @@ -278,6 +278,12 @@ function SideMenuWidgetView(sideMenuWidgetController, sideMenuWidgetModel) { entityType: "RESEARCH_COLLECTION_EXPORT_BUILDER", key: "RESEARCH_COLLECTION_EXPORT_BUILDER", folder: false, lazy: false, view: "showResearchCollectionExportPage" }); } + + if (profile.mainMenu.showZenodoExportBuilder) { + var zenodoExportBuilderLink = _this.getLinkForNode("Zenodo Export Builder", "ZENODO_EXPORT_BUILDER", "showZenodoExportPage", null); + treeModelUtils.push({ displayName: "Zenodo Export Builder", title: zenodoExportBuilderLink, entityType: "ZENODO_EXPORT_BUILDER", + key: "ZENODO_EXPORT_BUILDER", folder: false, lazy: false, view: "showZenodoExportPage", icon: "glyphicon glyphicon-export" }); + } if(profile.mainMenu.showStorageManager) { Â Â Â Â var storageManagerLink = _this.getLinkForNode("Storage Manager", "STORAGE_MANAGER", "showStorageManager", null); diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ZenodoExport/ZenodoExportController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ZenodoExport/ZenodoExportController.js new file mode 100644 index 00000000000..c79e5e40812 --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ZenodoExport/ZenodoExportController.js @@ -0,0 +1,109 @@ +/* + * Copyright 2011 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function ZenodoExportController(parentController) { + var exportModel = new ZenodoExportModel(); + var exportView = new ZenodoExportView(this, exportModel); + + this.init = function(views) { + exportView.repaint(views); + }; + + this.exportSelected = function() { + var _this = this; + var selectedNodes = $(exportModel.tree).fancytree('getTree').getSelectedNodes(); + + var selectedOption = exportView.$submissionTypeDropdown.find(":selected"); + var submissionUrl = selectedOption.val(); + var submissionType = selectedOption.text(); + + var toExport = []; + for (var eIdx = 0; eIdx < selectedNodes.length; eIdx++) { + var node = selectedNodes[eIdx]; + toExport.push({type: node.data.entityType, permId: node.key, expand: !node.expanded}); + } + + if (toExport.length === 0) { + Util.showInfo('First select something to export.'); + } else if (!submissionUrl) { + Util.showInfo('First select submission type.'); + } else { + Util.blockUI(); + this.getUserInformation(function(userInformation) { + mainController.serverFacade.exportRc(toExport, true, false, submissionUrl, submissionType, userInformation, + function(operationExecutionPermId) { + _this.waitForOpExecutionResponse(operationExecutionPermId, function(error, result) { + Util.unblockUI(); + if (result && result.data && result.data.url) { + var win = window.open(result.data.url, '_blank'); + win.focus(); + mainController.refreshView(); + } else { + if (error) { + Util.showError(error); + } else { + Util.showError('Returned result format is not correct.'); + } + } + }); + }); + }); + } + }; + + this.waitForOpExecutionResponse = function(operationExecutionPermIdString, callbackFunction) { + var _this = this; + require(['as/dto/operation/id/OperationExecutionPermId', + 'as/dto/operation/fetchoptions/OperationExecutionFetchOptions'], + function(OperationExecutionPermId, OperationExecutionFetchOptions) { + var operationExecutionPermId = new OperationExecutionPermId(operationExecutionPermIdString); + var fetchOptions = new OperationExecutionFetchOptions(); + var fetchOptionsDetails = fetchOptions.withDetails(); + fetchOptionsDetails.withResults(); + fetchOptionsDetails.withError(); + mainController.openbisV3.getOperationExecutions([operationExecutionPermId], fetchOptions).done(function(results) { + var result = results[operationExecutionPermIdString]; + var v2Result = null; + if (result && result.details && result.details.results) { + v2Result = result.details.results[0]; + } + + if (result && result.state === 'FINISHED') { + mainController.serverFacade.customELNApiCallbackHandler(v2Result, callbackFunction); + } else if (!result || result.state === 'FAILED') { + mainController.serverFacade.customELNApiCallbackHandler(v2Result, callbackFunction); + } else { + setTimeout(function() { + _this.waitForOpExecutionResponse(operationExecutionPermIdString, callbackFunction); + }, 3000); + } + }); + }); + }; + + this.getUserInformation = function(callback) { + var userId = mainController.serverFacade.getUserId(); + mainController.serverFacade.getSessionInformation(function(sessionInfo) { + var userInformation = { + firstName: sessionInfo.person.firstName, + lastName: sessionInfo.person.lastName, + email: sessionInfo.person.email, + id: userId, + }; + callback(userInformation); + }); + }; +} \ 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/ZenodoExport/ZenodoExportModel.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ZenodoExport/ZenodoExportModel.js new file mode 100644 index 00000000000..f555844b57e --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ZenodoExport/ZenodoExportModel.js @@ -0,0 +1,18 @@ +/* + * Copyright 2011 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function ZenodoExportModel() { +} \ 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/ZenodoExport/ZenodoExportView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ZenodoExport/ZenodoExportView.js new file mode 100644 index 00000000000..5c3fd4a7344 --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ZenodoExport/ZenodoExportView.js @@ -0,0 +1,49 @@ +/* + * Copyright 2011 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function ZenodoExportView(exportController, exportModel) { + this.repaint = function(views) { + var $header = views.header; + var $container = views.content; + + var $form = $("<div>"); + var $formColumn = $("<form>", { + 'name': 'rcExportForm', + 'role': 'form', + 'action': 'javascript:void(0);', + 'onsubmit': 'mainController.currentView.exportSelected();' + }); + $form.append($formColumn); + + var $infoBox = FormUtil.getInfoBox('You can select any parts of the accessible openBIS structure to export:', [ + 'If you select a tree node and do not expand it, everything below this node will be exported by default.', + 'To export selectively only parts of a tree, open the nodes and select what to export.' + ]); + $infoBox.css('border', 'none'); + $container.append($infoBox); + + var $tree = $('<div>', { 'id' : 'exportsTree' }); + $formColumn.append($('<br>')); + $formColumn.append(FormUtil.getBox().append($tree)); + + $container.append($form); + + exportModel.tree = TreeUtil.getCompleteTree($tree); + + var $formTitle = $('<h2>').append('Zenodo Export Builder'); + $header.append($formTitle); + }; +} \ No newline at end of file diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/zenodo-exports-api/plugin.properties b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/zenodo-exports-api/plugin.properties new file mode 100644 index 00000000000..e294424d54a --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/zenodo-exports-api/plugin.properties @@ -0,0 +1,4 @@ +label = Zenodo Exports API +class = ch.systemsx.cisd.openbis.dss.generic.server.plugins.jython.JythonIngestionService +script-path = zenodoExports.py +service-document-url=https://test.research-collection.ethz.ch/swordv2/servicedocument diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/zenodo-exports-api/zenodoExports.py b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/zenodo-exports-api/zenodoExports.py new file mode 100644 index 00000000000..9e00cec83ab --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/reporting-plugins/zenodo-exports-api/zenodoExports.py @@ -0,0 +1,34 @@ +# +# Copyright 2016 ETH Zuerich, Scientific IT Services +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from ch.systemsx.cisd.common.logging import LogCategory +from org.apache.log4j import Logger + +operationLog = Logger.getLogger(str(LogCategory.OPERATION) + '.rcExports.py') + + +def process(tr, params, tableBuilder): + method = params.get('method') + + # Set user using the service + tr.setUserId(userId) + + if method == 'exportAll': + resultUrl = export(tr, params) + + +def export(tr, params): + pass -- GitLab