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 6c4dd2b..f7a5d27 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java @@ -300,6 +300,28 @@ public class StorageHubClientService { } + /** + * Upload archive. + * + * @param folderId the folder id + * @param is the is + * @param extractionFolderName the extraction folder name + * @return the item + * @throws Exception the exception + */ + public Item uploadArchive(String folderId, InputStream is, String extractionFolderName) throws Exception{ + + try { + FolderContainer folderCont = shcClient.open(folderId).asFolder().uploadArchive(is, extractionFolderName); + return folderCont.get(); + } catch (Exception e) { + logger.error("Error during uploading the archive with extractionFolderName: "+extractionFolderName+" in the folderId: "+folderId, e); + throw new Exception("Error during uploading the archive. Try again", e); + } + } + + + /** * Gets the shared folder members. * 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 0ecaa71..18c47c4 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java @@ -483,6 +483,29 @@ public final class WorkspaceStorageHubClientService implements Workspace{ } } + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.server.tohl.Workspace#uploadFile(java.lang.String, java.io.InputStream, java.lang.String, java.lang.String) + */ + @Override + public WorkspaceItem uploadArchive( + String folderId, InputStream is, String extractionFolderName) + throws + WorkspaceFolderNotFoundException, InternalErrorException, + ItemAlreadyExistException, WrongDestinationException, InsufficientPrivilegesException{ + + WorkspaceItem wsItem = null; + try { + Item item = storageHubClientService.uploadArchive(folderId, is, extractionFolderName); + wsItem = HLMapper.toWorkspaceItem(item); + } + catch (Exception e) { + logger.error("Error during upload archive", e); + throw new InternalErrorException(e.getMessage()); + } + + return wsItem; + } + 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 666faf9..00fd13b 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 @@ -638,4 +638,24 @@ public interface Workspace{ */ List getPublicFolders() throws InternalErrorException; + + /** + * Upload archive. + * + * @param folderId the folder id + * @param is the is + * @param extractionFolderName the extraction folder name + * @return the workspace item + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + * @throws InternalErrorException the internal error exception + * @throws ItemAlreadyExistException the item already exist exception + * @throws WrongDestinationException the wrong destination exception + * @throws InsufficientPrivilegesException + */ + WorkspaceItem uploadArchive( + String folderId, InputStream is, String extractionFolderName) + throws + WorkspaceFolderNotFoundException, InternalErrorException, + ItemAlreadyExistException, WrongDestinationException, InsufficientPrivilegesException; + }