Compare commits
33 Commits
Author | SHA1 | Date |
---|---|---|
Lucio Lelii | d647e753d3 | |
Lucio Lelii | ae50530654 | |
Lucio Lelii | 2bc4138463 | |
Lucio Lelii | 78496153a4 | |
Lucio Lelii | 3d7c334afd | |
Lucio Lelii | 18d2fb9287 | |
Lucio Lelii | 28e4e9eb56 | |
Lucio Lelii | 9c5ba19f43 | |
Lucio Lelii | fec3941a37 | |
Lucio Lelii | 7e6d6e2325 | |
Lucio Lelii | 8d9aa86074 | |
Lucio Lelii | f6639bda23 | |
Lucio Lelii | 245461b7ee | |
Lucio Lelii | 10452d523b | |
Lucio Lelii | 3dce6154d2 | |
Lucio Lelii | b75672f081 | |
lucio.lelii | ceb01cf16f | |
lucio.lelii | 433e075326 | |
lucio.lelii | 6f96bab4ed | |
lucio.lelii | 11e5469dbf | |
Lucio Lelii | f8937c3ecc | |
lucio.lelii | 5f6660bcc4 | |
lucio.lelii | e7495bb8b2 | |
lucio.lelii | 74281ed64f | |
Lucio Lelii | 913fa3c9c0 | |
Lucio Lelii | 0befbaeb34 | |
Lucio Lelii | a66158fa22 | |
Lucio Lelii | c851738429 | |
Lucio Lelii | a2564298d8 | |
Lucio Lelii | 4135ed017a | |
lucio | 6e8600bbf3 | |
Lucio Lelii | f8cce90467 | |
lucio | 6b013ec305 |
33
.classpath
33
.classpath
|
@ -1,5 +1,21 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
|
<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">
|
||||||
|
<attributes>
|
||||||
|
<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">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
|
@ -13,22 +29,5 @@
|
||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<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">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
|
||||||
</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"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -7,7 +7,9 @@ org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
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.enumIdentifier=error
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||||
org.eclipse.jdt.core.compiler.release=disabled
|
org.eclipse.jdt.core.compiler.release=disabled
|
||||||
org.eclipse.jdt.core.compiler.source=1.8
|
org.eclipse.jdt.core.compiler.source=1.8
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||||
<wb-module deploy-name="storagehub-client_TRUNK">
|
<wb-module deploy-name="storagehub-client_TRUNK">
|
||||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
|
||||||
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
|
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
|
||||||
|
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
||||||
|
<wb-resource deploy-path="/" source-path="/src/test/java"/>
|
||||||
</wb-module>
|
</wb-module>
|
||||||
</project-modules>
|
</project-modules>
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
## [v2.0.0-SNAPSHOT] - [2022-02-07]
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
|
||||||
|
porting to model 2.0
|
||||||
|
|
||||||
|
## [v1.3.0] - [2021-06-18]
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
|
||||||
|
method for check item existance moved to a new rest call
|
||||||
|
|
||||||
|
## [v1.2.2] - [2021-02-08]
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
|
||||||
|
method for user existence check added
|
||||||
|
|
||||||
|
|
||||||
|
## [v1.2.1] - [2020-07-17]
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
|
||||||
|
method for description update added
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Acknowledgments
|
||||||
|
|
||||||
|
The projects leading to this software have received funding from a series of European Union programmes including:
|
||||||
|
|
||||||
|
- the Sixth Framework Programme for Research and Technological Development
|
||||||
|
- [DILIGENT](https://cordis.europa.eu/project/id/004260) (grant no. 004260).
|
||||||
|
- the Seventh Framework Programme for research, technological development and demonstration
|
||||||
|
- [D4Science](https://cordis.europa.eu/project/id/212488) (grant no. 212488);
|
||||||
|
- [D4Science-II](https://cordis.europa.eu/project/id/239019) (grant no.239019);
|
||||||
|
- [ENVRI](https://cordis.europa.eu/project/id/283465) (grant no. 283465);
|
||||||
|
- [iMarine](https://cordis.europa.eu/project/id/283644) (grant no. 283644);
|
||||||
|
- [EUBrazilOpenBio](https://cordis.europa.eu/project/id/288754) (grant no. 288754).
|
||||||
|
- the H2020 research and innovation programme
|
||||||
|
- [SoBigData](https://cordis.europa.eu/project/id/654024) (grant no. 654024);
|
||||||
|
- [PARTHENOS](https://cordis.europa.eu/project/id/654119) (grant no. 654119);
|
||||||
|
- [EGI-Engage](https://cordis.europa.eu/project/id/654142) (grant no. 654142);
|
||||||
|
- [ENVRI PLUS](https://cordis.europa.eu/project/id/654182) (grant no. 654182);
|
||||||
|
- [BlueBRIDGE](https://cordis.europa.eu/project/id/675680) (grant no. 675680);
|
||||||
|
- [PerformFISH](https://cordis.europa.eu/project/id/727610) (grant no. 727610);
|
||||||
|
- [AGINFRA PLUS](https://cordis.europa.eu/project/id/731001) (grant no. 731001);
|
||||||
|
- [DESIRA](https://cordis.europa.eu/project/id/818194) (grant no. 818194);
|
||||||
|
- [ARIADNEplus](https://cordis.europa.eu/project/id/823914) (grant no. 823914);
|
||||||
|
- [RISIS 2](https://cordis.europa.eu/project/id/824091) (grant no. 824091);
|
||||||
|
- [EOSC-Pillar](https://cordis.europa.eu/project/id/857650) (grant no. 857650);
|
||||||
|
- [Blue Cloud](https://cordis.europa.eu/project/id/862409) (grant no. 862409);
|
||||||
|
- [SoBigData-PlusPlus](https://cordis.europa.eu/project/id/871042) (grant no. 871042);
|
|
@ -1,5 +0,0 @@
|
||||||
<ReleaseNotes>
|
|
||||||
<Changeset component="storagehub-client-1.0.0" date="2018-05-15">
|
|
||||||
<Change>First Release</Change>
|
|
||||||
</Changeset>
|
|
||||||
</ReleaseNotes>
|
|
|
@ -1,31 +0,0 @@
|
||||||
<assembly
|
|
||||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
|
||||||
<id>servicearchive</id>
|
|
||||||
<formats>
|
|
||||||
<format>tar.gz</format>
|
|
||||||
</formats>
|
|
||||||
<baseDirectory>/</baseDirectory>
|
|
||||||
<fileSets>
|
|
||||||
<fileSet>
|
|
||||||
<directory>.</directory>
|
|
||||||
<outputDirectory>/</outputDirectory>
|
|
||||||
<useDefaultExcludes>true</useDefaultExcludes>
|
|
||||||
<includes>
|
|
||||||
<include>README</include>
|
|
||||||
<include>LICENSE</include>
|
|
||||||
<include>changelog.xml</include>
|
|
||||||
<include>profile.xml</include>
|
|
||||||
</includes>
|
|
||||||
<fileMode>755</fileMode>
|
|
||||||
<filtered>true</filtered>
|
|
||||||
</fileSet>
|
|
||||||
</fileSets>
|
|
||||||
<files>
|
|
||||||
<file>
|
|
||||||
<source>target/${build.finalName}.jar</source>
|
|
||||||
<outputDirectory>/${artifactId}</outputDirectory>
|
|
||||||
</file>
|
|
||||||
</files>
|
|
||||||
</assembly>
|
|
52
pom.xml
52
pom.xml
|
@ -18,31 +18,36 @@
|
||||||
|
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>storagehub-client-library</artifactId>
|
<artifactId>storagehub-client-library</artifactId>
|
||||||
<version>1.0.8</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
<name>storagehub-client-library</name>
|
<name>storagehub-client-library</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.distribution</groupId>
|
<groupId>org.gcube.distribution</groupId>
|
||||||
<artifactId>gcube-bom</artifactId>
|
<artifactId>gcube-bom</artifactId>
|
||||||
<version>1.3.1</version>
|
<version>2.1.0-SNAPSHOT</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.common</groupId>
|
|
||||||
<artifactId>gxJRS</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.10</version>
|
<version>4.11</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -54,13 +59,8 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>storagehub-model</artifactId>
|
<artifactId>storagehub-model</artifactId>
|
||||||
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
|
||||||
<artifactId>jackson-jaxrs-json-provider</artifactId>
|
|
||||||
<version>2.3.0</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.media</groupId>
|
<groupId>org.glassfish.jersey.media</groupId>
|
||||||
<artifactId>jersey-media-json-jackson</artifactId>
|
<artifactId>jersey-media-json-jackson</artifactId>
|
||||||
|
@ -77,7 +77,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>common-jaxrs-client</artifactId>
|
<artifactId>common-jaxrs-client</artifactId>
|
||||||
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
|
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -90,6 +90,8 @@
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
@ -99,7 +101,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>1.0.13</version>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -108,19 +109,12 @@
|
||||||
<version>2.4</version>
|
<version>2.4</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.opencsv</groupId>
|
||||||
|
<artifactId>opencsv</artifactId>
|
||||||
|
<version>5.3</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>2.3.2</version>
|
|
||||||
<configuration>
|
|
||||||
<target>1.8</target>
|
|
||||||
<source>1.8</source>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
</project>
|
26
profile.xml
26
profile.xml
|
@ -1,26 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
||||||
<ID />
|
|
||||||
<Type>Service</Type>
|
|
||||||
<Profile>
|
|
||||||
<Description>${description}</Description>
|
|
||||||
<Class>Common</Class>
|
|
||||||
<Name>${artifactId}</Name>
|
|
||||||
<Version>1.0.0</Version>
|
|
||||||
<Packages>
|
|
||||||
<Software>
|
|
||||||
<Name>${artifactId}</Name>
|
|
||||||
<Version>${version}</Version>
|
|
||||||
<MavenCoordinates>
|
|
||||||
<groupId>${groupId}</groupId>
|
|
||||||
<artifactId>${artifactId}</artifactId>
|
|
||||||
<version>${version}</version>
|
|
||||||
</MavenCoordinates>
|
|
||||||
<Files>
|
|
||||||
<File>${build.finalName}.jar</File>
|
|
||||||
</Files>
|
|
||||||
</Software>
|
|
||||||
</Packages>
|
|
||||||
</Profile>
|
|
||||||
</Resource>
|
|
||||||
|
|
|
@ -39,6 +39,11 @@ public class FileContainer extends ItemContainer<AbstractFileItem> {
|
||||||
return itemclient.downloadSpecificVersion(this.itemId, versionName);
|
return itemclient.downloadSpecificVersion(this.itemId, versionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FileContainer deleteVersion(String version) throws StorageHubException{
|
||||||
|
itemclient.deleteFileVersion(this.itemId, version);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public FileContainer copy(FolderContainer folder, String newFileName) throws StorageHubException {
|
public FileContainer copy(FolderContainer folder, String newFileName) throws StorageHubException {
|
||||||
return new FileContainer(itemclient, itemclient.copy(this.itemId, folder.get().getId(), newFileName));
|
return new FileContainer(itemclient, itemclient.copy(this.itemId, folder.get().getId(), newFileName));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package org.gcube.common.storagehub.client.dsl;
|
package org.gcube.common.storagehub.client.dsl;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -58,6 +60,52 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
||||||
return new FileContainer(itemclient, itemclient.uploadFile(stream, this.itemId , filename, description));
|
return new FileContainer(itemclient, itemclient.uploadFile(stream, this.itemId , filename, description));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* creates a {@AbstractFileItem} inside the folder represented by this FolderContainer
|
||||||
|
*
|
||||||
|
* @param stream the file stream
|
||||||
|
* @param filename the name of the item in the workspace
|
||||||
|
* @param description the description of the item in the workspace
|
||||||
|
* @param size the size of the stream in Bytes
|
||||||
|
* @return {@FileContainer} of the Item created
|
||||||
|
* @throws {@InvalidItemException}
|
||||||
|
* @throws {@UserNotAuthorizedException} if user is not authorized to write in this folder
|
||||||
|
*/
|
||||||
|
public FileContainer uploadFile(InputStream stream, String filename, String description, long size) throws StorageHubException {
|
||||||
|
return new FileContainer(itemclient, itemclient.uploadFile(stream, this.itemId , filename, description, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* creates a {@AbstractFileItem} inside the folder represented by this FolderContainer
|
||||||
|
*
|
||||||
|
* @param file the file
|
||||||
|
* @param description the description of the item in the workspace
|
||||||
|
* @return {@FileContainer} of the Item created
|
||||||
|
* @throws {@InvalidItemException}
|
||||||
|
* @throws {@UserNotAuthorizedException} if user is not authorized to write in this folder
|
||||||
|
*/
|
||||||
|
public FileContainer uploadFile(File file, String description) throws StorageHubException {
|
||||||
|
return new FileContainer(itemclient, itemclient.uploadFile(file, this.itemId , file.getName(), description));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* creates a {@AbstractFileItem} inside the folder represented by this FolderContainer
|
||||||
|
*
|
||||||
|
* @param uri URI of the file
|
||||||
|
* @param name the name of the item in the workspace
|
||||||
|
* @param description the description of the item in the workspace
|
||||||
|
* @return {@FileContainer} of the Item created
|
||||||
|
* @throws {@InvalidItemException}
|
||||||
|
* @throws {@UserNotAuthorizedException} if user is not authorized to write in this folder
|
||||||
|
*/
|
||||||
|
public FileContainer uploadFile(URI uri, String name, String description) throws StorageHubException {
|
||||||
|
return new FileContainer(itemclient, itemclient.uploadFile(uri, this.itemId, name, description));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* creates a {@ExternalLink} inside the folder represented by this FolderContainer
|
* creates a {@ExternalLink} inside the folder represented by this FolderContainer
|
||||||
|
@ -87,6 +135,20 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
||||||
return new FolderContainer(itemclient, itemclient.uploadArchive(stream, this.itemId , extractionFolderName));
|
return new FolderContainer(itemclient, itemclient.uploadArchive(stream, this.itemId , extractionFolderName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* creates a set of {@Item} in the workspace extracting the Archive
|
||||||
|
*
|
||||||
|
* @param stream the file stream
|
||||||
|
* @param extractionFolderName the root name of the folder where the archive will be extracted (A new folder with this name will be created)
|
||||||
|
* @return {@FolderContainer} of the extraction Folder
|
||||||
|
* @throws {@InvalidItemException}
|
||||||
|
* @throws {@UserNotAuthorizedException} if user is not authorized to write in this folder
|
||||||
|
*/
|
||||||
|
public FolderContainer uploadArchive(InputStream stream, String extractionFolderName, long size) throws StorageHubException {
|
||||||
|
return new FolderContainer(itemclient, itemclient.uploadArchive(stream, this.itemId , extractionFolderName, size));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* create a new {@FolderItem} inside the {@FolderItem} represented by this FolderContainer
|
* create a new {@FolderItem} inside the {@FolderItem} represented by this FolderContainer
|
||||||
|
@ -113,7 +175,7 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
||||||
* @throws {@InvalidItemException}
|
* @throws {@InvalidItemException}
|
||||||
* @throws {@UserNotAuthorizedException} if user is not authorized to write in this folder
|
* @throws {@UserNotAuthorizedException} if user is not authorized to write in this folder
|
||||||
*/
|
*/
|
||||||
public FolderContainer newHiddenFolder(String name, String description) throws Exception {
|
public FolderContainer newHiddenFolder(String name, String description) throws StorageHubException {
|
||||||
String newFolderId = itemclient.createFolder(this.itemId, name, description, true);
|
String newFolderId = itemclient.createFolder(this.itemId, name, description, true);
|
||||||
return new FolderContainer(itemclient, newFolderId);
|
return new FolderContainer(itemclient, newFolderId);
|
||||||
}
|
}
|
||||||
|
@ -129,7 +191,7 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
||||||
* @throws {@InvalidItemException}
|
* @throws {@InvalidItemException}
|
||||||
* @throws {@UserNotAuthorizedException} if user is not authorized to write in this folder
|
* @throws {@UserNotAuthorizedException} if user is not authorized to write in this folder
|
||||||
*/
|
*/
|
||||||
public GenericItemContainer newGcubeItem(GCubeItem item) throws Exception {
|
public GenericItemContainer newGcubeItem(GCubeItem item) throws StorageHubException {
|
||||||
String itemId = itemclient.createGcubeItem(this.itemId, item);
|
String itemId = itemclient.createGcubeItem(this.itemId, item);
|
||||||
return new GenericItemContainer(itemclient, itemId);
|
return new GenericItemContainer(itemclient, itemId);
|
||||||
}
|
}
|
||||||
|
@ -141,7 +203,7 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
||||||
* @return a List of {@ACL}
|
* @return a List of {@ACL}
|
||||||
* @throws {@StorageHubException}
|
* @throws {@StorageHubException}
|
||||||
*/
|
*/
|
||||||
public List<ACL> getAcls() throws Exception {
|
public List<ACL> getAcls() throws StorageHubException {
|
||||||
return itemclient.getACL(this.itemId);
|
return itemclient.getACL(this.itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +239,31 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
||||||
return new ListResolver((onlyType, includeHidden, excludes) -> itemclient.findChildrenByNamePattern(itemId, namePattern , excludes), itemclient);
|
return new ListResolver((onlyType, includeHidden, excludes) -> itemclient.findChildrenByNamePattern(itemId, namePattern , excludes), itemclient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* returns the children of this {@FolderContainer} that matches the name pattern
|
||||||
|
*
|
||||||
|
* @return {@ListResolver}
|
||||||
|
* @throws {@InvalidItemException}
|
||||||
|
* @throws {@UserNotAuthorizedException} if user is not authorized to read this folder
|
||||||
|
*/
|
||||||
|
public OpenResolver openByRelativePath(String relativePath) throws StorageHubException {
|
||||||
|
final String id = this.itemId;
|
||||||
|
return new OpenResolver(itemclient.getByRelativePath(id, relativePath), itemclient);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* returns the items that matches the name pattern searching recursively on all subfolders filtering the trashed Items
|
||||||
|
*
|
||||||
|
* @return {@ListResolver}
|
||||||
|
* @throws {@InvalidItemException}
|
||||||
|
* @throws {@UserNotAuthorizedException} if user is not authorized to read this folder
|
||||||
|
*/
|
||||||
|
public ListResolver search(String nameTomatch, boolean excludeTrashed) throws StorageHubException {
|
||||||
|
return new ListResolver((onlyType, includeHidden, excludes) -> itemclient.search(itemId, onlyType, includeHidden, excludeTrashed, nameTomatch, excludes), itemclient);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* returns the items that matches the name pattern searching recursively on all subfolders
|
* returns the items that matches the name pattern searching recursively on all subfolders
|
||||||
|
@ -186,7 +273,7 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
||||||
* @throws {@UserNotAuthorizedException} if user is not authorized to read this folder
|
* @throws {@UserNotAuthorizedException} if user is not authorized to read this folder
|
||||||
*/
|
*/
|
||||||
public ListResolver search(String nameTomatch) throws StorageHubException {
|
public ListResolver search(String nameTomatch) throws StorageHubException {
|
||||||
return new ListResolver((onlyType, includeHidden, excludes) -> itemclient.search(itemId, onlyType, includeHidden, nameTomatch, excludes), itemclient);
|
return search(nameTomatch, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -198,7 +285,7 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
||||||
* @throws {@InvalidItemException}
|
* @throws {@InvalidItemException}
|
||||||
* @throws {@UserNotAuthorizedException} if user is not authorized to share this folder
|
* @throws {@UserNotAuthorizedException} if user is not authorized to share this folder
|
||||||
*/
|
*/
|
||||||
public FolderContainer share(Set<String> users, AccessType accessType) throws Exception {
|
public FolderContainer share(Set<String> users, AccessType accessType) throws StorageHubException {
|
||||||
itemclient.shareFolder(this.itemId, users, accessType);
|
itemclient.shareFolder(this.itemId, users, accessType);
|
||||||
this.invalidateItem();
|
this.invalidateItem();
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
package org.gcube.common.storagehub.client.dsl;
|
||||||
|
|
|
@ -91,6 +91,22 @@ public abstract class ItemContainer<I extends Item> {
|
||||||
itemclient.setMetadata(this.getId(), metadata);
|
itemclient.setMetadata(this.getId(), metadata);
|
||||||
invalidateItem();
|
invalidateItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHidden() throws StorageHubException {
|
||||||
|
itemclient.setHidden(this.getId(), true);
|
||||||
|
invalidateItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) throws StorageHubException {
|
||||||
|
itemclient.setDescription(this.getId(), description);
|
||||||
|
invalidateItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setVisible() throws StorageHubException {
|
||||||
|
itemclient.setHidden(this.getId(), false);
|
||||||
|
invalidateItem();
|
||||||
|
}
|
||||||
|
|
||||||
public FolderContainer getRootSharedFolder() throws StorageHubException {
|
public FolderContainer getRootSharedFolder() throws StorageHubException {
|
||||||
return new FolderContainer(itemclient, (FolderItem)itemclient.getRootSharedFolder(this.itemId));
|
return new FolderContainer(itemclient, (FolderItem)itemclient.getRootSharedFolder(this.itemId));
|
||||||
|
|
|
@ -37,4 +37,15 @@ public class OpenResolver {
|
||||||
return new URLContainer(itemclient, (ExternalLink)item);
|
return new URLContainer(itemclient, (ExternalLink)item);
|
||||||
else throw new RuntimeException("this item is not a File");
|
else throw new RuntimeException("this item is not a File");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ItemContainer<?> resolve(){
|
||||||
|
if (item instanceof FolderItem)
|
||||||
|
return this.asFolder();
|
||||||
|
if (item instanceof AbstractFileItem)
|
||||||
|
return this.asFile();
|
||||||
|
if (item instanceof ExternalLink)
|
||||||
|
return this.asURL();
|
||||||
|
else return this.asItem();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package org.gcube.common.storagehub.client.dsl;
|
package org.gcube.common.storagehub.client.dsl;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||||
|
@ -10,11 +14,25 @@ import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
|
||||||
public class StorageHubClient {
|
public class StorageHubClient {
|
||||||
|
|
||||||
private WorkspaceManagerClient wsClient = AbstractPlugin.workspace().build();
|
protected WorkspaceManagerClient wsClient = AbstractPlugin.workspace().build();
|
||||||
private ItemManagerClient itemclient = AbstractPlugin.item().build();
|
protected ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||||
private GroupManagerClient groupClient = AbstractPlugin.groups().build();
|
protected GroupManagerClient groupClient = AbstractPlugin.groups().build();
|
||||||
private UserManagerClient userClient = AbstractPlugin.users().build();
|
protected UserManagerClient userClient = AbstractPlugin.users().build();
|
||||||
|
|
||||||
|
public StorageHubClient() {}
|
||||||
|
|
||||||
|
public StorageHubClient(URI uri) {
|
||||||
|
wsClient = AbstractPlugin.workspace().at(uri).build();
|
||||||
|
itemclient = AbstractPlugin.item().at(uri).build();
|
||||||
|
groupClient = AbstractPlugin.groups().at(uri).build();
|
||||||
|
userClient = AbstractPlugin.users().at(uri).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void impersonate(String user){
|
||||||
|
wsClient.impersonate(user);
|
||||||
|
itemclient.impersonate(user);
|
||||||
|
}
|
||||||
|
|
||||||
public FolderContainer getWSRoot(){
|
public FolderContainer getWSRoot(){
|
||||||
return new FolderContainer(itemclient, wsClient.getWorkspace());
|
return new FolderContainer(itemclient, wsClient.getWorkspace());
|
||||||
}
|
}
|
||||||
|
@ -28,7 +46,7 @@ public class StorageHubClient {
|
||||||
Item item = itemclient.get(id);
|
Item item = itemclient.get(id);
|
||||||
return new OpenResolver(item, itemclient);
|
return new OpenResolver(item, itemclient);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FolderContainer openVREFolder() {
|
public FolderContainer openVREFolder() {
|
||||||
return new FolderContainer(itemclient, wsClient.getVreFolder());
|
return new FolderContainer(itemclient, wsClient.getVreFolder());
|
||||||
}
|
}
|
||||||
|
@ -49,7 +67,7 @@ public class StorageHubClient {
|
||||||
return new FolderContainer(itemclient, wsClient.getTrashFolder());
|
return new FolderContainer(itemclient, wsClient.getTrashFolder());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void emptyTrash() {
|
public void emptyTrash() throws StorageHubException{
|
||||||
wsClient.emptyTrash();
|
wsClient.emptyTrash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +79,12 @@ public class StorageHubClient {
|
||||||
return wsClient.getTotalItemCount();
|
return wsClient.getTotalItemCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericItemContainer restoreThrashItem(String itemId) {
|
public GenericItemContainer restoreThrashItem(String trashItemId) throws StorageHubException {
|
||||||
return new GenericItemContainer(itemclient, wsClient.restoreFromTrash(itemId));
|
return new GenericItemContainer(itemclient, wsClient.restoreFromTrash(trashItemId, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenericItemContainer restoreThrashItem(String trashItemId, String destinationFolderId) throws StorageHubException {
|
||||||
|
return new GenericItemContainer(itemclient, wsClient.restoreFromTrash(trashItemId, destinationFolderId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createUserAccount(String userId) throws StorageHubException {
|
public void createUserAccount(String userId) throws StorageHubException {
|
||||||
|
@ -72,4 +94,21 @@ public class StorageHubClient {
|
||||||
public void deleteUserAccount(String userId) throws StorageHubException {
|
public void deleteUserAccount(String userId) throws StorageHubException {
|
||||||
userClient.removeUser(userId);
|
userClient.removeUser(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean userExists(String user) throws StorageHubException {
|
||||||
|
return userClient.exists(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String uploadFileOnVolatile(File file) throws StorageHubException {
|
||||||
|
return wsClient.uploadFileToVolatile(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String uploadFileOnVolatile(InputStream stream, String fileName) throws StorageHubException {
|
||||||
|
return wsClient.uploadFileToVolatile(stream, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String uploadFileOnVolatile(InputStream stream, String fileName, long size) throws StorageHubException {
|
||||||
|
return wsClient.uploadFileToVolatile(stream, fileName, size);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
package org.gcube.common.storagehub.client.dsl;
|
package org.gcube.common.storagehub.client.dsl;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
|
||||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
|
||||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
@ -19,10 +15,5 @@ public class Util {
|
||||||
else return new GenericItemContainer(itemClient, item);
|
else return new GenericItemContainer(itemClient, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getVREGroupFromContext(String context) throws BackendGenericError{
|
|
||||||
ScopeBean bean = new ScopeBean(context);
|
|
||||||
if (!bean.is(Type.VRE)) throw new BackendGenericError(context+ " is not a VRE context");
|
|
||||||
String entireScopeName= bean.toString().replaceAll("^/(.*)/?$", "$1").replaceAll("/", "-");
|
|
||||||
return entireScopeName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,14 @@ import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
|
|
||||||
public class VREFolderManager {
|
public class VREFolderManager {
|
||||||
|
|
||||||
private WorkspaceManagerClient wsClient;
|
//private WorkspaceManagerClient wsClient;
|
||||||
private GroupManagerClient groupClient;
|
private GroupManagerClient groupClient;
|
||||||
|
|
||||||
private String vreTitle;
|
private String vreTitle;
|
||||||
|
|
||||||
public VREFolderManager(WorkspaceManagerClient wsClient, GroupManagerClient groupClient, String vreTitle) {
|
protected VREFolderManager(WorkspaceManagerClient wsClient, GroupManagerClient groupClient, String vreTitle) {
|
||||||
super();
|
super();
|
||||||
this.wsClient = wsClient;
|
//this.wsClient = wsClient;
|
||||||
this.groupClient = groupClient;
|
this.groupClient = groupClient;
|
||||||
this.vreTitle = vreTitle;
|
this.vreTitle = vreTitle;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package org.gcube.common.storagehub.client.plugins;
|
package org.gcube.common.storagehub.client.plugins;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.policies.Users;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.clients.Plugin;
|
import org.gcube.common.clients.Plugin;
|
||||||
import org.gcube.common.clients.ProxyBuilder;
|
import org.gcube.common.clients.ProxyBuilder;
|
||||||
import org.gcube.common.clients.ProxyBuilderImpl;
|
import org.gcube.common.clients.ProxyBuilderImpl;
|
||||||
|
@ -8,6 +11,7 @@ import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||||
import org.gcube.common.storagehub.client.Constants;
|
import org.gcube.common.storagehub.client.Constants;
|
||||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||||
|
import org.gcube.common.storagehub.client.proxies.MessageManagerClient;
|
||||||
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
||||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||||
|
|
||||||
|
@ -15,12 +19,12 @@ import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||||
|
|
||||||
public abstract class AbstractPlugin<S,P> implements Plugin<S,P> {
|
public abstract class AbstractPlugin<S,P> implements Plugin<S,P> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static final ItemManagerPlugin item_plugin = new ItemManagerPlugin();
|
private static final ItemManagerPlugin item_plugin = new ItemManagerPlugin();
|
||||||
private static final WorkspaceManagerPlugin workspace_plugin = new WorkspaceManagerPlugin();
|
private static final WorkspaceManagerPlugin workspace_plugin = new WorkspaceManagerPlugin();
|
||||||
private static final UserManagerPlugin user_plugin = new UserManagerPlugin();
|
private static final UserManagerPlugin user_plugin = new UserManagerPlugin();
|
||||||
private static final GroupManagerPlugin group_plugin = new GroupManagerPlugin();
|
private static final GroupManagerPlugin group_plugin = new GroupManagerPlugin();
|
||||||
|
private static final MessageManagerPlugin messages_plugin = new MessageManagerPlugin();
|
||||||
|
|
||||||
|
|
||||||
public static ProxyBuilder<ItemManagerClient> item() {
|
public static ProxyBuilder<ItemManagerClient> item() {
|
||||||
|
@ -28,6 +32,7 @@ public abstract class AbstractPlugin<S,P> implements Plugin<S,P> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProxyBuilder<GroupManagerClient> groups() {
|
public static ProxyBuilder<GroupManagerClient> groups() {
|
||||||
|
|
||||||
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,GroupManagerClient>(group_plugin);
|
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,GroupManagerClient>(group_plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,9 +43,15 @@ public abstract class AbstractPlugin<S,P> implements Plugin<S,P> {
|
||||||
public static ProxyBuilder<WorkspaceManagerClient> workspace() {
|
public static ProxyBuilder<WorkspaceManagerClient> workspace() {
|
||||||
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,WorkspaceManagerClient>(workspace_plugin);
|
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,WorkspaceManagerClient>(workspace_plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ProxyBuilder<MessageManagerClient> messages() {
|
||||||
|
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,MessageManagerClient>(messages_plugin);
|
||||||
|
}
|
||||||
|
|
||||||
public final String name;
|
public final String name;
|
||||||
|
|
||||||
|
protected List<Class<?>> customClasses = Collections.emptyList();
|
||||||
|
|
||||||
public AbstractPlugin(String name) {
|
public AbstractPlugin(String name) {
|
||||||
this.name=name;
|
this.name=name;
|
||||||
}
|
}
|
||||||
|
@ -65,4 +76,7 @@ public abstract class AbstractPlugin<S,P> implements Plugin<S,P> {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void register(Class<?> ... _classes) {
|
||||||
|
customClasses = Arrays.asList(_classes);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -12,9 +12,7 @@ import org.gcube.common.gxrest.response.entity.SerializableErrorEntityTextReader
|
||||||
import org.gcube.common.storagehub.client.Constants;
|
import org.gcube.common.storagehub.client.Constants;
|
||||||
import org.gcube.common.storagehub.client.MyInputStreamProvider;
|
import org.gcube.common.storagehub.client.MyInputStreamProvider;
|
||||||
import org.gcube.common.storagehub.client.proxies.DefaultGroupManager;
|
import org.gcube.common.storagehub.client.proxies.DefaultGroupManager;
|
||||||
import org.gcube.common.storagehub.client.proxies.DefaultUserManager;
|
|
||||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||||
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
|
||||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
|
@ -29,6 +27,7 @@ public class GroupManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupManagerClient newProxy(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
public GroupManagerClient newProxy(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||||
return new DefaultGroupManager(delegate);
|
return new DefaultGroupManager(delegate);
|
||||||
|
@ -48,6 +47,10 @@ public class GroupManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest
|
||||||
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
||||||
requestAdapter.register(MyInputStreamProvider.class);
|
requestAdapter.register(MyInputStreamProvider.class);
|
||||||
requestAdapter.register(MultiPartFeature.class);
|
requestAdapter.register(MultiPartFeature.class);
|
||||||
|
customClasses.forEach(c -> requestAdapter.register(c));
|
||||||
return requestAdapter;
|
return requestAdapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.common.storagehub.client.plugins;
|
package org.gcube.common.storagehub.client.plugins;
|
||||||
|
|
||||||
|
|
||||||
import javax.xml.transform.dom.DOMResult;
|
import javax.xml.transform.dom.DOMResult;
|
||||||
import javax.xml.ws.EndpointReference;
|
import javax.xml.ws.EndpointReference;
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
public class ItemManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest, ItemManagerClient> {
|
public class ItemManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest, ItemManagerClient> {
|
||||||
|
|
||||||
public ItemManagerPlugin() {
|
public ItemManagerPlugin() {
|
||||||
super("storagehub/workspace");
|
super("storagehub/workspace");
|
||||||
}
|
}
|
||||||
|
@ -46,6 +47,7 @@ public class ItemManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest,
|
||||||
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
||||||
requestAdapter.register(MyInputStreamProvider.class);
|
requestAdapter.register(MyInputStreamProvider.class);
|
||||||
requestAdapter.register(MultiPartFeature.class);
|
requestAdapter.register(MultiPartFeature.class);
|
||||||
|
customClasses.forEach(c -> requestAdapter.register(c));
|
||||||
return requestAdapter;
|
return requestAdapter;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package org.gcube.common.storagehub.client.plugins;
|
||||||
|
|
||||||
|
import javax.xml.transform.dom.DOMResult;
|
||||||
|
import javax.xml.ws.EndpointReference;
|
||||||
|
|
||||||
|
import org.gcube.common.calls.jaxrs.GcubeService;
|
||||||
|
import org.gcube.common.calls.jaxrs.TargetFactory;
|
||||||
|
import org.gcube.common.clients.config.ProxyConfig;
|
||||||
|
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||||
|
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||||
|
import org.gcube.common.gxrest.response.entity.SerializableErrorEntityTextReader;
|
||||||
|
import org.gcube.common.storagehub.client.Constants;
|
||||||
|
import org.gcube.common.storagehub.client.MyInputStreamProvider;
|
||||||
|
import org.gcube.common.storagehub.client.proxies.DefaultMessageManager;
|
||||||
|
import org.gcube.common.storagehub.client.proxies.MessageManagerClient;
|
||||||
|
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
|
public class MessageManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest, MessageManagerClient> {
|
||||||
|
|
||||||
|
public MessageManagerPlugin() {
|
||||||
|
super("storagehub/workspace");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Exception convert(Exception e, ProxyConfig<?, ?> arg1) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageManagerClient newProxy(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||||
|
return new DefaultMessageManager(delegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GXWebTargetAdapterRequest resolve(EndpointReference epr, ProxyConfig<?, ?> config)
|
||||||
|
throws Exception {
|
||||||
|
DOMResult result = new DOMResult();
|
||||||
|
epr.writeTo(result);
|
||||||
|
Node node =result.getNode();
|
||||||
|
Node child=node.getFirstChild();
|
||||||
|
String address = child.getTextContent();
|
||||||
|
//GXWebTargetAdapterRequest request = GXWebTargetAdapterRequest.newRequest(address).path(this.name).path("items");
|
||||||
|
GcubeService service = GcubeService.service().withName(Constants.MANAGER_QNAME).andPath("messages");
|
||||||
|
GXWebTargetAdapterRequest requestAdapter = TargetFactory.stubFor(service).getAsGxRest(address);
|
||||||
|
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
||||||
|
requestAdapter.register(MyInputStreamProvider.class);
|
||||||
|
requestAdapter.register(MultiPartFeature.class);
|
||||||
|
customClasses.forEach(c -> requestAdapter.register(c));
|
||||||
|
return requestAdapter;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -46,6 +46,7 @@ public class UserManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest,
|
||||||
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
||||||
requestAdapter.register(MyInputStreamProvider.class);
|
requestAdapter.register(MyInputStreamProvider.class);
|
||||||
requestAdapter.register(MultiPartFeature.class);
|
requestAdapter.register(MultiPartFeature.class);
|
||||||
|
customClasses.forEach(c -> requestAdapter.register(c));
|
||||||
return requestAdapter;
|
return requestAdapter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ public class WorkspaceManagerPlugin extends AbstractPlugin<GXWebTargetAdapterReq
|
||||||
|
|
||||||
GXWebTargetAdapterRequest requestAdapter = TargetFactory.stubFor(service).getAsGxRest(address);
|
GXWebTargetAdapterRequest requestAdapter = TargetFactory.stubFor(service).getAsGxRest(address);
|
||||||
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
||||||
|
customClasses.forEach(c -> requestAdapter.register(c));
|
||||||
return requestAdapter;
|
return requestAdapter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,14 @@ import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||||
|
|
||||||
public class DefaultGroupManager implements GroupManagerClient {
|
public class DefaultGroupManager extends DefaultManagerClient implements GroupManagerClient {
|
||||||
|
|
||||||
private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
|
|
||||||
|
|
||||||
public DefaultGroupManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
public DefaultGroupManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||||
this.delegate = delegate;
|
super(delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addUserToGroup(String userId, String groupId) throws StorageHubException {
|
public void addUserToGroup(String userId, String groupId) throws StorageHubException {
|
||||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package org.gcube.common.storagehub.client.proxies;
|
package org.gcube.common.storagehub.client.proxies;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.net.URLEncoder;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -32,19 +34,22 @@ import org.gcube.common.storagehub.model.service.ItemWrapper;
|
||||||
import org.gcube.common.storagehub.model.service.Version;
|
import org.gcube.common.storagehub.model.service.Version;
|
||||||
import org.gcube.common.storagehub.model.service.VersionList;
|
import org.gcube.common.storagehub.model.service.VersionList;
|
||||||
import org.gcube.common.storagehub.model.types.ACLList;
|
import org.gcube.common.storagehub.model.types.ACLList;
|
||||||
|
import org.glassfish.jersey.media.multipart.BodyPart;
|
||||||
|
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||||
|
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
|
||||||
|
import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart;
|
||||||
|
|
||||||
public class DefaultItemManager implements ItemManagerClient {
|
public class DefaultItemManager extends DefaultManagerClient implements ItemManagerClient {
|
||||||
|
|
||||||
private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
|
|
||||||
|
|
||||||
|
|
||||||
private static final String CONTENT_DISPOSITION= "Content-Disposition";
|
private static final String CONTENT_DISPOSITION= "Content-Disposition";
|
||||||
private static final String CONTENT_TYPE= "Content-Type";
|
private static final String CONTENT_TYPE= "Content-Type";
|
||||||
private static final String CONTENT_LENGHT= "Content-Length";
|
private static final String CONTENT_LENGHT= "Content-Length";
|
||||||
|
|
||||||
public DefaultItemManager(ProxyDelegate<GXWebTargetAdapterRequest> config){
|
public DefaultItemManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||||
this.delegate = config;
|
super(delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +61,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
Objects.requireNonNull(identifier, "id cannot be null");
|
Objects.requireNonNull(identifier, "id cannot be null");
|
||||||
|
|
||||||
GXWebTargetAdapterRequest myManager = manager.path("publiclink").path(identifier);
|
GXWebTargetAdapterRequest myManager = manager.path("publiclink").path(identifier);
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
|
|
||||||
GXInboundResponse response = myManager.queryParams(params).get();
|
GXInboundResponse response = myManager.queryParams(params).get();
|
||||||
|
|
||||||
|
@ -96,14 +101,15 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
public ItemList call(GXWebTargetAdapterRequest manager) throws StorageHubException, Exception {
|
public ItemList call(GXWebTargetAdapterRequest manager) throws StorageHubException, Exception {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("children");
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("children");
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
if (excludeNodes !=null && excludeNodes.length>0)
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
params.put("exclude",excludeNodes);
|
params.put("exclude",excludeNodes);
|
||||||
|
|
||||||
if (onlyOfType!=null)
|
if (onlyOfType!=null)
|
||||||
params.put("onlyType", new Object[] {resolveNodeType(onlyOfType)});
|
params.put("onlyType", new Object[] {resolveNodeType(onlyOfType)});
|
||||||
params.put("showHidden", new Object[] {showHidden});
|
params.put("showHidden", new Object[] {showHidden});
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.queryParams(params).get();
|
GXInboundResponse response = myManager.queryParams(params).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
|
@ -137,7 +143,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
try {
|
try {
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("children").path("paged");
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("children").path("paged");
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
|
|
||||||
|
|
||||||
if (excludeNodes !=null && excludeNodes.length>0)
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
|
@ -150,6 +156,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
params.put("limit", new Object[] {limit});
|
params.put("limit", new Object[] {limit});
|
||||||
params.put("showHidden", new Object[] {showHidden});
|
params.put("showHidden", new Object[] {showHidden});
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.queryParams(params).get();
|
GXInboundResponse response = myManager.queryParams(params).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
|
@ -197,21 +204,23 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
return getChildren(id, null, showHidden, excludeNodes);
|
return getChildren(id, null, showHidden, excludeNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<? extends Item> search(String id, Class<? extends Item> onlyOfType, boolean showHidden, String nameToMatch, String ... excludeNodes) throws StorageHubException{
|
public List<? extends Item> search(String id, Class<? extends Item> onlyOfType, boolean showHidden, boolean excludeTrashed, String nameToMatch, String ... excludeNodes) throws StorageHubException{
|
||||||
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
||||||
@Override
|
@Override
|
||||||
public ItemList call(GXWebTargetAdapterRequest manager) throws StorageHubException, Exception {
|
public ItemList call(GXWebTargetAdapterRequest manager) throws StorageHubException, Exception {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("search");
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("search");
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
if (excludeNodes !=null && excludeNodes.length>0)
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
params.put("exclude",excludeNodes);
|
params.put("exclude",excludeNodes);
|
||||||
|
|
||||||
if (onlyOfType!=null)
|
if (onlyOfType!=null)
|
||||||
params.put("onlyType", new Object[] {resolveNodeType(onlyOfType)});
|
params.put("onlyType", new Object[] {resolveNodeType(onlyOfType)});
|
||||||
params.put("showHidden", new Object[] {showHidden});
|
params.put("showHidden", new Object[] {showHidden});
|
||||||
params.put("name", new Object[] {nameToMatch});
|
params.put("name", new String[] {URLEncoder.encode( nameToMatch, "UTF-8" )});
|
||||||
|
params.put("excludeTrashed", new Object[] {excludeTrashed});
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.queryParams(params).get();
|
GXInboundResponse response = myManager.queryParams(params).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
|
@ -250,12 +259,13 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
public Integer call(GXWebTargetAdapterRequest manager) throws Exception {
|
public Integer call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("children").path("count");
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("children").path("count");
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
if (onlyOfType!=null)
|
if (onlyOfType!=null)
|
||||||
params.put("onlyType", new Object[] {resolveNodeType(onlyOfType)});
|
params.put("onlyType", new Object[] {resolveNodeType(onlyOfType)});
|
||||||
|
|
||||||
params.put("showHidden", new Object[] {showHidden});
|
params.put("showHidden", new Object[] {showHidden});
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.queryParams(params).get();
|
GXInboundResponse response = myManager.queryParams(params).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
|
@ -291,7 +301,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
|
|
||||||
private String resolveNodeType(Class<? extends Item> itemClass) throws StorageHubException {
|
private String resolveNodeType(Class<? extends Item> itemClass) throws StorageHubException {
|
||||||
if (!itemClass.isAnnotationPresent(RootNode.class)) return null;
|
if (!itemClass.isAnnotationPresent(RootNode.class)) return null;
|
||||||
String nodeType= itemClass.getAnnotation(RootNode.class).value();
|
String nodeType= itemClass.getAnnotation(RootNode.class).value()[0];
|
||||||
return nodeType;
|
return nodeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,11 +313,11 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
public StreamDescriptor call(GXWebTargetAdapterRequest manager) throws Exception {
|
public StreamDescriptor call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("download");
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("download");
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
|
|
||||||
if (excludeNodes !=null && excludeNodes.length>0)
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
params.put("exclude",excludeNodes);
|
params.put("exclude",excludeNodes);
|
||||||
|
|
||||||
GXInboundResponse response = myManager.queryParams(params).get();
|
GXInboundResponse response = myManager.queryParams(params).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
|
@ -340,7 +350,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
Objects.requireNonNull(version, "version cannot be null");
|
Objects.requireNonNull(version, "version cannot be null");
|
||||||
|
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("versions").path(version).path("download");
|
GXWebTargetAdapterRequest myManager = manager.path(id).queryParams(initQueryParameters()).path("versions").path(version).path("download");
|
||||||
|
|
||||||
GXInboundResponse response = myManager.get();
|
GXInboundResponse response = myManager.get();
|
||||||
|
|
||||||
|
@ -375,7 +385,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("versions");
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("versions");
|
||||||
|
|
||||||
GXInboundResponse response = myManager.get();
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -399,6 +409,37 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteFileVersion(String id, String versionName) throws StorageHubException {
|
||||||
|
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||||
|
@Override
|
||||||
|
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
|
Objects.requireNonNull(versionName, "version name cannot be null");
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("versions").path(versionName);
|
||||||
|
|
||||||
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).delete();
|
||||||
|
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException())
|
||||||
|
throw response.getException();
|
||||||
|
else
|
||||||
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
delegate.make(call);
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item get(String id, String... excludeNodes) throws StorageHubException {
|
public Item get(String id, String... excludeNodes) throws StorageHubException {
|
||||||
Call<GXWebTargetAdapterRequest, ItemWrapper<Item>> call = new Call<GXWebTargetAdapterRequest, ItemWrapper<Item>>() {
|
Call<GXWebTargetAdapterRequest, ItemWrapper<Item>> call = new Call<GXWebTargetAdapterRequest, ItemWrapper<Item>>() {
|
||||||
|
@ -406,7 +447,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
public ItemWrapper<Item> call(GXWebTargetAdapterRequest manager) throws Exception {
|
public ItemWrapper<Item> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id);
|
GXWebTargetAdapterRequest myManager = manager.path(id);
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
|
|
||||||
if (excludeNodes !=null && excludeNodes.length>0)
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
params.put("exclude",excludeNodes);
|
params.put("exclude",excludeNodes);
|
||||||
|
@ -435,14 +476,55 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
throw new RuntimeException(e1);
|
throw new RuntimeException(e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item getByRelativePath(String id, String path, String... excludeNodes) throws StorageHubException {
|
||||||
|
Call<GXWebTargetAdapterRequest, ItemWrapper<Item>> call = new Call<GXWebTargetAdapterRequest, ItemWrapper<Item>>() {
|
||||||
|
@Override
|
||||||
|
public ItemWrapper<Item> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
|
Objects.requireNonNull(path, "path cannot be null");
|
||||||
|
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("path");
|
||||||
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
|
|
||||||
|
params.put("path",new String[] {path});
|
||||||
|
|
||||||
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
|
params.put("exclude",excludeNodes);
|
||||||
|
|
||||||
|
GXInboundResponse response = myManager.queryParams(params).get();
|
||||||
|
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException())
|
||||||
|
throw response.getException();
|
||||||
|
else
|
||||||
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemWrapper<Item> item = response.getSource().readEntity(ItemWrapper.class);
|
||||||
|
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
ItemWrapper<Item> result = delegate.make(call);
|
||||||
|
return result.getItem();
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item getRootSharedFolder(String id) throws StorageHubException {
|
public Item getRootSharedFolder(String id) throws StorageHubException {
|
||||||
Call<GXWebTargetAdapterRequest, ItemWrapper<Item>> call = new Call<GXWebTargetAdapterRequest, ItemWrapper<Item>>() {
|
Call<GXWebTargetAdapterRequest, ItemWrapper<Item>> call = new Call<GXWebTargetAdapterRequest, ItemWrapper<Item>>() {
|
||||||
@Override
|
@Override
|
||||||
public ItemWrapper<Item> call(GXWebTargetAdapterRequest manager) throws Exception {
|
public ItemWrapper<Item> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("rootSharedFolder");
|
GXWebTargetAdapterRequest myManager = manager.path(id).queryParams(initQueryParameters()).path("rootSharedFolder");
|
||||||
GXInboundResponse response = myManager.get();
|
GXInboundResponse response = myManager.get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
|
@ -476,7 +558,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
public URL call(GXWebTargetAdapterRequest manager) throws Exception {
|
public URL call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("publiclink");
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("publiclink");
|
||||||
GXInboundResponse response = myManager.get();
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -509,7 +591,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
Objects.requireNonNull(version, "version cannot be null");
|
Objects.requireNonNull(version, "version cannot be null");
|
||||||
|
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("publiclink");
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("publiclink");
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
params.put("version",new Object[] {version});
|
params.put("version",new Object[] {version});
|
||||||
GXInboundResponse response = myManager.queryParams(params).get();
|
GXInboundResponse response = myManager.queryParams(params).get();
|
||||||
|
|
||||||
|
@ -544,12 +626,13 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
Objects.requireNonNull(id, "name cannot be null");
|
Objects.requireNonNull(id, "name cannot be null");
|
||||||
|
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("items").path(name);
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("items");
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
|
|
||||||
if (excludeNodes !=null && excludeNodes.length>0)
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
params.put("exclude",excludeNodes);
|
params.put("exclude",excludeNodes);
|
||||||
|
params.put("name", new Object[] {name});
|
||||||
|
|
||||||
GXInboundResponse response = myManager.queryParams(params).get();
|
GXInboundResponse response = myManager.queryParams(params).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
|
@ -573,10 +656,14 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
throw new RuntimeException(e1);
|
throw new RuntimeException(e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String uploadFile(InputStream stream, String parentId, String fileName, String description) throws StorageHubException {
|
public String uploadFile(InputStream stream, String parentId, String fileName, String description) throws StorageHubException {
|
||||||
|
return this.uploadFile(stream, parentId, fileName, description, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String uploadFile(InputStream stream, String parentId, String fileName, String description, long contentLength) throws StorageHubException {
|
||||||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
@ -584,7 +671,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
Objects.requireNonNull(parentId, "parentId cannot be null");
|
Objects.requireNonNull(parentId, "parentId cannot be null");
|
||||||
Objects.requireNonNull(fileName, "parentId cannot be null");
|
Objects.requireNonNull(fileName, "parentId cannot be null");
|
||||||
Objects.requireNonNull(description, "parentId cannot be null");
|
Objects.requireNonNull(description, "parentId cannot be null");
|
||||||
|
|
||||||
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
||||||
.path("create").path("FILE");
|
.path("create").path("FILE");
|
||||||
|
|
||||||
|
@ -593,11 +680,14 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
|
|
||||||
multipart.field("name", fileName);
|
multipart.field("name", fileName);
|
||||||
multipart.field("description", description);
|
multipart.field("description", description);
|
||||||
multipart.field("file", stream, MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
|
||||||
|
|
||||||
Entity<FormDataMultiPart> entity = Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA);
|
StreamDataBodyPart filePart = new StreamDataBodyPart("file", stream);
|
||||||
|
filePart.setContentDisposition(FormDataContentDisposition.name("file").fileName(fileName).size(contentLength).build());
|
||||||
response = myManager.post(entity);
|
|
||||||
|
multipart.bodyPart(filePart);
|
||||||
|
|
||||||
|
response = myManager.queryParams(initQueryParameters()).post(Entity.entity(multipart, multipart.getMediaType()));
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException()) {
|
if (response.hasException()) {
|
||||||
|
@ -617,9 +707,97 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
throw new RuntimeException(e1);
|
throw new RuntimeException(e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String uploadArchive(InputStream stream, String parentId, String extractionFolderName) throws StorageHubException {
|
public String uploadFile(File file, String parentId, String fileName, String description) throws StorageHubException {
|
||||||
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||||
|
@Override
|
||||||
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
Objects.requireNonNull(file, "file cannot be null");
|
||||||
|
Objects.requireNonNull(parentId, "parentId cannot be null");
|
||||||
|
Objects.requireNonNull(fileName, "parentId cannot be null");
|
||||||
|
Objects.requireNonNull(description, "parentId cannot be null");
|
||||||
|
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
||||||
|
.path("create").path("FILE");
|
||||||
|
|
||||||
|
GXInboundResponse response =null;
|
||||||
|
FormDataMultiPart multipart = new FormDataMultiPart();
|
||||||
|
|
||||||
|
multipart.field("name", fileName);
|
||||||
|
multipart.field("description", description);
|
||||||
|
|
||||||
|
BodyPart fdp = new FileDataBodyPart("file", file);
|
||||||
|
|
||||||
|
multipart.bodyPart(fdp);
|
||||||
|
|
||||||
|
Entity<FormDataMultiPart> entity = Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA);
|
||||||
|
|
||||||
|
response = myManager.queryParams(initQueryParameters()).post(entity);
|
||||||
|
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException()) {
|
||||||
|
throw response.getException();
|
||||||
|
}else
|
||||||
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.getSource().readEntity(String.class);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
return delegate.make(call);
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String uploadFile(URI uri, String parentId, String fileName, String description) throws StorageHubException {
|
||||||
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||||
|
@Override
|
||||||
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
Objects.requireNonNull(uri, "uri cannot be null");
|
||||||
|
Objects.requireNonNull(parentId, "parentId cannot be null");
|
||||||
|
Objects.requireNonNull(fileName, "parentId cannot be null");
|
||||||
|
Objects.requireNonNull(description, "parentId cannot be null");
|
||||||
|
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
||||||
|
.path("create").path("FILE");
|
||||||
|
|
||||||
|
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
||||||
|
formData.add("url", uri.toString());
|
||||||
|
formData.add("name", fileName);
|
||||||
|
formData.add("description", description);
|
||||||
|
|
||||||
|
|
||||||
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
||||||
|
|
||||||
|
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException()) {
|
||||||
|
throw response.getException();
|
||||||
|
}else
|
||||||
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.getSource().readEntity(String.class);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
return delegate.make(call);
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String uploadArchive(InputStream stream, String parentId, String extractionFolderName, long contentLength)
|
||||||
|
throws StorageHubException {
|
||||||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
@ -633,8 +811,11 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
FormDataMultiPart multipart = new FormDataMultiPart();
|
FormDataMultiPart multipart = new FormDataMultiPart();
|
||||||
multipart.field("parentFolderName", extractionFolderName);
|
multipart.field("parentFolderName", extractionFolderName);
|
||||||
multipart.field("file", stream, MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
multipart.field("file", stream, MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
||||||
|
|
||||||
GXInboundResponse response = myManager.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
|
if (contentLength >0)
|
||||||
|
myManager = myManager.header("Content-Length", contentLength);
|
||||||
|
|
||||||
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -655,6 +836,11 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
throw new RuntimeException(e1);
|
throw new RuntimeException(e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String uploadArchive(InputStream stream, String parentId, String extractionFolderName) throws StorageHubException {
|
||||||
|
return this.uploadArchive(stream, parentId, extractionFolderName, 0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -694,7 +880,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
formData.add("hidden", Boolean.toString(hidden));
|
formData.add("hidden", Boolean.toString(hidden));
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -735,7 +921,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
formData.add("value", url.toString());
|
formData.add("value", url.toString());
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -770,7 +956,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
.path("create").path("GCUBEITEM");
|
.path("create").path("GCUBEITEM");
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.post(Entity.json(item));
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).post(Entity.json(item));
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -808,7 +994,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
multipart.field("defaultAccessType", accessType, MediaType.APPLICATION_JSON_TYPE);
|
multipart.field("defaultAccessType", accessType, MediaType.APPLICATION_JSON_TYPE);
|
||||||
multipart.field("users", users, MediaType.APPLICATION_JSON_TYPE);
|
multipart.field("users", users, MediaType.APPLICATION_JSON_TYPE);
|
||||||
|
|
||||||
GXInboundResponse response = myManager.put(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -843,7 +1029,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
|
|
||||||
try (FormDataMultiPart multipart = new FormDataMultiPart()){
|
try (FormDataMultiPart multipart = new FormDataMultiPart()){
|
||||||
multipart.field("users", users, MediaType.APPLICATION_JSON_TYPE);
|
multipart.field("users", users, MediaType.APPLICATION_JSON_TYPE);
|
||||||
GXInboundResponse response = myManager.put(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -878,7 +1064,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
|
|
||||||
HashMap<String, Object[]> queryParam = new HashMap<String, Object[]>();
|
Map<String, Object[]> queryParam = initQueryParameters();
|
||||||
queryParam.put("force", new Object[] {force});
|
queryParam.put("force", new Object[] {force});
|
||||||
|
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id);
|
GXWebTargetAdapterRequest myManager = manager.path(id);
|
||||||
|
@ -912,7 +1098,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
|
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("anchestors");
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("anchestors");
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
|
|
||||||
if (excludeNodes !=null && excludeNodes.length>0)
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
params.put("exclude",excludeNodes);
|
params.put("exclude",excludeNodes);
|
||||||
|
@ -946,7 +1132,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
public ACLList call(GXWebTargetAdapterRequest manager) throws Exception {
|
public ACLList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
|
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("acls");
|
GXWebTargetAdapterRequest myManager = manager.queryParams(initQueryParameters()).path(id).path("acls");
|
||||||
GXInboundResponse response = myManager.get();
|
GXInboundResponse response = myManager.get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
|
@ -977,7 +1163,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
public Boolean call(GXWebTargetAdapterRequest manager) throws Exception {
|
public Boolean call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
Objects.requireNonNull(id, "id cannot be null");
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
|
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("acls").path("write");
|
GXWebTargetAdapterRequest myManager = manager.queryParams(initQueryParameters()).path(id).path("acls").path("write");
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.get();
|
GXInboundResponse response = myManager.get();
|
||||||
|
@ -1015,7 +1201,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
Objects.requireNonNull(user, "user cannot be null");
|
Objects.requireNonNull(user, "user cannot be null");
|
||||||
|
|
||||||
|
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("acls");
|
GXWebTargetAdapterRequest myManager = manager.queryParams(initQueryParameters()).path(id).path("acls");
|
||||||
|
|
||||||
try (FormDataMultiPart multipart = new FormDataMultiPart()){
|
try (FormDataMultiPart multipart = new FormDataMultiPart()){
|
||||||
multipart.field("access", accessType, MediaType.APPLICATION_JSON_TYPE);
|
multipart.field("access", accessType, MediaType.APPLICATION_JSON_TYPE);
|
||||||
|
@ -1054,7 +1240,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
Objects.requireNonNull(user, "user cannot be null");
|
Objects.requireNonNull(user, "user cannot be null");
|
||||||
|
|
||||||
|
|
||||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("acls").path(user);
|
GXWebTargetAdapterRequest myManager = manager.queryParams(initQueryParameters()).path(id).path("acls").path(user);
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.delete();
|
GXInboundResponse response = myManager.delete();
|
||||||
|
@ -1098,7 +1284,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
formData.add("fileName", newFilename);
|
formData.add("fileName", newFilename);
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.put(Entity.form(formData));
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.form(formData));
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -1136,7 +1322,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
formData.add("publish", Boolean.toString(publish));
|
formData.add("publish", Boolean.toString(publish));
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.put(Entity.form(formData));
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.form(formData));
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -1174,7 +1360,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
formData.add("destinationId", destinationFolderId);
|
formData.add("destinationId", destinationFolderId);
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.put(Entity.form(formData));
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.form(formData));
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -1210,7 +1396,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
formData.add("newName", newName);
|
formData.add("newName", newName);
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.put(Entity.form(formData));
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.form(formData));
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -1231,6 +1417,76 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String setHidden(String id, Boolean value) throws StorageHubException {
|
||||||
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||||
|
@Override
|
||||||
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
|
Objects.requireNonNull(value, "value cannot be null");
|
||||||
|
|
||||||
|
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.path(id)
|
||||||
|
.path("hidden");
|
||||||
|
|
||||||
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.json(value));
|
||||||
|
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException())
|
||||||
|
throw response.getException();
|
||||||
|
else
|
||||||
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.getSource().readEntity(String.class);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
return delegate.make(call);
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String setDescription(String id, String description) throws StorageHubException {
|
||||||
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||||
|
@Override
|
||||||
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
|
Objects.requireNonNull(description, "description cannot be null");
|
||||||
|
|
||||||
|
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.path(id)
|
||||||
|
.path("description");
|
||||||
|
|
||||||
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.json(description));
|
||||||
|
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException())
|
||||||
|
throw response.getException();
|
||||||
|
else
|
||||||
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.getSource().readEntity(String.class);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
return delegate.make(call);
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String setMetadata(String id, Metadata metadata) throws StorageHubException {
|
public String setMetadata(String id, Metadata metadata) throws StorageHubException {
|
||||||
|
@ -1245,7 +1501,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
.path("metadata");
|
.path("metadata");
|
||||||
|
|
||||||
|
|
||||||
GXInboundResponse response = myManager.put(Entity.json(metadata));
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.json(metadata));
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -1280,4 +1536,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
}
|
}
|
||||||
return new StreamDescriptor(stream, fileName, contentType, contentLenght);
|
return new StreamDescriptor(stream, fileName, contentType, contentLenght);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package org.gcube.common.storagehub.client.proxies;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||||
|
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||||
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||||
|
|
||||||
|
public abstract class DefaultManagerClient implements ManagerClient{
|
||||||
|
|
||||||
|
protected ProxyDelegate<GXWebTargetAdapterRequest> delegate;
|
||||||
|
|
||||||
|
private String impersonedUser= null;
|
||||||
|
|
||||||
|
public DefaultManagerClient(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(Class<?> _classes) {
|
||||||
|
((AbstractPlugin<?,?>) delegate.config().plugin()).register(_classes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void impersonate(String user) {
|
||||||
|
this.impersonedUser = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<String, Object[]> initQueryParameters() {
|
||||||
|
Map<String, Object[]> params = new HashMap<String, Object[]>();
|
||||||
|
if (impersonedUser != null)
|
||||||
|
params.put("impersonate", new Object[] {impersonedUser});
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,253 @@
|
||||||
|
package org.gcube.common.storagehub.client.proxies;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import javax.ws.rs.client.Entity;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.MultivaluedHashMap;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
|
||||||
|
import org.gcube.common.clients.Call;
|
||||||
|
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||||
|
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||||
|
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
||||||
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
import org.gcube.common.storagehub.model.messages.Message;
|
||||||
|
import org.gcube.common.storagehub.model.service.ItemList;
|
||||||
|
import org.gcube.common.storagehub.model.types.MessageList;
|
||||||
|
|
||||||
|
public class DefaultMessageManager extends DefaultManagerClient implements MessageManagerClient {
|
||||||
|
|
||||||
|
|
||||||
|
public DefaultMessageManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||||
|
super(delegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Message get(String id) throws StorageHubException {
|
||||||
|
Call<GXWebTargetAdapterRequest, Message> call = new Call<GXWebTargetAdapterRequest, Message>() {
|
||||||
|
@Override
|
||||||
|
public Message call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.path(id);
|
||||||
|
|
||||||
|
GXInboundResponse response = myManager.get();
|
||||||
|
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException())
|
||||||
|
throw response.getException();
|
||||||
|
else
|
||||||
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
Message item = response.getSource().readEntity(Message.class);
|
||||||
|
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
return delegate.make(call);
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Message> getReceivedMessages(int reduceBody) throws StorageHubException {
|
||||||
|
return getMessages("inbox", reduceBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Message> getSentMessages(int reduceBody) throws StorageHubException {
|
||||||
|
return getMessages("sent", reduceBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Message> getReceivedMessages() throws StorageHubException {
|
||||||
|
return getMessages("inbox", -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Message> getSentMessages() throws StorageHubException {
|
||||||
|
return getMessages("sent", -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRead(String id, Boolean value) throws StorageHubException {
|
||||||
|
setBooleanProp("hl:read", value, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOpened(String id, Boolean value) throws StorageHubException {
|
||||||
|
setBooleanProp("hl:open", value, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void setBooleanProp(String prop, Boolean bool, String id) throws StorageHubException {
|
||||||
|
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||||
|
@Override
|
||||||
|
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.path(id).path(prop);
|
||||||
|
|
||||||
|
GXInboundResponse response = myManager.put(Entity.json(bool));
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException())
|
||||||
|
throw response.getException();
|
||||||
|
else
|
||||||
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
delegate.make(call);
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String sendMessage(List<String> recipients, String subject, String body, List<String> attachments) throws StorageHubException {
|
||||||
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||||
|
@Override
|
||||||
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
Objects.requireNonNull(recipients, "recipients cannot be null");
|
||||||
|
Objects.requireNonNull(subject, "subject cannot be null");
|
||||||
|
Objects.requireNonNull(body, "body cannot be null");
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.path("send");
|
||||||
|
MultivaluedMap<String, Object> formData = new MultivaluedHashMap<String, Object>();
|
||||||
|
|
||||||
|
recipients.forEach(r-> formData.add("to[]", r));
|
||||||
|
formData.add("subject", subject);
|
||||||
|
formData.add("body", body);
|
||||||
|
if (attachments!=null)
|
||||||
|
attachments.forEach(a -> formData.add("attachments[]", a));
|
||||||
|
|
||||||
|
GXInboundResponse response = myManager.post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException())
|
||||||
|
throw response.getException();
|
||||||
|
else
|
||||||
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.getSource().readEntity(String.class);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
return delegate.make(call);
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(String id) throws StorageHubException {
|
||||||
|
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||||
|
@Override
|
||||||
|
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
Objects.requireNonNull(id, "id cannot be null");
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.path(id);
|
||||||
|
|
||||||
|
GXInboundResponse response = myManager.delete();
|
||||||
|
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException())
|
||||||
|
throw response.getException();
|
||||||
|
else
|
||||||
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
delegate.make(call);
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<? extends Item> getAttachments(String messageId) throws StorageHubException{
|
||||||
|
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
||||||
|
@Override
|
||||||
|
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.path(messageId).path("attachments");
|
||||||
|
GXInboundResponse response = myManager.get();
|
||||||
|
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException())
|
||||||
|
throw response.getException();
|
||||||
|
else if (response.getHTTPCode()==403)
|
||||||
|
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||||
|
else
|
||||||
|
throw new BackendGenericError();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return response.getSource().readEntity(ItemList.class);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
return delegate.make(call).getItemlist();
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private List<Message> getMessages(final String path, int reduceBody ) throws StorageHubException{
|
||||||
|
Call<GXWebTargetAdapterRequest, List<Message>> call = new Call<GXWebTargetAdapterRequest, List<Message>>() {
|
||||||
|
@Override
|
||||||
|
public List<Message> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.path(path);
|
||||||
|
if (reduceBody>0)
|
||||||
|
myManager.queryParams(Collections.singletonMap("reduceBody", new Object[]{reduceBody}));
|
||||||
|
GXInboundResponse response = myManager.get();
|
||||||
|
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException())
|
||||||
|
throw response.getException();
|
||||||
|
else if (response.getHTTPCode()==403)
|
||||||
|
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||||
|
else
|
||||||
|
throw new BackendGenericError();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return response.getSource().readEntity(MessageList.class).getMessages();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
return delegate.make(call);
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -12,15 +12,16 @@ import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||||
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
|
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
|
||||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.IdNotFoundException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
||||||
|
|
||||||
public class DefaultUserManager implements UserManagerClient {
|
public class DefaultUserManager extends DefaultManagerClient implements UserManagerClient {
|
||||||
|
|
||||||
private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
|
|
||||||
|
|
||||||
public DefaultUserManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
public DefaultUserManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||||
this.delegate = delegate;
|
super(delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,7 +43,7 @@ public class DefaultUserManager implements UserManagerClient {
|
||||||
else if (response.getHTTPCode()==403)
|
else if (response.getHTTPCode()==403)
|
||||||
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||||
else
|
else
|
||||||
throw new BackendGenericError();
|
throw new BackendGenericError("error is "+response.getHTTPCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,5 +128,39 @@ public class DefaultUserManager implements UserManagerClient {
|
||||||
throw new RuntimeException(e1);
|
throw new RuntimeException(e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean exists(String user) throws StorageHubException {
|
||||||
|
Call<GXWebTargetAdapterRequest, Boolean> call = new Call<GXWebTargetAdapterRequest, Boolean>() {
|
||||||
|
@Override
|
||||||
|
public Boolean call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.path(user);
|
||||||
|
|
||||||
|
GXInboundResponse response = myManager.get();
|
||||||
|
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException())
|
||||||
|
if (response.getException().getClass().equals(IdNotFoundException.class))
|
||||||
|
return false;
|
||||||
|
else throw response.getException();
|
||||||
|
else if (response.getHTTPCode()==403)
|
||||||
|
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||||
|
|
||||||
|
else
|
||||||
|
throw new BackendGenericError();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
return delegate.make(call);
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +1,44 @@
|
||||||
package org.gcube.common.storagehub.client.proxies;
|
package org.gcube.common.storagehub.client.proxies;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.ws.rs.client.Entity;
|
import javax.ws.rs.client.Entity;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.MultivaluedHashMap;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
|
||||||
import org.gcube.common.clients.Call;
|
import org.gcube.common.clients.Call;
|
||||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||||
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
|
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
|
||||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
import org.gcube.common.storagehub.model.expressions.OrderField;
|
import org.gcube.common.storagehub.model.expressions.OrderField;
|
||||||
import org.gcube.common.storagehub.model.expressions.SearchableItem;
|
import org.gcube.common.storagehub.model.expressions.SearchableItem;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
import org.gcube.common.storagehub.model.query.Query;
|
import org.gcube.common.storagehub.model.query.Query;
|
||||||
import org.gcube.common.storagehub.model.service.ItemList;
|
import org.gcube.common.storagehub.model.service.ItemList;
|
||||||
import org.gcube.common.storagehub.model.service.ItemWrapper;
|
import org.gcube.common.storagehub.model.service.ItemWrapper;
|
||||||
|
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||||
|
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||||
|
import org.glassfish.jersey.media.multipart.MultiPart;
|
||||||
|
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||||
|
import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
public class DefaultWorkspaceManager extends DefaultManagerClient implements WorkspaceManagerClient {
|
||||||
|
|
||||||
private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
|
public DefaultWorkspaceManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||||
|
super(delegate);
|
||||||
|
|
||||||
public DefaultWorkspaceManager(ProxyDelegate<GXWebTargetAdapterRequest> config){
|
|
||||||
this.delegate = config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,7 +48,7 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
public ItemWrapper<T> call(GXWebTargetAdapterRequest manager) throws Exception {
|
public ItemWrapper<T> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
GXWebTargetAdapterRequest myManager = manager;
|
GXWebTargetAdapterRequest myManager = manager;
|
||||||
|
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
|
|
||||||
if (excludeNodes !=null && excludeNodes.length>0)
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
params.put("exclude",excludeNodes);
|
params.put("exclude",excludeNodes);
|
||||||
|
@ -93,7 +103,7 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
@Override
|
@Override
|
||||||
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
GXWebTargetAdapterRequest myManager = manager.path("vrefolders");
|
GXWebTargetAdapterRequest myManager = manager.path("vrefolders");
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
|
|
||||||
if (excludeNodes !=null && excludeNodes.length>0)
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
params.put("exclude",excludeNodes);
|
params.put("exclude",excludeNodes);
|
||||||
|
@ -106,7 +116,7 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
else
|
else
|
||||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.getSource().readEntity(ItemList.class);
|
return response.getSource().readEntity(ItemList.class);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -117,14 +127,14 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends Item> getVreFolders(int start, int limit, String ... excludeNodes) {
|
public List<? extends Item> getVreFolders(int start, int limit, String ... excludeNodes) {
|
||||||
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
||||||
@Override
|
@Override
|
||||||
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
GXWebTargetAdapterRequest myManager = manager.path("vrefolders").path("paged");
|
GXWebTargetAdapterRequest myManager = manager.path("vrefolders").path("paged");
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
|
|
||||||
if (excludeNodes !=null && excludeNodes.length>0)
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
params.put("exclude",excludeNodes);
|
params.put("exclude",excludeNodes);
|
||||||
|
@ -140,8 +150,8 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
else
|
else
|
||||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return response.getSource().readEntity(ItemList.class);
|
return response.getSource().readEntity(ItemList.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -160,20 +170,20 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
@Override
|
@Override
|
||||||
public ItemWrapper<T> call(GXWebTargetAdapterRequest manager) throws Exception {
|
public ItemWrapper<T> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
GXWebTargetAdapterRequest myManager = manager.path("vrefolder");
|
GXWebTargetAdapterRequest myManager = manager.path("vrefolder");
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
|
|
||||||
if (excludeNodes !=null && excludeNodes.length>0)
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
params.put("exclude",excludeNodes);
|
params.put("exclude",excludeNodes);
|
||||||
|
|
||||||
GXInboundResponse response = myManager.queryParams(params).get();
|
GXInboundResponse response = myManager.queryParams(params).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
throw response.getException();
|
throw response.getException();
|
||||||
else
|
else
|
||||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.getSource().readEntity(ItemWrapper.class);
|
return response.getSource().readEntity(ItemWrapper.class);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -192,7 +202,7 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
GXWebTargetAdapterRequest myManager = manager.path("vrefolder").path("recents");
|
GXWebTargetAdapterRequest myManager = manager.path("vrefolder").path("recents");
|
||||||
|
|
||||||
GXInboundResponse response = myManager.get();
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
|
@ -200,8 +210,8 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
else
|
else
|
||||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return response.getSource().readEntity(ItemList.class);
|
return response.getSource().readEntity(ItemList.class);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -220,20 +230,20 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
@Override
|
@Override
|
||||||
public ItemWrapper<T> call(GXWebTargetAdapterRequest manager) throws Exception {
|
public ItemWrapper<T> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
GXWebTargetAdapterRequest myManager = manager.path("trash");
|
GXWebTargetAdapterRequest myManager = manager.path("trash");
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
|
|
||||||
if (excludeNodes !=null && excludeNodes.length>0)
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
params.put("exclude",excludeNodes);
|
params.put("exclude",excludeNodes);
|
||||||
|
|
||||||
GXInboundResponse response = myManager.queryParams(params).get();
|
GXInboundResponse response = myManager.queryParams(params).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
throw response.getException();
|
throw response.getException();
|
||||||
else
|
else
|
||||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.getSource().readEntity(ItemWrapper.class);
|
return response.getSource().readEntity(ItemWrapper.class);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -246,53 +256,64 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void emptyTrash() {
|
public void emptyTrash() throws StorageHubException, BackendGenericError {
|
||||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
GXWebTargetAdapterRequest myManager = manager.path("trash").path("empty");
|
GXWebTargetAdapterRequest myManager = manager.path("trash").path("empty");
|
||||||
|
|
||||||
GXInboundResponse response = myManager.delete();
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).delete();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
throw response.getException();
|
throw response.getException();
|
||||||
else
|
else
|
||||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
delegate.make(call);
|
delegate.make(call);
|
||||||
}catch(Exception e) {
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Throwable e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String restoreFromTrash(final String id) {
|
public String restoreFromTrash(String trashedItemid, String destinationFolderId) throws StorageHubException, BackendGenericError{
|
||||||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
Objects.nonNull(trashedItemid);
|
||||||
GXWebTargetAdapterRequest myManager = manager.path("trash").path("restore");
|
GXWebTargetAdapterRequest myManager = manager.path("trash").path("restore");
|
||||||
|
|
||||||
GXInboundResponse response = myManager.put(Entity.text(id));
|
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
||||||
|
formData.add("trashedItemId", trashedItemid);
|
||||||
|
if (destinationFolderId !=null)
|
||||||
|
formData.add("destinationId", destinationFolderId);
|
||||||
|
|
||||||
|
|
||||||
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
throw response.getException();
|
throw response.getException();
|
||||||
else
|
else
|
||||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.getSource().readEntity(String.class);
|
return response.getSource().readEntity(String.class);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
return delegate.make(call);
|
return delegate.make(call);
|
||||||
}catch(Exception e) {
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Throwable e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,7 +324,7 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
@Override
|
@Override
|
||||||
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
GXWebTargetAdapterRequest myManager = manager.path("query");
|
GXWebTargetAdapterRequest myManager = manager.path("query");
|
||||||
Map<String, Object[]> params = new HashMap<>();
|
Map<String, Object[]> params = initQueryParameters();
|
||||||
|
|
||||||
if (excludeNodes !=null && excludeNodes.length>0)
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
params.put("exclude",excludeNodes);
|
params.put("exclude",excludeNodes);
|
||||||
|
@ -331,14 +352,14 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
params.put("e", new Object[] { URLEncoder.encode(serializedJson)});
|
params.put("e", new Object[] { URLEncoder.encode(serializedJson)});
|
||||||
|
|
||||||
GXInboundResponse response = myManager.queryParams(params).get();
|
GXInboundResponse response = myManager.queryParams(params).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
throw response.getException();
|
throw response.getException();
|
||||||
else
|
else
|
||||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.getSource().readEntity(ItemList.class);
|
return response.getSource().readEntity(ItemList.class);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -356,21 +377,21 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
@Override
|
@Override
|
||||||
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
GXWebTargetAdapterRequest myManager = manager.path("count");
|
GXWebTargetAdapterRequest myManager = manager.path("count");
|
||||||
|
|
||||||
GXInboundResponse response = myManager.get();
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
throw response.getException();
|
throw response.getException();
|
||||||
else
|
else
|
||||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.getSource().readEntity(String.class);
|
return response.getSource().readEntity(String.class);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
|
|
||||||
return Long.parseLong(delegate.make(call));
|
return Long.parseLong(delegate.make(call));
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -383,16 +404,16 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
@Override
|
@Override
|
||||||
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
GXWebTargetAdapterRequest myManager = manager.path("size");
|
GXWebTargetAdapterRequest myManager = manager.path("size");
|
||||||
|
|
||||||
GXInboundResponse response = myManager.get();
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).get();
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException())
|
||||||
throw response.getException();
|
throw response.getException();
|
||||||
else
|
else
|
||||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.getSource().readEntity(String.class);
|
return response.getSource().readEntity(String.class);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -403,6 +424,65 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String uploadFileToVolatile(InputStream stream, String fileName, long contentLength) throws StorageHubException{
|
||||||
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||||
|
@Override
|
||||||
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||||
|
Objects.requireNonNull(stream, "stream cannot be null");
|
||||||
|
Objects.requireNonNull(fileName, "parentId cannot be null");
|
||||||
|
|
||||||
|
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class)
|
||||||
|
.path("volatile");
|
||||||
|
|
||||||
|
GXInboundResponse response =null;
|
||||||
|
|
||||||
|
|
||||||
|
StreamDataBodyPart filePart = new StreamDataBodyPart("file", stream);
|
||||||
|
filePart.setContentDisposition(FormDataContentDisposition.name("file").fileName(fileName).size(contentLength).build());
|
||||||
|
|
||||||
|
MultiPart multipartEntity = new FormDataMultiPart().bodyPart(filePart);
|
||||||
|
|
||||||
|
response = myManager.queryParams(initQueryParameters()).post(Entity.entity(multipartEntity, multipartEntity.getMediaType()));
|
||||||
|
|
||||||
|
if (response.isErrorResponse()) {
|
||||||
|
if (response.hasException()) {
|
||||||
|
throw response.getException();
|
||||||
|
}else
|
||||||
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.getSource().readEntity(String.class);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
return delegate.make(call);
|
||||||
|
}catch(StorageHubException e) {
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e1) {
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String uploadFileToVolatile(InputStream stream, String fileName) throws StorageHubException {
|
||||||
|
return this.uploadFileToVolatile(stream, fileName, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String uploadFileToVolatile(File file) throws StorageHubException {
|
||||||
|
if (!file.exists()) throw new BackendGenericError("file "+file.getAbsolutePath()+" doesn't exist");
|
||||||
|
String fileName = file.getName();
|
||||||
|
|
||||||
|
long size = file.length();
|
||||||
|
try (InputStream is = new FileInputStream(file)){
|
||||||
|
return uploadFileToVolatile(is, fileName, size);
|
||||||
|
}catch (IOException io) {
|
||||||
|
throw new BackendGenericError("error closing stream", io);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import java.util.List;
|
||||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
|
|
||||||
public interface GroupManagerClient {
|
public interface GroupManagerClient extends ManagerClient{
|
||||||
|
|
||||||
void addUserToGroup(String userId, String groupId) throws StorageHubException;
|
void addUserToGroup(String userId, String groupId) throws StorageHubException;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package org.gcube.common.storagehub.client.proxies;
|
package org.gcube.common.storagehub.client.proxies;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -16,7 +18,7 @@ import org.gcube.common.storagehub.model.service.Version;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public interface ItemManagerClient {
|
public interface ItemManagerClient extends ManagerClient{
|
||||||
|
|
||||||
List<? extends Item> getChildren(String id, boolean includeHidden, String ... excludeNodes) throws StorageHubException;
|
List<? extends Item> getChildren(String id, boolean includeHidden, String ... excludeNodes) throws StorageHubException;
|
||||||
|
|
||||||
|
@ -28,7 +30,7 @@ public interface ItemManagerClient {
|
||||||
|
|
||||||
List<? extends Item> getAnchestors(String id, String ... excludeNodes) throws StorageHubException;
|
List<? extends Item> getAnchestors(String id, String ... excludeNodes) throws StorageHubException;
|
||||||
|
|
||||||
List<? extends Item> search(String id, Class<? extends Item> onlyOfType, boolean includeHidden, String nameToMatch, String ... excludeNodes) throws StorageHubException;
|
List<? extends Item> search(String id, Class<? extends Item> onlyOfType, boolean includeHidden, boolean excludeTrashed, String nameToMatch, String ... excludeNodes) throws StorageHubException;
|
||||||
|
|
||||||
Integer childrenCount(String id,boolean includeHidden) throws StorageHubException ;
|
Integer childrenCount(String id,boolean includeHidden) throws StorageHubException ;
|
||||||
|
|
||||||
|
@ -36,10 +38,18 @@ public interface ItemManagerClient {
|
||||||
|
|
||||||
Item get(String id, String ... excludeNodes) throws StorageHubException;
|
Item get(String id, String ... excludeNodes) throws StorageHubException;
|
||||||
|
|
||||||
|
Item getByRelativePath(String id, String path, String ... excludeNodes) throws StorageHubException;
|
||||||
|
|
||||||
StreamDescriptor download(String id, String... excludeNodes) throws StorageHubException;
|
StreamDescriptor download(String id, String... excludeNodes) throws StorageHubException;
|
||||||
|
|
||||||
String uploadFile(InputStream stream, String parentId, String fileName, String description) throws StorageHubException;
|
String uploadFile(InputStream stream, String parentId, String fileName, String description) throws StorageHubException;
|
||||||
|
|
||||||
|
String uploadFile(InputStream stream, String parentId, String fileName, String description, long size) throws StorageHubException;
|
||||||
|
|
||||||
|
String uploadFile(File file, String parentId, String fileName, String descriptionh) throws StorageHubException;
|
||||||
|
|
||||||
|
String uploadFile(URI uri, String parentId, String fileName, String description) throws StorageHubException;
|
||||||
|
|
||||||
String createFolder(String parentId, String name, String description, boolean hidden) throws StorageHubException;
|
String createFolder(String parentId, String name, String description, boolean hidden) throws StorageHubException;
|
||||||
|
|
||||||
String createURL(String parentId, String name, String description, URL url) throws StorageHubException;
|
String createURL(String parentId, String name, String description, URL url) throws StorageHubException;
|
||||||
|
@ -69,6 +79,8 @@ public interface ItemManagerClient {
|
||||||
String copy(String id, String destinationFolderId, String newFilename) throws StorageHubException;
|
String copy(String id, String destinationFolderId, String newFilename) throws StorageHubException;
|
||||||
|
|
||||||
String uploadArchive(InputStream stream, String parentId, String extractionFolderName) throws StorageHubException;
|
String uploadArchive(InputStream stream, String parentId, String extractionFolderName) throws StorageHubException;
|
||||||
|
|
||||||
|
String uploadArchive(InputStream stream, String parentId, String extractionFolderName, long contentLength) throws StorageHubException;
|
||||||
|
|
||||||
String unshareFolder(String id, Set<String> users) throws StorageHubException;
|
String unshareFolder(String id, Set<String> users) throws StorageHubException;
|
||||||
|
|
||||||
|
@ -80,7 +92,13 @@ public interface ItemManagerClient {
|
||||||
|
|
||||||
StreamDescriptor downloadSpecificVersion(String id, String version) throws StorageHubException;
|
StreamDescriptor downloadSpecificVersion(String id, String version) throws StorageHubException;
|
||||||
|
|
||||||
|
void deleteFileVersion(String id, String versionName) throws StorageHubException;
|
||||||
|
|
||||||
String setMetadata(String id,Metadata metadata) throws StorageHubException;
|
String setMetadata(String id,Metadata metadata) throws StorageHubException;
|
||||||
|
|
||||||
|
String setHidden(String id,Boolean value) throws StorageHubException;
|
||||||
|
|
||||||
|
String setDescription(String id,String description) throws StorageHubException;
|
||||||
|
|
||||||
String createGcubeItem(String parentId, GCubeItem item) throws StorageHubException;
|
String createGcubeItem(String parentId, GCubeItem item) throws StorageHubException;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package org.gcube.common.storagehub.client.proxies;
|
||||||
|
|
||||||
|
public interface ManagerClient {
|
||||||
|
|
||||||
|
void register(Class<?> _classes);
|
||||||
|
|
||||||
|
void impersonate(String user);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.gcube.common.storagehub.client.proxies;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
import org.gcube.common.storagehub.model.messages.Message;
|
||||||
|
|
||||||
|
public interface MessageManagerClient extends ManagerClient{
|
||||||
|
|
||||||
|
Message get(String id) throws StorageHubException;
|
||||||
|
|
||||||
|
List<? extends Item> getAttachments(String id) throws StorageHubException;
|
||||||
|
|
||||||
|
List<Message> getReceivedMessages(int reduceBody) throws StorageHubException;
|
||||||
|
|
||||||
|
List<Message> getSentMessages(int reduceBody) throws StorageHubException;
|
||||||
|
|
||||||
|
List<Message> getReceivedMessages() throws StorageHubException;
|
||||||
|
|
||||||
|
List<Message> getSentMessages() throws StorageHubException;
|
||||||
|
|
||||||
|
|
||||||
|
void delete(String id) throws StorageHubException;
|
||||||
|
|
||||||
|
String sendMessage(List<String> recipients, String subject, String body, List<String> attachments)
|
||||||
|
throws StorageHubException;
|
||||||
|
|
||||||
|
void setRead(String id, Boolean value) throws StorageHubException;
|
||||||
|
|
||||||
|
void setOpened(String id, Boolean value) throws StorageHubException;
|
||||||
|
}
|
|
@ -4,12 +4,14 @@ import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
|
|
||||||
public interface UserManagerClient {
|
public interface UserManagerClient extends ManagerClient{
|
||||||
|
|
||||||
void createUser(String userId) throws StorageHubException;
|
void createUser(String userId) throws StorageHubException;
|
||||||
|
|
||||||
void removeUser(String userId) throws StorageHubException;
|
void removeUser(String userId) throws StorageHubException;
|
||||||
|
|
||||||
List<String> getUsers() throws StorageHubException;
|
List<String> getUsers() throws StorageHubException;
|
||||||
|
|
||||||
|
boolean exists(String user) throws StorageHubException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package org.gcube.common.storagehub.client.proxies;
|
package org.gcube.common.storagehub.client.proxies;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
import org.gcube.common.storagehub.model.expressions.SearchableItem;
|
import org.gcube.common.storagehub.model.expressions.SearchableItem;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
import org.gcube.common.storagehub.model.query.Query;
|
import org.gcube.common.storagehub.model.query.Query;
|
||||||
|
|
||||||
public interface WorkspaceManagerClient {
|
public interface WorkspaceManagerClient extends ManagerClient{
|
||||||
|
|
||||||
<T extends Item> T getWorkspace(String ... excludeNodes);
|
<T extends Item> T getWorkspace(String ... excludeNodes);
|
||||||
|
|
||||||
|
@ -24,12 +28,18 @@ public interface WorkspaceManagerClient {
|
||||||
|
|
||||||
List<? extends Item> getRecentModifiedFilePerVre();
|
List<? extends Item> getRecentModifiedFilePerVre();
|
||||||
|
|
||||||
String restoreFromTrash(String id);
|
String restoreFromTrash(String thrashedItemid, String destinationFolderId) throws StorageHubException, BackendGenericError;
|
||||||
|
|
||||||
void emptyTrash();
|
void emptyTrash() throws StorageHubException, BackendGenericError;
|
||||||
|
|
||||||
long getTotalItemCount();
|
long getTotalItemCount();
|
||||||
|
|
||||||
long getTotalVolume();
|
long getTotalVolume();
|
||||||
|
|
||||||
|
String uploadFileToVolatile(InputStream stream, String filename, long contentLength) throws StorageHubException;
|
||||||
|
|
||||||
|
String uploadFileToVolatile(InputStream stream, String filename) throws StorageHubException;
|
||||||
|
|
||||||
|
String uploadFileToVolatile(File file) throws StorageHubException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,107 +0,0 @@
|
||||||
package org.gcube.data.access.fs;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class AddUserToVRes {
|
|
||||||
|
|
||||||
|
|
||||||
List<String> DORNE_VRE = Arrays.asList("mister.brown",
|
|
||||||
"jesus.santamariafernandez",
|
|
||||||
"noah.matovu",
|
|
||||||
"andrea.rossi",
|
|
||||||
"francesco.mangiacrapa",
|
|
||||||
"mister.pink",
|
|
||||||
"kostas.kakaletris",
|
|
||||||
"massimiliano.assante",
|
|
||||||
"mister.white",
|
|
||||||
"mister.blonde",
|
|
||||||
"aureliano.gentile",
|
|
||||||
"mister.blue",
|
|
||||||
"mister.orange",
|
|
||||||
"lucio.lelii");
|
|
||||||
|
|
||||||
List<String> PARTHENOS_VRE = Arrays.asList("francesco.mangiacrapa",
|
|
||||||
"massimiliano.assante",
|
|
||||||
"costantino.perciante",
|
|
||||||
"luca.frosini",
|
|
||||||
"pasquale.pagano",
|
|
||||||
"alessia.bardi",
|
|
||||||
"roberto.cirillo");
|
|
||||||
|
|
||||||
List<String> PRE_VRE = Arrays.asList("fabio.sinibaldi",
|
|
||||||
"valentina.marioli",
|
|
||||||
"statistical.manager",
|
|
||||||
"roberto.cirillo",
|
|
||||||
"francesco.mangiacrapa",
|
|
||||||
"leonardo.candela",
|
|
||||||
"costantino.perciante",
|
|
||||||
"mariaantonietta.digirolamo",
|
|
||||||
"gantzoulatos",
|
|
||||||
"massimiliano.assante",
|
|
||||||
"lucio.lelii",
|
|
||||||
"panagiota.koltsida",
|
|
||||||
"ngalante",
|
|
||||||
"efthymios",
|
|
||||||
"nikolas.laskaris",
|
|
||||||
"andrea.dellamico",
|
|
||||||
"gianpaolo.coro",
|
|
||||||
"giancarlo.panichi",
|
|
||||||
"kostas.kakaletris",
|
|
||||||
"scarponi",
|
|
||||||
"andrea.rossi",
|
|
||||||
"pasquale.pagano",
|
|
||||||
"mister.blue",
|
|
||||||
"m.assante",
|
|
||||||
"yannis.marketakis",
|
|
||||||
"grsf.publisher",
|
|
||||||
"kgiannakelos",
|
|
||||||
"mister.pink",
|
|
||||||
"luca.frosini",
|
|
||||||
"dkatris",
|
|
||||||
"paolo.fabriani",
|
|
||||||
"mister.brown",
|
|
||||||
"mister.white",
|
|
||||||
"mister.orange",
|
|
||||||
"gabriele.giammatteo");
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void add() throws Exception{
|
|
||||||
String group = "pred4s-preprod-preVRE";
|
|
||||||
URL addGroupUrl = new URL("http://storagehub.pre.d4science.net/storagehub/workspace/groups/"+group+"?gcube-token=");
|
|
||||||
|
|
||||||
for (String user : PRE_VRE) {
|
|
||||||
try {
|
|
||||||
HttpURLConnection connection =(HttpURLConnection)addGroupUrl.openConnection();
|
|
||||||
connection.setRequestMethod("PUT");
|
|
||||||
StringBuilder postData = new StringBuilder();
|
|
||||||
postData.append("userId");
|
|
||||||
postData.append("=");
|
|
||||||
postData.append(user);
|
|
||||||
/*postData.append("&");
|
|
||||||
postData.append("password");
|
|
||||||
postData.append("=");
|
|
||||||
postData.append("pwd"+user.hashCode());*/
|
|
||||||
byte[] postDataBytes = postData.toString().getBytes("UTF-8");
|
|
||||||
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
|
||||||
connection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
connection.getOutputStream().write(postDataBytes);
|
|
||||||
Reader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
|
||||||
|
|
||||||
for (int c; (c = in.read()) >= 0;)
|
|
||||||
System.out.print((char)c);
|
|
||||||
}catch (Exception e) {
|
|
||||||
System.out.println("error for user "+user);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
package org.gcube.data.access.fs;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.ContainerType;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.ItemContainer;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||||
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||||
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ImportTest {
|
||||||
|
|
||||||
|
private static final String propFile = "/home/lucio/tokens.properties";
|
||||||
|
|
||||||
|
private static final String devEnv = "dev-devvre";
|
||||||
|
private static final String prodEnv = "prod-root";
|
||||||
|
|
||||||
|
|
||||||
|
public void setUp(String env){
|
||||||
|
|
||||||
|
try(InputStream is = new FileInputStream(new File(propFile))){
|
||||||
|
Properties prop = new Properties();
|
||||||
|
prop.load(is);
|
||||||
|
String value =(String)prop.get(env);
|
||||||
|
String[] splitValue = value.split(",");
|
||||||
|
String token = splitValue[1];
|
||||||
|
//SecretManagerProvider.instance.set(new GCubeSecret(token));
|
||||||
|
|
||||||
|
SecurityTokenProvider.instance.set(token);
|
||||||
|
ScopeProvider.instance.set(splitValue[0]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void startImport() {
|
||||||
|
try {
|
||||||
|
//String folderId = "1c3bf96a-1143-48f8-8421-da176c87a016";
|
||||||
|
String folderId = "684614df-c742-4aec-8a34-411a594dc85c";
|
||||||
|
|
||||||
|
importTest(folderId, null);
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void importTest(String folderId, String relativePath) throws Exception {
|
||||||
|
setUp(prodEnv);
|
||||||
|
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
FolderContainer fc = shc.open(folderId).asFolder();
|
||||||
|
List<ItemContainer<? extends Item>> items = fc.list().includeHidden().withContent().getContainers();
|
||||||
|
|
||||||
|
System.out.println("folder "+folderId+" is with "+items.size());
|
||||||
|
for (ItemContainer<? extends Item> itemContainer : items) {
|
||||||
|
if (itemContainer.getType() == ContainerType.FOLDER) {
|
||||||
|
new Thread(()-> createInDev(itemContainer.get(), itemContainer.getType(), relativePath, null)).run();
|
||||||
|
setUp(prodEnv);
|
||||||
|
importTest(itemContainer.getId(), relativePath == null ? itemContainer.get().getName() : relativePath+"/"+itemContainer.get().getName() );
|
||||||
|
} else if (itemContainer.getType() == ContainerType.FILE){
|
||||||
|
setUp(prodEnv);
|
||||||
|
final URL publicLink = ((FileContainer)itemContainer).getPublicLink();
|
||||||
|
System.out.println("publik Link "+publicLink.toString());
|
||||||
|
new Thread(()-> createInDev(itemContainer.get(), itemContainer.getType(), relativePath, publicLink)).run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public <T extends Item> void createInDev(T item, ContainerType type, String relativePath, URL publicLink){
|
||||||
|
setUp(devEnv);
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
try {
|
||||||
|
FolderContainer currentFolder = shc.openVREFolder().openByRelativePath("testLucio").asFolder();
|
||||||
|
if (relativePath!=null) {
|
||||||
|
String[] paths = relativePath.split("/");
|
||||||
|
for (String path : paths)
|
||||||
|
currentFolder = currentFolder.openByRelativePath(path).asFolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == ContainerType.FOLDER) {
|
||||||
|
currentFolder.newFolder(item.getName(), item.getDescription());
|
||||||
|
} else if (type == ContainerType.FILE) {
|
||||||
|
try ( InputStream fileIS = publicLink.openStream()){
|
||||||
|
System.out.println("itemId is "+item.getId()) ;
|
||||||
|
currentFolder.uploadFile(fileIS, item.getName(), item.getDescription(), ((AbstractFileItem) item).getContent().getSize());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,22 +5,35 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.ContainerType;
|
||||||
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
||||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||||
import org.gcube.common.storagehub.client.dsl.ItemContainer;
|
import org.gcube.common.storagehub.client.dsl.ItemContainer;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.OpenResolver;
|
||||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.VREFolderManager;
|
||||||
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||||
|
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
||||||
import org.gcube.common.storagehub.model.Metadata;
|
import org.gcube.common.storagehub.model.Metadata;
|
||||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||||
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -29,80 +42,274 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class Items {
|
public class Items {
|
||||||
|
|
||||||
|
private static final String propFile = "/home/lucio/tokens.properties";
|
||||||
|
|
||||||
|
private static final String tokens = "dev-root";
|
||||||
|
//private static final String tokens = "prod-root";
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp(){
|
public static void setUp(){
|
||||||
SecurityTokenProvider.instance.set("b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548");
|
|
||||||
ScopeProvider.instance.set("/gcube");
|
try(InputStream is = new FileInputStream(new File(propFile))){
|
||||||
|
Properties prop = new Properties();
|
||||||
|
prop.load(is);
|
||||||
|
String value =(String)prop.get(tokens);
|
||||||
|
String[] splitValue = value.split(",");
|
||||||
|
String token = splitValue[1];
|
||||||
|
//SecretManagerProvider.instance.set(new GCubeSecret(token));
|
||||||
|
|
||||||
|
SecurityTokenProvider.instance.set(token);
|
||||||
|
ScopeProvider.instance.set(splitValue[0]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addUserToVRe() throws StorageHubException {
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
|
|
||||||
|
String vresFile = "C:\\Users\\tilli\\Downloads\\vresToAddGCat.txt";
|
||||||
|
|
||||||
|
try(InputStream is = new FileInputStream(new File(vresFile))){
|
||||||
|
Properties prop = new Properties();
|
||||||
|
prop.load(is);
|
||||||
|
Enumeration<Object> enumer = prop.keys();
|
||||||
|
while (enumer.hasMoreElements()) {
|
||||||
|
try {
|
||||||
|
String vre= (String) enumer.nextElement();
|
||||||
|
shc.getVreFolderManager(vre).addUser("gCat");
|
||||||
|
System.out.println("added to "+vre);
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void search() throws Exception{
|
public void removeVersion() throws Exception {
|
||||||
|
|
||||||
|
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
List<? extends Item> s = shc.getWSRoot().search("pippo").getItems();
|
String id = "024c8cab-f9f7-4fd8-bed2-f6076e5edf91";
|
||||||
s.forEach(i -> System.out.println(i.getPath()+" "+i.getName()));
|
FileContainer file = shc.open(id).asFile();
|
||||||
|
file.deleteVersion("1.0");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void uploadTovolatile() throws StorageHubException {
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
|
|
||||||
|
String vresFile = "/home/lucio/Scaricati/zoom_amd64.deb";
|
||||||
|
|
||||||
|
File file = new File(vresFile);
|
||||||
|
|
||||||
|
try ( InputStream fileIS = new FileInputStream(file)){
|
||||||
|
shc.getWSRoot().uploadFile(new URI("https://data.d4science.org/shub/E_RGNhNU9aaVhZM3ovNEN2dEdtdXpCWitac0tScmMvcGZSeDlISUtOb2JOMklRQkxrdjBCWnJ4YlJHVlM4VnVjVQ=="), "testfile.jpg", "description");
|
||||||
|
//shc.uploadFileOnVolatile(fileIS, "zoom_amd645.deb", file.length());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void uploadfile() {
|
||||||
|
try{
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
shc.impersonate("pasquale.pagano");
|
||||||
|
URI toUpload = new URI("https://data.d4science.org/shub/E_RGNhNU9aaVhZM3ovNEN2dEdtdXpCWitac0tScmMvcGZSeDlISUtOb2JOMklRQkxrdjBCWnJ4YlJHVlM4VnVjVQ==");
|
||||||
|
String fileName = "DRR014055.fastq.gz";
|
||||||
|
|
||||||
|
shc.open("514295c6-2176-49d5-9487-99fb0fb85372").asFolder().uploadFile(toUpload, fileName, "description");
|
||||||
|
//shc.uploadFileOnVolatile(fileIS, "zoom_amd645.deb", file.length());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeTest() {
|
||||||
|
try {
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
FolderContainer root = shc.getWSRoot();
|
||||||
|
root.list().getContainers().stream().filter(c -> c.get().getTitle().startsWith("stressTest")).forEach(c-> {
|
||||||
|
try {
|
||||||
|
c.forceDelete();
|
||||||
|
} catch (StorageHubException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});;
|
||||||
|
}catch (Exception e ) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stressTest() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
IntStream.range(1, 100).forEach( i-> {
|
||||||
|
try {
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
FolderContainer vre = shc.openVREFolder().openByRelativePath("testLucio").asFolder();
|
||||||
|
FolderContainer fc = vre.newFolder("folder"+i, "");
|
||||||
|
for (int t =1 ; t<5; t++) {
|
||||||
|
StorageHubClient shc1 = new StorageHubClient();
|
||||||
|
FolderContainer sub = shc1.open(fc.getId()).asFolder();
|
||||||
|
FolderContainer fcsub2 = sub.newFolder("folder"+i+"-"+t, "");
|
||||||
|
for (int k=0;k<4;k++) {
|
||||||
|
String vresFile = "/home/lucio/Scaricati/GNA_foto_Cuma Necropoli mediana_3B.jpg";
|
||||||
|
|
||||||
|
StorageHubClient shc2 = new StorageHubClient();
|
||||||
|
FolderContainer sub2 = shc2.open(fcsub2.getId()).asFolder();
|
||||||
|
|
||||||
|
File file = new File(vresFile);
|
||||||
|
|
||||||
|
try ( InputStream fileIS = new FileInputStream(file)){
|
||||||
|
final String filename ="file"+k;
|
||||||
|
FileContainer fileCont = sub2.uploadFile(fileIS, filename, "description");
|
||||||
|
new Thread(() -> {getPublicLinkAndDownload(fileCont.getId(), filename);}).start();;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (StorageHubException e) {
|
||||||
|
System.out.println("error creating stressTest"+i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}catch (Exception e ) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getPublicLinkAndDownload(String id, String fileName) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
URL link = shc.open(id).asFile().getPublicLink();
|
||||||
|
try( InputStream is = link.openStream()) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
for (int length; (length = is.read(buffer)) != -1; ) {}
|
||||||
|
}
|
||||||
|
System.out.println("downloaded file "+fileName);
|
||||||
|
|
||||||
|
}catch (Exception e) {
|
||||||
|
System.err.println("error downloading public link for id "+id);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void search() {
|
||||||
|
try {
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
List<? extends Item> s = shc.getWSRoot().search("WD%",false).getItems();
|
||||||
|
s.forEach(i -> System.out.println(i.getName()+" "+i.getId()));
|
||||||
|
}catch (Exception e ) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forceDelete() throws Exception{
|
public void forceDelete() throws Exception{
|
||||||
|
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
//shc.open("41b904cd-128a-4121-8fd7-82498187ca06").asFolder().getAnchestors().getItems().forEach(i -> System.out.println(i.getTitle()));
|
||||||
|
shc.open("7ac99eea-d768-4864-a248-6d4ccf43d931").asFile().setDescription("new descr");
|
||||||
|
|
||||||
long count = shc.getTotalItemCount();
|
|
||||||
|
|
||||||
long volume = shc.getTotalVolume();
|
|
||||||
|
|
||||||
System.out.println("items are "+count+" volume "+volume);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void changeAcls() throws Exception{
|
public void changeAcls() throws Exception{
|
||||||
|
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
System.out.println(shc.open("65e502ff-92ef-46cc-afbd-3e91f4b680be").asFolder().canWrite());
|
//System.out.println(shc.open("65e502ff-92ef-46cc-afbd-3e91f4b680be").asFolder().canWrite());
|
||||||
|
OpenResolver openResolver= shc.open("1322e7b2-bad6-4d64-a063-db0d05b16a67");
|
||||||
|
if(openResolver.resolve().getType()==ContainerType.FILE) {
|
||||||
|
String publicLink = openResolver.asFile().getPublicLink().toString();
|
||||||
|
String itemName = openResolver.asFile().get().getTitle();
|
||||||
|
|
||||||
|
builder.append(itemName + " ("+publicLink+")");
|
||||||
|
builder.append("\n");
|
||||||
|
} else {
|
||||||
|
System.out.println("\n\n\nNON e' un FILE cosè? = " + openResolver.resolve().getType());
|
||||||
|
}
|
||||||
|
System.out.println(builder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void renameFile() throws Exception{
|
public void setAdmin() throws Exception{
|
||||||
|
try {
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
|
shc.getVreFolderManager("gcube-devsec-devVRE").setAdmin("giancarlo.panichi");
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeAdmin() throws Exception{
|
||||||
|
try {
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
|
shc.getVreFolderManager("gcube-devsec-devVRE").removeAdmin("luca.frosini");
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getItem() throws Exception{
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
String owner = shc.open("fb838c64-0924-48b4-9b45-de9be39ba860").asItem().get().getOwner();
|
||||||
|
System.out.println("owner is "+owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void uploadFile() throws Exception{
|
||||||
|
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
|
|
||||||
FolderContainer myRoot = shc.getWSRoot();
|
|
||||||
|
|
||||||
myRoot.findByName("");
|
|
||||||
|
|
||||||
|
|
||||||
FolderContainer children = myRoot.newFolder("build", "build folder");
|
|
||||||
|
|
||||||
|
FolderContainer myRoot = shc.open("11cbdc0c-e873-418c-bc53-5f6329eb88fb").asFolder();
|
||||||
FileContainer file = null;
|
|
||||||
|
|
||||||
|
|
||||||
try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/mg.jpg"))){
|
|
||||||
file = myRoot.uploadFile(is, "mg.jpg", "file");
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
FileContainer copiedFile = file.copy(children, "mg.jpg");
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/bck.jpg"))){
|
File inFile = new File("/home/lucio/Downloads/scimmia braccia aperte.mp4");
|
||||||
file = myRoot.uploadFile(is, "mg.jpg", "file");
|
try(InputStream is = new FileInputStream(inFile)){
|
||||||
} catch (Exception e) {
|
myRoot.uploadFile(is, "scimmia braccia aperte.mp4", "file");
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
System.out.println("Response in "+(System.currentTimeMillis()-start));
|
||||||
|
|
||||||
FileContainer secodncopiedFile = file.copy(children, "mg.jpg");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,14 +318,14 @@ public class Items {
|
||||||
@Test
|
@Test
|
||||||
public void uploadAndcopyFile() throws Exception {
|
public void uploadAndcopyFile() throws Exception {
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
FileContainer file = null;
|
FileContainer file = null;
|
||||||
try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/.richiesta speroni.pdf"))){
|
try(InputStream is = new FileInputStream(new File("c:\\Users\\tilli\\Downloads\\expired.png"))){
|
||||||
file = shc.getWSRoot().uploadFile(is, ".richiesta speroni.pdf", "test");
|
file = shc.getWSRoot().uploadFile(is, "expired/exp.png", "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//file.copy(shc.getWSRoot(), "firstCopy.jpg");
|
//file.copy(shc.getWSRoot(), "firstCopy.jpg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,71 +333,119 @@ public class Items {
|
||||||
public void download() throws Exception {
|
public void download() throws Exception {
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
|
|
||||||
StreamDescriptor streamDescr = shc.open("a5bcf8b8-d149-42c2-92be-7f671223eba4").asFile().downloadSpecificVersion("1.2");
|
|
||||||
|
|
||||||
|
StreamDescriptor streamDescr = shc.open("abb59b44-e3cb-408d-a1ff-73d6d8ad2ca1").asFile().download();
|
||||||
|
System.out.println("length "+streamDescr.getContentLenght());
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
File output = Files.createTempFile("down", streamDescr.getFileName()).toFile();
|
File output = Files.createTempFile("down", streamDescr.getFileName()).toFile();
|
||||||
try (BufferedInputStream bi = new BufferedInputStream(streamDescr.getStream()); FileOutputStream fo = new FileOutputStream(output)){
|
try (BufferedInputStream bi = new BufferedInputStream(streamDescr.getStream()); FileOutputStream fo = new FileOutputStream(output)){
|
||||||
byte[] buf = new byte[2048];
|
byte[] buf = new byte[2046];
|
||||||
int read = -1;
|
int read = -1;
|
||||||
while ((read=bi.read(buf))!=-1) {
|
while ((read=bi.read(buf))!=-1) {
|
||||||
fo.write(buf, 0, read);
|
fo.write(buf, 0, read);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("file written "+output.getAbsolutePath());
|
|
||||||
|
|
||||||
|
System.out.println("file written "+output.getAbsolutePath()+" in "+(System.currentTimeMillis()-start));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyTrash() throws Exception {
|
public void addUser() throws Exception {
|
||||||
|
/*AccessTokenSecret secret = new AccessTokenSecret("eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJSSklZNEpoNF9qdDdvNmREY0NlUDFfS1l0akcxVExXVW9oMkQ2Tzk1bFNBIn0.eyJleHAiOjE2NDQyNDM4ODUsImlhdCI6MTY0NDI0MzU4NSwiYXV0aF90aW1lIjoxNjQ0MjQzNTg1LCJqdGkiOiI1NWQ4ZDc5OS1kNTIzLTQ0YmEtYTRkMC1iZjIyYzVlMTg4NzQiLCJpc3MiOiJodHRwczovL2FjY291bnRzLmRldi5kNHNjaWVuY2Uub3JnL2F1dGgvcmVhbG1zL2Q0c2NpZW5jZSIsImF1ZCI6IiUyRmdjdWJlIiwic3ViIjoiNGMxMWRlODQtZGRjOS00ZGQxLWI5N2EtZWE4MmQyZDEzOGE2IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibmV4dC5kNHNjaWVuY2Uub3JnIiwic2Vzc2lvbl9zdGF0ZSI6ImZkZTA3MGE2LTVkOTUtNDc3Ni1hMTFiLTBhZTI1MzQ5NGQyMyIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiLyoiXSwicmVzb3VyY2VfYWNjZXNzIjp7IiUyRmdjdWJlIjp7InJvbGVzIjpbIkluZnJhc3RydWN0dXJlLU1hbmFnZXIiLCJNZW1iZXIiXX19LCJhdXRob3JpemF0aW9uIjp7InBlcm1pc3Npb25zIjpbeyJyc2lkIjoiMTU5ZDcyMDQtNjlmYS00ZmY0LTlhOTQtMzVlMWUyMzA5MDQyIiwicnNuYW1lIjoiRGVmYXVsdCBSZXNvdXJjZSJ9XX0sInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJuYW1lIjoiTHVjaW8gTGVsaWkiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJsdWNpby5sZWxpaSIsImdpdmVuX25hbWUiOiJMdWNpbyIsImZhbWlseV9uYW1lIjoiTGVsaWkiLCJlbWFpbCI6Imx1Y2lvLmxlbGlpQGlzdGkuY25yLml0In0.SGuGXnY63WJ45tdypywaopO--FCxY6ZWAX74MGVw_zdNMMQI5zgtGfhZQewFWQ6HhVINDStXqvdSDluhF9JwFXCUGvxB2BipfKQYsAQnm3I4K3kgMl26kuQIL5Im-apw2XWvImTgLshX1AzpyqzFR1Jpf_p65GCMpcHLEwo_nTGLkrZNtfRdtqakZ8S8lowGaV2J2mNf4AHhtARSLJF3GqwynF5pPUXR2iOMUrjw_FLnIuPMfAjk_jHMeYKIxXNBLsoEpELju3pr2gEkv1ZRH9bZkyg7_3hW4mGzxq_Ea9w1FBVJOlkp6vypuISLNyJZcVOnBa4Dg1KRxxlp3aZ6vA");
|
||||||
|
SecretManagerProvider.instance.set(secret);*/
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
shc.emptyTrash();
|
shc.getVreFolderManager("gcube-devsec-devVre").addUser("vincenzo.cestone");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeUser() throws Exception {
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
|
shc.deleteUserAccount("");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void changeProp() throws Exception {
|
public void changeProp() throws Exception {
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
ItemContainer item = shc.open("6399daa7-2173-4314-b4f7-2afa24eae8f8").asItem();
|
ItemContainer item = shc.open("6399daa7-2173-4314-b4f7-2afa24eae8f8").asItem();
|
||||||
Metadata first = item.get().getMetadata();
|
Metadata first = item.get().getMetadata();
|
||||||
first.getMap().put("lucio", "ok");
|
first.getMap().put("lucio", "ok");
|
||||||
|
|
||||||
item.setMetadata(first);
|
item.setMetadata(first);
|
||||||
|
|
||||||
Metadata second = item.get().getMetadata();
|
Metadata second = item.get().getMetadata();
|
||||||
for (Entry<String, Object> entry: second.getMap().entrySet())
|
for (Entry<String, Object> entry: second.getMap().entrySet())
|
||||||
System.out.println(entry.getKey()+" "+entry.getValue());
|
System.out.println(entry.getKey()+" "+entry.getValue());
|
||||||
|
|
||||||
|
|
||||||
second.getMap().put("lucio", null);
|
second.getMap().put("lucio", null);
|
||||||
second.getMap().put("lelii", "0");
|
second.getMap().put("lelii", "0");
|
||||||
|
|
||||||
item.setMetadata(second);
|
item.setMetadata(second);
|
||||||
|
|
||||||
Metadata third = item.get().getMetadata();
|
Metadata third = item.get().getMetadata();
|
||||||
for (Entry<String, Object> entry: third.getMap().entrySet())
|
for (Entry<String, Object> entry: third.getMap().entrySet())
|
||||||
System.out.println(entry.getKey()+" "+entry.getValue());
|
System.out.println(entry.getKey()+" "+entry.getValue());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*private InputStream urlToInputStream(URL url, Map<String, String> args) {
|
||||||
|
HttpURLConnection con = null;
|
||||||
|
InputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
con = (HttpURLConnection) url.openConnection();
|
||||||
|
con.setConnectTimeout(15000);
|
||||||
|
con.setReadTimeout(15000);
|
||||||
|
if (args != null) {
|
||||||
|
for (Entry<String, String> e : args.entrySet()) {
|
||||||
|
con.setRequestProperty(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
con.connect();
|
||||||
|
int responseCode = con.getResponseCode();
|
||||||
|
|
||||||
|
if (responseCode < 400 && responseCode > 299) {
|
||||||
|
String redirectUrl = con.getHeaderField("Location");
|
||||||
|
try {
|
||||||
|
URL newUrl = new URL(redirectUrl);
|
||||||
|
return urlToInputStream(newUrl, args);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
URL newUrl = new URL(url.getProtocol() + "://" + url.getHost() + redirectUrl);
|
||||||
|
return urlToInputStream(newUrl, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inputStream = con.getInputStream();
|
||||||
|
return inputStream;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uploadArchive() throws Exception {
|
public void uploadArchive() throws Exception {
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
String afi = null;
|
URL remote = new URI("https://data.bluecloud.cineca.it/api/download/gAAAAABhaSJN8TUA71la3mKMOL9D"
|
||||||
|
+ "mioSBvOehbZlu54_jvscz8Zu3LXgqhr8RfJemd83QIh47z6TyMn3mD0OjpcG5g0qf9WUZCeW1J4btEqNObkaWv"
|
||||||
|
+ "pMhabvswweyFn1Jg4m5GpwCoKayvgsYYwjbjsGsQW5Hileiw==").toURL();
|
||||||
|
|
||||||
|
|
||||||
|
try(InputStream is = remote.openStream() ){
|
||||||
|
shc.getWSRoot().uploadArchive(is, "testUploadArchive");
|
||||||
|
|
||||||
try(InputStream is = new FileInputStream(new File("/tmp/down724121986692880606my new folder.zip"))){
|
|
||||||
shc.getWSRoot().uploadArchive(is, "testUpload2");
|
|
||||||
|
|
||||||
System.out.println(afi);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -222,12 +477,31 @@ public class Items {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void delete() throws Exception{
|
public void delete() throws Exception{
|
||||||
try {
|
StorageHubClient shc = new StorageHubClient();
|
||||||
StorageHubClient shc = new StorageHubClient();
|
FolderContainer container = shc.getWSRoot();
|
||||||
shc.open("328d0097-e024-43fd-afc8-3926a34a5953").asFile().delete();
|
try {
|
||||||
}catch(Exception e) {
|
FolderContainer attachmentFolder = container.openByRelativePath("Attachment").asFolder();
|
||||||
e.printStackTrace();
|
FolderItem folder = attachmentFolder.get();
|
||||||
|
} catch (StorageHubException e) {
|
||||||
|
System.out.println("creating folder");
|
||||||
|
container.newFolder("Attachment","Folder created automatically by the System");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createFolderWhenNotExists() throws Exception{
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
FolderContainer container = shc.openVREFolder();
|
||||||
|
|
||||||
|
try {
|
||||||
|
FolderContainer attachmentFolder = container.openByRelativePath("Attachment-Lucio").asFolder();
|
||||||
|
System.out.println("fodler name is "+attachmentFolder.get().getName());
|
||||||
|
} catch (StorageHubException e) {
|
||||||
|
System.out.println("creating folder");
|
||||||
|
container.newFolder("Attachment-Lucio","Folder created automatically by the System");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -306,7 +580,7 @@ public class Items {
|
||||||
public void downloadFolderWithExcludes() throws Exception{
|
public void downloadFolderWithExcludes() throws Exception{
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
|
|
||||||
StreamDescriptor streamDescr = shc.open("6eb20db1-2921-41ec-ab79-909edd9b58fd").asItem().download("05098be5-61a2-423a-b382-9399a04df11e");
|
StreamDescriptor streamDescr = shc.open("6eb20db1-2921-41ec-ab79-909edd9b58fd").asItem().download("05098be5-61a2-423a-b382-9399a04df11e");
|
||||||
|
|
||||||
File tmpFile = Files.createTempFile(streamDescr.getFileName(),"").toFile();
|
File tmpFile = Files.createTempFile(streamDescr.getFileName(),"").toFile();
|
||||||
|
@ -325,6 +599,25 @@ public class Items {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteUnusefulUsers() throws Exception{
|
||||||
|
final UserManagerClient client = AbstractPlugin.users().build();
|
||||||
|
List<String> users = client.getUsers();
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
for (String user : users)
|
||||||
|
if (user.startsWith("userm")) {
|
||||||
|
shc.deleteUserAccount(user);
|
||||||
|
System.out.println("user "+user+"removed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeGroup() throws Exception{
|
||||||
|
StorageHubClient sh = new StorageHubClient();
|
||||||
|
VREFolderManager vreMan = sh.getVreFolderManager("d4science.research-infrastructures.eu-OpenAIRE-OpenAIRE-Connect_EAB");
|
||||||
|
vreMan.removeVRE();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -4,35 +4,30 @@ import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.net.URI;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.ws.rs.client.Client;
|
|
||||||
import javax.ws.rs.client.ClientBuilder;
|
|
||||||
import javax.ws.rs.client.Entity;
|
|
||||||
import javax.ws.rs.client.WebTarget;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
//code-repo.d4science.org/gCubeSystem/storagehub-client-library.git
|
||||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||||
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
import org.gcube.common.storagehub.client.proxies.MessageManagerClient;
|
||||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||||
import org.gcube.common.storagehub.model.Metadata;
|
import org.gcube.common.storagehub.model.Metadata;
|
||||||
import org.gcube.common.storagehub.model.Paths;
|
import org.gcube.common.storagehub.model.Paths;
|
||||||
import org.gcube.common.storagehub.model.acls.ACL;
|
import org.gcube.common.storagehub.model.acls.ACL;
|
||||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
|
||||||
import org.gcube.common.storagehub.model.expressions.GenericSearchableItem;
|
import org.gcube.common.storagehub.model.expressions.GenericSearchableItem;
|
||||||
import org.gcube.common.storagehub.model.expressions.OrderField;
|
import org.gcube.common.storagehub.model.expressions.OrderField;
|
||||||
import org.gcube.common.storagehub.model.expressions.SearchableItem;
|
import org.gcube.common.storagehub.model.expressions.SearchableItem;
|
||||||
|
@ -42,9 +37,6 @@ import org.gcube.common.storagehub.model.items.GCubeItem;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
import org.gcube.common.storagehub.model.query.Queries;
|
import org.gcube.common.storagehub.model.query.Queries;
|
||||||
import org.gcube.common.storagehub.model.query.Query;
|
import org.gcube.common.storagehub.model.query.Query;
|
||||||
import org.glassfish.jersey.client.ClientProperties;
|
|
||||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
|
||||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -54,60 +46,82 @@ public class TestCall {
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(TestCall.class);
|
private static Logger log = LoggerFactory.getLogger(TestCall.class);
|
||||||
|
|
||||||
|
private static final String propFile = "/home/lucio/tokens.properties";
|
||||||
|
|
||||||
|
private static final String tokens = "dev-root";
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp(){
|
public static void setUp(){
|
||||||
|
|
||||||
|
try(InputStream is = new FileInputStream(new File(propFile))){
|
||||||
|
Properties prop = new Properties();
|
||||||
|
prop.load(is);
|
||||||
|
String value =(String)prop.get(tokens);
|
||||||
|
String[] splitValue = value.split(",");
|
||||||
|
String token = splitValue[1];
|
||||||
|
String scope = splitValue[0];
|
||||||
|
//SecretManagerProvider.instance.set(new GCubeSecret(token));
|
||||||
|
|
||||||
|
SecurityTokenProvider.instance.set(token);
|
||||||
|
ScopeProvider.instance.set(scope);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void removeUserFromGroup() throws StorageHubException {
|
public void sendMessagesWithAttachment() throws Exception {
|
||||||
GroupManagerClient client = AbstractPlugin.groups().build();
|
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||||
client.removeUserFromGroup("andrea.rossi", "gcube-devsec-devVRE");
|
client.sendMessage(Arrays.asList("massimiliano.assante"), "subject encodato ? è ", "è econdato ??", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
public void setUnread() throws Exception {
|
||||||
|
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||||
|
client.setRead("f3b7ce40-28df-40b3-ad17-f0b9bd658016", false);
|
||||||
|
}
|
||||||
|
|
||||||
public void addUserToGroup() throws StorageHubException {
|
public void addUserToGroup() throws StorageHubException {
|
||||||
GroupManagerClient client = AbstractPlugin.groups().build();
|
GroupManagerClient client = AbstractPlugin.groups().build();
|
||||||
client.addUserToGroup("andrea.rossi", "gcube-devsec-devVRE");
|
client.addUserToGroup("andrea.rossi", "gcube-devsec-devVRE");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=UserNotAuthorizedException.class)
|
|
||||||
public void createNotAuthorized() throws Exception{
|
public void createNotAuthorized() throws Exception{
|
||||||
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||||
itemclient.createFolder("3bc977be-37f0-4518-888f-a7cb96c9be8e", "cannot create", "", false);
|
itemclient.createFolder("3bc977be-37f0-4518-888f-a7cb96c9be8e", "cannot create", "", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createFolderAndShare() throws Exception{
|
public void createFolderAndShare() throws Exception{
|
||||||
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||||
|
|
||||||
itemclient.createFolder("fakeId", "test", "test", false);
|
itemclient.createFolder("fakeId", "test", "test", false);
|
||||||
|
|
||||||
/*WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
/*WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
||||||
Item ws = client.getWorkspace();
|
Item ws = client.getWorkspace();
|
||||||
String id = itemclient.createFolder(ws.getId(), "ok7SharingTest", "shared folder for test SHM");
|
String id = itemclient.createFolder(ws.getId(), "ok7SharingTest", "shared folder for test SHM");
|
||||||
|
|
||||||
String sharedId = itemclient.shareFolder(id, new HashSet<String>(Arrays.asList("giancarlo.panichi")), AccessType.WRITE_OWNER);
|
String sharedId = itemclient.shareFolder(id, new HashSet<String>(Arrays.asList("giancarlo.panichi")), AccessType.WRITE_OWNER);
|
||||||
itemclient.uploadFile(new FileInputStream("/home/lucio/Downloads/upload.pdf"), sharedId, "sharedFile.pdf" , "shared file in a shared folder");
|
itemclient.uploadFile(new FileInputStream("/home/lucio/Downloads/upload.pdf"), sharedId, "sharedFile.pdf" , "shared file in a shared folder");
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shareAnAlreadySharedFolder() throws Exception{
|
public void shareAnAlreadySharedFolder() throws Exception{
|
||||||
|
|
||||||
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||||
itemclient.shareFolder("86e8472a-6f66-4608-9d70-20102c9172ce", new HashSet<>(Arrays.asList("costantino.perciante")), AccessType.READ_ONLY);
|
itemclient.shareFolder("86e8472a-6f66-4608-9d70-20102c9172ce", new HashSet<>(Arrays.asList("costantino.perciante")), AccessType.READ_ONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void restore() throws Exception{
|
||||||
public void restore() {
|
|
||||||
|
|
||||||
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
||||||
client.restoreFromTrash("82af9e1c-6cc7-4e16-bba5-9bec6545015a");
|
System.out.println(client.restoreFromTrash("4fc0a9df-9a51-42ef-98f2-06c21bd0669b", "f3d336cc-cd00-48ba-8339-2bffcbef825e"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
|
|
||||||
public void unshareFolder() throws Exception{
|
public void unshareFolder() throws Exception{
|
||||||
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||||
itemclient.unshareFolder("86e8472a-6f66-4608-9d70-20102c9172ce", new HashSet<>(Arrays.asList("giancarlo.panichi")));
|
itemclient.unshareFolder("86e8472a-6f66-4608-9d70-20102c9172ce", new HashSet<>(Arrays.asList("giancarlo.panichi")));
|
||||||
|
@ -115,7 +129,6 @@ public class TestCall {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete() throws Exception{
|
public void delete() throws Exception{
|
||||||
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||||
itemclient.delete("7af3d5cb-5e74-4a80-be81-acb2fec74cd9");
|
itemclient.delete("7af3d5cb-5e74-4a80-be81-acb2fec74cd9");
|
||||||
|
@ -124,7 +137,6 @@ public class TestCall {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getById() throws Exception{
|
public void getById() throws Exception{
|
||||||
final ItemManagerClient client = AbstractPlugin.item().build();
|
final ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
List<? extends Item> items = client.getAnchestors("29b417e2-dc2f-419a-be0b-7f49e76c9d7c", "hl:accounting", "jcr:content");
|
List<? extends Item> items = client.getAnchestors("29b417e2-dc2f-419a-be0b-7f49e76c9d7c", "hl:accounting", "jcr:content");
|
||||||
|
@ -137,7 +149,6 @@ public class TestCall {
|
||||||
System.in.read();
|
System.in.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setMetadata() throws Exception{
|
public void setMetadata() throws Exception{
|
||||||
final ItemManagerClient client = AbstractPlugin.item().build();
|
final ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
Metadata meta = new Metadata();
|
Metadata meta = new Metadata();
|
||||||
|
@ -148,7 +159,6 @@ public class TestCall {
|
||||||
client.setMetadata("8822478a-4fd3-41d5-87de-9ff161d0935e", meta);
|
client.setMetadata("8822478a-4fd3-41d5-87de-9ff161d0935e", meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createGcubeItem() throws Exception {
|
public void createGcubeItem() throws Exception {
|
||||||
final ItemManagerClient client = AbstractPlugin.item().build();
|
final ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
GCubeItem item = new GCubeItem();
|
GCubeItem item = new GCubeItem();
|
||||||
|
@ -164,40 +174,34 @@ public class TestCall {
|
||||||
client.createGcubeItem(ws.getId(), item);
|
client.createGcubeItem(ws.getId(), item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void upload() throws Exception{
|
public void upload() throws Exception{
|
||||||
//final ItemManagerClient client = AbstractPlugin.item().at(new URI("http://workspace-repository1-d.d4science.org:8080/storagehub")).build();
|
|
||||||
|
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
|
||||||
Client client = ClientBuilder.newClient();
|
long start = System.currentTimeMillis();
|
||||||
client.register(MultiPartFeature.class).property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024).property(ClientProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, -1)
|
|
||||||
.property(ClientProperties.REQUEST_ENTITY_PROCESSING, "CHUNKED");
|
final ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
WebTarget target = client.target("http://workspace-repository1-d.d4science.org:8080/storagehub/workspace/items/bc1c9525-43f7-4565-b5ea-0a0f9d7853a0/create/test-upload?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
File file = new File("/home/lucio/Downloads/cali4gif.gif");
|
||||||
|
System.out.println(" file length is "+file.length());
|
||||||
FormDataMultiPart multipart = new FormDataMultiPart();
|
client.uploadFile(new FileInputStream(file), "e532a011-081a-4bbd-879a-f90394c40af1", "cali4gif.gif", "description", file.length());
|
||||||
|
|
||||||
multipart.field("name", "test1Gb2.db");
|
|
||||||
multipart.field("description", "description");
|
|
||||||
multipart.field("file", new FileInputStream("/home/lucio/Downloads/ar_bigdata_201705.csv"), MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
|
||||||
|
|
||||||
target.request().post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA));
|
|
||||||
|
|
||||||
//client.uploadFile(new FileInputStream("/home/lucio/Downloads/test5Gb.zip"), "bc1c9525-43f7-4565-b5ea-0a0f9d7853a0", "5gb.zip", "description");
|
|
||||||
|
|
||||||
|
System.out.println(" took "+(System.currentTimeMillis()-start));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uploadArchive() throws Exception{
|
public void uploadArchive() throws Exception{
|
||||||
final ItemManagerClient client = AbstractPlugin.item().at(new URI("http://workspace-repository1-d.d4science.org:8080/storagehub")).build();
|
final ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
|
|
||||||
client.uploadArchive(new FileInputStream("/home/lucio/Downloads/filezilla.tar"), "bc1c9525-43f7-4565-b5ea-0a0f9d7853a0", "filezillaTar1");
|
client.uploadArchive(new FileInputStream("/home/lucio/Downloads/Presentazioni utili.zip"), "bc1c9525-43f7-4565-b5ea-0a0f9d7853a0", "filezillaTar1");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getACL() throws Exception{
|
public void getACL() throws Exception{
|
||||||
final ItemManagerClient client = AbstractPlugin.item().build();
|
final ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
try {
|
try {
|
||||||
|
@ -213,7 +217,6 @@ public class TestCall {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void download() throws Exception{
|
public void download() throws Exception{
|
||||||
ItemManagerClient client = AbstractPlugin.item().build();
|
ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
StreamDescriptor streamDescr = client.download("6875651d-6510-4b82-a0f3-cc3356c1a143");
|
StreamDescriptor streamDescr = client.download("6875651d-6510-4b82-a0f3-cc3356c1a143");
|
||||||
|
@ -229,7 +232,6 @@ public class TestCall {
|
||||||
System.out.println("file written "+output.getAbsolutePath());
|
System.out.println("file written "+output.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getCount() throws Exception{
|
public void getCount() throws Exception{
|
||||||
final ItemManagerClient client = AbstractPlugin.item().build();
|
final ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
@ -240,7 +242,6 @@ public class TestCall {
|
||||||
System.in.read();
|
System.in.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getVreFolder() {
|
public void getVreFolder() {
|
||||||
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||||
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
||||||
|
@ -253,17 +254,16 @@ public class TestCall {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getRecents() {
|
public void getRecents() {
|
||||||
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
|
||||||
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
||||||
List<? extends Item> items = wsclient.getRecentModifiedFilePerVre();
|
List<? extends Item> items = wsclient.getRecentModifiedFilePerVre();
|
||||||
|
|
||||||
System.out.println("items are "+items.size());
|
System.out.println("items are "+items.size());
|
||||||
|
|
||||||
for (Item item: items)
|
for (Item item: items)
|
||||||
System.out.println(item.getName()+ " "+item.getPath());
|
System.out.println(item.getName()+ " "+item.getLastModificationTime().getTimeInMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createFolder() throws Exception{
|
public void createFolder() throws Exception{
|
||||||
long start= System.currentTimeMillis();
|
long start= System.currentTimeMillis();
|
||||||
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||||
|
@ -276,7 +276,6 @@ public class TestCall {
|
||||||
System.out.println("creating folder took total "+(System.currentTimeMillis()-start));
|
System.out.println("creating folder took total "+(System.currentTimeMillis()-start));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void share() throws Exception {
|
public void share() throws Exception {
|
||||||
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||||
itemclient.shareFolder("4fd4a4ca-c615-4076-8eaa-70268e4f6166", new HashSet<>(Arrays.asList("francesco.mangiacrapa","massimiliano.assante","giancarlo.panichi")), AccessType.WRITE_OWNER);
|
itemclient.shareFolder("4fd4a4ca-c615-4076-8eaa-70268e4f6166", new HashSet<>(Arrays.asList("francesco.mangiacrapa","massimiliano.assante","giancarlo.panichi")), AccessType.WRITE_OWNER);
|
||||||
|
@ -325,8 +324,8 @@ public class TestCall {
|
||||||
boolean b = m.find();
|
boolean b = m.find();
|
||||||
System.out.println("result: "+!b);
|
System.out.println("result: "+!b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* private InputStream getThumbnailAsPng(ImagePlus img, int thumbWidth,
|
/* private InputStream getThumbnailAsPng(ImagePlus img, int thumbWidth,
|
||||||
int thumbHeight) throws IOException {
|
int thumbHeight) throws IOException {
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
package org.gcube.data.access.fs;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.VREFolderManager;
|
||||||
|
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class TestWithLocalContainer {
|
||||||
|
|
||||||
|
private static StorageHubClient client;
|
||||||
|
|
||||||
|
private static Logger log = LoggerFactory.getLogger(TestWithLocalContainer.class);
|
||||||
|
|
||||||
|
public static URI storagehubUri;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void initialize() throws Exception{
|
||||||
|
storagehubUri = new URL(String.format("http://%s:%d/storagehub", "localhost",8081)).toURI();
|
||||||
|
/*AccessTokenSecret secret = new AccessTokenSecret("eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJSSklZNEpoNF9qdDdvNmREY0NlUDFfS1l0akcxVExXVW9oMkQ2Tzk1bFNBIn0.eyJleHAiOjE2NDQyNDM4ODUsImlhdCI6MTY0NDI0MzU4NSwiYXV0aF90aW1lIjoxNjQ0MjQzNTg1LCJqdGkiOiI1NWQ4ZDc5OS1kNTIzLTQ0YmEtYTRkMC1iZjIyYzVlMTg4NzQiLCJpc3MiOiJodHRwczovL2FjY291bnRzLmRldi5kNHNjaWVuY2Uub3JnL2F1dGgvcmVhbG1zL2Q0c2NpZW5jZSIsImF1ZCI6IiUyRmdjdWJlIiwic3ViIjoiNGMxMWRlODQtZGRjOS00ZGQxLWI5N2EtZWE4MmQyZDEzOGE2IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibmV4dC5kNHNjaWVuY2Uub3JnIiwic2Vzc2lvbl9zdGF0ZSI6ImZkZTA3MGE2LTVkOTUtNDc3Ni1hMTFiLTBhZTI1MzQ5NGQyMyIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiLyoiXSwicmVzb3VyY2VfYWNjZXNzIjp7IiUyRmdjdWJlIjp7InJvbGVzIjpbIkluZnJhc3RydWN0dXJlLU1hbmFnZXIiLCJNZW1iZXIiXX19LCJhdXRob3JpemF0aW9uIjp7InBlcm1pc3Npb25zIjpbeyJyc2lkIjoiMTU5ZDcyMDQtNjlmYS00ZmY0LTlhOTQtMzVlMWUyMzA5MDQyIiwicnNuYW1lIjoiRGVmYXVsdCBSZXNvdXJjZSJ9XX0sInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJuYW1lIjoiTHVjaW8gTGVsaWkiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJsdWNpby5sZWxpaSIsImdpdmVuX25hbWUiOiJMdWNpbyIsImZhbWlseV9uYW1lIjoiTGVsaWkiLCJlbWFpbCI6Imx1Y2lvLmxlbGlpQGlzdGkuY25yLml0In0.SGuGXnY63WJ45tdypywaopO--FCxY6ZWAX74MGVw_zdNMMQI5zgtGfhZQewFWQ6HhVINDStXqvdSDluhF9JwFXCUGvxB2BipfKQYsAQnm3I4K3kgMl26kuQIL5Im-apw2XWvImTgLshX1AzpyqzFR1Jpf_p65GCMpcHLEwo_nTGLkrZNtfRdtqakZ8S8lowGaV2J2mNf4AHhtARSLJF3GqwynF5pPUXR2iOMUrjw_FLnIuPMfAjk_jHMeYKIxXNBLsoEpELju3pr2gEkv1ZRH9bZkyg7_3hW4mGzxq_Ea9w1FBVJOlkp6vypuISLNyJZcVOnBa4Dg1KRxxlp3aZ6vA");
|
||||||
|
SecretManagerProvider.instance.set(secret);*/
|
||||||
|
client = new StorageHubClient(storagehubUri);
|
||||||
|
createUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void reset() throws Exception {
|
||||||
|
/*CredentialSecret secret = new CredentialSecret("sg4-test-client", "a156a7db-3b32-4cd5-b27b-2488e0e01698", "/gcube");
|
||||||
|
SecretManagerProvider.instance.set(secret);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createUser() throws Exception{
|
||||||
|
client.createUserAccount("test.user");
|
||||||
|
client.createUserAccount("test.user2");
|
||||||
|
VREFolderManager vremanager = client.getVreFolderManager("gcube-devVre-myvre");
|
||||||
|
vremanager.createVRE(AccessType.WRITE_OWNER, "test.user");
|
||||||
|
vremanager.addUser("test.user2");
|
||||||
|
}
|
||||||
|
|
||||||
|
//impersonating test.user
|
||||||
|
@Test
|
||||||
|
public void uploadFile() throws Exception{
|
||||||
|
|
||||||
|
client.impersonate("test.user");
|
||||||
|
FolderContainer vreFolder = (FolderContainer) client.getVREFolders().getContainers().stream().findFirst().get();
|
||||||
|
try(InputStream stream = this.getClass().getResourceAsStream("/output.xlsx")){
|
||||||
|
vreFolder.uploadFile(stream, "userTestfile2", "userTestfile" );
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(vreFolder.list().getItems().size()>0);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue