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..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()); @@ -236,6 +233,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, null); + 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 { diff --git a/src/test/java/org/icatproject/topcat/UserResourceTest.java b/src/test/java/org/icatproject/topcat/UserResourceTest.java index 30341062..a2737496 100644 --- a/src/test/java/org/icatproject/topcat/UserResourceTest.java +++ b/src/test/java/org/icatproject/topcat/UserResourceTest.java @@ -158,9 +158,7 @@ public void testSubmitCart() throws Exception { long entityId = dataset.getInt("id"); // 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(); @@ -190,7 +188,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 @@ -231,7 +229,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(); @@ -249,7 +247,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();