From 19d2937aee767e0ab3ee48572c56e8e714549e1f Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Mon, 2 Jul 2018 10:10:12 +0000 Subject: [PATCH] added method getRootSharedFolder git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@169592 82a268e6-3cf1-43bd-a215-b396298e98cf --- .project | 4 +- .settings/org.eclipse.wst.validation.prefs | 2 + .../server/StorageHubClientService.java | 40 ++++++++++++++----- 3 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 .settings/org.eclipse.wst.validation.prefs diff --git a/.project b/.project index 123276e..783743b 100644 --- a/.project +++ b/.project @@ -16,12 +16,12 @@ - org.eclipse.m2e.core.maven2Builder + org.eclipse.wst.validation.validationbuilder - org.eclipse.wst.validation.validationbuilder + org.eclipse.m2e.core.maven2Builder diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 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 2c7205f..5ef7cea 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java @@ -135,23 +135,40 @@ public class StorageHubClientService { //TODO MAP OF SHARED ROOT ID + /** - * Gets the parents. + * Gets the id shared folder. * * @param itemId the item id - * @return the parents + * @return the id shared folder + * @throws Exception */ - public String getIdSharedFolder(String itemId) { + public String getIdSharedFolder(String itemId) throws Exception { setContextProviders(scope, authorizationToken); - FolderContainer rootSharedFolder = shcClient.open(itemId).asItem().getRootSharedFolder(); - try{ - Validate.notNull(rootSharedFolder, "The root shared folder with id "+itemId+" does not exist"); - return rootSharedFolder.get().getId(); - }catch(Exception e){ + return getRootSharedFolder(itemId).getId(); + } - } - return null; + /** + * Gets the root shared folder. + * + * @param itemId the item id + * @return the root shared folder + * @throws Exception + */ + public FolderItem getRootSharedFolder(String itemId) throws Exception { + setContextProviders(scope, authorizationToken); + + ItemContainer item = shcClient.open(itemId).asItem(); + FolderContainer rootSharedFolder = null; + if(item.get().isShared()){ + rootSharedFolder = item.getRootSharedFolder(); + }else + throw new Exception("The item with id: "+itemId +" is not shared"); + + Validate.notNull(rootSharedFolder, "The root shared folder with id "+itemId+" does not exist"); + return rootSharedFolder.get(); + } @@ -189,7 +206,8 @@ public class StorageHubClientService { return null; } }catch (Exception e) { - e.printStackTrace(); + logger.error("Get VRE Folders Id ",e); + //e.printStackTrace(); } return toReturn; }