From a4b84539ccea052151f74a2336355c43ff1f3807 Mon Sep 17 00:00:00 2001 From: "Kacper Kowalik (Xarthisius)" Date: Wed, 28 Nov 2018 12:05:06 -0600 Subject: [PATCH] Fetch dataset title and pass it as query param --- server/rest/integration.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/rest/integration.py b/server/rest/integration.py index 68cd8ce1..250dc34c 100644 --- a/server/rest/integration.py +++ b/server/rest/integration.py @@ -4,10 +4,13 @@ import cherrypy import validators from urllib.parse import urlparse, urlunparse, urlencode +from urllib.error import HTTPError, URLError from girder.api import access from girder.api.describe import Description, autoDescribeRoute from girder.api.rest import Resource, RestException, setResponseHeader +from ..lib.dataverse.provider import DataverseImportProvider + class Integration(Resource): @@ -40,13 +43,20 @@ def dataverseExternalTools(self, fileId, siteUrl, apiToken): url = '{scheme}://{netloc}/api/access/datafile/{fileId}'.format( scheme=site.scheme, netloc=site.netloc, fileId=fileId ) + query = {'uri': url} + try: + title, _, _ = DataverseImportProvider._parse_access_url(urlparse(url)) + query['name'] = title + except (HTTPError, URLError): + # This doesn't bode well, but let's fail later when tale import happens + pass # TODO: Make base url a plugin setting, defaulting to dashboard. dashboard_url = os.environ.get('DASHBOARD_URL', 'https://dashboard.wholetale.org') location = urlunparse( urlparse(dashboard_url)._replace( path='/compose', - query=urlencode({'uri': url})) + query=urlencode(query)) ) setResponseHeader('Location', location) cherrypy.response.status = 303