method for VRE Administrators management added
This commit is contained in:
parent
c036bb3d95
commit
9732195398
2
pom.xml
2
pom.xml
|
@ -64,12 +64,10 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.media</groupId>
|
<groupId>org.glassfish.jersey.media</groupId>
|
||||||
<artifactId>jersey-media-json-jackson</artifactId>
|
<artifactId>jersey-media-json-jackson</artifactId>
|
||||||
<version>2.24.1</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.media</groupId>
|
<groupId>org.glassfish.jersey.media</groupId>
|
||||||
<artifactId>jersey-media-multipart</artifactId>
|
<artifactId>jersey-media-multipart</artifactId>
|
||||||
<version>2.24.1</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -35,8 +35,12 @@ public class StorageHubClient {
|
||||||
return new ListResolver((onlyType, includeHidden, excludes) -> wsClient.getVreFolders(excludes), itemclient);
|
return new ListResolver((onlyType, includeHidden, excludes) -> wsClient.getVreFolders(excludes), itemclient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public VREFolderManager getVreFolderManager(String vreTitle) {
|
||||||
|
return new VREFolderManager(wsClient, groupClient, vreTitle);
|
||||||
|
}
|
||||||
|
|
||||||
public VREFolderManager getVreFolderManager() {
|
public VREFolderManager getVreFolderManager() {
|
||||||
return new VREFolderManager(wsClient, groupClient);
|
return new VREFolderManager(wsClient, groupClient, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FolderContainer openTrash() {
|
public FolderContainer openTrash() {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package org.gcube.common.storagehub.client.dsl;
|
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.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.AbstractFileItem;
|
||||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
@ -14,4 +18,11 @@ public class Util {
|
||||||
return new FolderContainer(itemClient, (FolderItem)item);
|
return new FolderContainer(itemClient, (FolderItem)item);
|
||||||
else return new GenericItemContainer(itemClient, 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.common.storagehub.client.dsl;
|
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.GroupManagerClient;
|
||||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||||
import org.gcube.common.storagehub.model.Excludes;
|
import org.gcube.common.storagehub.model.Excludes;
|
||||||
|
@ -11,26 +13,41 @@ public class VREFolderManager {
|
||||||
private WorkspaceManagerClient wsClient;
|
private WorkspaceManagerClient wsClient;
|
||||||
private GroupManagerClient groupClient;
|
private GroupManagerClient groupClient;
|
||||||
|
|
||||||
public VREFolderManager(WorkspaceManagerClient wsClient, GroupManagerClient groupClient) {
|
private String vreTitle;
|
||||||
|
|
||||||
|
public VREFolderManager(WorkspaceManagerClient wsClient, GroupManagerClient groupClient, String vreTitle) {
|
||||||
super();
|
super();
|
||||||
this.wsClient = wsClient;
|
this.wsClient = wsClient;
|
||||||
this.groupClient = groupClient;
|
this.groupClient = groupClient;
|
||||||
|
this.vreTitle = vreTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeUser(String userId) throws StorageHubException{
|
public void removeUser(String userId) throws StorageHubException{
|
||||||
groupClient.removeUserFromGroup(userId, getVreFolder().getTitle());
|
groupClient.removeUserFromGroup(userId, vreTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUser(String userId) throws StorageHubException{
|
public void addUser(String userId) throws StorageHubException{
|
||||||
groupClient.addUserToGroup(userId, getVreFolder().getTitle());
|
groupClient.addUserToGroup(userId, vreTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getUsers() throws StorageHubException{
|
public List<String> getUsers() throws StorageHubException{
|
||||||
getVreFolder();
|
return groupClient.getUsersOfGroup(vreTitle);
|
||||||
groupClient.getUsersOfGroup(getVreFolder().getTitle());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Item getVreFolder() {
|
private Item getVreFolder() {
|
||||||
return wsClient.getVreFolder(Excludes.ALL.toArray(new String[0]));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
|
||||||
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
||||||
formData.add("userId", userId);
|
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.isErrorResponse()) {
|
||||||
if (response.hasException())
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1007,9 +1007,8 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
@Override
|
@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>() {
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
@ -1041,7 +1040,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
}catch(Exception e1) {
|
}catch(Exception e1) {
|
||||||
throw new RuntimeException(e1);
|
throw new RuntimeException(e1);
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,4 +18,11 @@ public interface GroupManagerClient {
|
||||||
List<String> getUsersOfGroup(String groupId) throws StorageHubException;
|
List<String> getUsersOfGroup(String groupId) throws StorageHubException;
|
||||||
|
|
||||||
List<String> getGroups() 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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,9 +49,7 @@ public interface ItemManagerClient {
|
||||||
|
|
||||||
String changeACL(String id, String user, AccessType accessType) throws StorageHubException;
|
String changeACL(String id, String user, AccessType accessType) throws StorageHubException;
|
||||||
|
|
||||||
/*
|
String removeAdmin(String id, String user) throws StorageHubException;
|
||||||
String removeSharedFolderAdmin(String id, String user) throws StorageHubException;
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
void delete(String id) throws StorageHubException;
|
void delete(String id) throws StorageHubException;
|
||||||
|
|
|
@ -7,7 +7,9 @@ import java.io.FileOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
@ -46,6 +48,27 @@ public class Items {
|
||||||
shc.getVreFolderManager().addUser("andrea.rossi");
|
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
|
@Test
|
||||||
public void emptyStatisticaManagerTrash() {
|
public void emptyStatisticaManagerTrash() {
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
@ -56,14 +79,26 @@ public class Items {
|
||||||
public void forceDelete() throws Exception{
|
public void forceDelete() throws Exception{
|
||||||
|
|
||||||
StorageHubClient shc = new StorageHubClient();
|
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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.plugins.AbstractPlugin;
|
||||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
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.client.proxies.WorkspaceManagerClient;
|
||||||
import org.gcube.common.storagehub.model.Metadata;
|
import org.gcube.common.storagehub.model.Metadata;
|
||||||
import org.gcube.common.storagehub.model.Paths;
|
import org.gcube.common.storagehub.model.Paths;
|
||||||
|
@ -55,8 +56,8 @@ public class TestCall {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp(){
|
public static void setUp(){
|
||||||
SecurityTokenProvider.instance.set("d9431600-9fef-41a7-946d-a5b402de30d6-98187548");
|
SecurityTokenProvider.instance.set("490eed48-dee3-478d-a856-cfb1132c1b92-843339462");
|
||||||
ScopeProvider.instance.set("/gcube");
|
ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -326,6 +327,8 @@ public class TestCall {
|
||||||
System.out.println("result: "+!b);
|
System.out.println("result: "+!b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* private InputStream getThumbnailAsPng(ImagePlus img, int thumbWidth,
|
/* private InputStream getThumbnailAsPng(ImagePlus img, int thumbWidth,
|
||||||
int thumbHeight) throws IOException {
|
int thumbHeight) throws IOException {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue