@@ -868,6 +868,8 @@ private long submitDownload(IdsClient idsClient, Download download, DownloadStat
868868 * @param facilityName ICAT Facility.name
869869 * @param sessionId ICAT sessionId
870870 * @param transport Transport mechanism to use
871+ * @param fileName Optional name to use as the root for each individual part
872+ * Download. Defaults to facilityName_visitId.
871873 * @param email Optional email to notify upon completion
872874 * @param visitId ICAT Investigation.visitId to submit
873875 * @return Array of Download ids
@@ -877,9 +879,10 @@ private long submitDownload(IdsClient idsClient, Download download, DownloadStat
877879 @ Path ("/queue/visit" )
878880 public Response queueVisitId (@ FormParam ("facilityName" ) String facilityName ,
879881 @ FormParam ("sessionId" ) String sessionId , @ FormParam ("transport" ) String transport ,
880- @ FormParam ("email" ) String email , @ FormParam ("visitId" ) String visitId ) throws TopcatException {
882+ @ FormParam ("fileName" ) String fileName , @ FormParam ("email" ) String email ,
883+ @ FormParam ("visitId" ) String visitId ) throws TopcatException {
881884
882- logger .info ("queueVisitId called" );
885+ logger .info ("queueVisitId called for {}" , visitId );
883886 validateTransport (transport );
884887
885888 String icatUrl = getIcatUrl (facilityName );
@@ -927,9 +930,12 @@ public Response queueVisitId(@FormParam("facilityName") String facilityName,
927930 downloads .add (newDownload );
928931
929932 int part = 1 ;
933+ if (fileName == null ) {
934+ fileName = facilityName + "_" + visitId ;
935+ }
930936 for (Download download : downloads ) {
931- String filename = formatQueuedFilename (facilityName , visitId , part , downloads .size ());
932- download .setFileName (filename );
937+ String partFilename = formatQueuedFilename (fileName , part , downloads .size ());
938+ download .setFileName (partFilename );
933939 downloadId = submitDownload (idsClient , download , DownloadStatus .PAUSED );
934940 jsonArrayBuilder .add (downloadId );
935941 part += 1 ;
@@ -968,6 +974,8 @@ public Response queueAllowed(@QueryParam("sessionId") String sessionId,
968974 * @param facilityName ICAT Facility.name
969975 * @param sessionId ICAT sessionId
970976 * @param transport Transport mechanism to use
977+ * @param fileName Optional name to use as the root for each individual part
978+ * Download. Defaults to facilityName_visitId.
971979 * @param email Optional email to notify upon completion
972980 * @param files ICAT Datafile.locations to download
973981 * @return Array of Download ids
@@ -978,13 +986,14 @@ public Response queueAllowed(@QueryParam("sessionId") String sessionId,
978986 @ Path ("/queue/files" )
979987 public Response queueFiles (@ FormParam ("facilityName" ) String facilityName ,
980988 @ FormParam ("sessionId" ) String sessionId , @ FormParam ("transport" ) String transport ,
981- @ FormParam ("email" ) String email , @ FormParam ("files" ) List <String > files ) throws TopcatException , UnsupportedEncodingException {
989+ @ FormParam ("fileName" ) String fileName , @ FormParam ("email" ) String email ,
990+ @ FormParam ("files" ) List <String > files ) throws TopcatException , UnsupportedEncodingException {
982991
983- logger .info ("queueFiles called" );
984- validateTransport (transport );
985- if (files .size () == 0 ) {
992+ if (files == null || files .size () == 0 ) {
986993 throw new BadRequestException ("At least one Datafile.location required" );
987994 }
995+ logger .info ("queueFiles called for {} files" , files .size ());
996+ validateTransport (transport );
988997
989998 String icatUrl = getIcatUrl (facilityName );
990999 IcatClient icatClient = new IcatClient (icatUrl , sessionId );
@@ -1023,9 +1032,12 @@ public Response queueFiles(@FormParam("facilityName") String facilityName,
10231032 downloads .add (newDownload );
10241033
10251034 int part = 1 ;
1035+ if (fileName == null ) {
1036+ fileName = facilityName + "_files" ;
1037+ }
10261038 for (Download download : downloads ) {
1027- String filename = formatQueuedFilename (facilityName , "files" , part , downloads .size ());
1028- download .setFileName (filename );
1039+ String partFilename = formatQueuedFilename (fileName , part , downloads .size ());
1040+ download .setFileName (partFilename );
10291041 downloadId = submitDownload (idsClient , download , DownloadStatus .PAUSED );
10301042 jsonArrayBuilder .add (downloadId );
10311043 part += 1 ;
@@ -1037,13 +1049,12 @@ public Response queueFiles(@FormParam("facilityName") String facilityName,
10371049 /**
10381050 * Format the filename for a queued Download, possibly one part of many.
10391051 *
1040- * @param facilityName ICAT Facility.name
1041- * @param visitId ICAT Investigation.visitId
1042- * @param part 1 indexed part of the overall request
1043- * @param size Number of parts in the overall request
1052+ * @param filename Root of the formatted filename, either user specified or defaulted.
1053+ * @param part 1 indexed part of the overall request
1054+ * @param size Number of parts in the overall request
10441055 * @return Formatted filename
10451056 */
1046- private static String formatQueuedFilename (String facilityName , String visitId , int part , int size ) {
1057+ private static String formatQueuedFilename (String filename , int part , int size ) {
10471058 String partString = String .valueOf (part );
10481059 String sizeString = String .valueOf (size );
10491060 StringBuilder partBuilder = new StringBuilder ();
@@ -1053,9 +1064,7 @@ private static String formatQueuedFilename(String facilityName, String visitId,
10531064 partBuilder .append (partString );
10541065
10551066 StringBuilder filenameBuilder = new StringBuilder ();
1056- filenameBuilder .append (facilityName );
1057- filenameBuilder .append ("_" );
1058- filenameBuilder .append (visitId );
1067+ filenameBuilder .append (filename );
10591068 filenameBuilder .append ("_part_" );
10601069 filenameBuilder .append (partBuilder );
10611070 filenameBuilder .append ("_of_" );
0 commit comments