Skip to content

Commit

Permalink
Mark downloads without preparedIds as PREPARING not RESTORING #40
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-austin committed Nov 22, 2024
1 parent 26a5bd2 commit a53f54e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/icatproject/topcat/AdminResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Download> downloads = (List<Download>) response.getEntity();

testDownload = findDownload(downloads, testDownload.getId());
assertEquals(DownloadStatus.PREPARING, testDownload.getStatus());
}

@Test
public void testSetDownloadTypeStatus() throws Exception {

Expand Down

0 comments on commit a53f54e

Please sign in to comment.