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 e1b9c9b..3e44f0a 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java @@ -6,6 +6,7 @@ import java.util.List; import org.apache.commons.lang.Validate; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.storagehub.client.StreamDescriptor; import org.gcube.common.storagehub.client.dsl.FileContainer; import org.gcube.common.storagehub.client.dsl.FolderContainer; import org.gcube.common.storagehub.client.dsl.GenericItemContainer; @@ -108,6 +109,19 @@ public class StorageHubClientService { return shcClient.open(id).asFolder().list().withContent().getItems(); } + /** + * Gets the children. + * + * @param id the id + * @return the children + */ + public List getFilteredChildren(String id, Class aType){ + setContextProviders(scope, authorizationToken); + return shcClient.open(id).asFolder().list().ofType(aType).withContent().getItems(); + } + + + /** * Gets the item. @@ -316,6 +330,26 @@ 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{ + + try { + StreamDescriptor streamDesc = shcClient.open(itemId).asFile().download(nodeIdsToExclude); + return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName()); + } catch (Exception e) { + logger.error("Error on downoloading the file: "+fileName+ " with id: "+itemId, e); + throw new Exception("Error on downoloading the file: "+fileName+". Try again"); + } + } + /** * 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 fe6660a..ee17eef 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java @@ -266,6 +266,23 @@ public final class WorkspaceStorageHubClientService implements Workspace{ return toChildren; } + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.tohl.Workspace#getChildren(java.lang.String) + */ + public List getFilteredChildren(String id, Class aType){ + + Validate.notNull(id,"The input id is null"); + List children = storageHubClientService.getFilteredChildren(id, aType); + List toChildren = new ArrayList(children.size()); + + for (Item item : children) { + WorkspaceItem child = HLMapper.toWorkspaceItem(item); + toChildren.add(child); + } + + return toChildren; + } + /* (non-Javadoc) * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getParentsById(java.lang.String) */ diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/converter/HLMapper.java b/src/main/java/org/gcube/common/storagehubwrapper/server/converter/HLMapper.java index f69c088..66c4c2d 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/converter/HLMapper.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/converter/HLMapper.java @@ -160,7 +160,7 @@ public class HLMapper { } } - ((WorkspaceFolder) theItem).setPublicFolder(folderItem.isPublicFolder()); + ((WorkspaceFolder) theItem).setPublicFolder(folderItem.getPublicFolder()); if(logger.isTraceEnabled()){ WorkspaceFolder theFolder = (WorkspaceFolder) theItem; 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 new file mode 100644 index 0000000..c4222eb --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/StreamDescriptor.java @@ -0,0 +1,53 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.impl; + +import java.io.InputStream; +import java.io.Serializable; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import org.gcube.common.storagehubwrapper.shared.tohl.items.FileStreamDescriptor; + + +/** + * Instantiates a new stream descriptor. + */ +@NoArgsConstructor + +/** + * Instantiates a new stream descriptor. + * + * @param stream the stream + * @param fileName the file name + */ +@AllArgsConstructor + +/** + * Gets the file name. + * + * @return the file name + */ +@Getter + +/** + * Sets the file name. + * + * @param fileName the new file name + */ +@Setter +public class StreamDescriptor implements FileStreamDescriptor, Serializable{ + + /** + * + */ + private static final long serialVersionUID = -5482612709953553644L; + private InputStream stream; + private String fileName; + + +} 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/FileStreamDescriptor.java new file mode 100644 index 0000000..79fcddc --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/items/FileStreamDescriptor.java @@ -0,0 +1,32 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.items; + +import java.io.InputStream; + + +/** + * The Interface FileStreamDescriptor. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Sep 26, 2018 + */ +public interface FileStreamDescriptor { + + /** + * Gets the stream. + * + * @return the stream + */ + public InputStream getStream(); + + /** + * Gets the file name. + * + * @return the fileName + */ + public String getFileName(); + + +}