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 all commits
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
35 changes: 28 additions & 7 deletions src/test/java/org/icatproject/topcat/AdminResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,14 @@ 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<Download>) response.getEntity();

// Check that the result tallies with the DownloadRepository contents

Map<String, Object> params = new HashMap<String, Object>();
params.put("queryOffset", queryOffset);
List<Download> repoDownloads = new ArrayList<Download>();
repoDownloads = downloadRepository.getDownloads(params);

Expand All @@ -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<Download>) response.getEntity();

Expand All @@ -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<Download>) response.getEntity();

Expand All @@ -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());
Expand Down Expand Up @@ -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<Download> downloads = (List<Download>) response.getEntity();

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

@Test
public void testSetDownloadTypeStatus() throws Exception {

Expand Down
10 changes: 4 additions & 6 deletions src/test/java/org/icatproject/topcat/UserResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ public void testSubmitCart() throws Exception {
List<Download> 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<Download>) response.getEntity();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Download>) response.getEntity();

Expand All @@ -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<Download>) response.getEntity();

Expand Down
Loading