From 12b079461024d069fabf61e1d756a864174ba7b5 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Wed, 14 Mar 2018 15:21:13 +0000 Subject: [PATCH] git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@165077 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/proxies/DefaultItemManager.java | 43 ++++++++++++++ .../proxies/DefaultWorkspaceManager.java | 57 +++++++++++++++++-- .../client/proxies/ItemManagerClient.java | 4 ++ .../proxies/WorkspaceManagerClient.java | 6 +- .../org/gcube/data/access/fs/TestCall.java | 41 ++++++------- 5 files changed, 126 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java index 98caaee..5ea6dd2 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java @@ -91,4 +91,47 @@ public class DefaultItemManager implements ItemManagerClient { } } + + @Override + public List getChildren(String id, int start, int limit, String... excludeNodes) { + Call call = new Call() { + @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 call = new Call() { + @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); + } + } + } diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java index b83a424..3455b2f 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java @@ -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 getWorkspace(String... excludeNodes) { - Call call = new Call() { + public T getWorkspace(String ... excludeNodes) { + Call> call = new Call>() { @Override - public ItemList call(WebTarget manager) throws Exception { + public ItemWrapper 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 response = builder.get(ItemWrapper.class); + System.out.println(manager.getUri().toString()); + return response; + } + }; + try { + ItemWrapper result = delegate.make(call); + return result.getItem(); + }catch(Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public List getVreFolders(String ... excludeNodes) { + Call call = new Call() { + @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 getVreFolders(int start, int limit, String ... excludeNodes) { + Call call = new Call() { + @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; } }; diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/ItemManagerClient.java b/src/main/java/org/gcube/common/storagehub/client/proxies/ItemManagerClient.java index 6ed2bfe..0900eaa 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/ItemManagerClient.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/ItemManagerClient.java @@ -13,6 +13,10 @@ public interface ItemManagerClient { List getChildren(String id, String ... excludeNodes); + List getChildren(String id, int start, int limit, String ... excludeNodes); + + Integer childrenCount(String id); + Item get(String id, String ... excludeNodes); StreamDescriptor download(String id); diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/WorkspaceManagerClient.java b/src/main/java/org/gcube/common/storagehub/client/proxies/WorkspaceManagerClient.java index 2811841..ff0555e 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/WorkspaceManagerClient.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/WorkspaceManagerClient.java @@ -6,6 +6,10 @@ import org.gcube.common.storagehub.model.items.Item; public interface WorkspaceManagerClient { - List getWorkspace(String ... excludeNodes); + T getWorkspace(String ... excludeNodes); + + List getVreFolders(String ... excludeNodes); + + List getVreFolders(int start, int limit, String ... excludeNodes); } diff --git a/src/test/java/org/gcube/data/access/fs/TestCall.java b/src/test/java/org/gcube/data/access/fs/TestCall.java index 31536c9..003c6bb 100644 --- a/src/test/java/org/gcube/data/access/fs/TestCall.java +++ b/src/test/java/org/gcube/data/access/fs/TestCall.java @@ -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 items = itemclient.getChildren(ws.getId(),10, 5, "hl:accounting", "jcr:content"); + List Vreitems = client.getVreFolders("hl:accounting"); + List 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 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{