76 lines
2.5 KiB
Java
76 lines
2.5 KiB
Java
|
package org.gcube.data.access.fs;
|
||
|
|
||
|
import java.io.BufferedInputStream;
|
||
|
import java.io.ByteArrayInputStream;
|
||
|
import java.io.File;
|
||
|
import java.io.FileOutputStream;
|
||
|
import java.io.InputStream;
|
||
|
import java.nio.file.Files;
|
||
|
import java.util.List;
|
||
|
|
||
|
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;
|
||
|
import org.gcube.common.storagehub.model.items.Item;
|
||
|
import org.junit.BeforeClass;
|
||
|
import org.junit.Test;
|
||
|
|
||
|
public class TestCall {
|
||
|
|
||
|
@BeforeClass
|
||
|
public static void setUp(){
|
||
|
SecurityTokenProvider.instance.set("94a3b80a-c66f-4000-ae2f-230f5dfad793-98187548");
|
||
|
ScopeProvider.instance.set("/gcube/devNext");
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void getListByPath(){
|
||
|
long start = System.currentTimeMillis();
|
||
|
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
||
|
List<? extends Item> items =client.getWorkspace("hl:accounting");
|
||
|
System.out.println("took: "+(System.currentTimeMillis()-start)+" for items "+items.size());
|
||
|
items.forEach(i -> System.out.println(i.getTitle()+" "+i.getId()+" "+i.isLocked()));
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void getById() throws Exception{
|
||
|
long start = System.currentTimeMillis();
|
||
|
ItemManagerClient client = AbstractPlugin.item().build();
|
||
|
client.getChildren("07cd8d55-a35b-4445-9680-c98f158c55de", "hl:accounting", "jcr:content").forEach(i -> System.out.println(i.getName()+" "+i.getId()));
|
||
|
System.out.println("took: "+(System.currentTimeMillis()-start) );
|
||
|
|
||
|
}
|
||
|
|
||
|
@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);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
System.out.println("file written "+output.getAbsolutePath());
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
@Test
|
||
|
public void createFolder() throws Exception{
|
||
|
Items.createFolder();
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void createFile() throws Exception{
|
||
|
Items.create();
|
||
|
}*/
|
||
|
}
|