diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/UploadingCommand.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/UploadingCommand.java index 8df3a40319bbfc7cf2f22b7bd625ec7dfa3736cd..a3c5d63a3bde9dec1b1baad1bb2dd5ff775c9141 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/UploadingCommand.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/UploadingCommand.java @@ -27,6 +27,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import ch.systemsx.cisd.cifex.rpc.ICIFEXRPCService; @@ -107,6 +108,7 @@ class UploadingCommand implements IDataSetCommand private final ICIFEXRPCServiceFactory cifexServiceFactory; private final List<String> dataSetLocations; + private final String fileName; private final String comment; private final String userID; private final String password; @@ -114,6 +116,7 @@ class UploadingCommand implements IDataSetCommand private final MailClientParameters mailClientParameters; private final TokenGenerator tokenGenerator; + UploadingCommand(ICIFEXRPCServiceFactory cifexServiceFactory, MailClientParameters mailClientParameters, List<String> dataSetLocations, DataSetUploadContext context) @@ -123,6 +126,7 @@ class UploadingCommand implements IDataSetCommand this.dataSetLocations = dataSetLocations; this.userID = context.getUserID(); this.password = context.getPassword(); + fileName = context.getFileName(); userEMail = context.getUserEMail(); this.comment = context.getComment(); tokenGenerator = new TokenGenerator(); @@ -132,8 +136,7 @@ class UploadingCommand implements IDataSetCommand { File tempFolder = new File(store, "tmp"); tempFolder.mkdirs(); - String token = tokenGenerator.getNewToken(System.currentTimeMillis()); - final File zipFile = new File(tempFolder, token + ".zip"); + final File zipFile = new File(tempFolder, createFileName()); boolean successful = fillZipFile(store, zipFile); if (successful) { @@ -154,6 +157,15 @@ class UploadingCommand implements IDataSetCommand zipFile.delete(); } + private String createFileName() + { + if (StringUtils.isBlank(fileName)) + { + return tokenGenerator.getNewToken(System.currentTimeMillis()) + ".zip"; + } + return fileName.toLowerCase().endsWith(".zip") ? fileName : fileName + ".zip"; + } + private boolean fillZipFile(File store, File zipFile) { OutputStream outputStream = null;