Compare commits

...

3 Commits

Author SHA1 Message Date
lucio 697ca73dd7 updated 2024-02-06 09:51:45 +01:00
lucio b8b4c9bc23 added possibility to use different bucket for vre folder 2023-06-01 18:59:56 +02:00
lucio aacaeea5da updated 2023-05-30 10:21:07 +02:00
12 changed files with 114 additions and 129 deletions

View File

@ -9,6 +9,7 @@
<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">

View File

@ -1,7 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="storagehub-client_TRUNK">
<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>
</project-modules>

View File

@ -3,7 +3,13 @@
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]
## [v3.0.0-SNAPSHOT] - [2023-05-23]
### Feature
porting GCUBE-BOM 3.0
## [v2.0.0] - [2022-02-07]
### Feature

64
pom.xml
View File

@ -2,65 +2,41 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.1.0</version>
<relativePath />
</parent>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/storagehub-client-library.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/storagehub-client-library.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/storagehub-client-library</url>
</scm>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<name>storagehub-client-library</name>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>gov.nih.imagej</groupId>
<artifactId>imagej</artifactId>
<version>1.47</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-model</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
@ -69,7 +45,6 @@
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-gcube-calls</artifactId>
@ -77,21 +52,37 @@
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-jaxrs-client</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-generic-clients</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>rt</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-security</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common.security</groupId>
<artifactId>gcube-secrets</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@ -115,6 +106,11 @@
<version>5.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>gov.nih.imagej</groupId>
<artifactId>imagej</artifactId>
<version>1.47</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -53,6 +53,10 @@ public class VREFolderManager {
groupClient.createGroup(vreTitle, accessType, folderOwner);
}
public void createVRE(AccessType accessType, String folderOwner, boolean useDefaultStorage) throws StorageHubException{
groupClient.createGroup(vreTitle, accessType, folderOwner, useDefaultStorage);
}
public void removeVRE() throws StorageHubException{
groupClient.removeGroup(vreTitle);
}

View File

@ -43,7 +43,7 @@ public class DefaultGroupManager extends DefaultManagerClient implements GroupMa
else if (response.getHTTPCode()==403)
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
else
throw new BackendGenericError();
throw new BackendGenericError("response is "+response.getHTTPCode());
}
@ -160,6 +160,11 @@ public class DefaultGroupManager extends DefaultManagerClient implements GroupMa
@Override
public void createGroup(String groupId, AccessType accessType, String folderOwner) throws StorageHubException {
this.createGroup(groupId, accessType, folderOwner, true);
}
@Override
public void createGroup(String groupId, AccessType accessType, String folderOwner, boolean useDefaultStorage) throws StorageHubException {
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
@Override
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
@ -169,7 +174,7 @@ public class DefaultGroupManager extends DefaultManagerClient implements GroupMa
multipart.field("accessType", accessType, MediaType.APPLICATION_JSON_TYPE);
multipart.field("group", groupId);
multipart.field("folderOwner", folderOwner);
multipart.field("useDefaultStorage", Boolean.toString(useDefaultStorage));
GXInboundResponse response = myManager.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));

View File

@ -15,6 +15,8 @@ public interface GroupManagerClient extends ManagerClient{
void createGroup(String groupId, AccessType accessType, String folderOwner) throws StorageHubException;
void createGroup(String groupId, AccessType accessType, String folderOwner, boolean useDefaultStorage) throws StorageHubException;
List<String> getUsersOfGroup(String groupId) throws StorageHubException;
List<String> getGroups() throws StorageHubException;

View File

@ -1,14 +1,9 @@
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;
@ -20,29 +15,7 @@ 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
@ -58,7 +31,7 @@ public class ImportTest {
}
public void importTest(String folderId, String relativePath) throws Exception {
setUp(prodEnv);
Initializer.setUp();
StorageHubClient shc = new StorageHubClient();
FolderContainer fc = shc.open(folderId).asFolder();
@ -68,10 +41,10 @@ public class ImportTest {
for (ItemContainer<? extends Item> itemContainer : items) {
if (itemContainer.getType() == ContainerType.FOLDER) {
new Thread(()-> createInDev(itemContainer.get(), itemContainer.getType(), relativePath, null)).run();
setUp(prodEnv);
Initializer.setUp();
importTest(itemContainer.getId(), relativePath == null ? itemContainer.get().getName() : relativePath+"/"+itemContainer.get().getName() );
} else if (itemContainer.getType() == ContainerType.FILE){
setUp(prodEnv);
Initializer.setUp();
final URL publicLink = ((FileContainer)itemContainer).getPublicLink();
System.out.println("publik Link "+publicLink.toString());
new Thread(()-> createInDev(itemContainer.get(), itemContainer.getType(), relativePath, publicLink)).run();
@ -83,7 +56,7 @@ public class ImportTest {
public <T extends Item> void createInDev(T item, ContainerType type, String relativePath, URL publicLink){
setUp(devEnv);
Initializer.setUp();
StorageHubClient shc = new StorageHubClient();
try {
FolderContainer currentFolder = shc.openVREFolder().openByRelativePath("testLucio").asFolder();

View File

@ -0,0 +1,38 @@
package org.gcube.data.access.fs;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.common.security.secrets.GCubeSecret;
public class Initializer {
private static final String propFile = "/Users/lucio/Documents/tokens.properties";
private static final String devEnv = "dev-devvre";
private static final String devRoot = "dev-root";
public static 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));
} catch (Exception e) {
e.printStackTrace();
}
}
public static void setUp(){
setUp(devRoot);
}
}

View File

@ -14,11 +14,8 @@ import java.util.HashSet;
import java.util.List;
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.scope.api.ScopeProvider;
import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.dsl.ContainerType;
import org.gcube.common.storagehub.client.dsl.FileContainer;
@ -32,7 +29,6 @@ import org.gcube.common.storagehub.client.proxies.UserManagerClient;
import org.gcube.common.storagehub.model.Metadata;
import org.gcube.common.storagehub.model.acls.AccessType;
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item;
import org.junit.BeforeClass;
@ -42,36 +38,15 @@ import org.junit.Test;
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
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];
//SecretManagerProvider.instance.set(new GCubeSecret(token));
SecurityTokenProvider.instance.set(token);
ScopeProvider.instance.set(splitValue[0]);
} catch (Exception e) {
e.printStackTrace();
}
Initializer.setUp();
}
@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))){
@ -97,6 +72,14 @@ public class Items {
}
@Test
public void opeVREfolder() throws StorageHubException{
StorageHubClient shc = new StorageHubClient();
//shc.openVREFolder();
shc.getVreFolderManager("gcube-devsec-devVRE").setAdmin("massimiliano.assante");
}
@Test
public void removeVersion() throws Exception {

View File

@ -4,18 +4,14 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
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.plugins.AbstractPlugin;
@ -46,29 +42,9 @@ public class TestCall {
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
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();
}
Initializer.setUp();
}

View File

@ -28,17 +28,14 @@ public class TestWithLocalContainer {
@BeforeClass
public static void initialize() throws Exception{
Initializer.setUp();
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{
@ -55,8 +52,8 @@ public class TestWithLocalContainer {
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" );
try (InputStream stream = this.getClass().getResourceAsStream("/output.xlsx")) {
vreFolder.uploadFile(stream, "userTestfile2", "userTestfile");
}
assertTrue(vreFolder.list().getItems().size()>0);