You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sdap.apache.org by sk...@apache.org on 2023/05/26 21:40:34 UTC

[incubator-sdap-nexus] branch SDAP-468 created (now 7f73fb6)

This is an automated email from the ASF dual-hosted git repository.

skperez pushed a change to branch SDAP-468
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-nexus.git


      at 7f73fb6  Updated matchup output filename

This branch includes the following new commits:

     new 7f73fb6  Updated matchup output filename

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-sdap-nexus] 01/01: Updated matchup output filename

Posted by sk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

skperez pushed a commit to branch SDAP-468
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-nexus.git

commit 7f73fb67e687a5840547e936753729a1b65b5889
Author: skorper <st...@gmail.com>
AuthorDate: Fri May 26 14:40:22 2023 -0700

    Updated matchup output filename
---
 CHANGELOG.md                                                       | 1 +
 analysis/webservice/algorithms/doms/BaseDomsHandler.py             | 3 +++
 .../webservice/nexus_tornado/request/renderers/NexusCSVRenderer.py | 7 ++++++-
 .../nexus_tornado/request/renderers/NexusNETCDFRenderer.py         | 7 ++++++-
 analysis/webservice/webmodel/NexusResults.py                       | 4 ++++
 5 files changed, 20 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/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,