From 9d59308a2187fe7ba6192293ddd42e6fc9c338e6 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Mon, 9 Sep 2019 14:29:40 +0000 Subject: [PATCH] set acl added to folder git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@181588 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/dsl/FolderContainer.java | 43 ++++++++++++++++++- .../client/plugins/ItemManagerPlugin.java | 2 + .../client/proxies/DefaultItemManager.java | 41 +++++++++++++++++- .../proxies/DefaultWorkspaceManager.java | 1 + .../client/proxies/ItemManagerClient.java | 2 +- .../java/org/gcube/data/access/fs/Items.java | 35 +++++++-------- 6 files changed, 102 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/gcube/common/storagehub/client/dsl/FolderContainer.java b/src/main/java/org/gcube/common/storagehub/client/dsl/FolderContainer.java index f59e77c..2186d9b 100644 --- a/src/main/java/org/gcube/common/storagehub/client/dsl/FolderContainer.java +++ b/src/main/java/org/gcube/common/storagehub/client/dsl/FolderContainer.java @@ -145,6 +145,19 @@ public class FolderContainer extends ItemContainer{ return itemclient.getACL(this.itemId); } + /** + * + * changes {@ACL} of the {FolderItem} represented by this FolderContainer for a user + * + * @return the {@FolderContainer} + * @throws {@InvalidItemException} + * @throws {@UserNotAuthorizedException} if user is not administrator of this folder + */ + public FolderContainer changeAcls(String user, AccessType accessType) throws StorageHubException { + itemclient.changeACL(this.itemId, user, accessType); + return this; + } + public boolean canWrite() throws Exception { return itemclient.canWriteInto(this.itemId); } @@ -179,7 +192,7 @@ public class FolderContainer extends ItemContainer{ /** * - * remove share form this Folder for a list of users, for everyone or only for the caller. Is applicable only on {@SharedFolder}. + * remove share from this Folder for a list of users, for everyone or only for the caller. Is applicable only on {@SharedFolder}. * if users is empty or null unshare the entire folder for everyone. * if users contains only the caller login the folder is removed only for him. * @@ -192,4 +205,32 @@ public class FolderContainer extends ItemContainer{ return new FolderContainer(itemclient, unsharedId); } + /** + * + * unpublish this Folder. + * + * @return the current {@FolderContainer} updated + * @throws {@InvalidCallParameter} if this is not a Folder + * @throws {@UserNotAuthorizedException} if user is not authorized to unpublish this folder + */ + public FolderContainer unpublish() throws Exception { + itemclient.setPublic(this.itemId, false); + this.invalidateItem(); + return this; + } + + /** + * + * makes this Folder public. + * + * @return the current {@FolderContainer} updated + * @throws {@InvalidCallParameter} if this is not a Folder + * @throws {@UserNotAuthorizedException} if user is not authorized to publish this folder + */ + public FolderContainer publish() throws Exception { + itemclient.setPublic(this.itemId, true); + this.invalidateItem(); + return this; + } + } diff --git a/src/main/java/org/gcube/common/storagehub/client/plugins/ItemManagerPlugin.java b/src/main/java/org/gcube/common/storagehub/client/plugins/ItemManagerPlugin.java index 708bfa2..085c38c 100644 --- a/src/main/java/org/gcube/common/storagehub/client/plugins/ItemManagerPlugin.java +++ b/src/main/java/org/gcube/common/storagehub/client/plugins/ItemManagerPlugin.java @@ -13,6 +13,7 @@ import org.gcube.common.storagehub.client.Constants; import org.gcube.common.storagehub.client.MyInputStreamProvider; import org.gcube.common.storagehub.client.proxies.DefaultItemManager; import org.gcube.common.storagehub.client.proxies.ItemManagerClient; +import org.glassfish.jersey.media.multipart.MultiPartFeature; import org.w3c.dom.Node; public class ItemManagerPlugin extends AbstractPlugin { @@ -44,6 +45,7 @@ public class ItemManagerPlugin extends AbstractPlugin call = new Call() { + @Override + public String call(GXWebTargetAdapterRequest manager) throws Exception { + Objects.requireNonNull(id, "id cannot be null"); + + GXWebTargetAdapterRequest myManager = manager.path(id) + .path("publish"); + + MultivaluedMap formData = new MultivaluedHashMap(); + formData.add("publish", Boolean.toString(publish)); + + + GXInboundResponse response = myManager.put(Entity.form(formData)); + + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } + + return response.getSource().readEntity(String.class); + } + }; + try { + return delegate.make(call); + }catch(StorageHubException e) { + throw e; + }catch(Exception e1) { + throw new RuntimeException(e1); + } + } + + @Override public String move(String id, String destinationFolderId) throws StorageHubException { Call call = new Call() { diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java index ee90cd1..4698814 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java @@ -370,6 +370,7 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient { } }; try { + return Long.parseLong(delegate.make(call)); }catch(Exception e) { throw new RuntimeException(e); diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/ItemManagerClient.java b/src/main/java/org/gcube/common/storagehub/client/proxies/ItemManagerClient.java index 498b812..4a55db0 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/ItemManagerClient.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/ItemManagerClient.java @@ -98,6 +98,6 @@ public interface ItemManagerClient { boolean canWriteInto(String id) throws StorageHubException; - + String setPublic(String id, boolean publish) throws StorageHubException; } diff --git a/src/test/java/org/gcube/data/access/fs/Items.java b/src/test/java/org/gcube/data/access/fs/Items.java index a3dda48..d90ab20 100644 --- a/src/test/java/org/gcube/data/access/fs/Items.java +++ b/src/test/java/org/gcube/data/access/fs/Items.java @@ -1,21 +1,16 @@ package org.gcube.data.access.fs; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; -import java.net.URI; -import java.net.URL; import java.nio.file.Files; import java.util.Arrays; -import java.util.Collections; import java.util.HashSet; -import java.util.List; import java.util.Map.Entry; -import java.util.Set; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.storagehub.client.StreamDescriptor; import org.gcube.common.storagehub.client.dsl.FileContainer; @@ -25,12 +20,7 @@ import org.gcube.common.storagehub.client.dsl.StorageHubClient; import org.gcube.common.storagehub.model.Metadata; import org.gcube.common.storagehub.model.acls.AccessType; import org.gcube.common.storagehub.model.exceptions.StorageHubException; -import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException; -import org.gcube.common.storagehub.model.items.FolderItem; import org.gcube.common.storagehub.model.items.Item; -import org.gcube.resources.discovery.client.api.DiscoveryClient; -import org.gcube.resources.discovery.client.queries.api.SimpleQuery; -import org.gcube.resources.discovery.icclient.ICFactory; import org.junit.BeforeClass; import org.junit.Test; @@ -58,10 +48,21 @@ public class Items { - shc.getWSRoot().addUrl(new URI("https://www.youtube.com/watch?v=bGef_U0S7Uo").toURL(), "video test 3", "video test descr 3"); + long count = shc.getTotalItemCount(); + + System.out.println("ims are "+count); } + @Test + public void changeAcls() throws Exception{ + + StorageHubClient shc = new StorageHubClient(); + + shc.open("2ca7e04a-b461-4098-a8b9-a31ddb691a2d").asFolder().changeAcls("giancarlo.panichi", AccessType.READ_ONLY); + + + } @@ -122,12 +123,8 @@ public class Items { public void download() throws Exception { StorageHubClient shc = new StorageHubClient(); - FolderContainer openResolver = shc.open("894d23bf-e2e9-42b6-a781-b99bb18119c8").asFolder(); - - openResolver.getAnchestors(); - - /* - StreamDescriptor streamDescr = openResolver.download(); + + StreamDescriptor streamDescr = shc.open("a5bcf8b8-d149-42c2-92be-7f671223eba4").asFile().downloadSpecificVersion("1.2"); File output = Files.createTempFile("down", streamDescr.getFileName()).toFile(); @@ -140,7 +137,7 @@ public class Items { } System.out.println("file written "+output.getAbsolutePath()); - */ + } @Test