Skip to content
Snippets Groups Projects
Commit 2cc498a2 authored by kaloyane's avatar kaloyane
Browse files

[LMS-2319] give NewDataSetDTO a constructor that is easier to use

SVN: 21716
parent 2e2fcc0d
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@ import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
/**
* Helper Class for creating FileInfoDss objects based on file system.
......@@ -33,6 +34,28 @@ import java.util.ArrayList;
public class FileInfoDssBuilder
{
/**
* Return a list of {@link FileInfoDssDTO} objects corresponding to all files existing within a
* certain folder. The list is accumulated recursively.
*/
public static List<FileInfoDssDTO> getFileInfos(File dataSetContents)
{
FileInfoDssBuilder fileInfoBuilder =
new FileInfoDssBuilder(dataSetContents.getAbsolutePath(),
dataSetContents.getAbsolutePath());
ArrayList<FileInfoDssDTO> fileInfos = new ArrayList<FileInfoDssDTO>();
try
{
fileInfoBuilder.appendFileInfosForFile(dataSetContents, fileInfos, true);
} catch (IOException ioex)
{
throw new RuntimeException(
"Error occurred while gathering information from the local data set contents: "
+ ioex.getMessage(), ioex);
}
return fileInfos;
}
private final File dataSetRootFile;
private final File listingRootFile;
......
......@@ -16,6 +16,7 @@
package ch.systemsx.cisd.openbis.dss.generic.shared.api.v1;
import java.io.File;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
......@@ -89,6 +90,16 @@ public class NewDataSetDTO implements Serializable
}
}
private static String getFolderNameOrNull(File dataSetFile)
{
String folderNameOrNull = null;
if (dataSetFile.isDirectory())
{
folderNameOrNull = dataSetFile.getName();
}
return folderNameOrNull;
}
private static final long serialVersionUID = 1L;
private final DataSetOwner dataSetOwner;
......@@ -99,6 +110,18 @@ public class NewDataSetDTO implements Serializable
private final NewDataSetMetadataDTO dataSetMetadata;
/**
* Constructor
*
* @param dataSetOwner the owner of the new data set
* @param dataSetFile a local file or directory whose contents will be uploaded to openBIS.
*/
public NewDataSetDTO(DataSetOwner dataSetOwner, File dataSetFile)
{
this(dataSetOwner, getFolderNameOrNull(dataSetFile), FileInfoDssBuilder
.getFileInfos(dataSetFile));
}
/**
* Constructor
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment