git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@171298 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0dfdfde605
commit
e31ec5e123
|
@ -40,12 +40,12 @@ public abstract class ItemContainer<I extends Item> {
|
|||
else return item;
|
||||
}
|
||||
|
||||
public StreamDescriptor download() {
|
||||
return itemclient.download(this.itemId);
|
||||
public StreamDescriptor download(String ... nodeIdsToExclude) {
|
||||
return itemclient.download(this.itemId, nodeIdsToExclude);
|
||||
}
|
||||
|
||||
public List<? extends Item> getAnchestors() {
|
||||
return itemclient.getAnchestors(this.itemId, NodeConstants.ACCOUNTING_NAME);
|
||||
public ListResolver getAnchestors() {
|
||||
return new ListResolver(excludes -> itemclient.getAnchestors(this.itemId,excludes) , itemclient);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
|
|
|
@ -63,11 +63,13 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
|
||||
|
||||
@Override
|
||||
public StreamDescriptor download(String id) {
|
||||
public StreamDescriptor download(String id, String... excludeNodes) {
|
||||
Call<WebTarget, StreamDescriptor> call = new Call<WebTarget, StreamDescriptor>() {
|
||||
@Override
|
||||
public StreamDescriptor call(WebTarget manager) throws Exception {
|
||||
WebTarget myManager = manager.path(id).path("download");
|
||||
if (excludeNodes !=null && excludeNodes.length>0)
|
||||
myManager = myManager.queryParam("exclude",excludeNodes);
|
||||
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_OCTET_STREAM);
|
||||
Response resp = builder.get();
|
||||
InputStream stream = resp.readEntity(InputStream.class);
|
||||
|
|
|
@ -24,7 +24,7 @@ public interface ItemManagerClient {
|
|||
|
||||
Item get(String id, String ... excludeNodes);
|
||||
|
||||
StreamDescriptor download(String id);
|
||||
StreamDescriptor download(String id, String... excludeNodes);
|
||||
|
||||
String uploadFile(InputStream stream, String parentId, String fileName, String description);
|
||||
|
||||
|
|
|
@ -2,10 +2,17 @@ package org.gcube.data.access.fs;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.ws.rs.client.Client;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
|
@ -32,7 +39,7 @@ import org.junit.Test;
|
|||
|
||||
|
||||
public class Items {
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp(){
|
||||
SecurityTokenProvider.instance.set("b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548");
|
||||
|
@ -47,7 +54,7 @@ public class Items {
|
|||
String afi = null;
|
||||
|
||||
try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/ar_bigdata_201705.csv"))){
|
||||
shc.getWSRoot().uploadFile(is, "bigfile1GB-test1.scv", "descr");
|
||||
shc.getWSRoot().uploadFile(is, "bigfile1GB-test2.scv", "descr");
|
||||
|
||||
System.out.println(afi);
|
||||
} catch (Exception e) {
|
||||
|
@ -61,11 +68,10 @@ public class Items {
|
|||
public void uploadArchive() throws Exception {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
|
||||
String afi = null;
|
||||
|
||||
try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/filezilla.zip"))){
|
||||
shc.getWSRoot().uploadFile(is, "1gbup.zip", "descr");
|
||||
try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/test7z.7z"))){
|
||||
shc.getWSRoot().uploadArchive(is, "test7z");
|
||||
|
||||
System.out.println(afi);
|
||||
} catch (Exception e) {
|
||||
|
@ -125,7 +131,29 @@ public class Items {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void downloadFolderWithExcludes() throws Exception{
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
StreamDescriptor streamDescr = shc.open("6eb20db1-2921-41ec-ab79-909edd9b58fd").asItem().download("05098be5-61a2-423a-b382-9399a04df11e");
|
||||
|
||||
File tmpFile = Files.createTempFile(streamDescr.getFileName(),"").toFile();
|
||||
System.out.println(tmpFile.getAbsolutePath());
|
||||
|
||||
try(FileOutputStream fos = new FileOutputStream(tmpFile)){
|
||||
InputStream is = streamDescr.getStream();
|
||||
byte[] buf = new byte[2048];
|
||||
int read= -1;
|
||||
while ((read=is.read(buf))!=-1) {
|
||||
fos.write(buf, 0, read);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
static String baseUrl="http://workspace-repository1-d.d4science.org/storagehub";
|
||||
|
|
|
@ -110,7 +110,7 @@ public class TestCall {
|
|||
|
||||
FormDataMultiPart multipart = new FormDataMultiPart();
|
||||
|
||||
multipart.field("name", "test1Gb.db");
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue