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
This commit is contained in:
Lucio Lelii 2019-09-09 14:29:40 +00:00
parent d2baa2dda7
commit 9d59308a21
6 changed files with 102 additions and 22 deletions

View File

@ -145,6 +145,19 @@ public class FolderContainer extends ItemContainer<FolderItem>{
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<FolderItem>{
/**
*
* 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<FolderItem>{
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;
}
}

View File

@ -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<GXWebTargetAdapterRequest, ItemManagerClient> {
@ -44,6 +45,7 @@ public class ItemManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest,
GXWebTargetAdapterRequest requestAdapter = TargetFactory.stubFor(service).getAsGxRest(address);
requestAdapter.register(SerializableErrorEntityTextReader.class);
requestAdapter.register(MyInputStreamProvider.class);
requestAdapter.register(MultiPartFeature.class);
return requestAdapter;
}

View File

@ -979,7 +979,7 @@ public class DefaultItemManager implements ItemManagerClient {
GXWebTargetAdapterRequest myManager = manager.path(id).path("acls");
try (FormDataMultiPart multipart = new FormDataMultiPart()){
multipart.field("accessType", accessType, MediaType.APPLICATION_JSON_TYPE);
multipart.field("access", accessType, MediaType.APPLICATION_JSON_TYPE);
multipart.field("user", user);
GXInboundResponse response = myManager.put(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
@ -1043,6 +1043,45 @@ public class DefaultItemManager implements ItemManagerClient {
}
}
@Override
public String setPublic(String id, boolean publish) throws StorageHubException {
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
@Override
public String call(GXWebTargetAdapterRequest manager) throws Exception {
Objects.requireNonNull(id, "id cannot be null");
GXWebTargetAdapterRequest myManager = manager.path(id)
.path("publish");
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
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<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {

View File

@ -370,6 +370,7 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
}
};
try {
return Long.parseLong(delegate.make(call));
}catch(Exception e) {
throw new RuntimeException(e);

View File

@ -98,6 +98,6 @@ public interface ItemManagerClient {
boolean canWriteInto(String id) throws StorageHubException;
String setPublic(String id, boolean publish) throws StorageHubException;
}

View File

@ -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