From ecf5bb095000577557ebdf46c57746f7204218ba Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Mon, 16 Sep 2019 10:25:15 +0000 Subject: [PATCH] Added method canWrite to interface git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@181696 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../server/StorageHubClientService.java | 16 ++++++++++++- .../WorkspaceStorageHubClientService.java | 24 +++++++++++++++---- .../server/tohl/Workspace.java | 9 +++++++ 3 files changed, 43 insertions(+), 6 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 9b043e5..1db8708 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java @@ -305,7 +305,21 @@ public class StorageHubClientService { return shcClient.open(itemId).asItem().get().isShared(); } + + + /** + * Can write. + * + * @param folderContainerId the folder container id + * @return true, if true. Otherwise false. + * @throws Exception the exception + */ + public boolean canWrite(String folderContainerId) throws Exception { + setContextProviders(scope, authorizationToken); + return shcClient.open(folderContainerId).asFolder().canWrite(); + } + /** * Gets the root shared folder. * @@ -849,7 +863,7 @@ public class StorageHubClientService { * @param folderId the folder id * @param setPublic the set public * @return boolean value of isPublicItem() - * @throws Exception + * @throws Exception the exception */ public boolean setFolderAsPublic(String folderId, boolean setPublic) throws Exception { Validate.notNull(folderId, "Bad request to setFolderAsPublic the folderId is null"); 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 cc0613d..b773650 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java @@ -1071,10 +1071,8 @@ public final class WorkspaceStorageHubClientService implements Workspace{ return HLMapper.toURLFile(extLink); } - - - - + + /* (non-Javadoc) * @see org.gcube.common.storagehubwrapper.server.tohl.Workspace#setFolderAsPublic(java.lang.String, boolean) */ @@ -1097,7 +1095,23 @@ public final class WorkspaceStorageHubClientService implements Workspace{ }else throw new Exception("The item with id '"+folderId+"' is not a folder"); } - + + /** + * Can user write into folder. + * + * @param folderId the folder id + * @return true, if successful + * @throws Exception the exception + */ + @Override + public boolean canUserWriteIntoFolder(String folderId) throws Exception{ + + WorkspaceItem item = getItem(folderId); + if (item.isFolder()) { + return storageHubClientService.canWrite(folderId); + }else + throw new Exception("The item with id '"+folderId+"' is not a folder"); + } 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 dcb1a8e..2d1185a 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 @@ -489,6 +489,15 @@ public interface Workspace{ InternalErrorException, ItemAlreadyExistException, InsufficientPrivilegesException, Exception; + /** + * Can user write into folder. + * + * @param folderId the folder id + * @return true, if successful + * @throws Exception the exception + */ + boolean canUserWriteIntoFolder(String folderId) throws Exception; + /* * *