Updated method as List<Member> getSharedFolderMembers

This commit is contained in:
Francesco Mangiacrapa 2022-04-29 17:34:01 +02:00
parent 6ef3fe98bc
commit 4081445ef7
6 changed files with 127 additions and 23 deletions

View File

@ -3,7 +3,7 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.1.2-SNAPSHOT] - 2022-04-28
## [v1.2.0-SNAPSHOT] - 2022-04-28
#### Enhancements

View File

@ -11,7 +11,7 @@
</parent>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-wrapper</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<name>storagehub-client-wrapper</name>
<description>This is a wrapper of storagehub-client library. It allows to interact with storagehub in a simplified way by exposing several utilities. Moreover, It exposes by another inteface java beans as defined in (the old) HL interfaces</description>
<scm>

View File

@ -19,6 +19,7 @@ import org.gcube.common.storagehub.client.dsl.ListResolver;
import org.gcube.common.storagehub.client.dsl.ListResolverTyped;
import org.gcube.common.storagehub.client.dsl.OpenResolver;
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
import org.gcube.common.storagehub.client.dsl.Util;
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
@ -38,6 +39,8 @@ import org.gcube.common.storagehub.model.items.nodes.ImageContent;
import org.gcube.common.storagehub.model.service.Version;
import org.gcube.common.storagehubwrapper.server.converter.HLMapper;
import org.gcube.common.storagehubwrapper.shared.ACLType;
import org.gcube.common.storagehubwrapper.shared.Member;
import org.gcube.common.storagehubwrapper.shared.Member.TYPE;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException;
import org.slf4j.Logger;
@ -568,37 +571,38 @@ public class StorageHubClientService {
* @return the shared folder members
* @throws Exception the exception
*/
public List<String> getSharedFolderMembers(String folderId) throws Exception {
public List<Member> getSharedFolderMembers(String folderId) throws Exception {
setContextProviders(scope, authorizationToken);
Item item = getItem(folderId, false, true);
List<String> users = null;
List<Member> members = null;
if (item instanceof SharedFolder) {
SharedFolder sharedFolder = (SharedFolder) item;
String vreGroupName = null;
if (sharedFolder.isVreFolder()) {
logger.info("Reading users from VRE folder by shClient.getVreFolderManager");
users = shClient.getVreFolderManager(sharedFolder.getTitle()).getUsers();
if (users == null) {
logger.warn("No users found, returning empty list of logins");
return new ArrayList<String>(1);
}
} else {
logger.info("Reading users from ACLs");
List<ACL> listACL = shClient.open(folderId).asFolder().getAcls();
if (listACL == null) {
throw new Exception("The item with " + folderId + " has not a valid ACLs");
}
users = new ArrayList<String>(listACL.size());
for (ACL acl : listACL) {
users.add(acl.getPricipal());
vreGroupName = Util.getVREGroupFromContext(scope);
logger.info("vreGroupName is: " + vreGroupName);
}
logger.info("Reading users from ACLs");
List<ACL> listACL = shClient.open(folderId).asFolder().getAcls();
if (listACL == null) {
throw new Exception("The item with " + folderId + " has not a valid ACLs");
}
members = new ArrayList<Member>(listACL.size());
for (ACL acl : listACL) {
Member member = new Member(acl.getPricipal(), Member.TYPE.USER);
if (vreGroupName != null && item.getTitle() != null && item.getTitle().compareTo(vreGroupName) == 0) {
member.setMemberType(TYPE.GROUP);
}
}
} else {
throw new Exception("The item with " + folderId + " is not a Shared Folder");
}
logger.info("Returning " + users.size() + " user/s");
return users;
logger.info("Returning " + members.size() + " user/s");
return members;
}

View File

@ -27,6 +27,7 @@ import org.gcube.common.storagehub.model.service.Version;
import org.gcube.common.storagehubwrapper.server.converter.HLMapper;
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
import org.gcube.common.storagehubwrapper.shared.ACLType;
import org.gcube.common.storagehubwrapper.shared.Member;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InsufficientPrivilegesException;
@ -684,7 +685,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
* @see org.gcube.portal.storagehubwrapper.server.tohl.Workspace#getSharedFolderMembers(java.lang.String)
*/
@Override
public List<String> getSharedFolderMembers(String folderId) throws Exception {
public List<Member> getSharedFolderMembers(String folderId) throws Exception {
try{
LOGGER.debug("called Shared Folder Members");

View File

@ -13,6 +13,7 @@ import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.items.nodes.accounting.AccountEntry;
import org.gcube.common.storagehubwrapper.server.WorkspaceStorageHubClientService;
import org.gcube.common.storagehubwrapper.shared.ACLType;
import org.gcube.common.storagehubwrapper.shared.Member;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
@ -193,7 +194,7 @@ public interface Workspace {
* @return the shared folder members
* @throws Exception the exception
*/
public List<String> getSharedFolderMembers(String folderid) throws Exception;
public List<Member> getSharedFolderMembers(String folderid) throws Exception;
/**
* Check if an item with the specified name exists in the specified folder.

View File

@ -0,0 +1,98 @@
package org.gcube.common.storagehubwrapper.shared;
import java.io.Serializable;
/**
* The Class Member.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 29, 2022
*/
public class Member implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1454948336452658186L;
/**
* The Enum TYPE.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 29, 2022
*/
public static enum TYPE {
USER, GROUP
}
private String identity;
private TYPE memberType;
/**
* Instantiates a new member.
*/
public Member() {
}
public Member(String identity, TYPE memberType) {
super();
this.identity = identity;
this.memberType = memberType;
}
/**
* Gets the identity.
*
* @return the identity
*/
public String getIdentity() {
return identity;
}
/**
* Gets the member type.
*
* @return the member type
*/
public TYPE getMemberType() {
return memberType;
}
/**
* Sets the identity.
*
* @param identity the new identity
*/
public void setIdentity(String identity) {
this.identity = identity;
}
/**
* Sets the member type.
*
* @param memberType the new member type
*/
public void setMemberType(TYPE memberType) {
this.memberType = memberType;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Member [identity=");
builder.append(identity);
builder.append(", memberType=");
builder.append(memberType);
builder.append("]");
return builder.toString();
}
}