2018-02-15 18:13:50 +01:00
|
|
|
package org.gcube.data.access.fs;
|
|
|
|
|
2019-09-09 16:29:40 +02:00
|
|
|
import java.io.BufferedInputStream;
|
2018-02-15 18:13:50 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
2018-09-04 11:21:08 +02:00
|
|
|
import java.io.FileOutputStream;
|
2018-03-29 18:19:01 +02:00
|
|
|
import java.io.InputStream;
|
2018-09-04 11:21:08 +02:00
|
|
|
import java.nio.file.Files;
|
2019-01-03 12:16:53 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashSet;
|
2019-07-25 17:47:18 +02:00
|
|
|
import java.util.Map.Entry;
|
2018-07-05 12:31:52 +02:00
|
|
|
|
2018-03-29 18:19:01 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
2018-06-22 10:52:56 +02:00
|
|
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
|
|
|
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
2018-09-26 15:24:21 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
2018-06-22 10:52:56 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.ItemContainer;
|
2018-04-18 15:55:20 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
2019-07-25 17:47:18 +02:00
|
|
|
import org.gcube.common.storagehub.model.Metadata;
|
2019-01-03 12:16:53 +01:00
|
|
|
import org.gcube.common.storagehub.model.acls.AccessType;
|
2019-03-13 18:33:58 +01:00
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
2018-06-22 10:52:56 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.Item;
|
2018-03-29 18:19:01 +02:00
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
2018-02-15 18:13:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Items {
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-03-29 18:19:01 +02:00
|
|
|
@BeforeClass
|
|
|
|
public static void setUp(){
|
2019-09-11 18:12:46 +02:00
|
|
|
SecurityTokenProvider.instance.set("257800d8-24bf-4bae-83cd-ea99369e7dd6-843339462");
|
|
|
|
ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
|
2018-03-29 18:19:01 +02:00
|
|
|
}
|
2019-05-06 16:54:51 +02:00
|
|
|
|
2018-07-30 12:38:34 +02:00
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
@Test
|
|
|
|
public void emptyStatisticaManagerTrash() {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
System.out.println(shc.openTrash().get().getId());
|
|
|
|
}
|
2018-12-11 17:58:49 +01:00
|
|
|
|
2019-05-23 15:18:37 +02:00
|
|
|
@Test
|
|
|
|
public void forceDelete() throws Exception{
|
2019-05-06 16:54:51 +02:00
|
|
|
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2019-05-23 15:18:37 +02:00
|
|
|
|
2019-07-29 16:25:52 +02:00
|
|
|
|
|
|
|
|
2019-09-09 16:29:40 +02:00
|
|
|
long count = shc.getTotalItemCount();
|
|
|
|
|
|
|
|
System.out.println("ims are "+count);
|
2019-05-06 16:54:51 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-09 16:29:40 +02:00
|
|
|
@Test
|
|
|
|
public void changeAcls() throws Exception{
|
|
|
|
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
|
|
|
|
shc.open("2ca7e04a-b461-4098-a8b9-a31ddb691a2d").asFolder().changeAcls("giancarlo.panichi", AccessType.READ_ONLY);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-05-06 16:54:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-11 18:36:21 +02:00
|
|
|
@Test
|
|
|
|
public void renameFile() throws Exception{
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-11 18:36:21 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
FolderContainer myRoot = shc.getWSRoot();
|
|
|
|
|
|
|
|
myRoot.findByName("");
|
|
|
|
|
2018-12-11 17:58:49 +01:00
|
|
|
|
|
|
|
FolderContainer children = myRoot.newFolder("build", "build folder");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-12-11 17:58:49 +01:00
|
|
|
FileContainer file = null;
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-12-11 17:58:49 +01:00
|
|
|
try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/mg.jpg"))){
|
|
|
|
file = myRoot.uploadFile(is, "mg.jpg", "file");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-11 17:58:49 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-12-11 17:58:49 +01:00
|
|
|
FileContainer copiedFile = file.copy(children, "mg.jpg");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-11 17:58:49 +01:00
|
|
|
try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/bck.jpg"))){
|
|
|
|
file = myRoot.uploadFile(is, "mg.jpg", "file");
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-11 17:58:49 +01:00
|
|
|
FileContainer secodncopiedFile = file.copy(children, "mg.jpg");
|
2018-10-11 18:36:21 +02:00
|
|
|
}
|
2018-12-11 17:58:49 +01:00
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-17 17:55:30 +02:00
|
|
|
@Test
|
2018-09-28 17:02:20 +02:00
|
|
|
public void uploadAndcopyFile() throws Exception {
|
2018-03-29 18:19:01 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2019-07-17 17:55:30 +02:00
|
|
|
|
2018-09-28 17:02:20 +02:00
|
|
|
FileContainer file = null;
|
2019-09-11 18:12:46 +02:00
|
|
|
try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/.richiesta speroni.pdf"))){
|
|
|
|
file = shc.getWSRoot().uploadFile(is, ".richiesta speroni.pdf", "test");
|
2019-05-07 11:41:57 +02:00
|
|
|
}
|
2019-07-17 17:55:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
//file.copy(shc.getWSRoot(), "firstCopy.jpg");
|
2018-03-29 18:19:01 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
@Test
|
|
|
|
public void download() throws Exception {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
|
2019-09-09 16:29:40 +02:00
|
|
|
|
|
|
|
StreamDescriptor streamDescr = shc.open("a5bcf8b8-d149-42c2-92be-7f671223eba4").asFile().downloadSpecificVersion("1.2");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
File output = Files.createTempFile("down", streamDescr.getFileName()).toFile();
|
|
|
|
try (BufferedInputStream bi = new BufferedInputStream(streamDescr.getStream()); FileOutputStream fo = new FileOutputStream(output)){
|
|
|
|
byte[] buf = new byte[2048];
|
|
|
|
int read = -1;
|
|
|
|
while ((read=bi.read(buf))!=-1) {
|
|
|
|
fo.write(buf, 0, read);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("file written "+output.getAbsolutePath());
|
2019-09-09 16:29:40 +02:00
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-09-24 16:42:00 +02:00
|
|
|
@Test
|
|
|
|
public void emptyTrash() throws Exception {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
shc.emptyTrash();
|
2018-09-24 16:42:00 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-07-25 17:47:18 +02:00
|
|
|
@Test
|
|
|
|
public void changeProp() throws Exception {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
|
|
|
|
ItemContainer item = shc.open("6399daa7-2173-4314-b4f7-2afa24eae8f8").asItem();
|
|
|
|
Metadata first = item.get().getMetadata();
|
|
|
|
first.getMap().put("lucio", "ok");
|
|
|
|
|
|
|
|
item.setMetadata(first);
|
|
|
|
|
|
|
|
Metadata second = item.get().getMetadata();
|
|
|
|
for (Entry<String, Object> entry: second.getMap().entrySet())
|
|
|
|
System.out.println(entry.getKey()+" "+entry.getValue());
|
|
|
|
|
|
|
|
|
|
|
|
second.getMap().put("lucio", null);
|
|
|
|
second.getMap().put("lelii", "0");
|
|
|
|
|
|
|
|
item.setMetadata(second);
|
|
|
|
|
|
|
|
Metadata third = item.get().getMetadata();
|
|
|
|
for (Entry<String, Object> entry: third.getMap().entrySet())
|
|
|
|
System.out.println(entry.getKey()+" "+entry.getValue());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-07-30 12:38:34 +02:00
|
|
|
@Test
|
|
|
|
public void uploadArchive() throws Exception {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
|
|
|
|
String afi = null;
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-04 16:53:47 +02:00
|
|
|
try(InputStream is = new FileInputStream(new File("/tmp/down724121986692880606my new folder.zip"))){
|
|
|
|
shc.getWSRoot().uploadArchive(is, "testUpload2");
|
2018-07-30 12:38:34 +02:00
|
|
|
|
|
|
|
System.out.println(afi);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-22 17:42:29 +02:00
|
|
|
@Test
|
2019-03-13 18:33:58 +01:00
|
|
|
public void getPublicLink() throws Exception{
|
2018-06-22 17:42:29 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
System.out.println(shc.open("c2573eec-3942-47ec-94a7-04869e97bb69").asFile().getPublicLink());
|
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-06-26 15:30:30 +02:00
|
|
|
@Test
|
|
|
|
public void findByName() throws Exception{
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-03 12:16:53 +01:00
|
|
|
FolderContainer root = shc.open("2fd081dc-3b57-4e5f-aadf-38439aea4c1f").asFolder();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-03 12:16:53 +01:00
|
|
|
FolderContainer fc = root.newFolder("Computations", "description");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-03 12:16:53 +01:00
|
|
|
fc.share(new HashSet<>(Arrays.asList("giancarlo.panichi")), AccessType.READ_ONLY);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-03 12:16:53 +01:00
|
|
|
System.out.println(fc.get().getPath()+" "+fc.getId());
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-06-26 15:30:30 +02:00
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-06-27 15:36:50 +02:00
|
|
|
@Test
|
|
|
|
public void delete() throws Exception{
|
2018-10-04 16:53:47 +02:00
|
|
|
try {
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2019-01-03 12:16:53 +01:00
|
|
|
shc.open("328d0097-e024-43fd-afc8-3926a34a5953").asFile().delete();
|
2018-10-04 16:53:47 +02:00
|
|
|
}catch(Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-06-27 15:36:50 +02:00
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-06-22 10:52:56 +02:00
|
|
|
@Test
|
2019-03-13 18:33:58 +01:00
|
|
|
public void downloadFile() throws Exception{
|
2018-06-22 10:52:56 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
try {
|
|
|
|
for (ItemContainer<? extends Item> cont : shc.getWSRoot().list().getContainers()) {
|
|
|
|
if (cont.get().getTitle().equals("LucioShare1")) {
|
|
|
|
for (ItemContainer<? extends Item> c: ((FolderContainer)cont).list().getContainers()) {
|
|
|
|
c.get().getTitle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch (StorageHubException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
for (ItemContainer<? extends Item> cont : shc.getWSRoot().list().getContainers()) {
|
|
|
|
System.out.println(cont.get().getTitle());
|
|
|
|
}
|
|
|
|
}catch (StorageHubException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
/*
|
2019-01-14 11:51:19 +01:00
|
|
|
List<? extends Item> items = shc.getWSRoot().findByName("MyFo*").getItems();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-14 11:51:19 +01:00
|
|
|
for (Item item: items)
|
|
|
|
System.out.println(item.getName()+" "+item.getTitle()+" "+item.getClass().getSimpleName());
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-14 11:51:19 +01:00
|
|
|
/*
|
|
|
|
URL link = shc.open("6c5fb143-3711-4097-9bdc-952e41355440").asFile().getPublicLink("1.1");
|
|
|
|
System.out.println(link.toString());
|
|
|
|
/*
|
2019-01-08 12:17:36 +01:00
|
|
|
File targetFile = new File("/tmp/"+descr.getFileName());
|
|
|
|
|
|
|
|
try {
|
|
|
|
java.nio.file.Files.copy(
|
|
|
|
descr.getStream(),
|
|
|
|
targetFile.toPath(),
|
|
|
|
StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
} catch (IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
System.out.println("file created "+targetFile.getAbsolutePath());
|
|
|
|
/*
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-06-22 10:52:56 +02:00
|
|
|
List<ItemContainer<? extends Item>> containers = shc.getWSRoot().list().getContainers();
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-06-22 10:52:56 +02:00
|
|
|
for (ItemContainer<? extends Item> container : containers) {
|
|
|
|
if (container.getType()==ContainerType.FILE) {
|
|
|
|
FileContainer file = (FileContainer) container;
|
|
|
|
StreamDescriptor descr = file.download();
|
|
|
|
File targetFile = new File("/tmp/"+descr.getFileName());
|
2018-07-05 16:24:49 +02:00
|
|
|
|
|
|
|
try {
|
2018-06-22 10:52:56 +02:00
|
|
|
java.nio.file.Files.copy(
|
|
|
|
descr.getStream(),
|
2018-07-05 16:24:49 +02:00
|
|
|
targetFile.toPath(),
|
|
|
|
StandardCopyOption.REPLACE_EXISTING);
|
2018-06-22 10:52:56 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
System.out.println("file created "+targetFile.getAbsolutePath());
|
|
|
|
break;
|
2018-06-22 10:52:56 +02:00
|
|
|
}
|
2019-01-08 12:17:36 +01:00
|
|
|
}*/
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-06-22 10:52:56 +02:00
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-09-04 11:21:08 +02:00
|
|
|
@Test
|
|
|
|
public void downloadFolderWithExcludes() throws Exception{
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
StreamDescriptor streamDescr = shc.open("6eb20db1-2921-41ec-ab79-909edd9b58fd").asItem().download("05098be5-61a2-423a-b382-9399a04df11e");
|
|
|
|
|
2018-09-04 11:21:08 +02:00
|
|
|
File tmpFile = Files.createTempFile(streamDescr.getFileName(),"").toFile();
|
|
|
|
System.out.println(tmpFile.getAbsolutePath());
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-04 11:21:08 +02:00
|
|
|
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);
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-04 11:21:08 +02:00
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-09-04 11:21:08 +02:00
|
|
|
}
|
2018-10-15 15:39:02 +02:00
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
/*
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
static String baseUrl="http://workspace-repository1-d.d4science.org/storagehub";
|
|
|
|
|
2018-07-05 16:24:49 +02:00
|
|
|
|
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
public static List<? extends Item> list(OrderBy order, Path path, ItemFilter<?> ... filters){
|
|
|
|
Client client = ClientBuilder.newClient();
|
|
|
|
WebTarget webTarget = client.target(baseUrl+"/list/byPath?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
|
|
|
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
|
|
|
|
List<? extends Item> r = invocationBuilder.get(ItemList.class).getItemlist();
|
|
|
|
return r;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void createFolder(){
|
|
|
|
//Client client = ClientBuilder.newClient();
|
|
|
|
Client client = ClientBuilder.newBuilder()
|
|
|
|
.register(MultiPartFeature.class).build();
|
|
|
|
WebTarget webTarget = client.target(baseUrl+"/item/create?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
|
|
|
|
|
|
|
FolderItem folder= new FolderItem();
|
|
|
|
folder.setName("My third folder");
|
|
|
|
folder.setTitle("My third title");
|
|
|
|
final MultiPart multiPart = new FormDataMultiPart()
|
|
|
|
.field("item", new ItemWrapper<FolderItem>(folder), MediaType.APPLICATION_JSON_TYPE)
|
|
|
|
/* .field("characterProfile", jsonToSend, MediaType.APPLICATION_JSON_TYPE)
|
|
|
|
.field("filename", fileToUpload.getName(), MediaType.TEXT_PLAIN_TYPE)
|
|
|
|
.bodyPart(fileDataBodyPart)*/;
|
2018-07-05 16:24:49 +02:00
|
|
|
/*
|
2018-02-15 18:13:50 +01:00
|
|
|
Response res = webTarget.request().post(Entity.entity(multiPart, multiPart.getMediaType()));
|
|
|
|
System.out.println("status is "+res.getStatus());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void create() throws Exception{
|
2018-07-05 16:24:49 +02:00
|
|
|
|
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
ClientConfig clientConfig = new ClientConfig();
|
|
|
|
clientConfig.property("DEFAULT_CHUNK_SIZE", 2048);
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
Clie
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
//Client client = ClientBuilder.newClient();
|
|
|
|
Client client = ClientBuilder.newClient(clientConfig)
|
|
|
|
.register(MultiPartFeature.class);
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
WebTarget webTarget = client.target(baseUrl+"/item/create?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
|
|
|
|
|
|
|
GenericFileItem folder= new GenericFileItem();
|
|
|
|
folder.setName("testUpload.tar.gz");
|
|
|
|
folder.setTitle("testUpload.tar.gz");
|
2018-07-05 16:24:49 +02:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("file", new File("/home/lucio/Downloads/testUpload.tar.gz"));
|
|
|
|
final MultiPart multiPart = new FormDataMultiPart().field("item", new ItemWrapper<GenericFileItem>(folder), MediaType.APPLICATION_JSON_TYPE)
|
|
|
|
.bodyPart(fileDataBodyPart, MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
|
|
|
multiPart.close();
|
|
|
|
|
|
|
|
Response res = webTarget.request().post(Entity.entity(multiPart, multiPart.getMediaType()));
|
|
|
|
System.out.println("status is "+res.getStatus());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void get() throws Exception{
|
|
|
|
Client client = ClientBuilder.newClient();
|
|
|
|
WebTarget webTarget = client.target(baseUrl+"/item/6e9b8350-4854-4c22-8aa1-ba2d8135ad6d/download?gcube-token=950a0702-6ada-40e9-92dc-d243d1b45206-98187548");
|
|
|
|
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_OCTET_STREAM);
|
|
|
|
Response res = invocationBuilder.get();
|
|
|
|
|
|
|
|
|
|
|
|
byte[] buf = new byte[1024];
|
|
|
|
/*while (is.read(buf)!=-1)
|
|
|
|
System.out.println("reading the buffer");
|
2018-07-05 16:24:49 +02:00
|
|
|
*/
|
2018-02-15 18:13:50 +01:00
|
|
|
|
2018-07-05 16:24:49 +02:00
|
|
|
/*
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static <T extends Item> T copy(T item, Path path){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T extends Item> T move(T item, Path path){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T extends Item> T unshareAll(T item){
|
|
|
|
return null;
|
|
|
|
}
|
2018-07-05 16:24:49 +02:00
|
|
|
*/
|
2018-02-15 18:13:50 +01:00
|
|
|
|
2018-07-05 16:24:49 +02:00
|
|
|
}
|