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-05-07 18:05:54 +02:00
|
|
|
import java.util.Calendar;
|
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-05-07 18:05:54 +02:00
|
|
|
import org.gcube.common.storagehub.model.Paths;
|
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-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-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-05-14 16:14:52 +02:00
|
|
|
SecurityTokenProvider.instance.set("595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
|
|
|
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
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();
|
|
|
|
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-05-23 18:26:06 +02:00
|
|
|
List<? extends Item> items = client.getAnchestors("29b417e2-dc2f-419a-be0b-7f49e76c9d7c", "hl:accounting", "jcr:content");
|
|
|
|
|
2018-03-14 16:21:13 +01:00
|
|
|
System.out.println("items are "+items.size());
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-05-23 18:26:06 +02:00
|
|
|
for (Item item: items)
|
|
|
|
System.out.println(item.getName()+ " "+item.getPath());
|
|
|
|
|
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();
|
2018-05-14 16:14:52 +02:00
|
|
|
wsclient.getVreFolders("hl:accounting");
|
2018-04-18 15:55:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-23 18:26:06 +02:00
|
|
|
@Test
|
|
|
|
public void createFolder() {
|
|
|
|
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
|
|
|
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
|
|
|
itemclient.createFolder(wsclient.getWorkspace().getId(),"terzo tentativo","secondo tentativo");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-20 18:26:44 +02:00
|
|
|
@Test
|
|
|
|
public void search() {
|
|
|
|
|
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-14 16:14:52 +02:00
|
|
|
*/
|
2018-04-20 18:26:44 +02:00
|
|
|
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
2018-05-14 16:14:52 +02:00
|
|
|
String path = wsclient.getVreFolder("hl:accounting").getPath();
|
|
|
|
System.out.println("path is "+path);
|
|
|
|
query.setExpression(new ISDescendant(Paths.getPath("/Home/lucio.lelii/Workspace/MySpecialFolders/gcube-devNext-NextNext")));
|
|
|
|
query.setLimit(10);
|
|
|
|
query.setOrder(new OrderField(GenericSearchableItem.get().lastModification,MODE.DESC));
|
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-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
|
|
|
}
|