method for VRE Administrators management added

This commit is contained in:
lucio 2020-01-15 19:10:33 +01:00
parent c036bb3d95
commit 9732195398
10 changed files with 184 additions and 24 deletions

View File

@ -64,12 +64,10 @@
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.24.1</version>
</dependency>
<dependency>

View File

@ -35,8 +35,12 @@ public class StorageHubClient {
return new ListResolver((onlyType, includeHidden, excludes) -> wsClient.getVreFolders(excludes), itemclient);
}
public VREFolderManager getVreFolderManager(String vreTitle) {
return new VREFolderManager(wsClient, groupClient, vreTitle);
}
public VREFolderManager getVreFolderManager() {
return new VREFolderManager(wsClient, groupClient);
return new VREFolderManager(wsClient, groupClient, null);
}
public FolderContainer openTrash() {

View File

@ -1,6 +1,10 @@
package org.gcube.common.storagehub.client.dsl;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item;
@ -14,4 +18,11 @@ public class Util {
return new FolderContainer(itemClient, (FolderItem)item);
else return new GenericItemContainer(itemClient, item);
}
public static String getVREGroupFromContext(String context) throws BackendGenericError{
ScopeBean bean = new ScopeBean(context);
if (!bean.is(Type.VRE)) throw new BackendGenericError(context+ " is not a VRE context");
String entireScopeName= bean.toString().replaceAll("^/(.*)/?$", "$1").replaceAll("/", "-");
return entireScopeName;
}
}

View File

@ -1,5 +1,7 @@
package org.gcube.common.storagehub.client.dsl;
import java.util.List;
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
import org.gcube.common.storagehub.model.Excludes;
@ -11,26 +13,41 @@ public class VREFolderManager {
private WorkspaceManagerClient wsClient;
private GroupManagerClient groupClient;
public VREFolderManager(WorkspaceManagerClient wsClient, GroupManagerClient groupClient) {
private String vreTitle;
public VREFolderManager(WorkspaceManagerClient wsClient, GroupManagerClient groupClient, String vreTitle) {
super();
this.wsClient = wsClient;
this.groupClient = groupClient;
this.vreTitle = vreTitle;
}
public void removeUser(String userId) throws StorageHubException{
groupClient.removeUserFromGroup(userId, getVreFolder().getTitle());
groupClient.removeUserFromGroup(userId, vreTitle);
}
public void addUser(String userId) throws StorageHubException{
groupClient.addUserToGroup(userId, getVreFolder().getTitle());
groupClient.addUserToGroup(userId, vreTitle);
}
public void getUsers() throws StorageHubException{
getVreFolder();
groupClient.getUsersOfGroup(getVreFolder().getTitle());
public List<String> getUsers() throws StorageHubException{
return groupClient.getUsersOfGroup(vreTitle);
}
private Item getVreFolder() {
return wsClient.getVreFolder(Excludes.ALL.toArray(new String[0]));
}
public void setAdmin(String userId) throws StorageHubException{
groupClient.addAdmin(vreTitle, userId);
}
public void removeAdmin(String userId) throws StorageHubException{
groupClient.removeAdmin(vreTitle, userId);
}
public List<String> getAdmins() throws StorageHubException{
return groupClient.getAdmins(vreTitle);
}
}

View File

@ -33,7 +33,7 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
formData.add("userId", userId);
GXInboundResponse response = myManager.path(groupId).put(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
GXInboundResponse response = myManager.path(groupId).path("users").put(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
if (response.isErrorResponse()) {
if (response.hasException())
@ -204,4 +204,92 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
}
}
@Override
public void addAdmin(String groupId, String userId) throws StorageHubException {
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
@Override
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
GXWebTargetAdapterRequest myManager = manager;
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
formData.add("userId", userId);
GXInboundResponse response = myManager.path(groupId).path("admins").put(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
if (response.isErrorResponse()) {
if (response.hasException())
throw response.getException();
else
throw new BackendGenericError();
}
return null;
}
};
try {
delegate.make(call);
}catch(Exception e) {
throw new RuntimeException(e);
}
}
@Override
public void removeAdmin(String groupId, String userId) throws StorageHubException {
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
@Override
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
GXWebTargetAdapterRequest myManager = manager;
GXInboundResponse response = myManager.path(groupId).path("admins").path(userId).delete();
if (response.isErrorResponse()) {
if (response.hasException())
throw response.getException();
else
throw new BackendGenericError();
}
return null;
}
};
try {
delegate.make(call);
return;
}catch(StorageHubException e) {
throw e;
}catch(Exception e1) {
throw new RuntimeException(e1);
}
}
@Override
public List<String> getAdmins(String groupId) throws StorageHubException {
Call<GXWebTargetAdapterRequest, List<String>> call = new Call<GXWebTargetAdapterRequest, List<String>>() {
@Override
public List<String> call(GXWebTargetAdapterRequest manager) throws Exception {
GXWebTargetAdapterRequest myManager = manager;
GXInboundResponse response = myManager.path(groupId).path("admins").get();
if (response.isErrorResponse()) {
if (response.hasException())
throw response.getException();
else
throw new BackendGenericError();
}
return response.getSource().readEntity(List.class);
}
};
try {
List<String> users = delegate.make(call);
return users;
}catch(Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -1007,9 +1007,8 @@ public class DefaultItemManager implements ItemManagerClient {
}
/*
@Override
public String removeSharedFolderAdmin(String id, String user) throws StorageHubException {
public String removeAdmin(String id, String user) throws StorageHubException {
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
@Override
public String call(GXWebTargetAdapterRequest manager) throws Exception {
@ -1041,7 +1040,7 @@ public class DefaultItemManager implements ItemManagerClient {
}catch(Exception e1) {
throw new RuntimeException(e1);
}
}*/
}
@Override

View File

@ -18,4 +18,11 @@ public interface GroupManagerClient {
List<String> getUsersOfGroup(String groupId) throws StorageHubException;
List<String> getGroups() throws StorageHubException;
void addAdmin(String groupId, String userId) throws StorageHubException;
void removeAdmin(String groupId, String userId) throws StorageHubException;
List<String> getAdmins(String groupId) throws StorageHubException;
}

View File

@ -49,10 +49,8 @@ public interface ItemManagerClient {
String changeACL(String id, String user, AccessType accessType) throws StorageHubException;
/*
String removeSharedFolderAdmin(String id, String user) throws StorageHubException;
*/
String removeAdmin(String id, String user) throws StorageHubException;
@Deprecated
void delete(String id) throws StorageHubException;

View File

@ -7,7 +7,9 @@ import java.io.FileOutputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
@ -46,6 +48,27 @@ public class Items {
shc.getVreFolderManager().addUser("andrea.rossi");
}
@Test
public void getAdminsFromVRE() throws StorageHubException {
StorageHubClient shc = new StorageHubClient();
for (String user: shc.getVreFolderManager().getAdmins()) {
System.out.println(user);
}
}
@Test
public void removeAdminsFromVRE() throws StorageHubException {
StorageHubClient shc = new StorageHubClient();
shc.getVreFolderManager().removeAdmin("vfloros");
}
@Test
public void addAdminToVRE() throws StorageHubException {
StorageHubClient shc = new StorageHubClient();
shc.getVreFolderManager().setAdmin("vfloros");
}
@Test
public void emptyStatisticaManagerTrash() {
StorageHubClient shc = new StorageHubClient();
@ -56,14 +79,26 @@ public class Items {
public void forceDelete() throws Exception{
StorageHubClient shc = new StorageHubClient();
/*
shc.getWSRoot().newFolder("lucioFolderTestMeta","desclucio" );
HashMap<String, Object> prop = new HashMap<>();
prop.put("folderProp", "test2");
prop.put("folderProp2", "test2");
*/
FolderContainer fc = shc.open("bfb0548b-92d0-47d4-a973-1253dc4694d1").asFolder();
List<ItemContainer<? extends Item>> children = fc.list().withMetadata().getContainers();
for (ItemContainer<? extends Item> cont : children) {
Metadata m = cont.get().getMetadata();
for (Object v : m.getMap().values())
System.out.println(v.toString());
}
long count = shc.getTotalItemCount();
long volume = shc.getTotalVolume();
System.out.println("items are "+count+" volume "+volume);
}

View File

@ -25,6 +25,7 @@ import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
import org.gcube.common.storagehub.model.Metadata;
import org.gcube.common.storagehub.model.Paths;
@ -55,8 +56,8 @@ public class TestCall {
@BeforeClass
public static void setUp(){
SecurityTokenProvider.instance.set("d9431600-9fef-41a7-946d-a5b402de30d6-98187548");
ScopeProvider.instance.set("/gcube");
SecurityTokenProvider.instance.set("490eed48-dee3-478d-a856-cfb1132c1b92-843339462");
ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
}
@Test
@ -325,6 +326,8 @@ public class TestCall {
boolean b = m.find();
System.out.println("result: "+!b);
}
/* private InputStream getThumbnailAsPng(ImagePlus img, int thumbWidth,
int thumbHeight) throws IOException {