From 2bf7130b37c1306e3e2f39578577d25c6278c633 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Thu, 4 Oct 2018 09:26:15 +0000 Subject: [PATCH] [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 --- distro/changelog.xml | 1 + .../server/StorageHubClientService.java | 21 +++++++++++-- .../WorkspaceStorageHubClientService.java | 30 +++++++++++++++++-- .../server/tohl/Workspace.java | 20 +++++++++++-- .../shared/tohl/impl/StreamDescriptor.java | 25 ++++++++++++---- ...criptor.java => ItemStreamDescriptor.java} | 14 +++++---- 6 files changed, 92 insertions(+), 19 deletions(-) rename src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/items/{FileStreamDescriptor.java => ItemStreamDescriptor.java} (59%) diff --git a/distro/changelog.xml b/distro/changelog.xml index b41a3d8..04411dc 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -4,6 +4,7 @@ [Task #12059] added delete item [Task #12533] added trash operations [Task #12556] added download facility + [Task #12601] added download folder facility diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java index 19ff24b..16b0c88 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java @@ -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. * diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java b/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java index 4316930..07a113a 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java @@ -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); + } + } + + + diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/tohl/Workspace.java b/src/main/java/org/gcube/common/storagehubwrapper/server/tohl/Workspace.java index ef26ea8..147d6c7 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/tohl/Workspace.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/tohl/Workspace.java @@ -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; + } diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/StreamDescriptor.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/StreamDescriptor.java index c4222eb..1f0cacb 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/StreamDescriptor.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/StreamDescriptor.java @@ -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; } diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/items/FileStreamDescriptor.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/items/ItemStreamDescriptor.java similarity index 59% rename from src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/items/FileStreamDescriptor.java rename to src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/items/ItemStreamDescriptor.java index 79fcddc..d658d03 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/items/FileStreamDescriptor.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/items/ItemStreamDescriptor.java @@ -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(); }