From 4e1e43c49d776dd67531e395c9f660b1a2a66b99 Mon Sep 17 00:00:00 2001 From: elmiomar Date: Fri, 15 Mar 2024 09:46:39 -0400 Subject: [PATCH 1/2] change purpose of selectDatasetObjects from INFO to GET --- .../nist/oar/distrib/service/RPACachingService.java | 2 +- .../oar/distrib/service/RPACachingServiceTest.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/gov/nist/oar/distrib/service/RPACachingService.java b/src/main/java/gov/nist/oar/distrib/service/RPACachingService.java index 8f87dc83..14bd206f 100644 --- a/src/main/java/gov/nist/oar/distrib/service/RPACachingService.java +++ b/src/main/java/gov/nist/oar/distrib/service/RPACachingService.java @@ -104,7 +104,7 @@ public Map retrieveMetadata(String randomID) throws CacheManagem logger.debug("Requesting metadata for temporary ID=" + randomID); JSONArray metadata = new JSONArray(); List objects = this.pdrCacheManager.selectDatasetObjects(randomID, - this.pdrCacheManager.VOL_FOR_INFO); + this.pdrCacheManager.VOL_FOR_GET); if (objects.size() > 0) { for (CacheObject obj : objects) { JSONObject objMd = formatMetadata(obj.exportMetadata(), randomID); diff --git a/src/test/java/gov/nist/oar/distrib/service/RPACachingServiceTest.java b/src/test/java/gov/nist/oar/distrib/service/RPACachingServiceTest.java index 52829497..949ab7ed 100644 --- a/src/test/java/gov/nist/oar/distrib/service/RPACachingServiceTest.java +++ b/src/test/java/gov/nist/oar/distrib/service/RPACachingServiceTest.java @@ -116,7 +116,7 @@ public void testRetrieveMetadata_success() throws Exception { List cacheObjects = Arrays.asList(cacheObject1, cacheObject2); - when(pdrCacheManager.selectDatasetObjects(randomID, pdrCacheManager.VOL_FOR_INFO)) + when(pdrCacheManager.selectDatasetObjects(randomID, pdrCacheManager.VOL_FOR_GET)) .thenReturn(cacheObjects); String testBaseDownloadUrl = "https://testdata.nist.gov"; @@ -192,7 +192,7 @@ public void testRetrieveMetadata_withMissingFilepath() throws Exception { List cacheObjects = Arrays.asList(cacheObject1, cacheObject2); - when(pdrCacheManager.selectDatasetObjects(randomID, pdrCacheManager.VOL_FOR_INFO)) + when(pdrCacheManager.selectDatasetObjects(randomID, pdrCacheManager.VOL_FOR_GET)) .thenReturn(cacheObjects); String testBaseDownloadUrl = "https://testdata.nist.gov"; @@ -241,7 +241,7 @@ public void testRetrieveMetadata_withOneObjectMissingFilepath() throws Exception List cacheObjects = Arrays.asList(cacheObject1); - when(pdrCacheManager.selectDatasetObjects(randomID, pdrCacheManager.VOL_FOR_INFO)) + when(pdrCacheManager.selectDatasetObjects(randomID, pdrCacheManager.VOL_FOR_GET)) .thenReturn(cacheObjects); rpaCachingService.retrieveMetadata(randomID); @@ -252,7 +252,7 @@ public void testRetrieveMetadata_WithEmptyMetadataList() throws Exception { String randomID = "randomId123"; List objects = new ArrayList<>(); - when(pdrCacheManager.selectDatasetObjects(randomID, pdrCacheManager.VOL_FOR_INFO)).thenReturn(objects); + when(pdrCacheManager.selectDatasetObjects(randomID, pdrCacheManager.VOL_FOR_GET)).thenReturn(objects); rpaCachingService.retrieveMetadata(randomID); } @@ -292,7 +292,7 @@ public void testRetrieveMetadata_WithMalformedBaseUrl() throws Exception { List cacheObjects = Arrays.asList(cacheObject1, cacheObject2); - when(pdrCacheManager.selectDatasetObjects(randomID, pdrCacheManager.VOL_FOR_INFO)) + when(pdrCacheManager.selectDatasetObjects(randomID, pdrCacheManager.VOL_FOR_GET)) .thenReturn(cacheObjects); String testBaseDownloadUrl = "htp://testdata.nist.gov/"; From 9aa70a7c44caf7134da1a9006611f50d3b8758e1 Mon Sep 17 00:00:00 2001 From: elmiomar Date: Fri, 29 Mar 2024 02:51:46 -0400 Subject: [PATCH 2/2] add 'attachment;' to the Content-Disposition header --- .../java/gov/nist/oar/distrib/web/DatasetAccessController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gov/nist/oar/distrib/web/DatasetAccessController.java b/src/main/java/gov/nist/oar/distrib/web/DatasetAccessController.java index 947216d8..6f88f9ee 100644 --- a/src/main/java/gov/nist/oar/distrib/web/DatasetAccessController.java +++ b/src/main/java/gov/nist/oar/distrib/web/DatasetAccessController.java @@ -493,7 +493,7 @@ public void downloadFile(String dsid, String filepath, String version, HttpServl response.setHeader("Content-Length", Long.toString(sh.getInfo().contentLength)); response.setHeader("Content-Type", sh.getInfo().contentType); response.setHeader("Content-Disposition", - "filename=\"" + Pattern.compile("/+").matcher(filepath).replaceAll("_") + "\""); + "attachment;filename=\"" + Pattern.compile("/+").matcher(filepath).replaceAll("_") + "\""); int len; byte[] buf = new byte[100000];