git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@169449 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-06-26 13:45:52 +00:00
parent 9a7ac83e67
commit d0d4b47c56
3 changed files with 40 additions and 30 deletions

View File

@ -17,6 +17,8 @@ import org.gcube.common.storagehub.model.acls.ACL;
import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.items.SharedFolder;
import org.gcube.common.storagehubwrapper.server.converter.ObjectMapper;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -69,7 +71,7 @@ public class StorageHubClientService {
* Gets the root.
*
* @return the root
* @throws Exception
* @throws Exception the exception
*/
public FolderItem getRoot() throws Exception {
setContextProviders(scope, authorizationToken);
@ -96,7 +98,6 @@ public class StorageHubClientService {
* Gets the children.
*
* @param id the id
* @param excludeNodes the exclude nodes
* @return the children
*/
public List<? extends Item> getChildren(String id){
@ -110,7 +111,7 @@ public class StorageHubClientService {
*
* @param itemId the item id
* @return the item
* @throws Exception
* @throws Exception the exception
*/
public Item getItem(String itemId) throws Exception{
setContextProviders(scope, authorizationToken);
@ -139,7 +140,7 @@ public class StorageHubClientService {
* @param folderName the folder name
* @param folderDescription the folder description
* @return the item
* @throws Exception
* @throws Exception the exception
*/
public Item createFolder(String parentId, String folderName, String folderDescription) throws Exception {
setContextProviders(scope, authorizationToken);
@ -175,10 +176,11 @@ public class StorageHubClientService {
/**
* Gets the user acl for folder id.
*
* @param request the request
* @param infrastructureName the infrastructure name
* @param userName the user name
* @param folderId the folder id
* @return the user acl for folder id
* @throws Exception
* @throws Exception the exception
*/
public String getUserACLForFolderId(String infrastructureName, String userName, String folderId) throws Exception {
setContextProviders(scope, authorizationToken);
@ -241,6 +243,30 @@ public class StorageHubClientService {
}
}
/**
* Gets the shared folder members.
*
* @param folderId the folder id
* @return the shared folder members
* @throws Exception the exception
*/
public List<String> getSharedFolderMembers(String folderId) throws Exception {
Item item;
try {
item = getItem(folderId);
if(item instanceof SharedFolder){
return ObjectMapper.toListLogins((SharedFolder)item);
}else
throw new Exception("The item with "+folderId+ " is not a Shared Folder");
}catch (Exception e) {
logger.error("Error during get item with id: "+folderId,e);
throw new ItemNotFoundException(e.getMessage());
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/

View File

@ -12,10 +12,8 @@ import java.util.Map;
import org.apache.commons.lang.Validate;
import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.items.SharedFolder;
import org.gcube.common.storagehub.model.types.GenericItemType;
import org.gcube.common.storagehubwrapper.server.converter.HLMapper;
import org.gcube.common.storagehubwrapper.server.converter.PortalMapper;
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
import org.gcube.common.storagehubwrapper.shared.ACLType;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
@ -400,23 +398,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
public List<String> getSharedFolderMembers(String folderId) throws Exception {
Validate.notNull(folderId,"The input folderid is null");
Item item;
try {
item = storageHubClientService.getItem(folderId);
}catch (Exception e) {
logger.error("Error during get item with id: "+folderId,e);
throw new ItemNotFoundException(e.getMessage());
}
Validate.notNull(item, "The item with id "+folderId+" was not found");
if(item instanceof SharedFolder){
return PortalMapper.toWorkspaceSharedFolderMembers((SharedFolder)item);
}else
throw new Exception("The item with "+folderId+ " is not a Shared Folder");
return storageHubClientService.getSharedFolderMembers(folderId);
}

View File

@ -13,23 +13,25 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class PortalMapper.
* The Class ObjectMapper.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Jun 26, 2018
*/
public class PortalMapper {
public class ObjectMapper {
private static Logger logger = LoggerFactory.getLogger(ObjectMapper.class);
private static Logger logger = LoggerFactory.getLogger(PortalMapper.class);
/**
* To workspace shared folder members.
* To list logins.
*
* @param sharedfolder the sharedfolder
* @return the list
*/
public static List<String> toWorkspaceSharedFolderMembers(SharedFolder sharedfolder){
public static List<String> toListLogins(SharedFolder sharedfolder){
Metadata users = sharedfolder.getUsers();
Map<String, Object> mapMember = users.getValues();