#23225 Updated the getSharedFolderMembers method

This commit is contained in:
Francesco Mangiacrapa 2022-04-28 11:29:25 +02:00
parent ad890bf313
commit 6ef3fe98bc
8 changed files with 472 additions and 481 deletions

View File

@ -13,6 +13,7 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -32,6 +33,7 @@
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes> <attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>

View File

@ -1,7 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="storagehub-client-wrapper"> <wb-module deploy-name="storagehub-client-wrapper">
<wb-resource deploy-path="/" source-path="/src/main/java"/> <wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/> <wb-resource deploy-path="/" source-path="/src/main/resources"/>
<wb-resource deploy-path="/" source-path="/.apt_generated"/> <wb-resource deploy-path="/" source-path="/.apt_generated"/>
</wb-module> </wb-module>
</project-modules> </project-modules>

View File

@ -3,11 +3,11 @@
All notable changes to this project will be documented in this file. 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). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1-1-1-SNAPSHOT] - 2022-03-08 ## [v1.1.2-SNAPSHOT] - 2022-04-28
#### Enhancements #### Enhancements
[#22782] Moved to SHUB(1.x, 3.x) - [#23225] Updated the method to read the members of VREs
## [v1-1-0] - 2021-05-12 ## [v1-1-0] - 2021-05-12

10
pom.xml
View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
@ -10,7 +11,7 @@
</parent> </parent>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-wrapper</artifactId> <artifactId>storagehub-client-wrapper</artifactId>
<version>1.1.1-SNAPSHOT</version> <version>1.1.2-SNAPSHOT</version>
<name>storagehub-client-wrapper</name> <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> <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> <scm>
@ -19,9 +20,12 @@
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url> <url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm> </scm>
<properties> <properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<distroDirectory>distro</distroDirectory> <distroDirectory>distro</distroDirectory>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
@ -88,6 +92,7 @@
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version> <version>1.6.4</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -96,6 +101,7 @@
<version>4.12</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<resources> <resources>

View File

@ -2,6 +2,7 @@ package org.gcube.common.storagehubwrapper.server;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -36,14 +37,12 @@ import org.gcube.common.storagehub.model.items.nodes.Accounting;
import org.gcube.common.storagehub.model.items.nodes.ImageContent; import org.gcube.common.storagehub.model.items.nodes.ImageContent;
import org.gcube.common.storagehub.model.service.Version; import org.gcube.common.storagehub.model.service.Version;
import org.gcube.common.storagehubwrapper.server.converter.HLMapper; import org.gcube.common.storagehubwrapper.server.converter.HLMapper;
import org.gcube.common.storagehubwrapper.server.converter.ObjectMapper;
import org.gcube.common.storagehubwrapper.shared.ACLType; import org.gcube.common.storagehubwrapper.shared.ACLType;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException; import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc // TODO: Auto-generated Javadoc
/** /**
* The Class StorageHubClientService. * The Class StorageHubClientService.
@ -53,7 +52,6 @@ import org.slf4j.LoggerFactory;
*/ */
public class StorageHubClientService { public class StorageHubClientService {
/** The logger. */ /** The logger. */
private static Logger logger = LoggerFactory.getLogger(StorageHubClientService.class); private static Logger logger = LoggerFactory.getLogger(StorageHubClientService.class);
@ -66,10 +64,8 @@ public class StorageHubClientService {
/** The authorization token. */ /** The authorization token. */
private String authorizationToken; private String authorizationToken;
private StorageHubClient shClient; private StorageHubClient shClient;
/** /**
* Instantiates a new storage hub service util. * Instantiates a new storage hub service util.
* *
@ -95,7 +91,8 @@ public class StorageHubClientService {
private void setContextProviders(String scope, String authorizationToken) { private void setContextProviders(String scope, String authorizationToken) {
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken); SecurityTokenProvider.instance.set(authorizationToken);
logger.debug("Saved the contexts [scope: "+scope+", token: "+authorizationToken.substring(0,15)+"-MASKED]"); logger.debug(
"Saved the contexts [scope: " + scope + ", token: " + authorizationToken.substring(0, 15) + "-MASKED]");
} }
/** /**
@ -122,7 +119,6 @@ public class StorageHubClientService {
return trash; return trash;
} }
/** /**
* Gets the children. * Gets the children.
* *
@ -132,9 +128,11 @@ public class StorageHubClientService {
* @return the children * @return the children
* @throws Exception the exception * @throws Exception the exception
*/ */
public List<? extends Item> getChildren(String id, boolean withAccounting, boolean withMapProperties) throws Exception{ public List<? extends Item> getChildren(String id, boolean withAccounting, boolean withMapProperties)
throws Exception {
setContextProviders(scope, authorizationToken); setContextProviders(scope, authorizationToken);
logger.trace("Requesting getChildren for id: "+id+" [withAccounting: "+withAccounting+", withMapProperties: "+withMapProperties+"]"); logger.trace("Requesting getChildren for id: " + id + " [withAccounting: " + withAccounting
+ ", withMapProperties: " + withMapProperties + "]");
ListResolverTyped resolverTyped = shClient.open(id).asFolder().list(); ListResolverTyped resolverTyped = shClient.open(id).asFolder().list();
ListResolver theResolver = resolverTyped.withContent(); ListResolver theResolver = resolverTyped.withContent();
@ -157,9 +155,11 @@ public class StorageHubClientService {
* @return the children * @return the children
* @throws Exception the exception * @throws Exception the exception
*/ */
public List<? extends Item> getChildren(String id, boolean withAccounting, boolean withMapProperties, boolean includeHidden) throws Exception{ public List<? extends Item> getChildren(String id, boolean withAccounting, boolean withMapProperties,
boolean includeHidden) throws Exception {
setContextProviders(scope, authorizationToken); setContextProviders(scope, authorizationToken);
logger.trace("Requesting getChildren for id: "+id+" [withAccounting: "+withAccounting+", withMapProperties: "+withMapProperties+"]"); logger.trace("Requesting getChildren for id: " + id + " [withAccounting: " + withAccounting
+ ", withMapProperties: " + withMapProperties + "]");
if (!includeHidden) { if (!includeHidden) {
return getChildren(id, withAccounting, withMapProperties); return getChildren(id, withAccounting, withMapProperties);
} }
@ -176,7 +176,6 @@ public class StorageHubClientService {
} }
/** /**
* Gets the filtered children. * Gets the filtered children.
* *
@ -187,7 +186,8 @@ public class StorageHubClientService {
* @return the filtered children * @return the filtered children
* @throws Exception the exception * @throws Exception the exception
*/ */
public List<? extends Item> getFilteredChildren(String id, Class<? extends Item> aType, boolean withAccounting, boolean withMapProperties) throws Exception{ public List<? extends Item> getFilteredChildren(String id, Class<? extends Item> aType, boolean withAccounting,
boolean withMapProperties) throws Exception {
setContextProviders(scope, authorizationToken); setContextProviders(scope, authorizationToken);
ListResolver resolverTyped = shClient.open(id).asFolder().list().ofType(aType); ListResolver resolverTyped = shClient.open(id).asFolder().list().ofType(aType);
@ -202,7 +202,6 @@ public class StorageHubClientService {
return theResolver.getItems(); return theResolver.getItems();
} }
/** /**
* Gets the item. * Gets the item.
* *
@ -221,13 +220,13 @@ public class StorageHubClientService {
itemCont = shClient.open(itemId).asItem(); // TODO itemCont = shClient.open(itemId).asItem(); // TODO
} else if (withAccounting) { } else if (withAccounting) {
itemCont = shClient.open(itemId).asItem(); // TODO itemCont = shClient.open(itemId).asItem(); // TODO
} } else {
else {
itemCont = shClient.open(itemId).asItem(); itemCont = shClient.open(itemId).asItem();
} }
return itemCont.get(); return itemCont.get();
} }
/** /**
* *
* @param folderId * @param folderId
@ -260,8 +259,6 @@ public class StorageHubClientService {
return getItem(itemId, false, true); return getItem(itemId, false, true);
} }
/** /**
* Sets the metadata and returns the Item with metadata updated. * Sets the metadata and returns the Item with metadata updated.
* *
@ -277,8 +274,6 @@ public class StorageHubClientService {
return itemCont.get(); return itemCont.get();
} }
/** /**
* Gets the metadata. * Gets the metadata.
* *
@ -296,7 +291,6 @@ public class StorageHubClientService {
return null; return null;
} }
/** /**
* Gets the folder container. * Gets the folder container.
* *
@ -309,7 +303,6 @@ public class StorageHubClientService {
return shClient.open(itemId).asFolder(); return shClient.open(itemId).asFolder();
} }
/** /**
* Gets the parents. * Gets the parents.
* *
@ -329,7 +322,6 @@ public class StorageHubClientService {
// TODO MAP OF SHARED ROOT ID // TODO MAP OF SHARED ROOT ID
/** /**
* Gets the id shared folder. * Gets the id shared folder.
* *
@ -342,7 +334,6 @@ public class StorageHubClientService {
return getRootSharedFolder(itemId).getId(); return getRootSharedFolder(itemId).getId();
} }
/** /**
* Gets the root shared folder. * Gets the root shared folder.
* *
@ -356,7 +347,6 @@ public class StorageHubClientService {
} }
/** /**
* Checks if is item shared. * Checks if is item shared.
* *
@ -370,7 +360,6 @@ public class StorageHubClientService {
} }
/** /**
* Can write. * Can write.
* *
@ -383,7 +372,6 @@ public class StorageHubClientService {
return shClient.open(folderContainerId).asFolder().canWrite(); return shClient.open(folderContainerId).asFolder().canWrite();
} }
/** /**
* Gets the root shared folder. * Gets the root shared folder.
* *
@ -400,7 +388,8 @@ public class StorageHubClientService {
} else } else
throw new Exception("The item with id: " + item.getId() + " is not shared"); throw new Exception("The item with id: " + item.getId() + " is not shared");
Validate.notNull(rootSharedFolder, "The root shared folder with children id "+item.getId()+" does not exist"); Validate.notNull(rootSharedFolder,
"The root shared folder with children id " + item.getId() + " does not exist");
return rootSharedFolder.get(); return rootSharedFolder.get();
} }
@ -419,7 +408,6 @@ public class StorageHubClientService {
return getItem(folderContainer.get().getId(), false, true); return getItem(folderContainer.get().getId(), false, true);
} }
/** /**
* Gets the VRE folders id. * Gets the VRE folders id.
* *
@ -445,9 +433,6 @@ public class StorageHubClientService {
return toReturn; return toReturn;
} }
/** /**
* Gets the user acl for folder id. * Gets the user acl for folder id.
* *
@ -468,7 +453,8 @@ public class StorageHubClientService {
List<ACL> acls = client.getACL(folderId); List<ACL> acls = client.getACL(folderId);
SharedFolder sharedFolder = (SharedFolder) theFolder; SharedFolder sharedFolder = (SharedFolder) theFolder;
boolean found = false; //this is needed because in case o VRE Foder the permission is assigned to the group and not to the user. boolean found = false; // this is needed because in case o VRE Foder the permission is assigned to the
// group and not to the user.
for (ACL acl : acls) { for (ACL acl : acls) {
if (acl.getPricipal().compareTo(userName) == 0) { if (acl.getPricipal().compareTo(userName) == 0) {
found = true; found = true;
@ -477,7 +463,8 @@ public class StorageHubClientService {
} }
if (!found && sharedFolder.isVreFolder()) { if (!found && sharedFolder.isVreFolder()) {
for (ACL acl : acls) { for (ACL acl : acls) {
if (acl.getPricipal().startsWith(infrastructureName)); if (acl.getPricipal().startsWith(infrastructureName))
;
return acl.getAccessTypes().get(0).toString(); return acl.getAccessTypes().get(0).toString();
} }
} }
@ -485,7 +472,6 @@ public class StorageHubClientService {
return "UNDEFINED"; return "UNDEFINED";
} }
/** /**
* Gets the item children count. * Gets the item children count.
* *
@ -517,18 +503,18 @@ public class StorageHubClientService {
return fileCont.get(); return fileCont.get();
} }
/** /**
* Download file. * Download file.
* *
* @param itemId the item id * @param itemId the item id
* @param versionName the version name. If is null or empty returns the latest version of file * @param versionName the version name. If is null or empty returns the
* latest version of file
* @param nodeIdsToExclude the node ids to exclude * @param nodeIdsToExclude the node ids to exclude
* @return the stream descriptor * @return the stream descriptor
* @throws Exception the exception * @throws Exception the exception
*/ */
public StreamDescriptor downloadFile(String itemId, String versionName, String... nodeIdsToExclude) throws Exception{ public StreamDescriptor downloadFile(String itemId, String versionName, String... nodeIdsToExclude)
throws Exception {
setContextProviders(scope, authorizationToken); setContextProviders(scope, authorizationToken);
StreamDescriptor streamDesc; StreamDescriptor streamDesc;
@ -537,11 +523,11 @@ public class StorageHubClientService {
} else { } else {
streamDesc = shClient.open(itemId).asFile().download(nodeIdsToExclude); streamDesc = shClient.open(itemId).asFile().download(nodeIdsToExclude);
} }
return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName(), streamDesc.getContentType(), streamDesc.getContentLenght()); return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName(), streamDesc.getContentType(),
streamDesc.getContentLenght());
} }
/** /**
* Download folder. * Download folder.
* *
@ -554,12 +540,11 @@ public class StorageHubClientService {
setContextProviders(scope, authorizationToken); setContextProviders(scope, authorizationToken);
StreamDescriptor streamDesc = shClient.open(folderId).asFolder().download(nodeIdsToExclude); StreamDescriptor streamDesc = shClient.open(folderId).asFolder().download(nodeIdsToExclude);
return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName(), streamDesc.getContentType(), streamDesc.getContentLenght()); return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName(), streamDesc.getContentType(),
streamDesc.getContentLenght());
} }
/** /**
* Upload archive. * Upload archive.
* *
@ -576,8 +561,6 @@ public class StorageHubClientService {
return folderCont.get(); return folderCont.get();
} }
/** /**
* Gets the shared folder members. * Gets the shared folder members.
* *
@ -589,13 +572,35 @@ public class StorageHubClientService {
setContextProviders(scope, authorizationToken); setContextProviders(scope, authorizationToken);
Item item = getItem(folderId, false, true); Item item = getItem(folderId, false, true);
List<String> users = null;
if (item instanceof SharedFolder) { if (item instanceof SharedFolder) {
return ObjectMapper.toListLogins((SharedFolder)item); SharedFolder sharedFolder = (SharedFolder) item;
}else 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());
}
}
} else {
throw new Exception("The item with " + folderId + " is not a Shared Folder"); throw new Exception("The item with " + folderId + " is not a Shared Folder");
} }
logger.info("Returning " + users.size() + " user/s");
return users;
}
/** /**
* Find by name. * Find by name.
@ -621,8 +626,6 @@ public class StorageHubClientService {
throw new Exception("The input folder id is not a folder"); throw new Exception("The input folder id is not a folder");
} }
/** /**
* Search for text. * Search for text.
* *
@ -648,8 +651,6 @@ public class StorageHubClientService {
throw new Exception("The input folder id is not a folder"); throw new Exception("The input folder id is not a folder");
} }
/** /**
* Delete item by id. * Delete item by id.
* *
@ -664,8 +665,6 @@ public class StorageHubClientService {
} }
/** /**
* Open trash. * Open trash.
* *
@ -679,8 +678,6 @@ public class StorageHubClientService {
} }
/** /**
* Empty trash. * Empty trash.
* *
@ -693,7 +690,6 @@ public class StorageHubClientService {
} }
/** /**
* Restore thrash item. * Restore thrash item.
* *
@ -724,7 +720,6 @@ public class StorageHubClientService {
} }
/** /**
* Move item. * Move item.
* *
@ -743,7 +738,6 @@ public class StorageHubClientService {
} }
/** /**
* Copy item. * Copy item.
* *
@ -753,18 +747,19 @@ public class StorageHubClientService {
* @return the abstract file item * @return the abstract file item
* @throws Exception the exception * @throws Exception the exception
*/ */
public AbstractFileItem copyFileItem(String fileItemId, FolderContainer destFolderContainer, String newFileName) throws Exception{ public AbstractFileItem copyFileItem(String fileItemId, FolderContainer destFolderContainer, String newFileName)
throws Exception {
Validate.notNull(fileItemId, "Bad request to copyFileItem, the fileItemId is null"); Validate.notNull(fileItemId, "Bad request to copyFileItem, the fileItemId is null");
Validate.notNull(destFolderContainer, "Bad request to copyFileItem, the destFolderContainer is null"); Validate.notNull(destFolderContainer, "Bad request to copyFileItem, the destFolderContainer is null");
setContextProviders(scope, authorizationToken); setContextProviders(scope, authorizationToken);
FileContainer copyingItem = shClient.open(fileItemId).asFile(); FileContainer copyingItem = shClient.open(fileItemId).asFile();
String newName = newFileName!=null && !newFileName.isEmpty()?newFileName:"Copy of "+copyingItem.get().getName(); String newName = newFileName != null && !newFileName.isEmpty() ? newFileName
: "Copy of " + copyingItem.get().getName();
FileContainer newItem = copyingItem.copy(destFolderContainer, newName); FileContainer newItem = copyingItem.copy(destFolderContainer, newName);
return newItem.get(); return newItem.get();
} }
/** /**
* Rename item. * Rename item.
* *
@ -782,7 +777,6 @@ public class StorageHubClientService {
} }
/** /**
* Gets the file public link. * Gets the file public link.
* *
@ -798,7 +792,6 @@ public class StorageHubClientService {
} }
/** /**
* Gets the public link for file version. * Gets the public link for file version.
* *
@ -817,7 +810,6 @@ public class StorageHubClientService {
} }
/** /**
* Gets the list versions. * Gets the list versions.
* *
@ -853,7 +845,6 @@ public class StorageHubClientService {
throw new Exception("Thumbnail Data is not available for type: " + item.getClass().getSimpleName()); throw new Exception("Thumbnail Data is not available for type: " + item.getClass().getSimpleName());
} }
/** /**
* Gets the total items. * Gets the total items.
* *
@ -866,7 +857,6 @@ public class StorageHubClientService {
return shClient.getTotalItemCount(); return shClient.getTotalItemCount();
} }
/** /**
* Gets the disk usage. * Gets the disk usage.
* *
@ -894,7 +884,6 @@ public class StorageHubClientService {
return item.getAccounting(); return item.getAccounting();
} }
/** /**
* Gets the gcube item properties. * Gets the gcube item properties.
* *
@ -912,11 +901,10 @@ public class StorageHubClientService {
GCubeItem theGcubeItem = (GCubeItem) item; GCubeItem theGcubeItem = (GCubeItem) item;
return theGcubeItem.getMetadata(); return theGcubeItem.getMetadata();
} else } else
throw new Exception("The item with id "+gcubeItemId+" is not an istance of "+GCubeItem.class.getSimpleName()); throw new Exception(
"The item with id " + gcubeItemId + " is not an istance of " + GCubeItem.class.getSimpleName());
} }
/** /**
* Sets the metadata. * Sets the metadata.
* *
@ -933,7 +921,6 @@ public class StorageHubClientService {
shClient.open(itemId).asItem().setMetadata(new Metadata(mapProperties)); shClient.open(itemId).asItem().setMetadata(new Metadata(mapProperties));
} }
/** /**
* Sets the Folder As Hidden or visible . * Sets the Folder As Hidden or visible .
* *
@ -951,7 +938,6 @@ public class StorageHubClientService {
folderContainer.setVisible(); // will appear in the workspace GUI folderContainer.setVisible(); // will appear in the workspace GUI
} }
/** /**
* *
* @param folderId the folder id to share * @param folderId the folder id to share
@ -1016,7 +1002,6 @@ public class StorageHubClientService {
return folder.addUrl(URL, name, description).get(); return folder.addUrl(URL, name, description).get();
} }
/** /**
* Sets the folder as public. * Sets the folder as public.
* *
@ -1041,7 +1026,6 @@ public class StorageHubClientService {
return shClient.open(folderId).asFolder().get().isPublicItem(); return shClient.open(folderId).asFolder().get().isPublicItem();
} }
/** /**
* Update description for item. * Update description for item.
* *
@ -1059,13 +1043,14 @@ public class StorageHubClientService {
} }
/** /**
* To string. * To string.
* *
* @return the string * @return the string
*/ */
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@Override @Override
@ -1082,6 +1067,4 @@ public class StorageHubClientService {
return builder.toString(); return builder.toString();
} }
} }

View File

@ -39,7 +39,6 @@ import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItemType;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class HLMapper. * The Class HLMapper.
* *
@ -50,19 +49,6 @@ public class HLMapper {
private static Logger logger = LoggerFactory.getLogger(HLMapper.class); private static Logger logger = LoggerFactory.getLogger(HLMapper.class);
// public static Function<org.gcube.common.storagehub.model.items.nodes.accounting.AccountEntry, AccountingEntry> toAccountingEntry = new Function<org.gcube.common.storagehub.model.items.nodes.accounting.AccountEntry, AccountingEntry>() {
//
// public AccountingEntry apply(org.gcube.common.storagehub.model.items.nodes.accounting.AccountEntry accountingEntry) {
//
// return new AccountingEntry(
// accountingEntry.getUser(),
// accountingEntry.getDate(),
// accountingEntry.getType(),
// accountingEntry.getVersion(),
// accountingEntry.getPrimaryType());
// }
// }
/** /**
* To URL file. * To URL file.
* *
@ -74,7 +60,6 @@ public class HLMapper {
return (URLFile) toWorkspaceItem(extLink, false, false, false); return (URLFile) toWorkspaceItem(extLink, false, false, false);
} }
/** /**
* To workspace item. * To workspace item.
* *
@ -88,8 +73,6 @@ public class HLMapper {
return toWorkspaceItem(item, false, false, false); return toWorkspaceItem(item, false, false, false);
} }
/** /**
* To accounting entries. * To accounting entries.
* *
@ -103,16 +86,11 @@ public class HLMapper {
Accounting accounting = item.getAccounting(); Accounting accounting = item.getAccounting();
if (accounting != null) { if (accounting != null) {
accountingEntries = accounting.getEntries(); accountingEntries = accounting.getEntries();
// for (AccountEntry ae : accounting.getEntries()) {
// accountingEntries.add(toAccountingEntry.apply(ae));
// }
} }
return accountingEntries; return accountingEntries;
} }
/** /**
* To property map. * To property map.
* *
@ -132,7 +110,6 @@ public class HLMapper {
return pm; return pm;
} }
/** /**
* To workspace file version. * To workspace file version.
* *
@ -160,7 +137,8 @@ public class HLMapper {
* @return the t * @return the t
* @throws Exception the exception * @throws Exception the exception
*/ */
public static<T extends WorkspaceItem> T toWorkspaceItem(Item item, boolean withAccounting, boolean withFileDetails, boolean withMapProperties) throws Exception{ public static <T extends WorkspaceItem> T toWorkspaceItem(Item item, boolean withAccounting,
boolean withFileDetails, boolean withMapProperties) throws Exception {
try { try {
List<AccountEntry> accountingEntries = null; List<AccountEntry> accountingEntries = null;
@ -188,12 +166,14 @@ public class HLMapper {
SharedFolder sharedfolder = (SharedFolder) item; // ?? SharedFolder sharedfolder = (SharedFolder) item; // ??
theItem = new WorkspaceSharedFolder(); theItem = new WorkspaceSharedFolder();
type = WorkspaceItemType.SHARED_FOLDER; type = WorkspaceItemType.SHARED_FOLDER;
itemName = sharedfolder.getTitle(); //IN CASE OF SHARED FOLDER THE NAME IS AN UUID, I'M USING THE TITLE itemName = sharedfolder.getTitle(); // IN CASE OF SHARED FOLDER THE NAME IS AN UUID, I'M USING THE
// TITLE
if (sharedfolder.isVreFolder()) { if (sharedfolder.isVreFolder()) {
// logger.debug("Converting shared folder: "+theItem.getClass()); // logger.debug("Converting shared folder: "+theItem.getClass());
// VreFolder vreFolder = (VreFolder) item; // VreFolder vreFolder = (VreFolder) item;
//theItem = new WorkspaceVREFolder(); //NEVER INSTANCE THE WorkspaceVREFolder because VreFolder is never used by HL/StorageHub // theItem = new WorkspaceVREFolder(); //NEVER INSTANCE THE WorkspaceVREFolder
// because VreFolder is never used by HL/StorageHub
itemName = sharedfolder.getDisplayName(); // IN CASE OF VRE FOLDER I'M USING THE DISPLAYNAME itemName = sharedfolder.getDisplayName(); // IN CASE OF VRE FOLDER I'M USING THE DISPLAYNAME
((WorkspaceSharedFolder) theItem).setVreFolder(true); ((WorkspaceSharedFolder) theItem).setVreFolder(true);
type = WorkspaceItemType.VRE_FOLDER; type = WorkspaceItemType.VRE_FOLDER;
@ -204,7 +184,8 @@ public class HLMapper {
// ((WorkspaceFolder) theItem).setPublicFolder(folderItem.isPublicItem()); // ((WorkspaceFolder) theItem).setPublicFolder(folderItem.isPublicItem());
// logger.debug("Wrapped as Folder"); // logger.debug("Wrapped as Folder");
//TODO THIS MUST BE REMOVED. Checking the old property isPublic added as "<boolean>true</boolean>" by HL // TODO THIS MUST BE REMOVED. Checking the old property isPublic added as
// "<boolean>true</boolean>" by HL
if (!isPublicItem) { if (!isPublicItem) {
try { try {
// Map<String, Object> map = item.getPropertyMap().getValues(); // Map<String, Object> map = item.getPropertyMap().getValues();
@ -372,10 +353,6 @@ public class HLMapper {
throw e; throw e;
} }
} }
} }

1
src/test/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/resources/

View File

@ -14,30 +14,25 @@ import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeEx
import org.gcube.common.storagehubwrapper.shared.tohl.impl.FileItem; import org.gcube.common.storagehubwrapper.shared.tohl.impl.FileItem;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.ImageFile; import org.gcube.common.storagehubwrapper.shared.tohl.impl.ImageFile;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.PDFFile; import org.gcube.common.storagehubwrapper.shared.tohl.impl.PDFFile;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/** /**
* *
*/ */
/** /**
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 20, 2018
* Jun 20, 2018
*/ */
public class WorkspaceInstance { public class WorkspaceInstance {
public static String SCOPE = "/gcube"; // public static String SCOPE = "/gcube";
//public static String SCOPE = "/d4science.research-infrastructures.eu"; public static String SCOPE = "/d4science.research-infrastructures.eu";
// public static String USERNAME = "massimiliano.assante"; // public static String USERNAME = "massimiliano.assante";
public static String USERNAME = "francesco.mangiacrapa"; public static String USERNAME = "francesco.mangiacrapa";
public static String TOKEN = System.getenv("TOKEN_gcube"); // YOU MUST SET THIS AS Environment variable public static String TOKEN = System.getenv("TOKEN_gcube"); // YOU MUST SET THIS AS Environment variable
public static String FIND_FILE_NAME = "francesco"; public static String FIND_FILE_NAME = "francesco";
public static String rootId = null; public static String rootId = null;
private StorageHubWrapper storageHubWrapper = null; private StorageHubWrapper storageHubWrapper = null;
@ -49,7 +44,6 @@ public class WorkspaceInstance {
if (TOKEN == null) { if (TOKEN == null) {
System.err.println("You must set the token as Environment variable"); System.err.println("You must set the token as Environment variable");
return;
} }
System.out.println("Read TOKEN_gcube: " + TOKEN); System.out.println("Read TOKEN_gcube: " + TOKEN);
@ -74,8 +68,7 @@ public class WorkspaceInstance {
root = storageHubWrapper.getWorkspace().getRoot(); root = storageHubWrapper.getWorkspace().getRoot();
rootId = root.getId(); rootId = root.getId();
System.out.println("The root is:" + root); System.out.println("The root is:" + root);
} } catch (Exception e) {
catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
@ -94,7 +87,8 @@ public class WorkspaceInstance {
int i = 0; int i = 0;
for (WorkspaceItem workspaceItem : children) { for (WorkspaceItem workspaceItem : children) {
System.out.println(++i+")"+workspaceItem.getId() + " name: "+workspaceItem.getName() + " type: "+workspaceItem.getType() +" class: "+workspaceItem.getClass()); System.out.println(++i + ")" + workspaceItem.getId() + " name: " + workspaceItem.getName() + " type: "
+ workspaceItem.getType() + " class: " + workspaceItem.getClass());
} }
} }
@ -109,20 +103,21 @@ public class WorkspaceInstance {
int i = 0; int i = 0;
for (WorkspaceItem workspaceItem : children) { for (WorkspaceItem workspaceItem : children) {
if (workspaceItem.isShared()) { if (workspaceItem.isShared()) {
System.out.println(++i+")"+workspaceItem.getId() + " name: "+workspaceItem.getName() + " type: "+workspaceItem.getPath()); System.out.println(++i + ")" + workspaceItem.getId() + " name: " + workspaceItem.getName() + " type: "
+ workspaceItem.getPath());
} }
} }
} }
// @Test // @Test
public void getFilteredChildren() throws Exception { public void getFilteredChildren() throws Exception {
System.out.println("Get children test"); System.out.println("Get children test");
WorkspaceFolder root = storageHubWrapper.getWorkspace().getRoot(); WorkspaceFolder root = storageHubWrapper.getWorkspace().getRoot();
Class filterClass = org.gcube.common.storagehub.model.items.FolderItem.class; Class filterClass = org.gcube.common.storagehub.model.items.FolderItem.class;
List<? extends WorkspaceItem> children = storageHubWrapper.getWorkspace().getFilteredChildren(root.getId(), filterClass); List<? extends WorkspaceItem> children = storageHubWrapper.getWorkspace().getFilteredChildren(root.getId(),
filterClass);
// WorkspaceFolder root = workspace.getRoot(); // WorkspaceFolder root = workspace.getRoot();
// List<? extends WorkspaceItem> children = workspace.getChildren(root.getId()); // List<? extends WorkspaceItem> children = workspace.getChildren(root.getId());
@ -132,7 +127,6 @@ public class WorkspaceInstance {
System.out.println(++i + ")" + workspaceItem); System.out.println(++i + ")" + workspaceItem);
System.out.println(workspaceItem.getType() + " " + workspaceItem.getClass()); System.out.println(workspaceItem.getType() + " " + workspaceItem.getClass());
// System.out.println(++i+")"); // System.out.println(++i+")");
// if(workspaceItem.isFolder()){ // if(workspaceItem.isFolder()){
// WorkspaceFolder folder = (WorkspaceFolder) workspaceItem; // WorkspaceFolder folder = (WorkspaceFolder) workspaceItem;
@ -147,7 +141,8 @@ public class WorkspaceInstance {
public static void printMap(WorkspaceItem workspaceItem) { public static void printMap(WorkspaceItem workspaceItem) {
if (workspaceItem.getPropertyMap() != null) { if (workspaceItem.getPropertyMap() != null) {
System.out.println(workspaceItem.getId() + " name: "+workspaceItem.getName() + " isFolder: "+workspaceItem.isFolder()); System.out.println(workspaceItem.getId() + " name: " + workspaceItem.getName() + " isFolder: "
+ workspaceItem.isFolder());
System.out.println("Property Map: " + workspaceItem.getPropertyMap().getValues().toString()); System.out.println("Property Map: " + workspaceItem.getPropertyMap().getValues().toString());
} }
} }
@ -170,6 +165,22 @@ public class WorkspaceInstance {
} }
} }
@Test
public void getSharedFolderMembers() {
System.out.println("Getting getSharedFolderMembers");
try {
String sharedFolderId = "b679c6fe-894c-4c4c-aebc-4155321a373a";
storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN);
List<String> listLogins = storageHubWrapper.getWorkspace().getSharedFolderMembers(sharedFolderId);
System.out.println("List: " + listLogins);
} catch (Exception e) {
e.printStackTrace();
}
}
// @Test // @Test
public void getChildrenPerWorkspaceItem() throws InternalErrorException { public void getChildrenPerWorkspaceItem() throws InternalErrorException {
System.out.println("Get children test per workspace item"); System.out.println("Get children test per workspace item");
@ -205,7 +216,8 @@ public class WorkspaceInstance {
case PDF_DOCUMENT: case PDF_DOCUMENT:
PDFFile pdfFile = (PDFFile) fileItem; PDFFile pdfFile = (PDFFile) fileItem;
System.out.println("PDF_DOCUMENT " + pdfFile); System.out.println("PDF_DOCUMENT " + pdfFile);
PDFFile completeItem = (PDFFile) storageHubWrapper.getWorkspace().getItem(fileItem.getId(), true, true, true); PDFFile completeItem = (PDFFile) storageHubWrapper.getWorkspace().getItem(fileItem.getId(),
true, true, true);
System.out.println(completeItem); System.out.println(completeItem);
break; break;
case IMAGE_DOCUMENT: case IMAGE_DOCUMENT:
@ -218,15 +230,13 @@ public class WorkspaceInstance {
System.out.println(fileItem.getFileItemType() + " " + workspaceItem.getClass()); System.out.println(fileItem.getFileItemType() + " " + workspaceItem.getClass());
break; break;
default: default:
break; break;
} }
} }
} }
} } catch (Exception e) {
catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
@ -238,7 +248,8 @@ public class WorkspaceInstance {
System.out.println("Find file name test"); System.out.println("Find file name test");
getRoot(); getRoot();
try { try {
//List<WorkspaceItem> foundItems = storageHubWrapper.getWorkspace().find(FIND_FILE_NAME,rootId); // List<WorkspaceItem> foundItems =
// storageHubWrapper.getWorkspace().find(FIND_FILE_NAME,rootId);
List<? extends WorkspaceItem> foundItems = workspace.find(FIND_FILE_NAME, rootId); List<? extends WorkspaceItem> foundItems = workspace.find(FIND_FILE_NAME, rootId);
if (foundItems == null || foundItems.size() == 0) { if (foundItems == null || foundItems.size() == 0) {
@ -250,8 +261,7 @@ public class WorkspaceInstance {
for (WorkspaceItem workspaceItem : foundItems) { for (WorkspaceItem workspaceItem : foundItems) {
System.out.println(workspaceItem); System.out.println(workspaceItem);
} }
} } catch (ItemNotFoundException | WrongItemTypeException e) {
catch (ItemNotFoundException | WrongItemTypeException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }