Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/main/config/run.properties.example
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ queue.visit.maxPartFileCount = 10000
# Any chunking should be done clientside
queue.files.maxFileCount = 10000

# If True, then submitted carts will enter the QUEUED state with an appropriate priority level.
# Otherwise, they will start immediately (historic behaviour).
queue.carts = False

# When queueing Downloads a positive priority will allow a User to proceed.
# Non-positive values will block that User from submitting a request to the queue.
# When automatically moving jobs from the queued to the PREPARING state, all Downloads
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/org/icatproject/topcat/web/rest/UserResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public class UserResource {
private boolean queryEnabled;
private int maxResults;
private int maxFileCount;
private boolean queueCarts;

/**
* Only used for testing.
*
* @param queueCarts
*/
public void setQueueCarts(boolean queueCarts) {
this.queueCarts = queueCarts;
System.out.println("set: " + this.queueCarts);

Choose a reason for hiding this comment

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

Can we remove this System.out?

}

@PersistenceContext(unitName = "topcat")
EntityManager em;
Expand All @@ -84,6 +95,7 @@ public UserResource() {
this.queryEnabled = Boolean.valueOf(properties.getProperty("search.enabled", "false"));
this.maxResults = Integer.valueOf(properties.getProperty("search.maxResults", "10000"));
this.maxFileCount = Integer.valueOf(properties.getProperty("queue.files.maxFileCount", "10000"));
this.queueCarts = Boolean.valueOf(properties.getProperty("queue.carts", "false"));
}

/**
Expand Down Expand Up @@ -798,8 +810,16 @@ public Response submitCart(@PathParam("facilityName") String facilityName,
downloadItems.add(downloadItem);
}
download.setDownloadItems(downloadItems);
download.setPriority(1);
downloadId = submitDownload(idsClient, download, DownloadStatus.PREPARING);

int priority = 1;
DownloadStatus downloadStatus = DownloadStatus.PREPARING;
if (queueCarts) {
priority = icatClient.getQueuePriority(userName);
downloadStatus = DownloadStatus.QUEUED;
}
download.setPriority(priority);
downloadId = submitDownload(idsClient, download, downloadStatus);

try {
em.remove(cart);
em.flush();
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/org/icatproject/topcat/UserResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,49 @@ public void testSubmitCart() throws Exception {
assertTrue(newDownload.getIsDeleted());
}

@Test
public void testSubmitQueuedCart() throws Exception {
System.out.println("DEBUG testSubmitQueuedCart");
Long downloadId = null;
try {
userResource.setQueueCarts(true);
String facilityName = "LILS";
String transport = "http";
String email = "";
String filename = "filename";
String zipType = "ZIP";
IcatClient icatClient = new IcatClient("https://localhost:8181", sessionId);
JsonObject dataset = icatClient.getEntity("dataset");
long entityId = dataset.getInt("id");
Response response = userResource.addCartItems(facilityName, sessionId, "dataset " + entityId, false);
assertEquals(200, response.getStatus());

response = userResource.submitCart(facilityName, sessionId, transport, email, filename, zipType);
assertEquals(200, response.getStatus());

JsonObject json = Utils.parseJsonObject(response.getEntity().toString());
assertEquals(0, json.getJsonArray("cartItems").size());
downloadId = json.getJsonNumber("downloadId").longValueExact();
Download download = downloadRepository.getDownload(downloadId);
assertNull(download.getPreparedId());
assertEquals(DownloadStatus.QUEUED, download.getStatus());
assertEquals(0, download.getInvestigationIds().size());
assertEquals(1, download.getDatasetIds().size());
assertEquals(0, download.getDatafileIds().size());
assertEquals(filename, download.getFileName());
assertEquals(transport, download.getTransport());
assertEquals("simple/root", download.getUserName());
assertEquals("simple/root", download.getFullName());
assertNull(download.getEmail());
assertEquals(2, download.getPriority());
} finally {
userResource.setQueueCarts(false);
if (downloadId != null) {
downloadRepository.removeDownload(downloadId);
}
}
}

private void submitCartFailure(String entityType, String field) throws Exception {
String facilityName = "LILS";
HttpClient httpClient = new HttpClient("https://localhost:8181/icat");
Expand Down
Loading