Skip to content
Open
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
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
6 changes: 5 additions & 1 deletion src/main/java/org/icatproject/topcat/FacilityMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public synchronized static FacilityMap getInstance() throws InternalException {
}
return instance;
}


synchronized static void setInstance(FacilityMap facilityMap) {
instance = facilityMap;
}

private Logger logger = LoggerFactory.getLogger(FacilityMap.class);

private Properties properties;
Expand Down
23 changes: 21 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,16 @@ 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;
}

@PersistenceContext(unitName = "topcat")
EntityManager em;
Expand All @@ -84,6 +94,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 +809,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
31 changes: 0 additions & 31 deletions src/test/java/org/icatproject/topcat/FacilityMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,12 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.HashMap;
import java.util.Map;

import org.icatproject.topcat.exceptions.InternalException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;

public class FacilityMapTest {

// A class to mock the Topcat Properties class
// We will use it to construct both good and bad property sets.

private class MockProperties extends Properties {

private Map<String,String> props;

public MockProperties() {
props = new HashMap<String,String>();
}

public void setMockProperty( String propName, String value ) {
props.put(propName, value);
}

public String getProperty( String propertyName ) {
return props.get(propertyName);
}

public String getProperty( String propertyName, String defaultValue ) {
String value = props.get(propertyName);
if( value == null ) {
value = defaultValue;
}
return value;
}
}

@Test
public void testSimpleConstruction() throws InternalException {

Expand Down
29 changes: 29 additions & 0 deletions src/test/java/org/icatproject/topcat/MockProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.icatproject.topcat;

import java.util.HashMap;
import java.util.Map;

public class MockProperties extends Properties {

private Map<String,String> props;

public MockProperties() {
props = new HashMap<String,String>();
}

public void setMockProperty( String propName, String value ) {
props.put(propName, value);
}

public String getProperty( String propertyName ) {
return props.get(propertyName);
}

public String getProperty( String propertyName, String defaultValue ) {
String value = props.get(propertyName);
if( value == null ) {
value = defaultValue;
}
return value;
}
}
52 changes: 52 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,58 @@ public void testSubmitCart() throws Exception {
assertTrue(newDownload.getIsDeleted());
}

@Test
public void testSubmitQueuedCart() throws Exception {
System.out.println("DEBUG testSubmitQueuedCart");
Long downloadId = null;
try {
MockProperties props = new MockProperties();
props.setMockProperty("facility.list", "LILS");
props.setMockProperty("facility.LILS.icatUrl", "https://localhost:8181");
props.setMockProperty("facility.LILS.idsUrl", "https://localhost:8181");
props.setMockProperty("facility.LILS.limit.count", "250000");
props.setMockProperty("facility.LILS.limit.size", "10000000000000");
FacilityMap facilityMap = new FacilityMap(props);
FacilityMap.setInstance(facilityMap);
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 {
FacilityMap.setInstance(null);
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