From a53f54e39cc875ed148eeca6876ec3f43d0e6c25 Mon Sep 17 00:00:00 2001 From: Patrick Austin Date: Fri, 22 Nov 2024 10:06:15 +0000 Subject: [PATCH 1/2] Mark downloads without preparedIds as PREPARING not RESTORING #40 --- .../topcat/web/rest/AdminResource.java | 7 +++++- .../icatproject/topcat/AdminResourceTest.java | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/icatproject/topcat/web/rest/AdminResource.java b/src/main/java/org/icatproject/topcat/web/rest/AdminResource.java index f8bcc154..16709634 100644 --- a/src/main/java/org/icatproject/topcat/web/rest/AdminResource.java +++ b/src/main/java/org/icatproject/topcat/web/rest/AdminResource.java @@ -175,7 +175,12 @@ public Response setDownloadStatus( throw new NotFoundException("could not find download"); } - download.setStatus(DownloadStatus.valueOf(value)); + if (download.getPreparedId() == null && value.equals("RESTORING")) { + // Queued jobs need to be marked PREPARING first to generate a preparedId before RESTORING + download.setStatus(DownloadStatus.PREPARING); + } else { + download.setStatus(DownloadStatus.valueOf(value)); + } if(value.equals("COMPLETE")){ download.setCompletedAt(new Date()); } diff --git a/src/test/java/org/icatproject/topcat/AdminResourceTest.java b/src/test/java/org/icatproject/topcat/AdminResourceTest.java index a223f82b..81bcabd6 100644 --- a/src/test/java/org/icatproject/topcat/AdminResourceTest.java +++ b/src/test/java/org/icatproject/topcat/AdminResourceTest.java @@ -236,6 +236,30 @@ public void testDownloadAPI() throws Exception { downloadRepository.removeDownload(testDownload.getId()); } + @Test + public void testSetDownloadStatus() throws Exception { + Download testDownload = new Download(); + String facilityName = "LILS"; + testDownload.setFacilityName(facilityName); + testDownload.setSessionId(adminSessionId); + testDownload.setStatus(DownloadStatus.PAUSED); + testDownload.setIsDeleted(false); + testDownload.setUserName("simple/root"); + testDownload.setFileName("testFile.txt"); + testDownload.setTransport("http"); + downloadRepository.save(testDownload); + + Response response = adminResource.setDownloadStatus(testDownload.getId(), facilityName, adminSessionId, DownloadStatus.RESTORING.toString()); + assertEquals(200, response.getStatus()); + + response = adminResource.getDownloads(facilityName, adminSessionId, "1 = 1"); + assertEquals(200, response.getStatus()); + List downloads = (List) response.getEntity(); + + testDownload = findDownload(downloads, testDownload.getId()); + assertEquals(DownloadStatus.PREPARING, testDownload.getStatus()); + } + @Test public void testSetDownloadTypeStatus() throws Exception { From c578c2edb3bc0bc6f199b3571233dc49ead99943 Mon Sep 17 00:00:00 2001 From: Patrick Austin Date: Thu, 2 Jan 2025 14:27:27 +0000 Subject: [PATCH 2/2] Replace queryOffset of '1 = 1' with null in tests --- .../org/icatproject/topcat/AdminResourceTest.java | 13 +++++-------- .../org/icatproject/topcat/UserResourceTest.java | 10 ++++------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/test/java/org/icatproject/topcat/AdminResourceTest.java b/src/test/java/org/icatproject/topcat/AdminResourceTest.java index 81bcabd6..a3b8cb46 100644 --- a/src/test/java/org/icatproject/topcat/AdminResourceTest.java +++ b/src/test/java/org/icatproject/topcat/AdminResourceTest.java @@ -141,9 +141,7 @@ public void testDownloadAPI() throws Exception { downloadRepository.save(testDownload); // Get the current downloads - may not be empty - // It appears queryOffset cannot be empty! - String queryOffset = "1 = 1"; - response = adminResource.getDownloads(facilityName, adminSessionId, queryOffset); + response = adminResource.getDownloads(facilityName, adminSessionId, null); assertEquals(200, response.getStatus()); downloads = (List) response.getEntity(); @@ -151,7 +149,6 @@ public void testDownloadAPI() throws Exception { // Check that the result tallies with the DownloadRepository contents Map params = new HashMap(); - params.put("queryOffset", queryOffset); List repoDownloads = new ArrayList(); repoDownloads = downloadRepository.getDownloads(params); @@ -171,7 +168,7 @@ public void testDownloadAPI() throws Exception { // and test that the new status has been set - response = adminResource.getDownloads(facilityName, adminSessionId, queryOffset); + response = adminResource.getDownloads(facilityName, adminSessionId, null); assertEquals(200, response.getStatus()); downloads = (List) response.getEntity(); @@ -190,7 +187,7 @@ public void testDownloadAPI() throws Exception { // and check that it has worked (again, not bothering to check that nothing else // has changed) - response = adminResource.getDownloads(facilityName, adminSessionId, queryOffset); + response = adminResource.getDownloads(facilityName, adminSessionId, null); assertEquals(200, response.getStatus()); downloads = (List) response.getEntity(); @@ -201,7 +198,7 @@ public void testDownloadAPI() throws Exception { // user try { - response = adminResource.getDownloads(facilityName, nonAdminSessionId, queryOffset); + response = adminResource.getDownloads(facilityName, nonAdminSessionId, null); // We should not see the following System.out.println("DEBUG: AdminRT.getDownloads response: " + response.getStatus() + ", " + (String) response.getEntity()); @@ -252,7 +249,7 @@ public void testSetDownloadStatus() throws Exception { Response response = adminResource.setDownloadStatus(testDownload.getId(), facilityName, adminSessionId, DownloadStatus.RESTORING.toString()); assertEquals(200, response.getStatus()); - response = adminResource.getDownloads(facilityName, adminSessionId, "1 = 1"); + response = adminResource.getDownloads(facilityName, adminSessionId, null); assertEquals(200, response.getStatus()); List downloads = (List) response.getEntity(); diff --git a/src/test/java/org/icatproject/topcat/UserResourceTest.java b/src/test/java/org/icatproject/topcat/UserResourceTest.java index 2ee7f646..d4e1f754 100644 --- a/src/test/java/org/icatproject/topcat/UserResourceTest.java +++ b/src/test/java/org/icatproject/topcat/UserResourceTest.java @@ -151,9 +151,7 @@ public void testSubmitCart() throws Exception { List downloads; // Get the initial state of the downloads - may not be empty - // It appears queryOffset cannot be empty! - String queryOffset = "1 = 1"; - response = userResource.getDownloads(facilityName, sessionId, queryOffset); + response = userResource.getDownloads(facilityName, sessionId, null); assertEquals(200, response.getStatus()); downloads = (List) response.getEntity(); @@ -183,7 +181,7 @@ public void testSubmitCart() throws Exception { assertTrue(downloadId > 0); // Now, there should be one download, whose downloadId matches - response = userResource.getDownloads(facilityName, sessionId, queryOffset); + response = userResource.getDownloads(facilityName, sessionId, null); assertEquals(200, response.getStatus()); // Doesn't parse as JSON, try a direct cast @@ -224,7 +222,7 @@ public void testSubmitCart() throws Exception { // and test that the new status has been set - response = userResource.getDownloads(facilityName, sessionId, queryOffset); + response = userResource.getDownloads(facilityName, sessionId, null); assertEquals(200, response.getStatus()); downloads = (List) response.getEntity(); @@ -242,7 +240,7 @@ public void testSubmitCart() throws Exception { // and check that it has worked (again, not bothering to check that nothing else // has changed) - response = userResource.getDownloads(facilityName, sessionId, queryOffset); + response = userResource.getDownloads(facilityName, sessionId, null); assertEquals(200, response.getStatus()); downloads = (List) response.getEntity();