From 3fa88ee8d3d54f00a0000df96980b98de9f6cb71 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Fri, 14 Sep 2018 13:34:12 +0000 Subject: [PATCH] Added method deleteItem Updated pom at 0-2-0 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@171465 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 4 ++ pom.xml | 2 +- .../server/StorageHubClientService.java | 54 ++++++++++++---- .../WorkspaceStorageHubClientService.java | 64 ++++++++++++++----- .../server/tohl/Workspace.java | 45 +++++++++++-- 5 files changed, 136 insertions(+), 33 deletions(-) diff --git a/distro/changelog.xml b/distro/changelog.xml index 1198658..1b45971 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,8 @@ + + [Task #12059] added delete item + [Task #12059] first release diff --git a/pom.xml b/pom.xml index b901fb1..389dfec 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.common storagehub-client-wrapper - 0.1.0-SNAPSHOT + 0.2.0-SNAPSHOT storagehub-client-wrapper This is a wrapper of storagehub-client library. It allows to interact with storagehub in a simplified way by exposing several utilities. Moreover, It exposes object as defined in (the old) HL interfaces 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 5c268a2..6c4dd2b 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java @@ -9,6 +9,7 @@ import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.storagehub.client.dsl.FileContainer; import org.gcube.common.storagehub.client.dsl.FolderContainer; import org.gcube.common.storagehub.client.dsl.ItemContainer; +import org.gcube.common.storagehub.client.dsl.ListResolver; import org.gcube.common.storagehub.client.dsl.StorageHubClient; import org.gcube.common.storagehub.client.plugins.AbstractPlugin; import org.gcube.common.storagehub.client.proxies.ItemManagerClient; @@ -129,8 +130,12 @@ public class StorageHubClientService { */ public List getParents(String itemId) { setContextProviders(scope, authorizationToken); - List toReturn = shcClient.open(itemId).asItem().getAnchestors(); - return toReturn; + ListResolver toReturn = shcClient.open(itemId).asItem().getAnchestors(); + if(toReturn==null || toReturn.getItems()==null){ + logger.warn("Parent List of item id "+itemId+" is null"); + return null; + } + return toReturn.getItems(); } //TODO MAP OF SHARED ROOT ID @@ -141,7 +146,7 @@ public class StorageHubClientService { * * @param itemId the item id * @return the id shared folder - * @throws Exception + * @throws Exception the exception */ public String getIdSharedFolder(String itemId) throws Exception { setContextProviders(scope, authorizationToken); @@ -154,22 +159,33 @@ public class StorageHubClientService { * * @param itemId the item id * @return the root shared folder - * @throws Exception + * @throws Exception the exception */ public FolderItem getRootSharedFolder(String itemId) throws Exception { setContextProviders(scope, authorizationToken); + return getRootSharedFolder(shcClient.open(itemId).asItem()); + + } + + /** + * Gets the root shared folder. + * + * @param itemContainer the item container + * @return the root shared folder + * @throws Exception the exception + */ + public FolderItem getRootSharedFolder(ItemContainer itemContainer) throws Exception { + setContextProviders(scope, authorizationToken); - ItemContainer item = shcClient.open(itemId).asItem(); FolderContainer rootSharedFolder = null; - if(item.get().isShared()){ - rootSharedFolder = item.getRootSharedFolder(); + Item item = itemContainer.get(); + if(item.isShared()){ + rootSharedFolder = itemContainer.getRootSharedFolder(); }else - throw new Exception("The item with id: "+itemId +" is not shared"); + throw new Exception("The item with id: "+item.getId() +" is not shared"); - Validate.notNull(rootSharedFolder, "The root shared folder with id "+itemId+" does not exist"); + Validate.notNull(rootSharedFolder, "The root shared folder with children id "+item.getId()+" does not exist"); return rootSharedFolder.get(); - - } /** @@ -332,6 +348,22 @@ public class StorageHubClientService { + /** + * Delete item by id. + * + * @param itemId the item id + * @throws Exception the exception + */ + public void deleteItemById(String itemId) throws Exception{ + + Validate.notNull(itemId, "Bad invoking operation the "+itemId+" is null"); + + shcClient.open(itemId).asItem().delete(); + + } + + + /* (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 fe1811d..0ecaa71 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java @@ -60,6 +60,8 @@ public final class WorkspaceStorageHubClientService implements Workspace{ /** + * Checks if is with accounting. + * * @return the withAccounting */ public boolean isWithAccounting() { @@ -69,6 +71,8 @@ public final class WorkspaceStorageHubClientService implements Workspace{ /** + * Checks if is with file details. + * * @return the withFileDetails */ public boolean isWithFileDetails() { @@ -78,6 +82,8 @@ public final class WorkspaceStorageHubClientService implements Workspace{ /** + * Checks if is with map properties. + * * @return the withMapProperties */ public boolean isWithMapProperties() { @@ -151,9 +157,6 @@ public final class WorkspaceStorageHubClientService implements Workspace{ * Instantiates a new workspace storage hub client service builder. * * @param storageHubClientService the storage hub client service - * @param withAccounting the with accounting - * @param withFileDetails the with file details - * @param withMapProperties the with map properties */ public WorkspaceStorageHubClientServiceBuilder( final StorageHubClientService storageHubClientService) { @@ -201,7 +204,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{ } /** - * Builds the WorkspaceStorageHubClientService + * Builds the WorkspaceStorageHubClientService. * * @return the workspace storage hub client service */ @@ -441,6 +444,48 @@ public final class WorkspaceStorageHubClientService implements Workspace{ } + /** + * Gets the root shared folder. + * + * @param itemId the item id + * @return the root shared folder + * @throws Exception the exception + */ + public WorkspaceItem getRootSharedFolder(String itemId) throws Exception { + Validate.notNull(itemId,"The input itemId is null"); + + try{ + FolderItem folderItem = storageHubClientService.getRootSharedFolder(itemId); + return HLMapper.toWorkspaceItem(folderItem); + }catch(Exception e){ + logger.error("Get root shared folder error: "+e.getMessage()); + throw new Exception("Get root shared folder error: "+e.getMessage()); + } + } + + + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#removeItem(java.lang.String) + */ + @Override + public void deleteItem(String itemId) + throws Exception { + + Validate.notNull(itemId,"The input itemId is null"); + + try{ + storageHubClientService.deleteItemById(itemId); + + }catch(Exception e){ + logger.error("Delete item by id error: "+e.getMessage()); + throw new Exception("Delete item by id error: "+e.getMessage()); + } + } + + + + @@ -498,17 +543,6 @@ public final class WorkspaceStorageHubClientService implements Workspace{ return null; } - /* (non-Javadoc) - * @see org.gcube.portal.storagehubwrapper.shared.Workspace#removeItem(java.lang.String) - */ - @Override - public void removeItem(String itemId) - throws ItemNotFoundException, InternalErrorException, - InsufficientPrivilegesException { - - // TODO Auto-generated method stub - - } /* (non-Javadoc) * @see org.gcube.portal.storagehubwrapper.shared.Workspace#moveItem(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 68bbe2a..666faf9 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 @@ -188,6 +188,36 @@ public interface Workspace{ public List find(String name, String folderId) throws InternalErrorException, ItemNotFoundException, WrongItemTypeException; + + + /** + * Gets the root shared folder. + * + * @param itemId the item id + * @return the root shared folder + * @throws Exception the exception + */ + public WorkspaceItem getRootSharedFolder(String itemId) throws Exception; + + + + + + + + + + + + + + + + + + + + @@ -247,14 +277,17 @@ public interface Workspace{ */ public URLFileItem createExternalUrl(String name, String description, InputStream url, String destinationfolderId) throws InsufficientPrivilegesException, InternalErrorException, ItemAlreadyExistException, WrongDestinationException, WorkspaceFolderNotFoundException, IOException; + /** - * Remove an item. - * @param itemId the item to remove. - * @throws ItemNotFoundException if the item has not been found. - * @throws InternalErrorException if an internal error occurs. - * @throws InsufficientPrivilegesException if the user don't have sufficient privileges to perform this operation. + * Delete item. + * + * @param itemId the item id + * @throws ItemNotFoundException the item not found exception + * @throws InternalErrorException the internal error exception + * @throws InsufficientPrivilegesException the insufficient privileges exception + * @throws Exception the exception */ - public void removeItem(String itemId) throws ItemNotFoundException, InternalErrorException, InsufficientPrivilegesException; + public void deleteItem(String itemId) throws ItemNotFoundException, InternalErrorException, InsufficientPrivilegesException, Exception; /** * Move a workspaceItem to a specified destination.