2018-02-15 18:13:50 +01:00
|
|
|
package org.gcube.data.access.fs;
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
import java.io.File;
|
2018-07-05 12:31:52 +02:00
|
|
|
import java.io.FileInputStream;
|
2018-02-15 18:13:50 +01:00
|
|
|
import java.io.FileOutputStream;
|
2018-07-05 12:31:52 +02:00
|
|
|
import java.io.InputStream;
|
|
|
|
import java.net.URI;
|
2018-02-15 18:13:50 +01:00
|
|
|
import java.nio.file.Files;
|
2018-06-29 15:03:05 +02:00
|
|
|
import java.util.Arrays;
|
2018-05-07 18:05:54 +02:00
|
|
|
import java.util.Calendar;
|
2018-06-29 15:03:05 +02:00
|
|
|
import java.util.HashSet;
|
2018-03-14 16:21:13 +01:00
|
|
|
import java.util.List;
|
2018-02-15 18:13:50 +01:00
|
|
|
|
2018-07-05 15:37:29 +02:00
|
|
|
import javax.ws.rs.client.Client;
|
|
|
|
import javax.ws.rs.client.ClientBuilder;
|
|
|
|
import javax.ws.rs.client.Entity;
|
|
|
|
import javax.ws.rs.client.WebTarget;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
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.plugins.AbstractPlugin;
|
|
|
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
|
|
|
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
2018-05-07 18:05:54 +02:00
|
|
|
import org.gcube.common.storagehub.model.Paths;
|
2018-05-25 18:05:44 +02:00
|
|
|
import org.gcube.common.storagehub.model.acls.ACL;
|
2018-06-29 15:03:05 +02:00
|
|
|
import org.gcube.common.storagehub.model.acls.AccessType;
|
2018-04-20 18:26:44 +02:00
|
|
|
import org.gcube.common.storagehub.model.expressions.GenericSearchableItem;
|
2018-05-14 16:14:52 +02:00
|
|
|
import org.gcube.common.storagehub.model.expressions.OrderField;
|
|
|
|
import org.gcube.common.storagehub.model.expressions.OrderField.MODE;
|
2018-04-20 18:26:44 +02:00
|
|
|
import org.gcube.common.storagehub.model.expressions.SearchableItem;
|
2018-05-07 18:05:54 +02:00
|
|
|
import org.gcube.common.storagehub.model.expressions.date.Before;
|
|
|
|
import org.gcube.common.storagehub.model.expressions.logical.And;
|
|
|
|
import org.gcube.common.storagehub.model.expressions.logical.ISDescendant;
|
2018-04-20 18:26:44 +02:00
|
|
|
import org.gcube.common.storagehub.model.expressions.text.Contains;
|
2018-06-26 10:51:34 +02:00
|
|
|
import org.gcube.common.storagehub.model.expressions.text.Like;
|
2018-05-14 16:14:52 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
2018-03-14 16:21:13 +01:00
|
|
|
import org.gcube.common.storagehub.model.items.Item;
|
2018-04-20 18:26:44 +02:00
|
|
|
import org.gcube.common.storagehub.model.query.Queries;
|
|
|
|
import org.gcube.common.storagehub.model.query.Query;
|
2018-07-05 15:37:29 +02:00
|
|
|
import org.glassfish.jersey.client.ClientProperties;
|
|
|
|
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
|
|
|
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
2018-02-15 18:13:50 +01:00
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
2018-05-14 16:14:52 +02:00
|
|
|
import com.fasterxml.jackson.annotation.JsonCreator.Mode;
|
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
public class TestCall {
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void setUp(){
|
2018-06-15 17:33:13 +02:00
|
|
|
/*
|
2018-06-11 16:58:02 +02:00
|
|
|
SecurityTokenProvider.instance.set("8effc529-44ec-4895-b727-ed0dc14ad113-843339462");
|
|
|
|
ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
|
2018-06-15 17:33:13 +02:00
|
|
|
*/
|
|
|
|
SecurityTokenProvider.instance.set("595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
|
|
|
ScopeProvider.instance.set("/gcube");
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
@Test
|
2018-03-07 18:42:10 +01:00
|
|
|
public void getListByPath() throws Exception{
|
2018-03-14 16:21:13 +01:00
|
|
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
2018-02-15 18:13:50 +01:00
|
|
|
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
2018-03-14 16:21:13 +01:00
|
|
|
Item ws = client.getWorkspace();
|
2018-06-11 16:58:02 +02:00
|
|
|
System.out.println("ws id is "+ws.getId());
|
2018-03-14 16:21:13 +01:00
|
|
|
List<? extends Item> items = itemclient.getChildren(ws.getId(),10, 5, "hl:accounting", "jcr:content");
|
|
|
|
List<? extends Item> Vreitems = client.getVreFolders("hl:accounting");
|
|
|
|
List<? extends Item> VreitemsPaged = client.getVreFolders(5,5, "hl:accounting");
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-03-14 16:21:13 +01:00
|
|
|
System.out.println("items are "+items.size());
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-03-14 16:21:13 +01:00
|
|
|
System.out.println("vreItems are "+Vreitems.size());
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-03-07 18:42:10 +01:00
|
|
|
System.in.read();
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-06-25 16:50:43 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void delete() throws Exception{
|
|
|
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
|
|
|
itemclient.delete("6d712458-cbba-4141-b7ef-c9bf6b9537c7");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
@Test
|
|
|
|
public void getById() throws Exception{
|
2018-03-07 18:42:10 +01:00
|
|
|
final ItemManagerClient client = AbstractPlugin.item().build();
|
2018-05-23 18:26:06 +02:00
|
|
|
List<? extends Item> items = client.getAnchestors("29b417e2-dc2f-419a-be0b-7f49e76c9d7c", "hl:accounting", "jcr:content");
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-03-14 16:21:13 +01:00
|
|
|
System.out.println("items are "+items.size());
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-05-23 18:26:06 +02:00
|
|
|
for (Item item: items)
|
|
|
|
System.out.println(item.getName()+ " "+item.getPath());
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-03-07 18:42:10 +01:00
|
|
|
System.in.read();
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|
2018-05-30 18:15:56 +02:00
|
|
|
|
|
|
|
|
2018-07-05 12:31:52 +02:00
|
|
|
@Test
|
|
|
|
public void upload() throws Exception{
|
2018-07-05 15:37:29 +02:00
|
|
|
//final ItemManagerClient client = AbstractPlugin.item().at(new URI("http://workspace-repository1-d.d4science.org:8080/storagehub")).build();
|
2018-07-05 12:31:52 +02:00
|
|
|
|
2018-07-05 15:37:29 +02:00
|
|
|
Client client = ClientBuilder.newClient();
|
2018-07-05 16:24:49 +02:00
|
|
|
client.register(MultiPartFeature.class).property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024).property(ClientProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, -1)
|
|
|
|
.property(ClientProperties.REQUEST_ENTITY_PROCESSING, "CHUNKED");
|
2018-07-30 12:38:34 +02:00
|
|
|
WebTarget target = client.target("http://workspace-repository1-d.d4science.org:8080/storagehub/workspace/items/bc1c9525-43f7-4565-b5ea-0a0f9d7853a0/create/test-upload?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
2018-07-05 15:37:29 +02:00
|
|
|
|
|
|
|
FormDataMultiPart multipart = new FormDataMultiPart();
|
|
|
|
|
2018-09-04 11:21:08 +02:00
|
|
|
multipart.field("name", "test1Gb2.db");
|
2018-07-05 15:37:29 +02:00
|
|
|
multipart.field("description", "description");
|
2018-07-30 12:38:34 +02:00
|
|
|
multipart.field("file", new FileInputStream("/home/lucio/Downloads/ar_bigdata_201705.csv"), MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
2018-07-05 12:31:52 +02:00
|
|
|
|
2018-07-05 15:37:29 +02:00
|
|
|
target.request().post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA));
|
2018-07-05 12:31:52 +02:00
|
|
|
|
2018-07-05 15:37:29 +02:00
|
|
|
//client.uploadFile(new FileInputStream("/home/lucio/Downloads/test5Gb.zip"), "bc1c9525-43f7-4565-b5ea-0a0f9d7853a0", "5gb.zip", "description");
|
2018-07-05 12:31:52 +02:00
|
|
|
|
|
|
|
}
|
2018-06-25 16:50:43 +02:00
|
|
|
|
2018-07-30 12:38:34 +02:00
|
|
|
@Test
|
|
|
|
public void uploadArchive() throws Exception{
|
|
|
|
final ItemManagerClient client = AbstractPlugin.item().at(new URI("http://workspace-repository1-d.d4science.org:8080/storagehub")).build();
|
|
|
|
|
|
|
|
client.uploadArchive(new FileInputStream("/home/lucio/Downloads/filezilla.tar"), "bc1c9525-43f7-4565-b5ea-0a0f9d7853a0", "filezillaTar1");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-05-25 18:05:44 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getACL() throws Exception{
|
|
|
|
final ItemManagerClient client = AbstractPlugin.item().build();
|
|
|
|
try {
|
2018-05-30 18:15:56 +02:00
|
|
|
List<ACL> acls = client.getACL("790e4c52-fbca-48e9-b267-67ea2ce708c0");
|
|
|
|
|
|
|
|
System.out.println("items are "+acls.size());
|
|
|
|
|
|
|
|
|
|
|
|
for (ACL acl: acls)
|
|
|
|
System.out.println(acl.getPricipal()+ " "+acl.getAccessTypes());
|
2018-05-25 18:05:44 +02:00
|
|
|
}catch(Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
@Test
|
|
|
|
public void download() throws Exception{
|
|
|
|
ItemManagerClient client = AbstractPlugin.item().build();
|
|
|
|
StreamDescriptor streamDescr = client.download("07cd8d55-a35b-4445-9680-c98f158c55de");
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
System.out.println("file written "+output.getAbsolutePath());
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
|
|
|
|
}
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-03-14 16:21:13 +01:00
|
|
|
@Test
|
|
|
|
public void getCount() throws Exception{
|
|
|
|
final ItemManagerClient client = AbstractPlugin.item().build();
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
System.out.println("found "+client.childrenCount("07cd8d55-a35b-4445-9680-c98f158c55de")+" children");
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-03-14 16:21:13 +01:00
|
|
|
System.out.println("count took: "+(System.currentTimeMillis()-start) );
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-03-14 16:21:13 +01:00
|
|
|
System.in.read();
|
|
|
|
}
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-04-18 15:55:20 +02:00
|
|
|
@Test
|
|
|
|
public void getVreFolder() {
|
|
|
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
|
|
|
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
2018-05-14 16:14:52 +02:00
|
|
|
wsclient.getVreFolders("hl:accounting");
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-04-18 15:55:20 +02:00
|
|
|
}
|
2018-06-15 17:33:13 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getRecents() {
|
|
|
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
|
|
|
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
|
|
|
List<? extends Item> items = wsclient.getRecentModifiedFilePerVre();
|
|
|
|
|
|
|
|
System.out.println("items are "+items.size());
|
|
|
|
|
|
|
|
for (Item item: items)
|
|
|
|
System.out.println(item.getName()+ " "+item.getPath());
|
|
|
|
}
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-05-23 18:26:06 +02:00
|
|
|
@Test
|
|
|
|
public void createFolder() {
|
2018-05-25 18:05:44 +02:00
|
|
|
long start= System.currentTimeMillis();
|
2018-05-23 18:26:06 +02:00
|
|
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
|
|
|
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
2018-05-25 18:05:44 +02:00
|
|
|
String id = wsclient.getWorkspace("hl:accounting", "jcr:content").getId();
|
|
|
|
System.out.println("getting the WS id took "+(System.currentTimeMillis()-start));
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-06-11 16:58:02 +02:00
|
|
|
itemclient.createFolder(id,"sesto tentativo","6 tentativo");
|
2018-05-25 18:05:44 +02:00
|
|
|
System.out.println("creating folder took total "+(System.currentTimeMillis()-start));
|
2018-05-23 18:26:06 +02:00
|
|
|
}
|
2018-06-29 15:03:05 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void share() {
|
|
|
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
|
|
|
itemclient.shareFolder("4fd4a4ca-c615-4076-8eaa-70268e4f6166", new HashSet<>(Arrays.asList("francesco.mangiacrapa","massimiliano.assante","giancarlo.panichi")), AccessType.WRITE_OWNER);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-20 18:26:44 +02:00
|
|
|
@Test
|
|
|
|
public void search() {
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-05-14 16:14:52 +02:00
|
|
|
Query<SearchableItem<?>> query = Queries.queryFor(AbstractFileItem.class);
|
|
|
|
/*
|
2018-05-07 18:05:54 +02:00
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
calendar.set(Calendar.YEAR, 2015);
|
2018-05-30 18:15:56 +02:00
|
|
|
*/
|
|
|
|
|
2018-04-20 18:26:44 +02:00
|
|
|
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
2018-06-11 16:58:02 +02:00
|
|
|
//String path = wsclient.getVreFolder("hl:accounting").getPath();
|
|
|
|
//System.out.println("path is "+path);
|
2018-06-26 10:51:34 +02:00
|
|
|
query.setExpression(new And(new ISDescendant(Paths.getPath("/Home/massimiliano.assante/Workspace/MySpecialFolders/gcube-devNext-NextNext/")),
|
|
|
|
new Like(GenericSearchableItem.get().title,"title")));
|
2018-05-14 16:14:52 +02:00
|
|
|
query.setLimit(10);
|
2018-06-26 10:51:34 +02:00
|
|
|
query.setOrder(new OrderField(GenericSearchableItem.get().title));
|
2018-04-20 18:26:44 +02:00
|
|
|
List<? extends Item> items = wsclient.search(query, "hl:accounting", "jcr:content");
|
2018-05-14 16:14:52 +02:00
|
|
|
for (Item item: items) {
|
|
|
|
System.out.println(item.getName()+" "+item.getLastModificationTime().getTimeInMillis());
|
|
|
|
}
|
2018-04-20 18:26:44 +02:00
|
|
|
System.out.println("items are "+items.size());
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-04-20 18:26:44 +02:00
|
|
|
}
|
2018-05-30 18:15:56 +02:00
|
|
|
|
2018-03-07 18:42:10 +01:00
|
|
|
/*
|
2018-02-15 18:13:50 +01:00
|
|
|
@Test
|
|
|
|
public void createFolder() throws Exception{
|
|
|
|
Items.createFolder();
|
|
|
|
}
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
@Test
|
|
|
|
public void createFile() throws Exception{
|
|
|
|
Items.create();
|
|
|
|
}*/
|
2018-03-07 18:42:10 +01:00
|
|
|
|
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|