You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sdap.apache.org by nc...@apache.org on 2023/05/30 05:59:36 UTC
[incubator-sdap-nexus] branch master updated: Updated matchup output filename (#257)
This is an automated email from the ASF dual-hosted git repository.
nchung pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-nexus.git
The following commit(s) were added to refs/heads/master by this push:
new 81c9531 Updated matchup output filename (#257)
81c9531 is described below
commit 81c95312e676138552db81371bb7a7657b62afd5
Author: Stepheny Perez <sk...@users.noreply.github.com>
AuthorDate: Mon May 29 22:59:31 2023 -0700
Updated matchup output filename (#257)
* Updated matchup output filename
* added filename param to cdmsresults endpoint
---
CHANGELOG.md | 1 +
analysis/webservice/algorithms/doms/BaseDomsHandler.py | 3 +++
analysis/webservice/apidocs/openapi.yml | 10 ++++++++++
.../nexus_tornado/request/renderers/NexusCSVRenderer.py | 7 ++++++-
.../nexus_tornado/request/renderers/NexusNETCDFRenderer.py | 7 ++++++-
analysis/webservice/webmodel/NexusResults.py | 4 ++++
6 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2e16b12..e1a59a4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved speed of results insert
- Updated `id` field of insitu points to include depth. This solves an issue with NetCDF result rendering where different insitu observations at the same place & time but at different depths were being excluded for having the same `id`.
- SDAP-466: Matchup now defines secondary `platform` fields with `platform.id` if it is available and not blank. It then uses `platform.code` and `platform.type` as fallbacks, then just the value of `platform` if none work.
+- SDAP-468: Updated matchup output filename
### Deprecated
### Removed
### Fixed
diff --git a/analysis/webservice/algorithms/doms/BaseDomsHandler.py b/analysis/webservice/algorithms/doms/BaseDomsHandler.py
index dad1605..2897e8d 100644
--- a/analysis/webservice/algorithms/doms/BaseDomsHandler.py
+++ b/analysis/webservice/algorithms/doms/BaseDomsHandler.py
@@ -106,6 +106,9 @@ class DomsQueryResults(NexusResults):
def toNetCDF(self):
return DomsNetCDFFormatter.create(self.__executionId, self.results(), self.__args, self.__details)
+ def filename(self):
+ return f'CDMS_{self.__executionId}'
+
class DomsCSVFormatter:
@staticmethod
diff --git a/analysis/webservice/apidocs/openapi.yml b/analysis/webservice/apidocs/openapi.yml
index b8250ee..e691f86 100644
--- a/analysis/webservice/apidocs/openapi.yml
+++ b/analysis/webservice/apidocs/openapi.yml
@@ -535,6 +535,16 @@ paths:
type: string
enum: ['CSV', 'NETCDF', 'JSON']
example: CSV
+ - in: query
+ name: filename
+ description: |
+ Name of output file. Only works with CSV and NETCDF
+ output types. Do not include file extension in this field.
+ If this value is not provided, the filename will be
+ `CDMS_[execution_id].[csv|nc]`
+ required: false
+ schema:
+ type: string
responses:
'200':
description: Successful operation
diff --git a/analysis/webservice/nexus_tornado/request/renderers/NexusCSVRenderer.py b/analysis/webservice/nexus_tornado/request/renderers/NexusCSVRenderer.py
index 8c4a306..38c2ec0 100644
--- a/analysis/webservice/nexus_tornado/request/renderers/NexusCSVRenderer.py
+++ b/analysis/webservice/nexus_tornado/request/renderers/NexusCSVRenderer.py
@@ -23,8 +23,13 @@ class NexusCSVRenderer(object):
self._request = nexus_request
def render(self, tornado_handler, result):
+ filename = self._request.get_argument('filename')
+ if filename is None:
+ filename = result.filename()
+ filename = f'{filename}.csv'
+
tornado_handler.set_header("Content-Type", "text/csv")
- tornado_handler.set_header("Content-Disposition", "filename=\"%s\"" % self._request.get_argument('filename', "download.csv"))
+ tornado_handler.set_header("Content-Disposition", f"filename=\"{filename}\"")
try:
tornado_handler.write(result.toCSV())
tornado_handler.finish()
diff --git a/analysis/webservice/nexus_tornado/request/renderers/NexusNETCDFRenderer.py b/analysis/webservice/nexus_tornado/request/renderers/NexusNETCDFRenderer.py
index 9049d26..271081d 100644
--- a/analysis/webservice/nexus_tornado/request/renderers/NexusNETCDFRenderer.py
+++ b/analysis/webservice/nexus_tornado/request/renderers/NexusNETCDFRenderer.py
@@ -23,8 +23,13 @@ class NexusNETCDFRenderer(object):
self._request = nexus_request
def render(self, tornado_handler, result):
+ filename = self._request.get_argument('filename')
+ if filename is None:
+ filename = result.filename()
+ filename = f'{filename}.nc'
+
tornado_handler.set_header("Content-Type", "application/x-netcdf")
- tornado_handler.set_header("Content-Disposition", "attachment; filename=\"%s\"" % self._request.get_argument('filename', "download.nc"))
+ tornado_handler.set_header("Content-Disposition", f"attachment; filename=\"{filename}\"")
try:
tornado_handler.write(result.toNetCDF())
except:
diff --git a/analysis/webservice/webmodel/NexusResults.py b/analysis/webservice/webmodel/NexusResults.py
index 842bc31..42c1ca0 100644
--- a/analysis/webservice/webmodel/NexusResults.py
+++ b/analysis/webservice/webmodel/NexusResults.py
@@ -107,6 +107,10 @@ class NexusResults:
self.__meta = self.__meta # Risky
self._extendMeta(self.__meta, minLat, maxLat, minLon, maxLon, ds, startTime, endTime)
+ @staticmethod
+ def filename(self):
+ return 'download'
+
def toJson(self):
data = {
'meta': self.__meta,