2018-02-15 18:13:50 +01:00
|
|
|
package org.gcube.data.access.fs;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
2018-03-29 18:19:01 +02:00
|
|
|
import java.io.InputStream;
|
2018-02-15 18:13:50 +01: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-04-18 15:55:20 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
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 {
|
|
|
|
|
2018-03-29 18:19:01 +02:00
|
|
|
@BeforeClass
|
|
|
|
public static void setUp(){
|
2018-04-18 15:55:20 +02:00
|
|
|
SecurityTokenProvider.instance.set("595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
|
|
|
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
2018-03-29 18:19:01 +02:00
|
|
|
}
|
2018-04-18 15:55:20 +02:00
|
|
|
|
2018-03-29 18:19:01 +02:00
|
|
|
@Test
|
2018-04-18 15:55:20 +02:00
|
|
|
public void uploadFile() {
|
2018-03-29 18:19:01 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
2018-04-18 15:55:20 +02:00
|
|
|
|
2018-06-19 11:42:57 +02:00
|
|
|
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/fattunite.pdf"))){
|
|
|
|
String afi = shc.getWSRoot().uploadFile(is, "fattureTest2.pdf", "descr");
|
|
|
|
System.out.println(afi);
|
2018-04-18 15:55:20 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-03-29 18:19:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2018-04-18 15:55:20 +02:00
|
|
|
public void getVreFolder() {
|
2018-03-29 18:19:01 +02:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
|
2018-04-18 15:55:20 +02:00
|
|
|
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/bonifico ferrara anricipo.pdf"))){
|
2018-06-20 16:56:51 +02:00
|
|
|
String newId = shc.getWSRoot().uploadFile(is, "bonificopdf", "descr");
|
|
|
|
System.out.println(newId);
|
2018-03-29 18:19:01 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 15:55:20 +02:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
/*
|
|
|
|
|
|
|
|
static String baseUrl="http://workspace-repository1-d.d4science.org/storagehub";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)*/;
|
|
|
|
/*
|
|
|
|
Response res = webTarget.request().post(Entity.entity(multiPart, multiPart.getMediaType()));
|
|
|
|
System.out.println("status is "+res.getStatus());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void create() throws Exception{
|
|
|
|
|
|
|
|
|
|
|
|
ClientConfig clientConfig = new ClientConfig();
|
|
|
|
clientConfig.property("DEFAULT_CHUNK_SIZE", 2048);
|
|
|
|
|
|
|
|
Clie
|
|
|
|
|
|
|
|
//Client client = ClientBuilder.newClient();
|
|
|
|
Client client = ClientBuilder.newClient(clientConfig)
|
|
|
|
.register(MultiPartFeature.class);
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
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");
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|