Skip to content

Commit

Permalink
Merge pull request #43 from ral-facilities/40_admin_put_status
Browse files Browse the repository at this point in the history
Mark downloads without preparedIds as PREPARING not RESTORING #40
  • Loading branch information
patrick-austin authored Jan 6, 2025
2 parents 4eeba44 + c578c2e commit 74286ee
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
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 @@ -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<Download>) response.getEntity();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Download>) response.getEntity();

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

Expand Down

0 comments on commit 74286ee

Please sign in to comment.