This commit is contained in:
Lucio Lelii 2018-03-14 15:21:13 +00:00
parent a4b07aa980
commit 12b0794610
5 changed files with 126 additions and 25 deletions

View File

@ -91,4 +91,47 @@ public class DefaultItemManager implements ItemManagerClient {
}
}
@Override
public List<? extends Item> getChildren(String id, int start, int limit, String... excludeNodes) {
Call<WebTarget, ItemList> call = new Call<WebTarget, ItemList>() {
@Override
public ItemList call(WebTarget manager) throws Exception {
WebTarget myManager = manager.path(id).path("children").path("paged");
if (excludeNodes !=null && excludeNodes.length>0)
myManager = myManager.queryParam("exclude",excludeNodes);
myManager = myManager.queryParam("start", start).queryParam("limit", limit);
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON);
ItemList response = builder.get(ItemList.class);
return response;
}
};
try {
ItemList result = delegate.make(call);
return result.getItemlist();
}catch(Exception e) {
throw new RuntimeException(e);
}
}
@Override
public Integer childrenCount(String id) {
Call<WebTarget, Integer> call = new Call<WebTarget, Integer>() {
@Override
public Integer call(WebTarget manager) throws Exception {
WebTarget myManager = manager.path(id).path("children").path("count");
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON);
Integer response = builder.get(Integer.class);
return response;
}
};
try {
Integer result = delegate.make(call);
return result;
}catch(Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -10,6 +10,7 @@ import org.gcube.common.clients.Call;
import org.gcube.common.clients.delegates.ProxyDelegate;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.service.ItemList;
import org.gcube.common.storagehub.model.service.ItemWrapper;
public class DefaultWorkspaceManager implements WorkspaceManagerClient {
@ -20,18 +21,64 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
this.delegate = config;
}
@Override
public List<? extends Item> getWorkspace(String... excludeNodes) {
Call<WebTarget, ItemList> call = new Call<WebTarget, ItemList>() {
public <T extends Item> T getWorkspace(String ... excludeNodes) {
Call<WebTarget, ItemWrapper<T>> call = new Call<WebTarget, ItemWrapper<T>>() {
@Override
public ItemList call(WebTarget manager) throws Exception {
public ItemWrapper<T> call(WebTarget manager) throws Exception {
WebTarget myManager = manager;
if (excludeNodes !=null && excludeNodes.length>0)
myManager = myManager.queryParam("exclude",excludeNodes);
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON);
ItemWrapper<T> response = builder.get(ItemWrapper.class);
System.out.println(manager.getUri().toString());
return response;
}
};
try {
ItemWrapper<T> result = delegate.make(call);
return result.getItem();
}catch(Exception e) {
throw new RuntimeException(e);
}
}
@Override
public List<? extends Item> getVreFolders(String ... excludeNodes) {
Call<WebTarget, ItemList> call = new Call<WebTarget, ItemList>() {
@Override
public ItemList call(WebTarget manager) throws Exception {
WebTarget myManager = manager.path("vrefolders");
if (excludeNodes !=null && excludeNodes.length>0)
myManager = myManager.queryParam("exclude",excludeNodes);
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON);
ItemList response = builder.get(ItemList.class);
System.out.println(myManager.getUri().toString());
System.out.println(manager.getUri().toString());
return response;
}
};
try {
ItemList result = delegate.make(call);
return result.getItemlist();
}catch(Exception e) {
throw new RuntimeException(e);
}
}
@Override
public List<? extends Item> getVreFolders(int start, int limit, String ... excludeNodes) {
Call<WebTarget, ItemList> call = new Call<WebTarget, ItemList>() {
@Override
public ItemList call(WebTarget manager) throws Exception {
WebTarget myManager = manager.path("vrefolders");
if (excludeNodes !=null && excludeNodes.length>0)
myManager = myManager.queryParam("exclude",excludeNodes);
myManager = myManager.queryParam("start", start).queryParam("limit", limit);
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON);
ItemList response = builder.get(ItemList.class);
System.out.println(manager.getUri().toString());
return response;
}
};

View File

@ -13,6 +13,10 @@ public interface ItemManagerClient {
List<? extends Item> getChildren(String id, String ... excludeNodes);
List<? extends Item> getChildren(String id, int start, int limit, String ... excludeNodes);
Integer childrenCount(String id);
Item get(String id, String ... excludeNodes);
StreamDescriptor download(String id);

View File

@ -6,6 +6,10 @@ import org.gcube.common.storagehub.model.items.Item;
public interface WorkspaceManagerClient {
List<? extends Item> getWorkspace(String ... excludeNodes);
<T extends Item> T getWorkspace(String ... excludeNodes);
List<? extends Item> getVreFolders(String ... excludeNodes);
List<? extends Item> getVreFolders(int start, int limit, String ... excludeNodes);
}

View File

@ -4,6 +4,7 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.util.List;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
@ -11,6 +12,7 @@ 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;
@ -24,18 +26,16 @@ public class TestCall {
@Test
public void getListByPath() throws Exception{
ItemManagerClient itemclient = AbstractPlugin.item().build();
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
Runnable runnable = new Runnable() {
public void run() {
long start = System.currentTimeMillis();
client.getWorkspace("hl:accounting", "jcr:content");
System.out.println("["+Thread.currentThread().getName()+"] took: "+(System.currentTimeMillis()-start) );
}
};
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");
for (int i=0; i<=1; i++)
new Thread(runnable).start();
System.out.println("items are "+items.size());
System.out.println("vreItems are "+Vreitems.size());
System.in.read();
}
@ -43,17 +43,9 @@ public class TestCall {
@Test
public void getById() throws Exception{
final ItemManagerClient client = AbstractPlugin.item().build();
Runnable runnable = new Runnable() {
public void run() {
long start = System.currentTimeMillis();
client.getChildren("07cd8d55-a35b-4445-9680-c98f158c55de", "hl:accounting", "jcr:content");
System.out.println("["+Thread.currentThread().getName()+"] took: "+(System.currentTimeMillis()-start) );
}
};
for (int i=0; i<=1; i++)
new Thread(runnable).start();
List<? extends Item> items = client.getChildren("07cd8d55-a35b-4445-9680-c98f158c55de",10, 5, "hl:accounting", "jcr:content");
System.out.println("items are "+items.size());
System.in.read();
}
@ -76,6 +68,17 @@ public class TestCall {
}
@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();
}
/*
@Test
public void createFolder() throws Exception{