Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark downloads without preparedIds as PREPARING not RESTORING #40 #43

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a value of null be passed for the queryOffset? I was confused at first as to what the "1 = 1" was for but found it in other tests with a comment, so if null doesn't work, then at least a comment as to what it's for would be useful here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I based the test on the other existing tests which used "1 = 1", taking the comment on faith (but not copying it across to the new test). Having had a look though it seems like the code should handle null values - these tests still passed for me locally without it so I've removed it in all three places. Maybe it didn't used to work, the comments were written, then the null case handling was added but the tests were never updated? In any case hopefully they are all simpler now.

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
Loading