2018-02-15 18:13:50 +01:00
|
|
|
package org.gcube.data.access.fs;
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.nio.file.Files;
|
2018-03-14 16:21:13 +01:00
|
|
|
import java.util.List;
|
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-04-20 18:26:44 +02:00
|
|
|
import org.gcube.common.storagehub.model.expressions.GenericSearchableItem;
|
|
|
|
import org.gcube.common.storagehub.model.expressions.SearchableItem;
|
|
|
|
import org.gcube.common.storagehub.model.expressions.text.Contains;
|
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-02-15 18:13:50 +01:00
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
public class TestCall {
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void setUp(){
|
2018-03-07 18:42:10 +01:00
|
|
|
SecurityTokenProvider.instance.set("52b59669-ccde-46d2-a4da-108b9e941f7c-98187548");
|
2018-02-15 18:13:50 +01:00
|
|
|
ScopeProvider.instance.set("/gcube/devNext");
|
|
|
|
}
|
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();
|
|
|
|
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-03-07 18:42:10 +01:00
|
|
|
|
2018-03-14 16:21:13 +01:00
|
|
|
System.out.println("items are "+items.size());
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-03-14 16:21:13 +01:00
|
|
|
System.out.println("vreItems are "+Vreitems.size());
|
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-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-03-14 16:21:13 +01:00
|
|
|
List<? extends Item> items = client.getChildren("07cd8d55-a35b-4445-9680-c98f158c55de",10, 5, "hl:accounting", "jcr:content");
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-03-14 16:21:13 +01:00
|
|
|
System.out.println("items are "+items.size());
|
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-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");
|
|
|
|
|
|
|
|
System.out.println("count took: "+(System.currentTimeMillis()-start) );
|
|
|
|
|
|
|
|
System.in.read();
|
|
|
|
}
|
|
|
|
|
2018-04-18 15:55:20 +02:00
|
|
|
@Test
|
|
|
|
public void getVreFolder() {
|
|
|
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
|
|
|
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
|
|
|
Item item = wsclient.getVreFolder("hl:accounting");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-20 18:26:44 +02:00
|
|
|
@Test
|
|
|
|
public void search() {
|
|
|
|
|
|
|
|
Query<SearchableItem<?>> query = Queries.queryFor(Item.class);
|
|
|
|
|
|
|
|
query.setExpression(new Contains(GenericSearchableItem.get().title, "Data"));
|
|
|
|
|
|
|
|
|
|
|
|
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
|
|
|
List<? extends Item> items = wsclient.search(query, "hl:accounting", "jcr:content");
|
|
|
|
System.out.println("items are "+items.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|