Skip to content
Merged
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
33 changes: 19 additions & 14 deletions src/main/java/org/icatproject/topcat/web/rest/UserResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,8 @@ 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");

Choose a reason for hiding this comment

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

I think it would be useful to add the visitId to the log message

validateTransport(transport);
Expand Down Expand Up @@ -927,9 +928,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 @@ -955,7 +959,8 @@ 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");

Choose a reason for hiding this comment

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

I think it would be useful to report the number of files being queued here eg. "queueFiles called for nnn files"

validateTransport(transport);
Expand Down Expand Up @@ -1000,9 +1005,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 +1022,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 +1037,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