From 9632887519c08e8abc49ed6d07a88b0dd71a7f48 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Fri, 5 Oct 2018 13:20:16 +0000 Subject: [PATCH] updated moveItems git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@171977 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../server/StorageHubClientService.java | 9 ++++++--- .../server/WorkspaceStorageHubClientService.java | 16 ++++++++++++---- .../storagehubwrapper/server/tohl/Workspace.java | 6 ++++-- 3 files changed, 22 insertions(+), 9 deletions(-) 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 3217019..ff62ce7 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java @@ -12,6 +12,7 @@ import org.gcube.common.storagehub.client.dsl.FolderContainer; import org.gcube.common.storagehub.client.dsl.GenericItemContainer; import org.gcube.common.storagehub.client.dsl.ItemContainer; import org.gcube.common.storagehub.client.dsl.ListResolver; +import org.gcube.common.storagehub.client.dsl.OpenResolver; import org.gcube.common.storagehub.client.dsl.StorageHubClient; import org.gcube.common.storagehub.client.plugins.AbstractPlugin; import org.gcube.common.storagehub.client.proxies.ItemManagerClient; @@ -505,16 +506,18 @@ public class StorageHubClientService { /** * Move item. * - * @param itemId the move item id + * @param itemId the item id * @param destFolderContainer the dest folder container + * @return the abstract file item * @throws Exception the exception */ - public void moveItem(String itemId, FolderContainer destFolderContainer) throws Exception{ + public AbstractFileItem moveItem(String itemId, FolderContainer destFolderContainer) throws Exception{ Validate.notNull(itemId, "Bad invoking move file, the itemId is null"); Validate.notNull(destFolderContainer, "Bad invoking move file, the itemId is null"); - shcClient.open(itemId).asItem().move(destFolderContainer); + OpenResolver openResolver = shcClient.open(itemId).asItem().move(destFolderContainer); + return openResolver.asFile().get(); } 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 d7d4fe0..04efc65 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java @@ -683,7 +683,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{ @Override - public void moveItems(List itemIds, String folderDestinationId) throws ItemNotFoundException, WrongDestinationException, InsufficientPrivilegesException, InternalErrorException, ItemAlreadyExistException, Exception { + public List moveItems(List itemIds, String folderDestinationId) throws ItemNotFoundException, WrongDestinationException, InsufficientPrivilegesException, InternalErrorException, ItemAlreadyExistException, Exception { FolderContainer destFolderContainer = null; @@ -696,15 +696,20 @@ public final class WorkspaceStorageHubClientService implements Workspace{ destFolderContainer = storageHubClientService.getFolderContainer(folderDestinationId); + List toReturnItems = new ArrayList(itemIds.size()); + for (String itemId : itemIds) { try{ - storageHubClientService.moveItem(itemId, destFolderContainer); + AbstractFileItem movedItem = storageHubClientService.moveItem(itemId, destFolderContainer); + toReturnItems.add(HLMapper.toWorkspaceItem(movedItem)); }catch(Exception e){ logger.error("Error on moving the item with id: "+itemId+ " in the folder id: "+destFolderContainer.get().getId(), e); } } + return toReturnItems; + } catch (Exception e) { logger.error("Error on moving item/items in the folder with id: "+folderDestinationId, e); String error = e.getMessage()!=null?e.getMessage():""; @@ -768,9 +773,12 @@ public final class WorkspaceStorageHubClientService implements Workspace{ /* (non-Javadoc) * @see org.gcube.common.storagehubwrapper.server.tohl.Workspace#moveItem(java.lang.String, java.lang.String) */ - public void moveItem(String itemId, String folderDestinationId) throws ItemNotFoundException, WrongDestinationException, InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, Exception{ + @Override + public WorkspaceItem moveItem(String itemId, String folderDestinationId) throws ItemNotFoundException, WrongDestinationException, InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, Exception{ - moveItems(Arrays.asList(itemId), folderDestinationId); + List list = moveItems(Arrays.asList(itemId), folderDestinationId); + + return list==null||list.isEmpty()?null:list.get(0); } 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 c77d08b..41a8781 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 @@ -361,6 +361,7 @@ public interface Workspace{ * * @param itemId the item id * @param destinationFolderId the destination folder id + * @return the workspace item * @throws ItemNotFoundException the item not found exception * @throws WrongDestinationException the wrong destination exception * @throws InsufficientPrivilegesException the insufficient privileges exception @@ -369,7 +370,7 @@ public interface Workspace{ * @throws WorkspaceFolderNotFoundException the workspace folder not found exception * @throws Exception the exception */ - public void moveItem(String itemId, String destinationFolderId) throws ItemNotFoundException, WrongDestinationException, InsufficientPrivilegesException, InternalErrorException, ItemAlreadyExistException, WorkspaceFolderNotFoundException, Exception; + public WorkspaceItem moveItem(String itemId, String destinationFolderId) throws ItemNotFoundException, WrongDestinationException, InsufficientPrivilegesException, InternalErrorException, ItemAlreadyExistException, WorkspaceFolderNotFoundException, Exception; /** * Rename an item. @@ -455,6 +456,7 @@ public interface Workspace{ * * @param itemIds the item ids * @param folderDestinationId the folder destination id + * @return the list * @throws ItemNotFoundException the item not found exception * @throws WrongDestinationException the wrong destination exception * @throws InsufficientPrivilegesException the insufficient privileges exception @@ -462,7 +464,7 @@ public interface Workspace{ * @throws ItemAlreadyExistException the item already exist exception * @throws Exception the exception */ - void moveItems(List itemIds, String folderDestinationId) + List moveItems(List itemIds, String folderDestinationId) throws ItemNotFoundException, WrongDestinationException, InsufficientPrivilegesException, InternalErrorException, ItemAlreadyExistException, Exception;