Compare commits

...

31 Commits

Author SHA1 Message Date
Roberto Cirillo 1850670588 Update 'CHANGELOG.md'
removed wrong char ' " in changelog
2023-04-04 17:00:59 +02:00
Roberto Cirillo 925c938352 Update 'CHANGELOG.md'
fix changelog comment
2023-04-04 16:50:52 +02:00
Francesco Mangiacrapa 66cfd00f3f removed -SNAPSHOT to be released. 2023-04-04 12:19:26 +02:00
Francesco Mangiacrapa 16d4ecf848 Moved to gcube-bom 2.2.0-SNAPSHOT. Moved to lombok 1.18.4 2023-04-03 16:01:33 +02:00
Francesco Mangiacrapa 3e6207d7b9 Fixing incident [#24597], revisited the getSharedFolderMembers 2023-04-03 15:55:43 +02:00
Francesco Mangiacrapa 050c554845 ObjectMapper.toListLogins has been deprecated 2022-05-03 16:14:20 +02:00
Francesco Mangiacrapa 5b09af3767 Removed -SNAPSHOT to be released. Passed to gcube-bom v2.0.2 2022-05-03 15:50:16 +02:00
Francesco Mangiacrapa 0e168409a2 Merge pull request 'task_23225' (!2) from task_23225 into master
Reviewed-on: #2
2022-05-03 15:48:03 +02:00
Francesco Mangiacrapa 9ed457016b updated description 2022-05-03 15:45:24 +02:00
Francesco Mangiacrapa 3ec5bf03c5 improved JUnit test 2022-05-02 14:33:31 +02:00
Francesco Mangiacrapa ed482f9675 commented JUnit Test 2022-05-02 14:27:34 +02:00
Francesco Mangiacrapa 1d24ded221 fixed the method getSharedFolderMembers 2022-05-02 14:27:02 +02:00
Francesco Mangiacrapa 4081445ef7 Updated method as List<Member> getSharedFolderMembers 2022-04-29 17:34:01 +02:00
Francesco Mangiacrapa 6ef3fe98bc #23225 Updated the getSharedFolderMembers method 2022-04-28 11:29:25 +02:00
Francesco Mangiacrapa ad890bf313 moved to gcube-bom 2.1.0-SNAPSHOT, in order to use SHUB 2.x 2022-03-09 16:20:41 +01:00
Francesco Mangiacrapa 0deeb4b1c6 used new gcube-bom 2.0.2-SNAPSHOT, removed SHUB ranges from the pom 2022-03-09 16:10:51 +01:00
Francesco Mangiacrapa e6ed812d26 #22782 Moved to SHUB(1.x, 3.x) 2022-03-08 11:24:32 +01:00
Francesco Mangiacrapa 00bdf06ad3 removed -SNAPSHOT to be released. Moved to gcube-bom 2.0.1 2021-06-24 11:08:04 +02:00
Francesco Mangiacrapa f1af31e117 Merge pull request 'Feature #21412 Added some missing HL methods needed for performfish apps' (#1) from Feature/21319 into master
Reviewed-on: #1
2021-06-14 18:31:42 +02:00
Massimiliano Assante cc56f9889f Feature #21412 Added some missing HL methods needed for performfish apps 2021-06-14 17:09:42 +02:00
Francesco Mangiacrapa 3bf02b8d41 only added Junit Test 2021-03-03 11:19:26 +01:00
Francesco Mangiacrapa 658c89dfee removed -SNAPSHOT to be released 2020-08-25 14:25:51 +02:00
Francesco Mangiacrapa 75945888a2 fixing open from asFile to asItem 2020-07-21 17:19:51 +02:00
Francesco Mangiacrapa b66c0b3b54 updated the setDescription with open(itemId).asItem() 2020-07-20 17:32:58 +02:00
Francesco Mangiacrapa d203bf71e9 integrated with the method setDescription reported at #19652#note-1 2020-07-20 10:38:14 +02:00
Francesco Mangiacrapa bd5cfa29ea fixed exception error 2020-07-16 11:56:17 +02:00
Francesco Mangiacrapa 9fb05560e2 added CHANGELOG.md 2020-07-15 16:36:26 +02:00
Francesco Mangiacrapa 2e43e8029f implementing subtasks under #19669 2020-07-15 15:40:15 +02:00
Francesco Mangiacrapa eb703801a8 remove -SNAPSHOT to be released 2020-05-20 14:32:32 +02:00
Francesco Mangiacrapa d62d1b4c8a propagated the exception thrown by SHUB for restore and delete operation 2020-05-19 16:27:33 +02:00
Francesco Mangiacrapa 807ea16878 [#19058] added the folder destination Id to restore operation, removed
changelog.xml, added changelog.md
2020-05-18 16:53:59 +02:00
18 changed files with 1431 additions and 1347 deletions

View File

@ -13,9 +13,10 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
@ -24,21 +25,20 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<classpathentry kind="src" path=".apt_generated">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<classpathentry kind="src" output="target/test-classes" path=".apt_generated_tests">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>

2
.gitignore vendored
View File

@ -1 +1,3 @@
/target/
/.apt_generated/
/.apt_generated_tests/

View File

@ -6,7 +6,7 @@ org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.processAnnotations=enabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

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

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="1.8"/>
<installed facet="jst.utility" version="1.0"/>
<installed facet="java" version="1.8"/>
</faceted-project>

119
CHANGELOG.md Normal file
View File

@ -0,0 +1,119 @@
# Changelog for storagehub-client-wrapper
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.2.1] - 2023-04-04
- [#24597] Fixed no notification sent for items updated in the VRE Folder with score char in the name
## [v1.2.0] - 2022-05-02
#### Enhancements
- [#23225] Updated the method to read the members of (VRE or Simple) shared folders
## [v1-1-0] - 2021-05-12
#### Enhancements
[#21412] Added some methods that were missing
## [v1-0-1-SNAPSHOT] - 2021-03-03
Improved JUnit Test
## [v1-0-0]- 2020-07-15
#### Enhancements
[#19317] component moved from 0.y.z to 1.y.z version
[#19668] add the method updateDescriptionForItem
## [v0-7-1] - 2020-05-18
#### Enhancements
[#19058] added the folder destination Id to restore operation
## [v0-7-0] - 2020-04-16
#### Enhancements
[#19087] provide a getItem (without getRoot inside) for Workspace-Explorer-App
## [v0-6-2] - 2020-03-11
#### New features
[#18174] Moved to new search facility provided by SHUB
## [v0-6-1] - 2019-12-19
Ported to Git and Jenkins
## [v0-6-0] - 2019-10-01
[Task #16688] Integrating new method added into SHUB
## [v0-5-0] - 2019-08-01
Released due to exceptions thrown by SHUB
## [v0-4-0] - 2019-06-01
Updated to new SHub interface
Added method getMetadata
## [v0-3-0] - 2018-03-01
[Task #12059] added delete item
[Task #12533] added trash operations
[Task #12556] added download facility
[Task #12601] added download folder facility
[Task #12604] added Move operation to StorageHub
[Task #12603] added Copy operation to StorageHub
[Task #12603] added Rename facility to StorageHub
[Task #12603] added Public Link facility to StorageHub
[Task #12664] added Versions facility to StorageHub
[Task #12720] added Image Preview to StorageHub
## [v0-2-0] - 2018-06-20
minor fixes
## [v0-1-0] - 2018-06-20
[Task #12059] first release

View File

@ -1,53 +0,0 @@
<ReleaseNotes>
<Changeset
component="org.gcube.common.storagehubwrapper.0-7-0" date="2020-04-16">
<Change>[Task #19087] provide a getItem (without getRoot inside) for Workspace-Explorer-App
</Change>
</Changeset>
<Changeset
component="org.gcube.common.storagehubwrapper.0-6-2" date="2020-03-11">
<Change>[Feature #18174] Moved to new search facility provided by SHUB
</Change>
</Changeset>
<Changeset
component="org.gcube.common.storagehubwrapper.0-6-1" date="2019-12-19">
<Change>Updated to Git and Jenkins</Change>
</Changeset>
<Changeset
component="org.gcube.common.storagehubwrapper.0-6-0" date="2019-10-01">
<Change>[Task #16688] Integrating new method added into SHUB</Change>
</Changeset>
<Changeset
component="org.gcube.common.storagehubwrapper.0-5-0" date="2019-08-01">
<Change>Released due to exceptions thrown by SHUB</Change>
</Changeset>
<Changeset
component="org.gcube.common.storagehubwrapper.0-4-0" date="2019-06-01">
<Change>Updated to new SHub interface</Change>
<Change>Added method getMetadata</Change>
</Changeset>
<Changeset
component="org.gcube.common.storagehubwrapper.0-3-0" date="2018-03-01">
<Change>[Task #12059] added delete item</Change>
<Change>[Task #12533] added trash operations</Change>
<Change>[Task #12556] added download facility</Change>
<Change>[Task #12601] added download folder facility</Change>
<Change>[Task #12604] added Move operation to StorageHub</Change>
<Change>[Task #12603] added Copy operation to StorageHub</Change>
<Change>[Task #12603] added Rename facility to StorageHub</Change>
<Change>[Task #12603] added Public Link facility to StorageHub
</Change>
<Change>[Task #12664] added Versions facility to StorageHub
</Change>
<Change>[Task #12720] added Image Preview to StorageHub
</Change>
</Changeset>
<Changeset
component="org.gcube.common.storagehubwrapper.0-2-0" date="2018-06-20">
<Change>minor fixes</Change>
</Changeset>
<Changeset
component="org.gcube.common.storagehubwrapper.0-1-0" date="2018-06-20">
<Change>[Task #12059] first release</Change>
</Changeset>
</ReleaseNotes>

View File

@ -14,8 +14,8 @@
<includes>
<include>README.md</include>
<include>LICENSE.md</include>
<include>changelog.xml</include>
<include>profile.xml</include>
<include>CHANGELOG.md</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>

42
pom.xml
View File

@ -1,5 +1,6 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -10,7 +11,7 @@
</parent>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-wrapper</artifactId>
<version>0.7.0</version>
<version>1.2.1</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>
@ -19,15 +20,18 @@
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm>
<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>
<distroDirectory>distro</distroDirectory>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>1.4.0</version>
<version>2.3.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -51,13 +55,21 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.8</version>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-model</artifactId>
<!--<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version> -->
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
<!--<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version> -->
<scope>compile</scope>
</dependency>
@ -89,6 +101,7 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<dependency>
@ -97,6 +110,7 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
@ -143,6 +157,24 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
<additionalJOption>-Xdoclint:none</additionalJOption>
</configuration>
<version>3.1.0</version>
<executions>
<execution>
<id>generate-doc</id>
<phase>install</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -2,12 +2,15 @@ package org.gcube.common.storagehubwrapper.server;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.Validate;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.FolderContainer;
@ -15,12 +18,14 @@ import org.gcube.common.storagehub.client.dsl.GenericItemContainer;
import org.gcube.common.storagehub.client.dsl.ItemContainer;
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.plugins.AbstractPlugin;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
import org.gcube.common.storagehub.model.Metadata;
import org.gcube.common.storagehub.model.acls.ACL;
import org.gcube.common.storagehub.model.acls.AccessType;
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
import org.gcube.common.storagehub.model.items.ExternalLink;
@ -32,12 +37,15 @@ import org.gcube.common.storagehub.model.items.VreFolder;
import org.gcube.common.storagehub.model.items.nodes.Accounting;
import org.gcube.common.storagehub.model.items.nodes.ImageContent;
import org.gcube.common.storagehub.model.service.Version;
import org.gcube.common.storagehubwrapper.server.converter.ObjectMapper;
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;
import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/**
* The Class StorageHubClientService.
@ -47,7 +55,6 @@ import org.slf4j.LoggerFactory;
*/
public class StorageHubClientService {
/** The logger. */
private static Logger logger = LoggerFactory.getLogger(StorageHubClientService.class);
@ -60,9 +67,7 @@ public class StorageHubClientService {
/** The authorization token. */
private String authorizationToken;
/** The shc client. */
private StorageHubClient shcClient;
private StorageHubClient shClient;
/**
* Instantiates a new storage hub service util.
@ -76,7 +81,7 @@ public class StorageHubClientService {
this.scope = scope;
this.authorizationToken = authorizationToken;
setContextProviders(scope, authorizationToken);
shcClient = new StorageHubClient();
shClient = new StorageHubClient();
logger.info("Instancied the " + StorageHubClientService.class.getSimpleName() + " as: " + this.toString());
}
@ -89,7 +94,8 @@ public class StorageHubClientService {
private void setContextProviders(String scope, String authorizationToken) {
ScopeProvider.instance.set(scope);
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]");
}
/**
@ -100,7 +106,7 @@ public class StorageHubClientService {
*/
public FolderItem getRoot() throws Exception {
setContextProviders(scope, authorizationToken);
FolderContainer root = shcClient.getWSRoot();
FolderContainer root = shClient.getWSRoot();
return root.get();
}
@ -116,7 +122,6 @@ public class StorageHubClientService {
return trash;
}
/**
* Gets the children.
*
@ -126,10 +131,12 @@ public class StorageHubClientService {
* @return the children
* @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);
logger.trace("Requesting getChildren for id: "+id+" [withAccounting: "+withAccounting+", withMapProperties: "+withMapProperties+"]");
ListResolverTyped resolverTyped = shcClient.open(id).asFolder().list();
logger.trace("Requesting getChildren for id: " + id + " [withAccounting: " + withAccounting
+ ", withMapProperties: " + withMapProperties + "]");
ListResolverTyped resolverTyped = shClient.open(id).asFolder().list();
ListResolver theResolver = resolverTyped.withContent();
if (withAccounting)
@ -142,6 +149,36 @@ public class StorageHubClientService {
}
/**
* Gets the children.
*
* @param id the id
* @param withAccounting the with accounting
* @param withMapProperties the with map properties
* @param includeHidden the include hidden
* @return the children
* @throws Exception the exception
*/
public List<? extends Item> getChildren(String id, boolean withAccounting, boolean withMapProperties,
boolean includeHidden) throws Exception {
setContextProviders(scope, authorizationToken);
logger.trace("Requesting getChildren for id: " + id + " [withAccounting: " + withAccounting
+ ", withMapProperties: " + withMapProperties + "]");
if (!includeHidden) {
return getChildren(id, withAccounting, withMapProperties);
}
ListResolver theResolver = shClient.open(id).asFolder().list().includeHidden().withContent();
if (withAccounting)
theResolver = theResolver.withAccounting();
if (withMapProperties)
theResolver = theResolver.withMetadata();
return theResolver.getItems();
}
/**
* Gets the filtered children.
@ -153,10 +190,11 @@ public class StorageHubClientService {
* @return the filtered children
* @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);
ListResolver resolverTyped = shcClient.open(id).asFolder().list().ofType(aType);
ListResolver resolverTyped = shClient.open(id).asFolder().list().ofType(aType);
ListResolver theResolver = resolverTyped.withContent();
if (withAccounting)
@ -168,7 +206,6 @@ public class StorageHubClientService {
return theResolver.getItems();
}
/**
* Gets the item.
*
@ -184,17 +221,38 @@ public class StorageHubClientService {
// I'M GOING TO REMAIN THESE OPTIONS FOR POSSIBLE FUTURE SUPPORTING ON SHUB
if (withMetadata) {
itemCont = shcClient.open(itemId).asItem(); //TODO
itemCont = shClient.open(itemId).asItem(); // TODO
} else if (withAccounting) {
itemCont = shcClient.open(itemId).asItem(); //TODO
}
else {
itemCont = shcClient.open(itemId).asItem();
itemCont = shClient.open(itemId).asItem(); // TODO
} else {
itemCont = shClient.open(itemId).asItem();
}
return itemCont.get();
}
/**
* Gets the item by path.
*
* @param folderId the folder id
* @param relativePath the relative path
* @return the item by path
* @throws Exception the exception
*/
public Item getItemByPath(String folderId, String relativePath) throws Exception {
setContextProviders(scope, authorizationToken);
FolderContainer itemCont = shClient.open(folderId).asFolder();
FolderContainer attachmentFolder = null;
try {
OpenResolver oRes = itemCont.openByRelativePath(relativePath);
attachmentFolder = oRes.asFolder();
return (Item) attachmentFolder.get();
} catch (StorageHubException e) {
e.printStackTrace();
}
return null;
}
/**
* Gets the item.
*
@ -206,8 +264,6 @@ public class StorageHubClientService {
return getItem(itemId, false, true);
}
/**
* Sets the metadata and returns the Item with metadata updated.
*
@ -218,13 +274,11 @@ public class StorageHubClientService {
*/
public Item setMetadata(String itemId, Metadata metadata) throws Exception {
setContextProviders(scope, authorizationToken);
ItemContainer<Item> itemCont = shcClient.open(itemId).asItem();
ItemContainer<Item> itemCont = shClient.open(itemId).asItem();
itemCont.setMetadata(metadata);
return itemCont.get();
}
/**
* Gets the metadata.
*
@ -234,15 +288,14 @@ public class StorageHubClientService {
*/
public Map<String, Object> getMetadata(String itemId) throws Exception {
setContextProviders(scope, authorizationToken);
ItemContainer<Item> itemCont = shcClient.open(itemId).asItem();
Metadata metadata = shcClient.open(itemId).asItem().get().getMetadata();
ItemContainer<Item> itemCont = shClient.open(itemId).asItem();
Metadata metadata = shClient.open(itemId).asItem().get().getMetadata();
if (metadata != null)
return metadata.getMap();
return null;
}
/**
* Gets the folder container.
*
@ -252,10 +305,9 @@ public class StorageHubClientService {
*/
public FolderContainer getFolderContainer(String itemId) throws Exception {
setContextProviders(scope, authorizationToken);
return shcClient.open(itemId).asFolder();
return shClient.open(itemId).asFolder();
}
/**
* Gets the parents.
*
@ -265,7 +317,7 @@ public class StorageHubClientService {
*/
public List<? extends Item> getParents(String itemId) throws Exception {
setContextProviders(scope, authorizationToken);
ListResolver toReturn = shcClient.open(itemId).asItem().getAnchestors();
ListResolver toReturn = shClient.open(itemId).asItem().getAnchestors();
if (toReturn == null || toReturn.getItems() == null) {
logger.warn("Parent List of item id " + itemId + " is null");
return null;
@ -275,7 +327,6 @@ public class StorageHubClientService {
// TODO MAP OF SHARED ROOT ID
/**
* Gets the id shared folder.
*
@ -288,7 +339,6 @@ public class StorageHubClientService {
return getRootSharedFolder(itemId).getId();
}
/**
* Gets the root shared folder.
*
@ -298,11 +348,10 @@ public class StorageHubClientService {
*/
public FolderItem getRootSharedFolder(String itemId) throws Exception {
setContextProviders(scope, authorizationToken);
return getRootSharedFolder(shcClient.open(itemId).asItem());
return getRootSharedFolder(shClient.open(itemId).asItem());
}
/**
* Checks if is item shared.
*
@ -312,11 +361,10 @@ public class StorageHubClientService {
*/
public boolean isItemShared(String itemId) throws Exception {
setContextProviders(scope, authorizationToken);
return shcClient.open(itemId).asItem().get().isShared();
return shClient.open(itemId).asItem().get().isShared();
}
/**
* Can write.
*
@ -326,10 +374,9 @@ public class StorageHubClientService {
*/
public boolean canWrite(String folderContainerId) throws Exception {
setContextProviders(scope, authorizationToken);
return shcClient.open(folderContainerId).asFolder().canWrite();
return shClient.open(folderContainerId).asFolder().canWrite();
}
/**
* Gets the root shared folder.
*
@ -346,7 +393,8 @@ public class StorageHubClientService {
} else
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();
}
@ -361,11 +409,10 @@ public class StorageHubClientService {
*/
public Item createFolder(String parentId, String folderName, String folderDescription) throws Exception {
setContextProviders(scope, authorizationToken);
FolderContainer folderContainer = shcClient.open(parentId).asFolder().newFolder(folderName, folderDescription);
FolderContainer folderContainer = shClient.open(parentId).asFolder().newFolder(folderName, folderDescription);
return getItem(folderContainer.get().getId(), false, true);
}
/**
* Gets the VRE folders id.
*
@ -391,9 +438,6 @@ public class StorageHubClientService {
return toReturn;
}
/**
* Gets the user acl for folder id.
*
@ -414,7 +458,8 @@ public class StorageHubClientService {
List<ACL> acls = client.getACL(folderId);
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) {
if (acl.getPricipal().compareTo(userName) == 0) {
found = true;
@ -423,7 +468,8 @@ public class StorageHubClientService {
}
if (!found && sharedFolder.isVreFolder()) {
for (ACL acl : acls) {
if (acl.getPricipal().startsWith(infrastructureName));
if (acl.getPricipal().startsWith(infrastructureName))
;
return acl.getAccessTypes().get(0).toString();
}
}
@ -431,7 +477,6 @@ public class StorageHubClientService {
return "UNDEFINED";
}
/**
* Gets the item children count.
*
@ -459,35 +504,35 @@ public class StorageHubClientService {
public Item uploadFile(String folderId, InputStream is, String fileName, String fileDescription) throws Exception {
setContextProviders(scope, authorizationToken);
FileContainer fileCont = shcClient.open(folderId).asFolder().uploadFile(is, fileName, fileDescription);
FileContainer fileCont = shClient.open(folderId).asFolder().uploadFile(is, fileName, fileDescription);
return fileCont.get();
}
/**
* Download file.
*
* @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
* @return the stream descriptor
* @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);
StreamDescriptor streamDesc;
if (versionName != null && !versionName.isEmpty()) {
streamDesc = shcClient.open(itemId).asFile().downloadSpecificVersion(versionName);
streamDesc = shClient.open(itemId).asFile().downloadSpecificVersion(versionName);
} else {
streamDesc = shcClient.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.
*
@ -499,13 +544,12 @@ public class StorageHubClientService {
public StreamDescriptor downloadFolder(String folderId, String nodeIdsToExclude) throws Exception {
setContextProviders(scope, authorizationToken);
StreamDescriptor streamDesc = shcClient.open(folderId).asFolder().download(nodeIdsToExclude);
return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName(), streamDesc.getContentType(), streamDesc.getContentLenght());
StreamDescriptor streamDesc = shClient.open(folderId).asFolder().download(nodeIdsToExclude);
return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName(), streamDesc.getContentType(),
streamDesc.getContentLenght());
}
/**
* Upload archive.
*
@ -518,12 +562,10 @@ public class StorageHubClientService {
public Item uploadArchive(String folderId, InputStream is, String extractionFolderName) throws Exception {
setContextProviders(scope, authorizationToken);
FolderContainer folderCont = shcClient.open(folderId).asFolder().uploadArchive(is, extractionFolderName);
FolderContainer folderCont = shClient.open(folderId).asFolder().uploadArchive(is, extractionFolderName);
return folderCont.get();
}
/**
* Gets the shared folder members.
*
@ -531,17 +573,144 @@ 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<Member> members = new ArrayList<Member>();
if (item instanceof SharedFolder) {
return ObjectMapper.toListLogins((SharedFolder)item);
}else
SharedFolder sharedfolder = (SharedFolder) item;
String vreName = null;
if (sharedfolder.isVreFolder()) {
vreName = sharedfolder.getDisplayName(); // the displayName should matching the VRE Name
// this class is used?
if (sharedfolder instanceof VreFolder) {
VreFolder vreFolder = (VreFolder) sharedfolder;
vreName = vreFolder.getDisplayName(); // the displayName should matching the VRE Name
}
}
String infra = WrapperUtility.getInfrastructureNameFromScope(scope);
logger.debug("Infrastructure is: " + infra);
logger.debug("vreName is: " + vreName);
List<ACL> listACL = shClient.open(folderId).asFolder().getAcls();
logger.info("Reading users from ACLs");
for (ACL acl : listACL) {
logger.info("acl principal is: " + acl.getPricipal());
Member member = new Member(acl.getPricipal(), acl.getPricipal(), Member.TYPE.USER);
boolean isAGroup = isGroupName(acl.getPricipal(), infra, vreName);
if (isAGroup) {
member.setMemberType(TYPE.GROUP);
// gcube-devsec-devVRE -> devVRE that is the groupName
// the VRE Name should be the group name
member.setName(vreName);
logger.info("pricipal: " + acl.getPricipal() + " is "+member.getMemberType()+": "+member.getName());
}
members.add(member);
logger.debug("added member: " + member);
}
} else {
throw new Exception("The item with " + folderId + " is not a Shared Folder");
}
logger.info("Returning " + members.size() + " member/s");
return members;
}
/**
* Checks if is group name.
*
* @param pricipal the pricipal
* @param infrastructureName the infrastructur name
* @param vreName the vre name
* @return true, if is group name E.g. with the input 'gcube-devNext-NextNext'
* returns true
*/
private boolean isGroupName(String pricipal, String infrastructureName, String vreName) {
if (pricipal == null || pricipal.isEmpty())
return false;
if (vreName == null || vreName.isEmpty())
return false;
ScopeBean scope = null;
//Removing the first / from the infrastructure name. E.g /gcube -> gcube
infrastructureName = infrastructureName.replace(WrapperUtility.SCOPE_SEPARATOR, "");
if (principalContainsScopes(pricipal, infrastructureName, vreName)) {
String theScope = getScopeFromVREGroupName(pricipal, infrastructureName, vreName);
try {
//Just to be sure of the format /RootVO/VO/VRE
scope = new ScopeBean(theScope);
logger.info("pricipal '" + pricipal + "' remapping as "+theScope+" should be a valid scope");
} catch (IllegalArgumentException e) {
logger.trace("principal '" + pricipal + "' is not a scope");
return false;
}
}
return scope != null;
}
/**
* Principal contains scopes.
*
* @param principal the principal
* @param infrastructurName the infrastructur name
* @param vreName the vre name
* @return true, if principal (as string) contains the RootVO and the VRE name.
*/
private static boolean principalContainsScopes(String principal, String infrastructurName, String vreName) {
if (principal.contains(infrastructurName)) {
if (principal.contains(vreName)) {
return true;
}
}
return false;
}
public static String getScopeFromVREGroupName(String context, String infrastructurName, String vreName) {
if (vreName == null)
vreName = "";
logger.debug("vreName: " + vreName);
if (infrastructurName.startsWith("/"))
infrastructurName = infrastructurName.substring(1, infrastructurName.length());
logger.debug("infrastructurName: " + infrastructurName);
String voGroup = context.replaceAll(infrastructurName, "");
if (vreName != null) {
voGroup = voGroup.replaceAll(vreName, "").replaceAll("-", "");
}
String voName = voGroup.replaceAll("-", "");
logger.debug("voName: " + voName);
StringBuilder theScopeBuilder = new StringBuilder();
theScopeBuilder.append("/" + infrastructurName);
if (voName != null && !voName.isEmpty()) {
theScopeBuilder.append(WrapperUtility.SCOPE_SEPARATOR + voName);
}
if (vreName != null && !vreName.isEmpty()) {
theScopeBuilder.append(WrapperUtility.SCOPE_SEPARATOR + vreName);
}
String theScope = theScopeBuilder.toString();
logger.debug("Built scope: " + theScope);
return theScope;
}
/**
* Find by name.
@ -562,13 +731,11 @@ public class StorageHubClientService {
}
if (item instanceof FolderItem || item instanceof SharedFolder || item instanceof VreFolder) {
return shcClient.open(folderId).asFolder().findByName(name).withContent().getItems();
return shClient.open(folderId).asFolder().findByName(name).withContent().getItems();
} else
throw new Exception("The input folder id is not a folder");
}
/**
* Search for text.
*
@ -589,13 +756,11 @@ public class StorageHubClientService {
if (item instanceof FolderItem || item instanceof SharedFolder || item instanceof VreFolder) {
// this does not return the trashed items
return shcClient.open(folderId).asFolder().search(text,true).withContent().getItems();
return shClient.open(folderId).asFolder().search(text, true).withContent().getItems();
} else
throw new Exception("The input folder id is not a folder");
}
/**
* Delete item by id.
*
@ -606,12 +771,10 @@ public class StorageHubClientService {
Validate.notNull(itemId, "Bad request to deleteItemById, the itemId is null");
setContextProviders(scope, authorizationToken);
shcClient.open(itemId).asItem().delete();
shClient.open(itemId).asItem().delete();
}
/**
* Open trash.
*
@ -621,12 +784,10 @@ public class StorageHubClientService {
public Item openTrash() throws Exception {
setContextProviders(scope, authorizationToken);
return shcClient.openTrash().get();
return shClient.openTrash().get();
}
/**
* Empty trash.
*
@ -635,23 +796,28 @@ public class StorageHubClientService {
public void emptyTrash() throws Exception {
setContextProviders(scope, authorizationToken);
shcClient.emptyTrash();
shClient.emptyTrash();
}
/**
* Restore thrash item.
*
* @param itemId the item id
* @param destinationFolderId the destination folder id
* @return the item
* @throws Exception the exception
*/
public Item restoreThrashItem(String itemId) throws Exception{
public Item restoreThrashItem(String itemId, String destinationFolderId) throws Exception {
Validate.notNull(itemId, "Bad request to restoreThrashItem, the itemId is null");
setContextProviders(scope, authorizationToken);
GenericItemContainer container = shcClient.restoreThrashItem(itemId);
GenericItemContainer container = null;
if (destinationFolderId == null)
container = shClient.restoreThrashItem(itemId);
else
container = shClient.restoreThrashItem(itemId, destinationFolderId);
if (container != null) {
Item item = container.get();
@ -664,7 +830,6 @@ public class StorageHubClientService {
}
/**
* Move item.
*
@ -678,12 +843,11 @@ public class StorageHubClientService {
Validate.notNull(itemId, "Bad request to moveItem, the itemId is null");
Validate.notNull(destFolderContainer, "Bad request to moveItem, the itemId is null");
setContextProviders(scope, authorizationToken);
shcClient.open(itemId).asItem().move(destFolderContainer);
return shcClient.open(itemId).asItem().get();
shClient.open(itemId).asItem().move(destFolderContainer);
return shClient.open(itemId).asItem().get();
}
/**
* Copy item.
*
@ -693,18 +857,19 @@ public class StorageHubClientService {
* @return the abstract file item
* @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(destFolderContainer, "Bad request to copyFileItem, the destFolderContainer is null");
setContextProviders(scope, authorizationToken);
FileContainer copyingItem = shcClient.open(fileItemId).asFile();
String newName = newFileName!=null && !newFileName.isEmpty()?newFileName:"Copy of "+copyingItem.get().getName();
FileContainer copyingItem = shClient.open(fileItemId).asFile();
String newName = newFileName != null && !newFileName.isEmpty() ? newFileName
: "Copy of " + copyingItem.get().getName();
FileContainer newItem = copyingItem.copy(destFolderContainer, newName);
return newItem.get();
}
/**
* Rename item.
*
@ -717,12 +882,11 @@ public class StorageHubClientService {
Validate.notNull(itemId, "Bad request to renameItem, the itemId is null");
setContextProviders(scope, authorizationToken);
shcClient.open(itemId).asItem().rename(newName);
return shcClient.open(itemId).asItem().get();
shClient.open(itemId).asItem().rename(newName);
return shClient.open(itemId).asItem().get();
}
/**
* Gets the file public link.
*
@ -734,11 +898,10 @@ public class StorageHubClientService {
Validate.notNull(fileItemId, "Bad request to getPublicLinkForFile, the fileItemId is null");
setContextProviders(scope, authorizationToken);
return shcClient.open(fileItemId).asFile().getPublicLink();
return shClient.open(fileItemId).asFile().getPublicLink();
}
/**
* Gets the public link for file version.
*
@ -753,11 +916,10 @@ public class StorageHubClientService {
Validate.notNull(version, "Bad request to getPublicLinkForFileVersion, the version is null");
Validate.notEmpty(version, "Bad request to getPublicLinkForFileVersion, the version is empty");
setContextProviders(scope, authorizationToken);
return shcClient.open(fileItemId).asFile().getPublicLink(version);
return shClient.open(fileItemId).asFile().getPublicLink(version);
}
/**
* Gets the list versions.
*
@ -769,7 +931,7 @@ public class StorageHubClientService {
Validate.notNull(fileItemId, "Bad request to getListVersions, the fileItemId is null");
return shcClient.open(fileItemId).asFile().getVersions();
return shClient.open(fileItemId).asFile().getVersions();
}
@ -784,7 +946,7 @@ public class StorageHubClientService {
Validate.notNull(itemId, "Bad request to getImageContent, the itemId is null");
setContextProviders(scope, authorizationToken);
ItemContainer<Item> itemCont = shcClient.open(itemId).asItem();
ItemContainer<Item> itemCont = shClient.open(itemId).asItem();
Item item = itemCont.get();
if (item instanceof org.gcube.common.storagehub.model.items.ImageFile) {
org.gcube.common.storagehub.model.items.ImageFile imgFI = (org.gcube.common.storagehub.model.items.ImageFile) item; // ??
@ -793,7 +955,6 @@ public class StorageHubClientService {
throw new Exception("Thumbnail Data is not available for type: " + item.getClass().getSimpleName());
}
/**
* Gets the total items.
*
@ -803,10 +964,9 @@ public class StorageHubClientService {
public long getTotalItems() throws Exception {
setContextProviders(scope, authorizationToken);
return shcClient.getTotalItemCount();
return shClient.getTotalItemCount();
}
/**
* Gets the disk usage.
*
@ -815,7 +975,7 @@ public class StorageHubClientService {
*/
public long getDiskUsage() throws Exception {
setContextProviders(scope, authorizationToken);
return shcClient.getTotalVolume();
return shClient.getTotalVolume();
}
/**
@ -829,12 +989,11 @@ public class StorageHubClientService {
Validate.notNull(itemId, "Bad request to getAccounting, the itemId is null");
setContextProviders(scope, authorizationToken);
ItemContainer<Item> itemCont = shcClient.open(itemId).asItem();
ItemContainer<Item> itemCont = shClient.open(itemId).asItem();
Item item = itemCont.get();
return item.getAccounting();
}
/**
* Gets the gcube item properties.
*
@ -845,18 +1004,17 @@ public class StorageHubClientService {
public Metadata getGcubeItemProperties(String gcubeItemId) throws Exception {
Validate.notNull(gcubeItemId, "Bad request to loadGcubeItemProperties, the itemId is null");
setContextProviders(scope, authorizationToken);
ItemContainer<Item> itemCont = shcClient.open(gcubeItemId).asItem();
ItemContainer<Item> itemCont = shClient.open(gcubeItemId).asItem();
Item item = itemCont.get();
if (item instanceof GCubeItem) {
GCubeItem theGcubeItem = (GCubeItem) item;
return theGcubeItem.getMetadata();
} 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.
*
@ -870,10 +1028,77 @@ public class StorageHubClientService {
// ItemContainer<Item> itemCont = shcClient.open(itemId).asItem();
// itemCont.get().setMetadata(new Metadata(mapProperties));
// item.setMetadata(new Metadata(mapProperties));
shcClient.open(itemId).asItem().setMetadata(new Metadata(mapProperties));
shClient.open(itemId).asItem().setMetadata(new Metadata(mapProperties));
}
/**
* Sets the Folder As Hidden or visible .
*
* @param folderId the folder id
* @param hide true to set hide, false to set visible
* @throws Exception the exception
*/
public void setFolderAsHidden(String folderId, boolean hide) throws Exception {
Validate.notNull(folderId, "Bad request to setFolderAsHidden the folderId is null");
setContextProviders(scope, authorizationToken);
FolderContainer folderContainer = shClient.open(folderId).asFolder();
if (hide)
folderContainer.setHidden(); // will not appear in the workspace GUI
else
folderContainer.setVisible(); // will appear in the workspace GUI
}
/**
* Share folder.
*
* @param folderId the folder id to share
* @param users the users to share
* @param type the permission
* @return the workspace shared folder
* @throws Exception the exception
*/
public WorkspaceSharedFolder shareFolder(String folderId, Set<String> users, ACLType type) throws Exception {
Validate.notNull(folderId, "Bad request to setFolderAsHidden the folderId is null");
setContextProviders(scope, authorizationToken);
AccessType acType;
switch (type) {
case READ_ONLY:
acType = AccessType.READ_ONLY;
break;
case ADMINISTRATOR:
acType = AccessType.ADMINISTRATOR;
break;
case WRITE_ALL:
acType = AccessType.WRITE_ALL;
break;
case WRITE_OWNER:
acType = AccessType.WRITE_OWNER;
break;
case NONE:
acType = null;
break;
default:
acType = AccessType.WRITE_OWNER;
break;
}
FolderContainer fContainer = shClient.open(folderId).asFolder().share(users, acType);
return HLMapper.toWorkspaceItem(fContainer.get());
}
/**
* Unshare folder.
*
* @param folderId the folder id to share
* @param users the users to share
* @return the workspace shared folder
* @throws Exception the exception
*/
public WorkspaceSharedFolder unshareFolder(String folderId, Set<String> users) throws Exception {
Validate.notNull(folderId, "Bad request to setFolderAsHidden the folderId is null");
setContextProviders(scope, authorizationToken);
FolderContainer fContainer = shClient.open(folderId).asFolder().unshare(users);
return HLMapper.toWorkspaceItem(fContainer.get());
}
/**
* Adds the URL.
@ -888,12 +1113,11 @@ public class StorageHubClientService {
public ExternalLink addURL(String folderId, URL URL, String name, String description) throws StorageHubException {
Validate.notNull(folderId, "Bad request to createURL the folderId is null");
setContextProviders(scope, authorizationToken);
FolderContainer folder = shcClient.open(folderId).asFolder();
FolderContainer folder = shClient.open(folderId).asFolder();
return folder.addUrl(URL, name, description).get();
}
/**
* Sets the folder as public.
*
@ -905,7 +1129,7 @@ public class StorageHubClientService {
public boolean setFolderAsPublic(String folderId, boolean setPublic) throws Exception {
Validate.notNull(folderId, "Bad request to setFolderAsPublic the folderId is null");
setContextProviders(scope, authorizationToken);
FolderContainer folderCont = shcClient.open(folderId).asFolder();
FolderContainer folderCont = shClient.open(folderId).asFolder();
if (setPublic) {
folderCont.publish();
@ -915,17 +1139,34 @@ public class StorageHubClientService {
logger.debug("Unpublished the folder id: " + folderId);
}
return shcClient.open(folderId).asFolder().get().isPublicItem();
return shClient.open(folderId).asFolder().get().isPublicItem();
}
/**
* Update description for item.
*
* @param itemId the item id
* @param newDescription the new description
* @return the description updated
* @throws Exception the exception
*/
public String updateDescriptionForItem(String itemId, String newDescription) throws Exception {
Validate.notNull(itemId, "Bad request the itemId is null");
setContextProviders(scope, authorizationToken);
shClient.open(itemId).asItem().setDescription(newDescription);
return shClient.open(itemId).asItem().get().getDescription();
}
/**
* To string.
*
* @return the string
*/
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
@ -935,12 +1176,11 @@ public class StorageHubClientService {
builder.append("StorageHubClientService [scope=");
builder.append(scope);
builder.append(", authorizationToken=");
builder.append(authorizationToken.substring(0, authorizationToken.length()-5)+"XXXXX");
builder.append(authorizationToken.substring(0, authorizationToken.length() - 8) + "XXXXXXXX");
builder.append(", itemManagerClient=");
builder.append(shcClient);
builder.append(shClient);
builder.append("]");
return builder.toString();
}
}

View File

@ -11,6 +11,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.Validate;
import org.gcube.common.storagehub.client.StreamDescriptor;
@ -26,9 +27,9 @@ 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.WorkspaceVREFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InsufficientPrivilegesException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemAlreadyExistException;
@ -348,6 +349,33 @@ public final class WorkspaceStorageHubClientService implements Workspace{
return toChildren;
}
/**
* Gets the children.
*
* @param id the id
* @return the children
* @throws Exception the exception
*/
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.tohl.Workspace#getChildren(java.lang.String)
*/
public List<? extends WorkspaceItem> getChildren(String id, boolean includeHidden)throws Exception{
LOGGER.debug("called get Children include hidden");
Validate.notNull(id,"The input id is null");
List<? extends Item> children = storageHubClientService.getChildren(id, withAccounting, withMapProperties, includeHidden);
List<WorkspaceItem> toChildren = new ArrayList<WorkspaceItem>(children.size());
for (Item item : children) {
WorkspaceItem child = HLMapper.toWorkspaceItem(item, withAccounting, withFileDetails, withMapProperties);
toChildren.add(child);
}
return toChildren;
}
/**
* Gets the filtered children.
*
@ -526,6 +554,23 @@ public final class WorkspaceStorageHubClientService implements Workspace{
return workspaceItem;
}
@Override
public WorkspaceItem getItemByPath(String folderId, String relativePath) throws ItemNotFoundException, InternalErrorException, Exception {
LOGGER.debug("called get getItemByPath");
Validate.notNull(folderId,"The input folderId is null");
Item item;
try {
item = storageHubClientService.getItemByPath(folderId, relativePath);
}
catch (Exception e) {
LOGGER.error("Error during get item with id: "+folderId,e);
throw new InternalErrorException(e.getMessage());
}
WorkspaceItem workspaceItem = HLMapper.toWorkspaceItem(item, withAccounting, withFileDetails, withMapProperties);
setIsRoot((org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceItem) workspaceItem);
return workspaceItem;
}
/**
* Gets the item. This call is the same of {@link WorkspaceStorageHubClientService#getItem(String, boolean, boolean, boolean)}
* except to getRoot called inside (to check if an item is root or not). {@link WorkspaceItem#isRoot()} returns always false.
@ -640,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");
@ -669,7 +714,6 @@ public final class WorkspaceStorageHubClientService implements Workspace{
public boolean exists(String name, String folderId)
throws InternalErrorException, ItemNotFoundException,
WrongItemTypeException {
LOGGER.debug("called exists");
List<WorkspaceItem> foundItems = find(name, folderId);
@ -792,8 +836,8 @@ public final class WorkspaceStorageHubClientService implements Workspace{
storageHubClientService.deleteItemById(itemId);
}catch(Exception e){
LOGGER.error("Delete item by id error: "+e.getMessage());
throw new Exception("Erro on deleting the item. "+e.getMessage());
LOGGER.error("Error on deleting the trash item by id: "+itemId,e);
throw e;
}
}
@ -910,7 +954,6 @@ public final class WorkspaceStorageHubClientService implements Workspace{
try{
Item baseFolderTrash = storageHubClientService.openTrash();
return HLMapper.toWorkspaceItem(baseFolderTrash);
}catch(Exception e){
throw new Exception("Error on getting the Trash content: "+e.getMessage());
}
@ -934,25 +977,25 @@ public final class WorkspaceStorageHubClientService implements Workspace{
}
/**
* Restore thrash item.
*
* @param itemId the item id
* @param destinationFolderId the destination folder id
* @return the workspace item
* @throws Exception the exception
*/
/* (non-Javadoc)
* @see org.gcube.common.storagehubwrapper.server.tohl.Workspace#restoreThrashItem(java.lang.String)
*/
@Override
public WorkspaceItem restoreThrashItem(String itemId) throws Exception{
public WorkspaceItem restoreThrashItem(String itemId, String destinationFolderId) throws Exception{
try{
Item theItem = storageHubClientService.restoreThrashItem(itemId);
Item theItem = storageHubClientService.restoreThrashItem(itemId,destinationFolderId);
return HLMapper.toWorkspaceItem(theItem);
}catch(Exception e){
throw new Exception("Error on restoring the Trash Item: "+e.getMessage());
LOGGER.error("Error on restoring the trash item by id: "+itemId,e);
throw e;
}
}
@ -1502,355 +1545,37 @@ public final class WorkspaceStorageHubClientService implements Workspace{
}
/*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
* TODO
*
* FOLLOWING METHODS ARE NOT IMPLEMENTED;
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
/**
* Change description.
*
* @param itemId the item id
* @param newDescription the new description
* @throws ItemNotFoundException the item not found exception
* @throws InternalErrorException the internal error exception
*/
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.Workspace#changeDescription(java.lang.String, java.lang.String)
*/
@Override
public void changeDescription(String itemId, String newDescription)
throws ItemNotFoundException, InternalErrorException {
public String updateDescriptionForItem(String itemId, String newDescription) throws Exception {
// TODO Auto-generated method stub
String updatedDescription = null;
try{
updatedDescription = storageHubClientService.updateDescriptionForItem(itemId, newDescription);
}catch(Exception e){
String error = "Error on updating the description for item with id: "+itemId;
LOGGER.error(error, e);
throw new Exception(e);
}
return updatedDescription;
}
/**
* Search by mime type.
*
* @param mimeType the mime type
* @return the list
* @throws InternalErrorException the internal error exception
*/
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.Workspace#searchByMimeType(java.lang.String)
*/
@Override
public List<WorkspaceItem> searchByMimeType(String mimeType)
throws InternalErrorException {
// TODO Auto-generated method stub
return null;
public void setFolderAsHidden(String folderId, boolean hide) throws Exception {
storageHubClientService.setFolderAsHidden(folderId, hide);
}
/**
* Creates the shared folder.
*
* @param name the name
* @param description the description
* @param users the users
* @param destinationFolderId the destination folder id
* @return the workspace shared folder
* @throws InternalErrorException the internal error exception
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws ItemAlreadyExistException the item already exist exception
* @throws WrongDestinationException the wrong destination exception
* @throws ItemNotFoundException the item not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.Workspace#createSharedFolder(java.lang.String, java.lang.String, java.util.List, java.lang.String)
*/
@Override
public WorkspaceSharedFolder createSharedFolder(
String name, String description, List<String> users,
String destinationFolderId)
throws InternalErrorException, InsufficientPrivilegesException,
ItemAlreadyExistException, WrongDestinationException,
ItemNotFoundException, WorkspaceFolderNotFoundException {
// TODO Auto-generated method stub
return null;
public WorkspaceSharedFolder shareFolder(String folderId, Set<String> users, ACLType type) throws Exception {
return storageHubClientService.shareFolder(folderId, users, type);
}
/**
* Share folder.
*
* @param users the users
* @param destinationFolderId the destination folder id
* @return the workspace shared folder
* @throws InternalErrorException the internal error exception
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws ItemAlreadyExistException the item already exist exception
* @throws WrongDestinationException the wrong destination exception
* @throws ItemNotFoundException the item not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.Workspace#shareFolder(java.util.List, java.lang.String)
*/
@Override
public WorkspaceSharedFolder shareFolder(
List<String> users, String destinationFolderId)
throws InternalErrorException, InsufficientPrivilegesException,
ItemAlreadyExistException, WrongDestinationException,
ItemNotFoundException, WorkspaceFolderNotFoundException {
// TODO Auto-generated method stub
return null;
public WorkspaceSharedFolder unshareFolder(String folderId, Set<String> users) throws Exception {
return storageHubClientService.unshareFolder(folderId, users);
}
/**
* Share.
*
* @param users the users
* @param itemId the item id
* @return the workspace shared folder
* @throws InternalErrorException the internal error exception
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws ItemAlreadyExistException the item already exist exception
* @throws WrongDestinationException the wrong destination exception
* @throws ItemNotFoundException the item not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.Workspace#share(java.util.List, java.lang.String)
*/
@Override
public WorkspaceSharedFolder share(List<String> users, String itemId)
throws InternalErrorException, InsufficientPrivilegesException,
ItemAlreadyExistException, WrongDestinationException,
ItemNotFoundException, WorkspaceFolderNotFoundException {
// TODO Auto-generated method stub
return null;
}
/**
* Creates the gcube item.
*
* @param name the name
* @param description the description
* @param scopes the scopes
* @param creator the creator
* @param itemType the item type
* @param properties the properties
* @param destinationFolderId the destination folder id
* @return the workspace item
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
* @throws InternalErrorException the internal error exception
* @throws ItemAlreadyExistException the item already exist exception
* @throws WrongDestinationException the wrong destination exception
* @throws ItemNotFoundException the item not found exception
*/
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.Workspace#createGcubeItem(java.lang.String, java.lang.String, java.util.List, java.lang.String, java.lang.String, java.util.Map, java.lang.String)
*/
@Override
public WorkspaceItem createGcubeItem(
String name, String description, List<String> scopes, String creator,
String itemType, Map<String, String> properties,
String destinationFolderId)
throws InsufficientPrivilegesException,
WorkspaceFolderNotFoundException, InternalErrorException,
ItemAlreadyExistException, WrongDestinationException,
ItemNotFoundException {
// TODO Auto-generated method stub
return null;
}
/**
* Unshare.
*
* @param itemId the item id
* @return the workspace item
* @throws InternalErrorException the internal error exception
* @throws ItemNotFoundException the item not found exception
*/
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.Workspace#unshare(java.lang.String)
*/
@Override
public WorkspaceItem unshare(String itemId)
throws InternalErrorException, ItemNotFoundException {
// TODO Auto-generated method stub
return null;
}
/**
* Gets the my special folders.
*
* @return the my special folders
* @throws InternalErrorException the internal error exception
* @throws ItemNotFoundException the item not found exception
*/
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.Workspace#getMySpecialFolders()
*/
@Override
public WorkspaceFolder getMySpecialFolders()
throws InternalErrorException, ItemNotFoundException {
// TODO Auto-generated method stub
return null;
}
/**
* Search by properties.
*
* @param properties the properties
* @return the list
* @throws InternalErrorException the internal error exception
*/
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.Workspace#searchByProperties(java.util.List)
*/
@Override
public List<WorkspaceItem> searchByProperties(List<String> properties)
throws InternalErrorException {
// TODO Auto-generated method stub
return null;
}
/**
* Creates the VRE folder.
*
* @param scope the scope
* @param description the description
* @param displayName the display name
* @param privilege the privilege
* @return the workspace VRE folder
* @throws InternalErrorException the internal error exception
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws ItemAlreadyExistException the item already exist exception
* @throws WrongDestinationException the wrong destination exception
* @throws ItemNotFoundException the item not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.Workspace#createVREFolder(java.lang.String, java.lang.String, java.lang.String, org.gcube.portal.storagehubwrapper.shared.ACLType)
*/
@Override
public WorkspaceVREFolder createVREFolder(
String scope, String description, String displayName, ACLType privilege)
throws InternalErrorException, InsufficientPrivilegesException,
ItemAlreadyExistException, WrongDestinationException,
ItemNotFoundException, WorkspaceFolderNotFoundException {
// TODO Auto-generated method stub
return null;
}
/**
* Gets the public folders.
*
* @return the public folders
* @throws InternalErrorException the internal error exception
*/
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.Workspace#getPublicFolders()
*/
@Override
public List<WorkspaceItem> getPublicFolders()
throws InternalErrorException {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -12,10 +12,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class WrapperUtility.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Oct 17, 2018
*/
public class WrapperUtility {
public static final String SCOPE_SEPARATOR = "/";
private static Logger logger = LoggerFactory.getLogger(WrapperUtility.class);
/**
@ -47,4 +51,35 @@ public class WrapperUtility {
}
}
}
/**
* Gets the infrastructure name from scope.
*
* @param scope the scope
* @return the infrastructure name from scope
* @throws Exception the exception
*/
public static String getInfrastructureNameFromScope(String scope) throws Exception{
if(scope==null || scope.isEmpty()){
throw new Exception("Scope is null or empty");
}
if(!scope.startsWith(SCOPE_SEPARATOR)){
logger.warn("Input scope: "+scope+" not have / is a really scope?");
scope = SCOPE_SEPARATOR+scope;
logger.warn("Tentative as scope: "+scope);
}
String[] splitScope = scope.split(SCOPE_SEPARATOR);
String rootScope = SCOPE_SEPARATOR + splitScope[1];
if(rootScope.length()<2){
throw new Exception("Infrastructure name not found in "+scope);
}
return rootScope;
}
}

View File

@ -39,7 +39,6 @@ import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItemType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class HLMapper.
*
@ -50,19 +49,6 @@ public class HLMapper {
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.
*
@ -74,7 +60,6 @@ public class HLMapper {
return (URLFile) toWorkspaceItem(extLink, false, false, false);
}
/**
* To workspace item.
*
@ -88,8 +73,6 @@ public class HLMapper {
return toWorkspaceItem(item, false, false, false);
}
/**
* To accounting entries.
*
@ -103,16 +86,11 @@ public class HLMapper {
Accounting accounting = item.getAccounting();
if (accounting != null) {
accountingEntries = accounting.getEntries();
// for (AccountEntry ae : accounting.getEntries()) {
// accountingEntries.add(toAccountingEntry.apply(ae));
// }
}
return accountingEntries;
}
/**
* To property map.
*
@ -132,7 +110,6 @@ public class HLMapper {
return pm;
}
/**
* To workspace file version.
*
@ -160,7 +137,8 @@ public class HLMapper {
* @return the t
* @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 {
List<AccountEntry> accountingEntries = null;
@ -188,12 +166,14 @@ public class HLMapper {
SharedFolder sharedfolder = (SharedFolder) item; // ??
theItem = new WorkspaceSharedFolder();
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()) {
// logger.debug("Converting shared folder: "+theItem.getClass());
// 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
((WorkspaceSharedFolder) theItem).setVreFolder(true);
type = WorkspaceItemType.VRE_FOLDER;
@ -204,7 +184,8 @@ public class HLMapper {
// ((WorkspaceFolder) theItem).setPublicFolder(folderItem.isPublicItem());
// 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) {
try {
// Map<String, Object> map = item.getPropertyMap().getValues();
@ -298,7 +279,8 @@ public class HLMapper {
// CONVERTING TRASH ITEM
if (item.isTrashed() && item instanceof TrashItem) {
type = WorkspaceItemType.TRASH_ITEM;
TrashItem trashItem = (TrashItem) item; //??
TrashItem trashItem = (TrashItem) item;
itemName = trashItem.getTitle(); // IN CASE OF TRASHED ITEM THE NAME IS THE ID, SO I'M USING THE TITLE
theItem = new org.gcube.common.storagehubwrapper.shared.tohl.impl.TrashItem();
org.gcube.common.storagehubwrapper.shared.tohl.impl.TrashItem theTrashItem = (org.gcube.common.storagehubwrapper.shared.tohl.impl.TrashItem) theItem;
theTrashItem.setDeletedBy(trashItem.getDeletedBy());
@ -307,6 +289,7 @@ public class HLMapper {
theTrashItem.setDeletedFrom(trashItem.getDeletedFrom());
theTrashItem.setLenght(trashItem.getLenght());
theTrashItem.setMimeType(trashItem.getMimeType());
isFolder = trashItem.isFolder(); // DO NOT MOVE THIS SET
if (isFolder) // Avoiding null exception on
type = WorkspaceItemType.TRASH_FOLDER;
@ -370,10 +353,6 @@ public class HLMapper {
throw e;
}
}
}

View File

@ -12,8 +12,6 @@ import org.gcube.common.storagehub.model.items.SharedFolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class ObjectMapper.
*
@ -24,15 +22,14 @@ public class ObjectMapper {
private static Logger logger = LoggerFactory.getLogger(ObjectMapper.class);
/**
* To list logins.
*
* @param sharedfolder the sharedfolder
* @return the list
*/
@Deprecated
public static List<String> toListLogins(SharedFolder sharedfolder) {
Metadata users = sharedfolder.getUsers();
Map<String, Object> mapMember = users.getMap();
List<String> listUsers = new ArrayList<String>(mapMember.size());

View File

@ -7,14 +7,16 @@ import java.io.InputStream;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Set;
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;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceVREFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InsufficientPrivilegesException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemAlreadyExistException;
@ -27,8 +29,6 @@ import org.gcube.common.storagehubwrapper.shared.tohl.items.ItemStreamDescriptor
import org.gcube.common.storagehubwrapper.shared.tohl.items.PropertyMap;
import org.gcube.common.storagehubwrapper.shared.tohl.items.URLItem;
// TODO: Auto-generated Javadoc
/**
* The Interface Workspace.
@ -40,7 +40,6 @@ import org.gcube.common.storagehubwrapper.shared.tohl.items.URLItem;
*/
public interface Workspace {
/**
* Gets the owner.
*
@ -59,9 +58,8 @@ public interface Workspace{
*/
public WorkspaceFolder getRoot() throws InternalErrorException, Exception;
/**
* Gets the children.
* Gets the children not including the ones marked as hidden.
*
* @param id the id
* @return the children
@ -69,6 +67,15 @@ public interface Workspace{
*/
public List<? extends WorkspaceItem> getChildren(String id) throws Exception;
/**
* Gets the children including the ones marked as hidden if the bool param is true.
*
* @param id the id
* @param hidden true to return also the hidden ones
* @return the children
* @throws Exception the exception
*/
public List<? extends WorkspaceItem> getChildren(String id, boolean includeHidden) throws Exception;
/**
* Gets the parents by id.
@ -91,7 +98,6 @@ public interface Workspace{
*/
public WorkspaceItem getItem(String itemId) throws ItemNotFoundException, InternalErrorException, Exception;
/**
* Return the item with the specified id.
*
@ -104,26 +110,47 @@ public interface Workspace{
* @throws InternalErrorException the internal error exception
* @throws Exception the exception
*/
public WorkspaceItem getItem(String itemId, boolean withAccounting, boolean withFileDetails, boolean withMapProperties) throws ItemNotFoundException, InternalErrorException, Exception;
public WorkspaceItem getItem(String itemId, boolean withAccounting, boolean withFileDetails,
boolean withMapProperties) throws ItemNotFoundException, InternalErrorException, Exception;
/**
*
* @param idFolder
* @param relativePath
* @return the item.
* @throws ItemNotFoundException if the item has not been found.
* @throws InternalErrorException the internal error exception
* @throws Exception the exception
*/
public WorkspaceItem getItemByPath(String idFolder, String relativePath) throws ItemNotFoundException, InternalErrorException, Exception;
/**
* Create a new folder with specified name.
* The new folder is created into the specified folder.
* Create a new folder with specified name. The new folder is created into the
* specified folder.
*
* @param name the folder name.
* @param description the folder description.
* @param destinationFolderId the destination folder.
* @return the new folder.
* @throws InternalErrorException if an internal error occurs.
* @throws InsufficientPrivilegesException if the user don't have sufficient privileges to perform this operation.
* @throws ItemAlreadyExistException if an item with the same exist in the destination folder.
* @throws WrongDestinationException if the destination item is not a folder.
* @throws ItemNotFoundException if the destination folder has not been found.
* @throws WorkspaceFolderNotFoundException if the destination folder has not been found.
* @throws InsufficientPrivilegesException if the user don't have sufficient
* privileges to perform this
* operation.
* @throws ItemAlreadyExistException if an item with the same exist in
* the destination folder.
* @throws WrongDestinationException if the destination item is not a
* folder.
* @throws ItemNotFoundException if the destination folder has not
* been found.
* @throws WorkspaceFolderNotFoundException if the destination folder has not
* been found.
* @throws Exception the exception
*/
public WorkspaceFolder createFolder(String name, String description, String destinationFolderId) throws InternalErrorException, InsufficientPrivilegesException, ItemAlreadyExistException, WrongDestinationException, ItemNotFoundException, WorkspaceFolderNotFoundException, Exception;
public WorkspaceFolder createFolder(String name, String description, String destinationFolderId)
throws InternalErrorException, InsufficientPrivilegesException, ItemAlreadyExistException,
WrongDestinationException, ItemNotFoundException, WorkspaceFolderNotFoundException, Exception;
/**
* Create a new folder with properties.
@ -134,14 +161,18 @@ public interface Workspace{
* @param properties the properties
* @return the new folder
* @throws InternalErrorException the internal error exception
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws InsufficientPrivilegesException the insufficient privileges
* exception
* @throws ItemAlreadyExistException the item already exist exception
* @throws WrongDestinationException the wrong destination exception
* @throws ItemNotFoundException the item not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found
* exception
*/
public WorkspaceFolder createFolder(String name, String description, String destinationFolderId, Map<String, String> properties) throws InternalErrorException, InsufficientPrivilegesException, ItemAlreadyExistException, WrongDestinationException, ItemNotFoundException, WorkspaceFolderNotFoundException;
public WorkspaceFolder createFolder(String name, String description, String destinationFolderId,
Map<String, String> properties)
throws InternalErrorException, InsufficientPrivilegesException, ItemAlreadyExistException,
WrongDestinationException, ItemNotFoundException, WorkspaceFolderNotFoundException;
/**
* Upload file.
@ -153,7 +184,8 @@ public interface Workspace{
* @return the workspace item
* @throws Exception the exception
*/
public WorkspaceItem uploadFile(String folderId, InputStream inputStream, String fileName, String fileDescription) throws Exception;
public WorkspaceItem uploadFile(String folderId, InputStream inputStream, String fileName, String fileDescription)
throws Exception;
/**
* Gets the shared folder members.
@ -162,31 +194,35 @@ 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.
*
* @param name the name to check.
* @param folderId the folder where to search the item.
* @return <code>true</code> if the item exists, <code>false</code> otherwise.
* @throws InternalErrorException if an error occurs.
* @throws ItemNotFoundException if the folder has not been found.
* @throws WrongItemTypeException if the folderId referrer to an item with type different from Workspace or folder.
* @throws WrongItemTypeException if the folderId referrer to an item with type
* different from Workspace or folder.
*/
public boolean exists(String name, String folderId) throws InternalErrorException, ItemNotFoundException, WrongItemTypeException;
public boolean exists(String name, String folderId)
throws InternalErrorException, ItemNotFoundException, WrongItemTypeException;
/**
* Get an item with the specified name in the specified folder.
*
* @param name the item name to find.
* @param folderId the folder where to search the item.
* @return the item if the item is found, <code>null</code> otherwise.
* @throws InternalErrorException if an error occurs.
* @throws ItemNotFoundException if the folder has not been found.
* @throws WrongItemTypeException if the folderId referrer to an item with type different from Workspace or folder.
* @throws WrongItemTypeException if the folderId referrer to an item with type
* different from Workspace or folder.
*/
public List<WorkspaceItem> find(String name, String folderId) throws InternalErrorException, ItemNotFoundException, WrongItemTypeException;
public List<WorkspaceItem> find(String name, String folderId)
throws InternalErrorException, ItemNotFoundException, WrongItemTypeException;
/**
* Gets the root shared folder.
@ -197,8 +233,6 @@ public interface Workspace{
*/
public WorkspaceItem getRootSharedFolder(String itemId) throws Exception;
/**
* Checks if is item shared.
*
@ -208,7 +242,6 @@ public interface Workspace{
*/
public boolean isItemShared(String itemId) throws Exception;
/**
* Gets the VRE folders id.
*
@ -227,7 +260,6 @@ public interface Workspace{
*/
public WorkspaceItem getTrash() throws InternalErrorException, ItemNotFoundException, Exception;
/**
* Empty trash.
*
@ -235,18 +267,15 @@ public interface Workspace{
*/
public void emptyTrash() throws Exception;
/**
* Restore thrash item.
*
* @param itemId the item id
* @return the item
* @param destinationFolderId the destination folder id
* @return the workspace item
* @throws Exception the exception
*/
public WorkspaceItem restoreThrashItem(String itemId) throws Exception;
public WorkspaceItem restoreThrashItem(String itemId, String destinationFolderId) throws Exception;
/**
* Gets the filtered children.
@ -258,8 +287,6 @@ public interface Workspace{
*/
public List<? extends WorkspaceItem> getFilteredChildren(String id, Class<? extends Item> aType) throws Exception;
/**
* Rename an item.
*
@ -268,12 +295,13 @@ public interface Workspace{
* @return the workspace item
* @throws ItemNotFoundException if the item has not been found.
* @throws InternalErrorException if an internal error occurs.
* @throws ItemAlreadyExistException if the user don't have sufficient privileges to perform this operation.
* @throws ItemAlreadyExistException if the user don't have sufficient
* privileges to perform this operation.
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws Exception the exception
*/
public WorkspaceItem renameItem(String itemId, String newName) throws ItemNotFoundException, InternalErrorException, ItemAlreadyExistException, InsufficientPrivilegesException, Exception;
public WorkspaceItem renameItem(String itemId, String newName) throws ItemNotFoundException, InternalErrorException,
ItemAlreadyExistException, InsufficientPrivilegesException, Exception;
/**
* Gets the public link to the latest version of file item.
@ -294,7 +322,6 @@ public interface Workspace{
*/
public URL getPublicLinkForFile(String fileItemId, String version) throws Exception;
/**
* Gets the list versions for file.
*
@ -304,7 +331,6 @@ public interface Workspace{
*/
public List<WorkspaceFileVersion> getListVersionsForFile(String fileItemId) throws Exception;
/**
* Gets the thumbnail data.
*
@ -314,7 +340,6 @@ public interface Workspace{
*/
public ItemStreamDescriptor getThumbnailData(String itemId) throws Exception;
/**
* Gets the metadata.
*
@ -324,7 +349,6 @@ public interface Workspace{
*/
public Map<String, Object> getMetadata(String itemId) throws Exception;
/**
* Get the disk usage of a worskpace.
*
@ -341,7 +365,6 @@ public interface Workspace{
*/
public long getTotalItems() throws Exception;
/**
* Gets the accounting.
*
@ -351,7 +374,6 @@ public interface Workspace{
*/
public List<AccountEntry> getAccounting(String itemId) throws Exception;
/**
* Gets the gcube item properties.
*
@ -361,7 +383,6 @@ public interface Workspace{
*/
public PropertyMap getGcubeItemProperties(String gcubeItemId) throws Exception;
/**
* Update metadata.
*
@ -371,7 +392,6 @@ public interface Workspace{
*/
public void updateMetadata(String itemId, Map<String, Object> mapObjs) throws Exception;
/**
* Creates the URL.
*
@ -384,7 +404,6 @@ public interface Workspace{
*/
public URLItem createURL(String name, String description, String url, String destinationFolderId) throws Exception;
/**
* Sets the folder as public.
*
@ -395,7 +414,6 @@ public interface Workspace{
*/
public boolean setFolderAsPublic(String folderId, boolean bool) throws Exception;
/**
* Move items.
*
@ -410,10 +428,8 @@ public interface Workspace{
* @throws Exception the exception
*/
List<WorkspaceItem> moveItems(List<String> itemIds, String folderDestinationId)
throws ItemNotFoundException, WrongDestinationException,
InsufficientPrivilegesException, InternalErrorException,
ItemAlreadyExistException, Exception;
throws ItemNotFoundException, WrongDestinationException, InsufficientPrivilegesException,
InternalErrorException, ItemAlreadyExistException, Exception;
/**
* Delete item.
@ -424,16 +440,21 @@ public interface Workspace{
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws Exception the exception
*/
/* Delete item.
/*
* Delete item.
*
* @param itemId the item id
*
* @throws ItemNotFoundException the item not found exception
*
* @throws InternalErrorException the internal error exception
*
* @throws InsufficientPrivilegesException the insufficient privileges exception
*
* @throws Exception the exception
*/
public void deleteItem(String itemId) throws ItemNotFoundException, InternalErrorException, InsufficientPrivilegesException, Exception;
public void deleteItem(String itemId)
throws ItemNotFoundException, InternalErrorException, InsufficientPrivilegesException, Exception;
/**
* Move item.
@ -443,14 +464,17 @@ public interface Workspace{
* @return the workspace item
* @throws ItemNotFoundException the item not found exception
* @throws WrongDestinationException the wrong destination exception
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws InsufficientPrivilegesException the insufficient privileges
* exception
* @throws InternalErrorException the internal error exception
* @throws ItemAlreadyExistException the item already exist exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found
* exception
* @throws Exception the exception
*/
public WorkspaceItem moveItem(String itemId, String destinationFolderId) throws ItemNotFoundException, WrongDestinationException, InsufficientPrivilegesException, InternalErrorException, ItemAlreadyExistException, WorkspaceFolderNotFoundException, Exception;
public WorkspaceItem moveItem(String itemId, String destinationFolderId)
throws ItemNotFoundException, WrongDestinationException, InsufficientPrivilegesException,
InternalErrorException, ItemAlreadyExistException, WorkspaceFolderNotFoundException, Exception;
/**
* Copy file.
@ -466,11 +490,9 @@ public interface Workspace{
* @throws Exception the exception
*/
WorkspaceItem copyFile(String itemId, String folderDestinationId)
throws ItemNotFoundException, WrongDestinationException,
InternalErrorException, ItemAlreadyExistException,
throws ItemNotFoundException, WrongDestinationException, InternalErrorException, ItemAlreadyExistException,
InsufficientPrivilegesException, Exception;
/**
* Copy file items.
*
@ -484,10 +506,8 @@ public interface Workspace{
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws Exception the exception
*/
List<WorkspaceItem> copyFileItems(
List<String> itemIds, String folderDestinationId)
throws ItemNotFoundException, WrongDestinationException,
InternalErrorException, ItemAlreadyExistException,
List<WorkspaceItem> copyFileItems(List<String> itemIds, String folderDestinationId)
throws ItemNotFoundException, WrongDestinationException, InternalErrorException, ItemAlreadyExistException,
InsufficientPrivilegesException, Exception;
/**
@ -499,8 +519,6 @@ public interface Workspace{
*/
boolean canUserWriteIntoFolder(String folderId) throws Exception;
/**
* Search.
*
@ -515,7 +533,7 @@ public interface Workspace{
throws InternalErrorException, ItemNotFoundException, WrongItemTypeException;
/**
* Gets the item for Explorer
* Gets the item for Explorer.
*
* @param itemId the item id
* @param withAccounting the with accounting
@ -530,8 +548,10 @@ public interface Workspace{
boolean withMapProperties) throws ItemNotFoundException, InternalErrorException, Exception;
/**
* Gets the parents for explorer by id. This call is the same of {@link WorkspaceStorageHubClientService#getParentsById(String)}
* except to getRoot called inside (to check if a parent is root or not). {@link WorkspaceItem#isRoot()} returns always false.
* Gets the parents for explorer by id. This call is the same of
* {@link WorkspaceStorageHubClientService#getParentsById(String)} except to
* getRoot called inside (to check if a parent is root or not).
* {@link WorkspaceItem#isRoot()} returns always false.
*
* @param id the id
* @return the parents for explorer by id
@ -540,257 +560,19 @@ public interface Workspace{
*/
List<? extends WorkspaceItem> getParentsForExplorerById(String id) throws InternalErrorException, Exception;
/*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
* TODO
*
* FOLLOWING METHODS ARE NOT IMPLEMENTED;
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
/**
* Change an item description.
* @param itemId the item to update.
* @param newDescription the new item description.
* @throws ItemNotFoundException if the item has not been found.
* @throws InternalErrorException if an internal error occurs.
*/
public void changeDescription(String itemId, String newDescription) throws ItemNotFoundException, InternalErrorException;
/**
* Search By MimeType.
*
* @param mimeType the mime type
* @return a list of SearchFolderItem
* @throws InternalErrorException the internal error exception
*/
public List<WorkspaceItem> searchByMimeType(String mimeType)
throws InternalErrorException;
/**
* Create a shared folder with a list of users.
*
* @param name the name
* @param description the description
* @param users A list of portal logins
* @param destinationFolderId the destination folder id
* @return the shared folder
* @throws InternalErrorException the internal error exception
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws ItemAlreadyExistException the item already exist exception
* @throws WrongDestinationException the wrong destination exception
* @throws ItemNotFoundException the item not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
public WorkspaceSharedFolder createSharedFolder(String name, String description,
List<String> users, String destinationFolderId)
throws InternalErrorException, InsufficientPrivilegesException,
ItemAlreadyExistException, WrongDestinationException,
ItemNotFoundException, WorkspaceFolderNotFoundException;
/**
* Shared an exist {@link WorkspaceFolder} with a list of users.
*
* @param users A list of portal logins.
* @param destinationFolderId the destination folder id
* @return the shared folder
* @throws InternalErrorException the internal error exception
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws ItemAlreadyExistException the item already exist exception
* @throws WrongDestinationException the wrong destination exception
* @throws ItemNotFoundException the item not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
public WorkspaceSharedFolder shareFolder(List<String> users, String destinationFolderId)
throws InternalErrorException, InsufficientPrivilegesException,
ItemAlreadyExistException, WrongDestinationException,
ItemNotFoundException, WorkspaceFolderNotFoundException;
/**
* Shared an exist {@link WorkspaceFolder} with a list of users.
*
* @param users A list of portal logins.
* @param itemId the item id
* @return the shared folder
* @throws InternalErrorException the internal error exception
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws ItemAlreadyExistException the item already exist exception
* @throws WrongDestinationException the wrong destination exception
* @throws ItemNotFoundException the item not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
public WorkspaceSharedFolder share(List<String> users, String itemId)
throws InternalErrorException, InsufficientPrivilegesException,
ItemAlreadyExistException, WrongDestinationException,
ItemNotFoundException, WorkspaceFolderNotFoundException;
/**
* Create a GCubeItem.
*
* @param name the name
* @param description the description
* @param scopes the scopes
* @param creator the creator
* @param itemType the item type
* @param properties the properties
* @param destinationFolderId the destination folder id
* @return a GCubeItem
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
* @throws InternalErrorException the internal error exception
* @throws ItemAlreadyExistException the item already exist exception
* @throws WrongDestinationException the wrong destination exception
* @throws ItemNotFoundException the item not found exception
*/
public WorkspaceItem createGcubeItem(String name, String description,
List<String> scopes, String creator, String itemType, Map<String, String> properties,
String destinationFolderId) throws InsufficientPrivilegesException,
WorkspaceFolderNotFoundException, InternalErrorException,
ItemAlreadyExistException, WrongDestinationException, ItemNotFoundException;
/**
* Unshare a shared item.
* Download file.
*
* @param itemId the item id
* @return the workspace item
* @throws InternalErrorException the internal error exception
* @throws ItemNotFoundException the item not found exception
* @param fileName the file name
* @param versionName the version name. If is null or empty returns the
* latest version of file
* @param nodeIdsToExclude the node ids to exclude
* @return the item stream descriptor
* @throws Exception the exception
*/
public WorkspaceItem unshare(String itemId) throws InternalErrorException, ItemNotFoundException;
/**
* Get MySpecialFolders.
*
* @return my special folders
* @throws InternalErrorException the internal error exception
* @throws ItemNotFoundException the item not found exception
*/
public WorkspaceFolder getMySpecialFolders() throws InternalErrorException, ItemNotFoundException;
/**
* Search By Properties.
*
* @param properties the properties
* @return a list of WorkspaceItem
* @throws InternalErrorException the internal error exception
*/
public List<WorkspaceItem> searchByProperties(List<String> properties)
throws InternalErrorException;
/**
* Removes the items.
*
* @param id the id
* @return the map of errors (id,error)
* @throws ItemNotFoundException the item not found exception
* @throws InternalErrorException the internal error exception
* @throws InsufficientPrivilegesException the insufficient privileges exception
*/
public Map<String, String> removeItems(String... id) throws ItemNotFoundException,
InternalErrorException, InsufficientPrivilegesException;
/**
* Create a VRE folder.
*
* @param scope the scope
* @param description the description
* @param displayName the display name
* @param privilege the privilege
* @return a new VRE folder
* @throws InternalErrorException the internal error exception
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws ItemAlreadyExistException the item already exist exception
* @throws WrongDestinationException the wrong destination exception
* @throws ItemNotFoundException the item not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
public WorkspaceVREFolder createVREFolder(String scope, String description,
String displayName, ACLType privilege) throws InternalErrorException,
InsufficientPrivilegesException, ItemAlreadyExistException,
WrongDestinationException, ItemNotFoundException,
WorkspaceFolderNotFoundException;
/**
* Get public folders.
*
* @return a list of public folder
* @throws InternalErrorException the internal error exception
*/
List<WorkspaceItem> getPublicFolders() throws InternalErrorException;
ItemStreamDescriptor downloadFile(String itemId, String fileName, String versionName, String nodeIdsToExclude)
throws Exception;
/**
* Upload archive.
@ -801,24 +583,7 @@ public interface Workspace{
* @return the workspace item
* @throws Exception the exception
*/
WorkspaceItem uploadArchive(
String folderId, InputStream is, String extractionFolderName)
throws Exception;
/**
* Download file.
*
* @param itemId the item id
* @param fileName the file name
* @param versionName the version name. If is null or empty returns the latest version of file
* @param nodeIdsToExclude the node ids to exclude
* @return the item stream descriptor
* @throws Exception the exception
*/
ItemStreamDescriptor downloadFile(String itemId, String fileName, String versionName, String nodeIdsToExclude) throws Exception;
WorkspaceItem uploadArchive(String folderId, InputStream is, String extractionFolderName) throws Exception;
/**
* Download folder.
@ -829,9 +594,51 @@ public interface Workspace{
* @return the item stream descriptor
* @throws Exception the exception
*/
ItemStreamDescriptor downloadFolder(
String folderId, String folderName, String nodeIdsToExclude)
throws Exception;
ItemStreamDescriptor downloadFolder(String folderId, String folderName, String nodeIdsToExclude) throws Exception;
/**
* Removes the items.
*
* @param id the id
* @return the map of errors (id,error)
* @throws ItemNotFoundException the item not found exception
* @throws InternalErrorException the internal error exception
* @throws InsufficientPrivilegesException the insufficient privileges exception
*/
public Map<String, String> removeItems(String... id)
throws ItemNotFoundException, InternalErrorException, InsufficientPrivilegesException;
/**
* Update description for item.
*
* @param itemId the item id
* @param newDescription the new description
* @return the description updated read by SHUB
* @throws Exception the exception
*/
public String updateDescriptionForItem(String itemId, String newDescription) throws Exception;
/**
* Sets the Folder As Hidden or visible .
*
* @param folderId the folder id to set as hidden
* @param hide true to set hide, false to set visible
* @throws Exception the exception
*/
public void setFolderAsHidden(String folderId, boolean hide) throws Exception;
/**
*
* @param folderId the folder id to share
* @param users the Set of users to share
* @param type the permission
*/
public WorkspaceSharedFolder shareFolder(String folderId, Set<String> users, ACLType type) throws Exception;
/**
*
* @param folderId the folder id to share
* @param users the Set of users to share
* @param type the permission
*/
public WorkspaceSharedFolder unshareFolder(String folderId, Set<String> users) throws Exception;
}

View File

@ -0,0 +1,125 @@
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 String name;
private TYPE memberType = TYPE.USER;
/**
* Instantiates a new member.
*/
public Member() {
}
/**
* Instantiates a new member.
*
* @param identity the identity is the username of a User or the name of a
* Group. In general is key to identify he/she/it in the in
* the infrastructure
* @param name the name is the name of a User or the name of a Group
* @param memberType the member type
*/
public Member(String identity, String name, TYPE memberType) {
super();
this.identity = identity;
this.name = name;
this.memberType = memberType;
}
/**
* Gets the identity.
*
* @return the login in case of user and the groupName stored in SHUB (e.g.
* gcube-devsec-devVRE) in case of group
*/
public String getIdentity() {
return identity;
}
/**
* Gets the name.
*
* @return the login in case of user and the groupName in case of group
*/
public String getName() {
return name;
}
/**
* 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 name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Sets the member type.
*
* @param memberType the new member type
*/
public void setMemberType(TYPE memberType) {
this.memberType = memberType;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Member [identity=");
builder.append(identity);
builder.append(", name=");
builder.append(name);
builder.append(", memberType=");
builder.append(memberType);
builder.append("]");
return builder.toString();
}
}

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

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

View File

@ -3,9 +3,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.storagehub.client.dsl.FolderContainer;
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
import org.gcube.common.storagehubwrapper.server.WorkspaceStorageHubClientService;
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
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.exceptions.InternalErrorException;
@ -14,29 +19,26 @@ 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.ImageFile;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.PDFFile;
import org.junit.Before;
import org.junit.Test;
/**
*
*/
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 20, 2018
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 20, 2018
*/
public class WorkspaceInstance {
public static String SCOPE = "/gcube";
public static String SCOPE = "/gcube/devsec/devVRE";
//public static String SCOPE = "/d4science.research-infrastructures.eu";
// public static String USERNAME = "massimiliano.assante";
public static String USERNAME = "francesco.mangiacrapa";
public static String TOKEN; //YOU MUST SET THIS AS VM PARAMETER
//public static String TOKEN = System.getenv("TOKEN_gcube"); // YOU MUST SET THIS AS Environment variable
public static String TOKEN = "";
public static String FIND_FILE_NAME = "francesco";
public static String rootId = null;
@ -44,12 +46,17 @@ public class WorkspaceInstance {
private WorkspaceStorageHubClientService workspace;
@Before
//@Before
public void init() {
TOKEN = System.getProperty("token");
if (TOKEN == null) {
System.err.println("You must set the token as Environment variable");
}
System.out.println("Read TOKEN: "+TOKEN);
System.out.println("Read TOKEN_gcube: " + TOKEN);
ScopeProvider.instance.set(SCOPE);
SecurityTokenProvider.instance.set(TOKEN);
// METHOD 1
storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN, false, false, true);
@ -71,15 +78,14 @@ public class WorkspaceInstance {
root = storageHubWrapper.getWorkspace().getRoot();
rootId = root.getId();
System.out.println("The root is:" + root);
}
catch (Exception e) {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Test
// @Test
public void getChildren() throws Exception {
System.out.println("Get children test");
@ -91,21 +97,38 @@ public class WorkspaceInstance {
int i = 0;
for (WorkspaceItem workspaceItem : children) {
System.out.println(++i+")"+workspaceItem.getId() + " name: "+workspaceItem.getName() + " type: "+workspaceItem.getType() +" class: "+workspaceItem.getClass());
//System.out.println(workspaceItem.getType() +" "+workspaceItem.getClass());
// System.out.println(++i+")");
// if(workspaceItem.isFolder()){
// WorkspaceFolder folder = (WorkspaceFolder) workspaceItem;
// System.out.println("is public? "+folder.isPublicFolder());
// }
//printMap(workspaceItem);
System.out.println(++i + ")" + workspaceItem.getId() + " name: " + workspaceItem.getName() + " type: "
+ workspaceItem.getType() + " class: " + workspaceItem.getClass());
}
}
// @Test
public void getPathOnShared() throws Exception {
System.out.println("Get Path on Shared");
WorkspaceFolder root = storageHubWrapper.getWorkspace().getRoot();
List<? extends WorkspaceItem> children = storageHubWrapper.getWorkspace().getChildren(root.getId());
int i = 0;
for (WorkspaceItem workspaceItem : children) {
if (workspaceItem.isShared()) {
System.out.println(++i + ")" + workspaceItem.getId() + " name: " + workspaceItem.getName() + " type: "
+ workspaceItem.getPath());
}
}
}
//@Test
public void getVREFolder() throws Exception {
System.out.println("Get VRE Folder");
StorageHubClient shClient = new StorageHubClient();
FolderContainer vre= shClient.openVREFolder();
System.out.println("VRE folder: "+vre.getId() + " ACLs: "+vre.getAcls());
}
// @Test
public void getFilteredChildren() throws Exception {
@ -113,7 +136,8 @@ public class WorkspaceInstance {
WorkspaceFolder root = storageHubWrapper.getWorkspace().getRoot();
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();
// List<? extends WorkspaceItem> children = workspace.getChildren(root.getId());
@ -123,7 +147,6 @@ public class WorkspaceInstance {
System.out.println(++i + ")" + workspaceItem);
System.out.println(workspaceItem.getType() + " " + workspaceItem.getClass());
// System.out.println(++i+")");
// if(workspaceItem.isFolder()){
// WorkspaceFolder folder = (WorkspaceFolder) workspaceItem;
@ -138,7 +161,8 @@ public class WorkspaceInstance {
public static void printMap(WorkspaceItem workspaceItem) {
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());
}
}
@ -161,6 +185,33 @@ public class WorkspaceInstance {
}
}
@Test
public void getSharedFolderMembers() {
System.out.println("Getting getSharedFolderMembers");
try {
//String sharedFolderId = "7e3c6636-927c-4139-9fcc-64986ea70cbf"; // devVRE (VRE Folder)
String sharedFolderId = "f8275521-5da1-4501-8385-bb9c79055aa6"; // PROD - d4science.research-infrastructures.eu-D4OS-Blue-Cloud2026Project (VRE Folder)
//String sharedFolderId = "4d6f1fe9-8f04-45c9-a87e-ee6093553d77"; // PROD - AriadnePlus-LiDAR Dataset (simple Shared Folder)
//String sharedFolderId = "a4837a77-c1d0-4ea4-9f9d-c4bd5cf07e9a"; // PROD - Sample Reports and Templates (private Folder)
//sharedFolderId = "c141d53d-4cae-4bfc-a6f7-9b8bbd8c0e2b"; //NextNext
SCOPE = "/gcube";
SCOPE = "/d4science.research-infrastructures.eu";
TOKEN = "";
storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN);
List<Member> listMembers = storageHubWrapper.getWorkspace().getSharedFolderMembers(sharedFolderId);
System.out.println("Foud " + listMembers.size() + " member/s");
for (Member member : listMembers) {
System.out.println(member);
}
} catch (Exception e) {
e.printStackTrace();
}
}
// @Test
public void getChildrenPerWorkspaceItem() throws InternalErrorException {
System.out.println("Get children test per workspace item");
@ -196,7 +247,8 @@ public class WorkspaceInstance {
case PDF_DOCUMENT:
PDFFile pdfFile = (PDFFile) fileItem;
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);
break;
case IMAGE_DOCUMENT:
@ -209,15 +261,13 @@ public class WorkspaceInstance {
System.out.println(fileItem.getFileItemType() + " " + workspaceItem.getClass());
break;
default:
break;
}
}
}
}
catch (Exception e) {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@ -229,7 +279,8 @@ public class WorkspaceInstance {
System.out.println("Find file name test");
getRoot();
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);
if (foundItems == null || foundItems.size() == 0) {
@ -241,8 +292,7 @@ public class WorkspaceInstance {
for (WorkspaceItem workspaceItem : foundItems) {
System.out.println(workspaceItem);
}
}
catch (ItemNotFoundException | WrongItemTypeException e) {
} catch (ItemNotFoundException | WrongItemTypeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}