[Task #12601] added download folder facility
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@171919 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9c16237ed7
commit
2bf7130b37
|
@ -4,6 +4,7 @@
|
|||
<Change>[Task #12059] added delete item</Change>
|
||||
<Change>[Task #12533] added trash operations</Change>
|
||||
<Change>[Task #12556] added download facility</Change>
|
||||
<Change>[Task #12601] added download folder facility</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.common.storagehubwrapper.0-1-0"
|
||||
date="2018-06-20">
|
||||
|
|
|
@ -327,16 +327,16 @@ public class StorageHubClientService {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Download file.
|
||||
*
|
||||
* @param itemId the item id
|
||||
* @param fileName the file name
|
||||
* @param nodeIdsToExclude the node ids to exclude
|
||||
* @return the stream descriptor
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public StreamDescriptor downloadFile(String itemId, String fileName, String nodeIdsToExclude) throws Exception{
|
||||
public StreamDescriptor downloadFile(String itemId, String nodeIdsToExclude) throws Exception{
|
||||
|
||||
StreamDescriptor streamDesc = shcClient.open(itemId).asFile().download(nodeIdsToExclude);
|
||||
return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName());
|
||||
|
@ -344,6 +344,23 @@ public class StorageHubClientService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Download folder.
|
||||
*
|
||||
* @param folderId the folder id
|
||||
* @param nodeIdsToExclude the node ids to exclude
|
||||
* @return the stream descriptor
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public StreamDescriptor downloadFolder(String folderId, String nodeIdsToExclude) throws Exception{
|
||||
|
||||
StreamDescriptor streamDesc = shcClient.open(folderId).asFolder().download(nodeIdsToExclude);
|
||||
return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Upload archive.
|
||||
*
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolder
|
|||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongDestinationException;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeException;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFolder;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.items.FileStreamDescriptor;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.items.ItemStreamDescriptor;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -641,10 +641,10 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public FileStreamDescriptor downloadFile(String itemId, String fileName, String nodeIdsToExclude) throws Exception{
|
||||
public ItemStreamDescriptor downloadFile(String itemId, String fileName, String nodeIdsToExclude) throws Exception{
|
||||
|
||||
try {
|
||||
StreamDescriptor streamDesc = storageHubClientService.downloadFile(itemId, fileName, nodeIdsToExclude);
|
||||
StreamDescriptor streamDesc = storageHubClientService.downloadFile(itemId, nodeIdsToExclude);
|
||||
return new org.gcube.common.storagehubwrapper.shared.tohl.impl.StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error on downloading the file: "+fileName+ " with id: "+itemId, e);
|
||||
|
@ -655,6 +655,30 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Download folder.
|
||||
*
|
||||
* @param folderId the folder id
|
||||
* @param folderName the folder name
|
||||
* @param nodeIdsToExclude the node ids to exclude
|
||||
* @return the file stream descriptor
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public ItemStreamDescriptor downloadFolder(String folderId, String folderName, String nodeIdsToExclude) throws Exception{
|
||||
|
||||
try {
|
||||
StreamDescriptor streamDesc = storageHubClientService.downloadFolder(folderId, nodeIdsToExclude);
|
||||
return new org.gcube.common.storagehubwrapper.shared.tohl.impl.StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error on downloading the folder: "+folderName+ " with id: "+folderId, e);
|
||||
String error = e.getMessage()!=null?e.getMessage():"";
|
||||
throw new Exception("Error on downloading the folder: "+folderName+". "+error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundExc
|
|||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongDestinationException;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeException;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.items.FileStreamDescriptor;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.items.ItemStreamDescriptor;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem;
|
||||
|
||||
|
||||
|
@ -717,11 +717,25 @@ public interface Workspace{
|
|||
* @param itemId the item id
|
||||
* @param fileName the file name
|
||||
* @param nodeIdsToExclude the node ids to exclude
|
||||
* @return the file stream descriptor
|
||||
* @return the item stream descriptor
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
FileStreamDescriptor downloadFile(
|
||||
ItemStreamDescriptor downloadFile(
|
||||
String itemId, String fileName, String nodeIdsToExclude)
|
||||
throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Download folder.
|
||||
*
|
||||
* @param folderId the folder id
|
||||
* @param folderName the folder name
|
||||
* @param nodeIdsToExclude the node ids to exclude
|
||||
* @return the item stream descriptor
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
ItemStreamDescriptor downloadFolder(
|
||||
String folderId, String folderName, String nodeIdsToExclude)
|
||||
throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -11,9 +11,16 @@ import lombok.Getter;
|
|||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.items.FileStreamDescriptor;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.items.ItemStreamDescriptor;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new stream descriptor.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Oct 4, 2018
|
||||
*/
|
||||
|
||||
/**
|
||||
* Instantiates a new stream descriptor.
|
||||
*/
|
||||
|
@ -25,6 +32,13 @@ import org.gcube.common.storagehubwrapper.shared.tohl.items.FileStreamDescriptor
|
|||
* @param stream the stream
|
||||
* @param fileName the file name
|
||||
*/
|
||||
|
||||
/**
|
||||
* Instantiates a new stream descriptor.
|
||||
*
|
||||
* @param stream the stream
|
||||
* @param itemName the item name
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
|
||||
/**
|
||||
|
@ -32,22 +46,23 @@ import org.gcube.common.storagehubwrapper.shared.tohl.items.FileStreamDescriptor
|
|||
*
|
||||
* @return the file name
|
||||
*/
|
||||
|
||||
@Getter
|
||||
|
||||
/**
|
||||
* Sets the file name.
|
||||
* Sets the item name.
|
||||
*
|
||||
* @param fileName the new file name
|
||||
* @param itemName the new item name
|
||||
*/
|
||||
@Setter
|
||||
public class StreamDescriptor implements FileStreamDescriptor, Serializable{
|
||||
public class StreamDescriptor implements ItemStreamDescriptor, Serializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5482612709953553644L;
|
||||
private InputStream stream;
|
||||
private String fileName;
|
||||
private String itemName;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,12 +7,12 @@ import java.io.InputStream;
|
|||
|
||||
|
||||
/**
|
||||
* The Interface FileStreamDescriptor.
|
||||
* The Interface ItemStreamDescriptor.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Sep 26, 2018
|
||||
* Oct 4, 2018
|
||||
*/
|
||||
public interface FileStreamDescriptor {
|
||||
public interface ItemStreamDescriptor {
|
||||
|
||||
/**
|
||||
* Gets the stream.
|
||||
|
@ -21,12 +21,14 @@ public interface FileStreamDescriptor {
|
|||
*/
|
||||
public InputStream getStream();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the file name.
|
||||
* Gets the item name.
|
||||
* It can be a file or a folder
|
||||
*
|
||||
* @return the fileName
|
||||
* @return the item name
|
||||
*/
|
||||
public String getFileName();
|
||||
public String getItemName();
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue