From 6e8f680fb6fc797711f89861eeb113863fec9ef7 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Tue, 9 Oct 2018 15:38:06 +0000 Subject: [PATCH] Migrate Rename facility to StorageHub git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@172102 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 1 + .../server/StorageHubClientService.java | 19 +++++++++ .../WorkspaceStorageHubClientService.java | 39 ++++++++++++++----- .../server/tohl/Workspace.java | 25 ++++++------ 4 files changed, 63 insertions(+), 21 deletions(-) diff --git a/distro/changelog.xml b/distro/changelog.xml index 27e8012..2d23cf8 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -7,6 +7,7 @@ [Task #12601] added download folder facility [Task #12604] Migrate Move operation to StorageHub [Task #12603] Migrate Copy operation to StorageHub + [Task #12603] Migrate Rename facility to StorageHub 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 a947dd6..37e2007 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java @@ -543,6 +543,25 @@ public class StorageHubClientService { } + + /** + * Rename item. + * + * @param itemId the item id + * @param newName the new name + * @return the item + * @throws Exception the exception + */ + public Item renameItem(String itemId, String newName) throws Exception{ + + Validate.notNull(itemId, "Bad invoking rename item, the itemId is null"); + + OpenResolver resolver = shcClient.open(itemId).asItem().rename(newName); + return resolver.asItem().get(); + + } + + /* (non-Javadoc) * @see java.lang.Object#toString() */ 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 4babaf4..3ff61b0 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java @@ -780,6 +780,35 @@ public final class WorkspaceStorageHubClientService implements Workspace{ } + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#renameItem(java.lang.String, java.lang.String) + */ + @Override + public WorkspaceItem renameItem(String itemId, String newName) + throws ItemNotFoundException, InternalErrorException, + ItemAlreadyExistException, InsufficientPrivilegesException, Exception{ + + try{ + Item item = storageHubClientService.renameItem(itemId, newName); + return HLMapper.toWorkspaceItem(item); + }catch(Exception e){ + logger.error("Error on renaming item with id: "+itemId, e); + String error = e.getMessage()!=null?e.getMessage():"Operation not allowed"; + throw new Exception("Error on renaming. "+error); + } + + } + + + + + + + + + + + @@ -841,17 +870,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{ } - /* (non-Javadoc) - * @see org.gcube.portal.storagehubwrapper.shared.Workspace#renameItem(java.lang.String, java.lang.String) - */ - @Override - public void renameItem(String itemId, String newName) - throws ItemNotFoundException, InternalErrorException, - ItemAlreadyExistException, InsufficientPrivilegesException { - // TODO Auto-generated method stub - - } /* (non-Javadoc) * @see org.gcube.portal.storagehubwrapper.shared.Workspace#changeDescription(java.lang.String, java.lang.String) 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 41a8781..c040766 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 @@ -256,6 +256,20 @@ public interface Workspace{ + /** + * Rename an item. + * + * @param itemId the item id. + * @param newName the new name. + * @return the workspace item + * @throws ItemNotFoundException if the item has not been found. + * @throws InternalErrorException if an internal error occurs. + * @throws ItemAlreadyExistException if the user don't have sufficient privileges to perform this operation. + * @throws InsufficientPrivilegesException the insufficient privileges exception + * @throws Exception the exception + */ + public WorkspaceItem renameItem(String itemId, String newName) throws ItemNotFoundException, InternalErrorException, ItemAlreadyExistException, InsufficientPrivilegesException, Exception; + @@ -372,17 +386,6 @@ public interface Workspace{ */ public WorkspaceItem moveItem(String itemId, String destinationFolderId) throws ItemNotFoundException, WrongDestinationException, InsufficientPrivilegesException, InternalErrorException, ItemAlreadyExistException, WorkspaceFolderNotFoundException, Exception; - /** - * Rename an item. - * - * @param itemId the item id. - * @param newName the new name. - * @throws ItemNotFoundException if the item has not been found. - * @throws InternalErrorException if an internal error occurs. - * @throws ItemAlreadyExistException if the user don't have sufficient privileges to perform this operation. - * @throws InsufficientPrivilegesException the insufficient privileges exception - */ - public void renameItem(String itemId, String newName) throws ItemNotFoundException, InternalErrorException, ItemAlreadyExistException, InsufficientPrivilegesException; /** * Change an item description.