Added downloadFile facility

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@171813 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-10-02 08:35:46 +00:00
parent 9b2c118a86
commit 4e994f75f5
2 changed files with 52 additions and 10 deletions

View File

@ -11,6 +11,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.model.items.FolderItem; import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item; import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.types.GenericItemType; import org.gcube.common.storagehub.model.types.GenericItemType;
@ -28,6 +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.WrongDestinationException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeException; 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.impl.WorkspaceFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.items.FileStreamDescriptor;
import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem; import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -552,6 +554,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
* @return true, if is item shared * @return true, if is item shared
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override
public boolean isItemShared(String itemId) throws Exception { public boolean isItemShared(String itemId) throws Exception {
Validate.notNull(itemId,"The input itemId is null"); Validate.notNull(itemId,"The input itemId is null");
try{ try{
@ -570,6 +573,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
* @return the VRE folders id * @return the VRE folders id
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override
public String getVREFoldersId() throws Exception{ public String getVREFoldersId() throws Exception{
try{ try{
return storageHubClientService.getVREFoldersId(); return storageHubClientService.getVREFoldersId();
@ -583,6 +587,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
/* (non-Javadoc) /* (non-Javadoc)
* @see org.gcube.common.storagehubwrapper.server.tohl.Workspace#getTrash() * @see org.gcube.common.storagehubwrapper.server.tohl.Workspace#getTrash()
*/ */
@Override
public WorkspaceItem getTrash() public WorkspaceItem getTrash()
throws Exception { throws Exception {
try{ try{
@ -600,6 +605,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
* *
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override
public void emptyTrash() throws Exception{ public void emptyTrash() throws Exception{
try{ try{
@ -611,18 +617,15 @@ public final class WorkspaceStorageHubClientService implements Workspace{
} }
/* (non-Javadoc)
/** * @see org.gcube.common.storagehubwrapper.server.tohl.Workspace#restoreThrashItem(java.lang.String)
* Restore thrash item.
*
* @param itemId the item id
* @return the item
* @throws Exception the exception
*/ */
public Item restoreThrashItem(String itemId) throws Exception{ @Override
public WorkspaceItem restoreThrashItem(String itemId) throws Exception{
try{ try{
return storageHubClientService.restoreThrashItem(itemId); Item theItem = storageHubClientService.restoreThrashItem(itemId);
return HLMapper.toWorkspaceItem(theItem);
}catch(Exception e){ }catch(Exception e){
throw new Exception("Error restoring the Trash Item: "+e.getMessage()); throw new Exception("Error restoring the Trash Item: "+e.getMessage());
@ -631,6 +634,29 @@ public final class WorkspaceStorageHubClientService implements Workspace{
} }
/**
* Download file.
*
* @param itemId the item id
* @param fileName the file name
* @param nodeIdsToExclude the node ids to exclude
* @return the file stream descriptor
* @throws Exception the exception
*/
@Override
public FileStreamDescriptor downloadFile(String itemId, String fileName, String nodeIdsToExclude) throws Exception{
try {
StreamDescriptor streamDesc = storageHubClientService.downloadFile(itemId, fileName, nodeIdsToExclude);
return new org.gcube.common.storagehubwrapper.shared.tohl.impl.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+". Refresh and Try again");
}
}

View File

@ -22,6 +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.WorkspaceFolderNotFoundException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongDestinationException; 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.exceptions.WrongItemTypeException;
import org.gcube.common.storagehubwrapper.shared.tohl.items.FileStreamDescriptor;
import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem; import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem;
@ -246,7 +247,7 @@ public interface Workspace{
* @return the item * @return the item
* @throws Exception the exception * @throws Exception the exception
*/ */
public Item restoreThrashItem(String itemId) throws Exception; public WorkspaceItem restoreThrashItem(String itemId) throws Exception;
@ -714,4 +715,19 @@ public interface Workspace{
WorkspaceFolderNotFoundException, InternalErrorException, WorkspaceFolderNotFoundException, InternalErrorException,
ItemAlreadyExistException, WrongDestinationException, InsufficientPrivilegesException; ItemAlreadyExistException, WrongDestinationException, InsufficientPrivilegesException;
/**
* Download file.
*
* @param itemId the item id
* @param fileName the file name
* @param nodeIdsToExclude the node ids to exclude
* @return the file stream descriptor
* @throws Exception the exception
*/
FileStreamDescriptor downloadFile(
String itemId, String fileName, String nodeIdsToExclude)
throws Exception;
} }