Skip to content
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
45 changes: 27 additions & 18 deletions src/main/java/org/icatproject/topcat/web/rest/UserResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,8 @@ private long submitDownload(IdsClient idsClient, Download download, DownloadStat
* @param facilityName ICAT Facility.name
* @param sessionId ICAT sessionId
* @param transport Transport mechanism to use
* @param fileName Optional name to use as the root for each individual part
* Download. Defaults to facilityName_visitId.
* @param email Optional email to notify upon completion
* @param visitId ICAT Investigation.visitId to submit
* @return Array of Download ids
Expand All @@ -877,9 +879,10 @@ private long submitDownload(IdsClient idsClient, Download download, DownloadStat
@Path("/queue/visit")
public Response queueVisitId(@FormParam("facilityName") String facilityName,
@FormParam("sessionId") String sessionId, @FormParam("transport") String transport,
@FormParam("email") String email, @FormParam("visitId") String visitId) throws TopcatException {
@FormParam("fileName") String fileName, @FormParam("email") String email,

Choose a reason for hiding this comment

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

Also need an entry for filename in the method javadoc

@FormParam("visitId") String visitId) throws TopcatException {

logger.info("queueVisitId called");
logger.info("queueVisitId called for {}", visitId);
validateTransport(transport);

String icatUrl = getIcatUrl(facilityName);
Expand Down Expand Up @@ -927,9 +930,12 @@ public Response queueVisitId(@FormParam("facilityName") String facilityName,
downloads.add(newDownload);

int part = 1;
if (fileName == null) {
fileName = facilityName + "_" + visitId;
}
for (Download download : downloads) {
String filename = formatQueuedFilename(facilityName, visitId, part, downloads.size());
download.setFileName(filename);
String partFilename = formatQueuedFilename(fileName, part, downloads.size());
download.setFileName(partFilename);
downloadId = submitDownload(idsClient, download, DownloadStatus.PAUSED);
jsonArrayBuilder.add(downloadId);
part += 1;
Expand All @@ -945,6 +951,8 @@ public Response queueVisitId(@FormParam("facilityName") String facilityName,
* @param facilityName ICAT Facility.name
* @param sessionId ICAT sessionId
* @param transport Transport mechanism to use
* @param fileName Optional name to use as the root for each individual part
* Download. Defaults to facilityName_visitId.
* @param email Optional email to notify upon completion
* @param files ICAT Datafile.locations to download
* @return Array of Download ids
Expand All @@ -955,13 +963,14 @@ public Response queueVisitId(@FormParam("facilityName") String facilityName,
@Path("/queue/files")
public Response queueFiles(@FormParam("facilityName") String facilityName,
@FormParam("sessionId") String sessionId, @FormParam("transport") String transport,
@FormParam("email") String email, @FormParam("files") List<String> files) throws TopcatException, UnsupportedEncodingException {
@FormParam("fileName") String fileName, @FormParam("email") String email,

Choose a reason for hiding this comment

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

Again fileName needs adding to the javadoc comment

@FormParam("files") List<String> files) throws TopcatException, UnsupportedEncodingException {

logger.info("queueFiles called");
validateTransport(transport);
if (files.size() == 0) {
if (files == null || files.size() == 0) {
throw new BadRequestException("At least one Datafile.location required");
}
logger.info("queueFiles called for {} files", files.size());
validateTransport(transport);

String icatUrl = getIcatUrl(facilityName);
IcatClient icatClient = new IcatClient(icatUrl, sessionId);
Expand Down Expand Up @@ -1000,9 +1009,12 @@ public Response queueFiles(@FormParam("facilityName") String facilityName,
downloads.add(newDownload);

int part = 1;
if (fileName == null) {
fileName = facilityName + "_files";
}
for (Download download : downloads) {
String filename = formatQueuedFilename(facilityName, "files", part, downloads.size());
download.setFileName(filename);
String partFilename = formatQueuedFilename(fileName, part, downloads.size());
download.setFileName(partFilename);
downloadId = submitDownload(idsClient, download, DownloadStatus.PAUSED);
jsonArrayBuilder.add(downloadId);
part += 1;
Expand All @@ -1014,13 +1026,12 @@ public Response queueFiles(@FormParam("facilityName") String facilityName,
/**
* Format the filename for a queued Download, possibly one part of many.
*
* @param facilityName ICAT Facility.name
* @param visitId ICAT Investigation.visitId
* @param part 1 indexed part of the overall request
* @param size Number of parts in the overall request
* @param filename Root of the formatted filename, either user specified or defaulted.
* @param part 1 indexed part of the overall request
* @param size Number of parts in the overall request
* @return Formatted filename
*/
private static String formatQueuedFilename(String facilityName, String visitId, int part, int size) {
private static String formatQueuedFilename(String filename, int part, int size) {
String partString = String.valueOf(part);
String sizeString = String.valueOf(size);
StringBuilder partBuilder = new StringBuilder();
Expand All @@ -1030,9 +1041,7 @@ private static String formatQueuedFilename(String facilityName, String visitId,
partBuilder.append(partString);

StringBuilder filenameBuilder = new StringBuilder();
filenameBuilder.append(facilityName);
filenameBuilder.append("_");
filenameBuilder.append(visitId);
filenameBuilder.append(filename);
filenameBuilder.append("_part_");
filenameBuilder.append(partBuilder);
filenameBuilder.append("_of_");
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/icatproject/topcat/UserResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public void testQueueVisitId() throws Exception {
String transport = "http";
String email = "";
String visitId = "Proposal 0 - 0 0";
Response response = userResource.queueVisitId(facilityName, sessionId, transport, email, visitId);
Response response = userResource.queueVisitId(facilityName, sessionId, transport, null, email, visitId);
assertEquals(200, response.getStatus());

JsonArray downloadIdsArray = Utils.parseJsonArray(response.getEntity().toString());
Expand Down Expand Up @@ -327,7 +327,7 @@ public void testQueueFiles() throws Exception {
for (JsonObject datafile : datafiles) {
files.add(datafile.getString("location"));
}
Response response = userResource.queueFiles(facilityName, sessionId, transport, email, files);
Response response = userResource.queueFiles(facilityName, sessionId, transport, null, email, files);
assertEquals(200, response.getStatus());

JsonArray downloadIdsArray = Utils.parseJsonArray(response.getEntity().toString());
Expand Down
Loading