test removed
This commit is contained in:
parent
244a13845b
commit
57cf44ade2
5
pom.xml
5
pom.xml
|
@ -350,11 +350,6 @@
|
|||
<artifactId>minio</artifactId>
|
||||
<version>8.3.3</version>
|
||||
</dependency> -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>storagehub-client-library</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
package org.gcube.data.access.fs.container;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.common.security.secrets.AccessTokenSecret;
|
||||
import org.gcube.common.security.secrets.UmaTokenSecret;
|
||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testcontainers.containers.DockerComposeContainer;
|
||||
import org.testcontainers.containers.output.Slf4jLogConsumer;
|
||||
import org.testcontainers.containers.wait.strategy.Wait;
|
||||
|
||||
|
||||
|
||||
public class CreateUsers {
|
||||
|
||||
private static StorageHubClient client;
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CreateUsers.class);
|
||||
|
||||
public static DockerComposeContainer environment =
|
||||
new DockerComposeContainer(new File("src/test/resources/compose-test.yml"))
|
||||
.withExposedService("postgres", 5432)
|
||||
.withExposedService("storagehub", 8081).withLogConsumer("storagehub", new Slf4jLogConsumer(log)).waitingFor("storagehub_1",Wait.forHttp("/"));
|
||||
|
||||
public static URI storagehubUri;
|
||||
|
||||
public static void before() throws Exception{
|
||||
String address = environment.getServiceHost("storagehub_1", 8080);
|
||||
int port = environment.getServicePort("storagehub_1", 8080);
|
||||
storagehubUri = new URL(String.format("http://%s:%d/storagehub", address,port)).toURI();
|
||||
client = new StorageHubClient(storagehubUri);
|
||||
}
|
||||
|
||||
public void setTokenAndScope() {
|
||||
UmaTokenSecret secret = new UmaTokenSecret("eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJSSklZNEpoNF9qdDdvNmREY0NlUDFfS1l0akcxVExXVW9oMkQ2Tzk1bFNBIn0.eyJleHAiOjE2NDQyNDM4ODUsImlhdCI6MTY0NDI0MzU4NSwiYXV0aF90aW1lIjoxNjQ0MjQzNTg1LCJqdGkiOiI1NWQ4ZDc5OS1kNTIzLTQ0YmEtYTRkMC1iZjIyYzVlMTg4NzQiLCJpc3MiOiJodHRwczovL2FjY291bnRzLmRldi5kNHNjaWVuY2Uub3JnL2F1dGgvcmVhbG1zL2Q0c2NpZW5jZSIsImF1ZCI6IiUyRmdjdWJlIiwic3ViIjoiNGMxMWRlODQtZGRjOS00ZGQxLWI5N2EtZWE4MmQyZDEzOGE2IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibmV4dC5kNHNjaWVuY2Uub3JnIiwic2Vzc2lvbl9zdGF0ZSI6ImZkZTA3MGE2LTVkOTUtNDc3Ni1hMTFiLTBhZTI1MzQ5NGQyMyIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiLyoiXSwicmVzb3VyY2VfYWNjZXNzIjp7IiUyRmdjdWJlIjp7InJvbGVzIjpbIkluZnJhc3RydWN0dXJlLU1hbmFnZXIiLCJNZW1iZXIiXX19LCJhdXRob3JpemF0aW9uIjp7InBlcm1pc3Npb25zIjpbeyJyc2lkIjoiMTU5ZDcyMDQtNjlmYS00ZmY0LTlhOTQtMzVlMWUyMzA5MDQyIiwicnNuYW1lIjoiRGVmYXVsdCBSZXNvdXJjZSJ9XX0sInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJuYW1lIjoiTHVjaW8gTGVsaWkiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJsdWNpby5sZWxpaSIsImdpdmVuX25hbWUiOiJMdWNpbyIsImZhbWlseV9uYW1lIjoiTGVsaWkiLCJlbWFpbCI6Imx1Y2lvLmxlbGlpQGlzdGkuY25yLml0In0.SGuGXnY63WJ45tdypywaopO--FCxY6ZWAX74MGVw_zdNMMQI5zgtGfhZQewFWQ6HhVINDStXqvdSDluhF9JwFXCUGvxB2BipfKQYsAQnm3I4K3kgMl26kuQIL5Im-apw2XWvImTgLshX1AzpyqzFR1Jpf_p65GCMpcHLEwo_nTGLkrZNtfRdtqakZ8S8lowGaV2J2mNf4AHhtARSLJF3GqwynF5pPUXR2iOMUrjw_FLnIuPMfAjk_jHMeYKIxXNBLsoEpELju3pr2gEkv1ZRH9bZkyg7_3hW4mGzxq_Ea9w1FBVJOlkp6vypuISLNyJZcVOnBa4Dg1KRxxlp3aZ6vA");
|
||||
SecretManagerProvider.set(secret);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createUser() throws Exception{
|
||||
|
||||
client.createUserAccount("lucio.lelii");
|
||||
client.getWSRoot();
|
||||
|
||||
}
|
||||
}
|
|
@ -1,365 +0,0 @@
|
|||
package org.gcube.data.access.fs.external;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.common.security.secrets.CredentialSecret;
|
||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.items.SharedFolder;
|
||||
import org.gcube.common.storagehub.model.types.SHUBUser;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CreateUsers {
|
||||
|
||||
private static StorageHubClient client;
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CreateUsers.class);
|
||||
|
||||
private String user1 = "pippo.test";
|
||||
private String user2 = "lucio.lelii";
|
||||
private String vreWA = "vre-write-all";
|
||||
private String vreRO = "vre-read-only";
|
||||
private String vreWO = "vre-write-owner";
|
||||
|
||||
private static final int TEST_USERS_NUMBER = 5000;
|
||||
|
||||
@BeforeClass
|
||||
public static void before() throws Exception {
|
||||
String address = "localhost";
|
||||
int port = 8081;
|
||||
URI storagehubUri = new URL(String.format("http://%s:%d/storagehub", address, port)).toURI();
|
||||
client = new StorageHubClient(storagehubUri);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setSecret() {
|
||||
CredentialSecret secret = new CredentialSecret("sg4-test-client", "a156a7db-3b32-4cd5-b27b-2488e0e01698",
|
||||
"/gcube");
|
||||
SecretManagerProvider.set(secret);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialiseEnvironment() throws Exception {
|
||||
this.createUser(user1);
|
||||
this.createAllVREsAndAddUser1AsAdmin();
|
||||
client.impersonate(user1);
|
||||
this.createUser(user2);
|
||||
this.addUser2ToAllVres();
|
||||
client.impersonate(user1);
|
||||
createRandomFolderAndFileForCurrentUser();
|
||||
createRandomFolderAndFileForCurrentUser();
|
||||
createRandomFolderAndFileForCurrentUser();
|
||||
|
||||
client.impersonate(user2);
|
||||
createRandomFolderAndFileForCurrentUser();
|
||||
createRandomFolderAndFileForCurrentUser();
|
||||
createRandomFolderAndFileForCurrentUser();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUsers() throws Exception {
|
||||
client.getUsers().forEach(u -> System.out.println(u.getUserName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemCountPerUsers() throws Exception {
|
||||
for (SHUBUser user : client.getUsers()) {
|
||||
client.impersonate(user.getUserName());
|
||||
int size = client.getWSRoot().list().getItems().size();
|
||||
System.out.println(String.format("%s has %d items", user.getUserName(), size));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUser2FromVre() throws Exception {
|
||||
client.getVreFolderManager(vreRO).removeUser(user2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createUri() throws Exception{
|
||||
client.impersonate(user2);
|
||||
client.getWSRoot().addUrl(new URL("https://www.google.it"), "google", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createRandomFileAndFolderOnEveryUser() throws Exception {
|
||||
for (SHUBUser user : client.getUsers()) {
|
||||
client.impersonate(user.getUserName());
|
||||
String rootId = this.getUserRootId();
|
||||
for (int i = 0; i<=500; i++)
|
||||
this.createRandomFolderForCurrentUser(rootId);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFileAndFolderUser2() throws Exception {
|
||||
client.impersonate(user2);
|
||||
for (int i = 0; i<=100; i++)
|
||||
createRandomFolderAndFileForCurrentUser();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uploadFileUser2() throws Exception {
|
||||
client.impersonate(user2);
|
||||
String rootId = this.getUserRootId();
|
||||
this.uploadFileWithRandomNameForCurrentUser(rootId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFileAndFolderFarAllUsers() throws Exception {
|
||||
client.impersonate(user2);
|
||||
for (int i = 0; i<=100; i++)
|
||||
createRandomFolderAndFileForCurrentUser();
|
||||
}
|
||||
|
||||
public void createRandomFolderAndFileForCurrentUser() throws Exception{
|
||||
String rootId = this.getUserRootId();
|
||||
this.uploadFileWithRandomNameForCurrentUser(rootId);
|
||||
FolderContainer fc = this.createRandomFolderForCurrentUser(rootId);
|
||||
this.uploadFileWithRandomNameForCurrentUser(fc.getId());
|
||||
}
|
||||
|
||||
// USED TO CREATE TEST USERS
|
||||
final String lexicon = "ABCDEFGHIJKLMNOPQRSTUVWXYZ12345674890";
|
||||
|
||||
final java.util.Random rand = new java.util.Random();
|
||||
|
||||
// consider using a Map<String,Boolean> to say whether the identifier is being
|
||||
// used or not
|
||||
final Set<String> identifiers = new HashSet<String>();
|
||||
|
||||
public String randomIdentifier() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
while (builder.toString().length() == 0) {
|
||||
int length = rand.nextInt(5) + 5;
|
||||
for (int i = 0; i < length; i++) {
|
||||
builder.append(lexicon.charAt(rand.nextInt(lexicon.length())));
|
||||
}
|
||||
if (identifiers.contains(builder.toString())) {
|
||||
builder = new StringBuilder();
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
// END
|
||||
|
||||
@Test
|
||||
public void createTestUsers() throws Exception {
|
||||
for (int i = 0; i < TEST_USERS_NUMBER; i++)
|
||||
client.createUserAccount(String.format("%s.%s", randomIdentifier().toLowerCase(), randomIdentifier().toLowerCase() ));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAccountforManging() throws Exception {
|
||||
client.createUserAccount("service-account-sg4-test-client");
|
||||
client.getVreFolderManager(vreWA).addUser("service-account-sg4-test-client");
|
||||
client.getVreFolderManager(vreRO).addUser("service-account-sg4-test-client");
|
||||
client.getVreFolderManager(vreWO).addUser("service-account-sg4-test-client");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUserRootTest() throws Exception {
|
||||
client.impersonate("lucio.lelii");
|
||||
client.getWSRoot().getId();
|
||||
}
|
||||
|
||||
public String getUserRootId() throws Exception {
|
||||
return client.getWSRoot().getId();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBearerToken() {
|
||||
System.out.println(SecretManagerProvider.get().getHTTPAuthorizationHeaders());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFolderACLsOnrROVRE() throws Exception {
|
||||
client.impersonate(user1);
|
||||
FolderContainer vre = (FolderContainer) client.getVREFolders().getContainers().stream()
|
||||
.filter(f -> f.get().getTitle().equals(vreWA)).findFirst().get();
|
||||
FolderContainer folder = (FolderContainer) vre.list().getContainers().stream().findFirst().get();
|
||||
System.out.println(folder.get().getTitle() + " " + folder.getAcls());
|
||||
}
|
||||
|
||||
public void createUser(String user) throws Exception {
|
||||
client.createUserAccount(user);
|
||||
}
|
||||
|
||||
public void removeUserFromGroup(String user) throws Exception {
|
||||
client.getVreFolderManager(vreWA).removeAdmin(user);
|
||||
client.getVreFolderManager(vreWA).removeUser(user);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void createVRE(String vre, AccessType accesstype, String owner) throws Exception {
|
||||
client.getVreFolderManager(vre).createVRE(accesstype, owner, true);
|
||||
}
|
||||
|
||||
public void setAdmin(String vre, String user) throws Exception {
|
||||
client.getVreFolderManager(vre).setAdmin(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAllVREsAndAddUser1AsAdmin() throws Exception {
|
||||
createVRE(vreWA, AccessType.WRITE_ALL, user1 );
|
||||
setAdmin(vreWA, user1);
|
||||
createVRE(vreRO, AccessType.READ_ONLY, user1 );
|
||||
setAdmin(vreWA, user1);
|
||||
createVRE(vreWO, AccessType.WRITE_OWNER, user1 );
|
||||
setAdmin(vreWA, user1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addUser2ToAllVres() throws Exception {
|
||||
addUserToVre(vreRO, user2);
|
||||
addUserToVre(vreWA, user2);
|
||||
addUserToVre(vreWO, user2);
|
||||
}
|
||||
|
||||
public void createFolderByAdmin(String vre) throws Exception {
|
||||
retrieveVREbyName(vre).newFolder("test created by admin", "");
|
||||
}
|
||||
|
||||
|
||||
public void addUserToVre(String vre, String user) throws Exception {
|
||||
client.getVreFolderManager(vre).addUser(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void printVREFoldersAdmin() throws StorageHubException {
|
||||
System.out.println("launching .....");
|
||||
List<FolderContainer> vreFolders = client.getVREFolders().getContainers().stream()
|
||||
.map(c -> ((FolderContainer) c)).collect(Collectors.toList());
|
||||
for (FolderContainer fc : vreFolders) {
|
||||
System.out.println(fc.get().getTitle());
|
||||
System.out.println(fc.getAcls());
|
||||
System.out.println(client.getVreFolderManager(fc.get().getTitle()).getAdmins());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVREs() throws Exception {
|
||||
client.impersonate(user1);
|
||||
client.getVREFolders().getItems().stream().map(i -> ((SharedFolder) i))
|
||||
.forEach(s -> System.out.println(s.getDisplayName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWsRoot() throws Exception {
|
||||
client.impersonate(user1);
|
||||
client.getWSRoot().list().getItems().forEach(i -> System.out.println(i.getId() + " " + i.getTitle()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void download() throws Exception {
|
||||
client.impersonate(user1);
|
||||
try (InputStream is = client.open("5b5236d2-ec88-49f2-a2c5-04ecf8284191").asFile().download().getStream()) {
|
||||
String text = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)).lines()
|
||||
.collect(Collectors.joining("\n"));
|
||||
System.out.println(text);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uploadImageTest1() {
|
||||
client.impersonate(user1);
|
||||
try (InputStream is = CreateUsers.class.getResourceAsStream("/test1.jpg")) {
|
||||
client.getWSRoot().uploadFile(is, "test1.jpg", "a test");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void uploadFileWithRandomNameForCurrentUser(String folderId) throws URISyntaxException {
|
||||
long size = new File(CreateUsers.class.getResource("/pdf-test.pdf").toURI()).length();
|
||||
|
||||
try (InputStream is = CreateUsers.class.getResourceAsStream("/pdf-test.pdf")) {
|
||||
client.open(folderId).asFolder().uploadFile(is, randomIdentifier() + ".pdf", "a test", size);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public FolderContainer createRandomFolderForCurrentUser(String folderId) {
|
||||
try {
|
||||
return client.open(folderId).asFolder().newFolder(randomIdentifier(), "a test");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private FolderContainer retrieveVREbyName(String name) throws StorageHubException {
|
||||
List<FolderContainer> vreFolders = client.getVREFolders().getContainers().stream()
|
||||
.map(c -> ((FolderContainer) c)).collect(Collectors.toList());
|
||||
return vreFolders.stream().filter(c -> ((SharedFolder) c.get()).getDisplayName().equals(name)).findFirst()
|
||||
.get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uploadFileToVREWriteAll() throws StorageHubException {
|
||||
client.impersonate(user2);
|
||||
try (InputStream is = CreateUsers.class.getResourceAsStream("/test1.jpg")) {
|
||||
retrieveVREbyName(vreWA).uploadFile(is, "test1.jpg", "a test");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = StorageHubException.class)
|
||||
public void uploadFileToVREReadOnly() throws StorageHubException {
|
||||
client.impersonate(user2);
|
||||
try (InputStream is = CreateUsers.class.getResourceAsStream("/test1.jpg")) {
|
||||
retrieveVREbyName(vreRO).uploadFile(is, "test1.jpg", "a test");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uploadFileToVREReadOnlyAdmin() throws StorageHubException {
|
||||
client.impersonate(user1);
|
||||
try (InputStream is = CreateUsers.class.getResourceAsStream("/test1.jpg")) {
|
||||
retrieveVREbyName(vreRO).uploadFile(is, "test1.jpg", "a test");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uploadFileToVREWriteOwner() throws StorageHubException {
|
||||
client.impersonate(user2);
|
||||
try (InputStream is = CreateUsers.class.getResourceAsStream("/test1.jpg")) {
|
||||
retrieveVREbyName(vreWO).uploadFile(is, "test1.jpg", "a test");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUser() throws Exception {
|
||||
client.deleteUserAccount(user1);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
package org.gcube.data.access.storages.mock;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageIdNotFoundException;
|
||||
import org.gcube.common.storagehub.model.items.nodes.Content;
|
||||
import org.gcube.common.storagehub.model.items.nodes.PayloadBackend;
|
||||
import org.gcube.common.storagehub.model.storages.MetaInfo;
|
||||
import org.gcube.common.storagehub.model.storages.StorageBackend;
|
||||
|
||||
public class FSStorage extends StorageBackend {
|
||||
|
||||
public FSStorage(PayloadBackend payloadConfiguration) {
|
||||
super(payloadConfiguration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaInfo onCopy(Content content, String newParentPath, String newName) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaInfo onMove(Content content, String newParentPath) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String id) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaInfo upload(InputStream stream, String relativePath, String name, String user) {
|
||||
return this.upload(stream, relativePath, name, -1l, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaInfo upload(InputStream stream, String relativePath, String name, Long size, String user) {
|
||||
|
||||
try {
|
||||
InputStream is = new BufferedInputStream(stream);
|
||||
String id = UUID.randomUUID().toString();
|
||||
File targetFile = new File("/tmp/" + id);
|
||||
targetFile.createNewFile();
|
||||
OutputStream outStream = new FileOutputStream(targetFile);
|
||||
|
||||
byte[] buffer = new byte[1024 * 64];
|
||||
int bytesRead;
|
||||
while ((bytesRead = is.read(buffer, 0, 1024 * 64)) != -1) {
|
||||
outStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
IOUtils.closeQuietly(outStream);
|
||||
|
||||
return new MetaInfo(targetFile.length(), id, user, getPayloadConfiguration());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream download(Content item) throws StorageIdNotFoundException {
|
||||
return this.download(item.getStorageId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream download(String id) throws StorageIdNotFoundException {
|
||||
try {
|
||||
return new FileInputStream(new File("/tmp/" + id));
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getFileMetadata(String id) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaInfo upload(InputStream stream, String relativePath, String name, String storageId, Long size,
|
||||
String user) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTotalSizeStored() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTotalItemsCount() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package org.gcube.data.access.storages.mock;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
|
||||
import org.gcube.common.storagehub.model.items.nodes.PayloadBackend;
|
||||
import org.gcube.common.storagehub.model.storages.StorageBackend;
|
||||
import org.gcube.common.storagehub.model.storages.StorageBackendFactory;
|
||||
|
||||
@Singleton
|
||||
public class FSStorageFactory implements StorageBackendFactory {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "local-filesystem";
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageBackend create(PayloadBackend payloadConfiguration) throws InvalidCallParameters {
|
||||
return new FSStorage(payloadConfiguration);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue