diff --git a/src/main/java/org/gcube/gcat/client/Item.java b/src/main/java/org/gcube/gcat/client/Item.java index 14d21cc..5fd7bc4 100644 --- a/src/main/java/org/gcube/gcat/client/Item.java +++ b/src/main/java/org/gcube/gcat/client/Item.java @@ -23,6 +23,12 @@ public class Item extends GCatClient implements org.gcube.gcat.api.interfaces.It super(enforcedServiceURL, ITEMS); } + /** + * List the item in the organization correspondent to the current VRE. + * + * If the client is entitled to run at VO or ROOT level the method return all the item in all the organization + * in the catalogue. To filter per organization used the method {@link #list(int, int, String)} + */ @Override public String list(int limit, int offset) throws WebApplicationException { Map queryParams = new HashMap<>(); @@ -31,6 +37,17 @@ public class Item extends GCatClient implements org.gcube.gcat.api.interfaces.It return super.list(queryParams); } + /** + * List the item of a specific organization. + * This API is only available if the client is entitles to run at VO and ROOT level. + */ + public String list(int limit, int offset, String organizationName) throws WebApplicationException { + Map queryParams = new HashMap<>(); + queryParams.put(GCatConstants.LIMIT_PARAMETER, String.valueOf(limit)); + queryParams.put(GCatConstants.OFFSET_PARAMETER, String.valueOf(offset)); + queryParams.put(GCatConstants.ORGANIZATION_PARAMETER, organizationName); + return super.list(queryParams); + } public String create(String json, boolean socialPost) { try { diff --git a/src/test/java/org/gcube/gcat/client/ItemTest.java b/src/test/java/org/gcube/gcat/client/ItemTest.java index 8d1894c..1a452d5 100644 --- a/src/test/java/org/gcube/gcat/client/ItemTest.java +++ b/src/test/java/org/gcube/gcat/client/ItemTest.java @@ -71,7 +71,6 @@ public class ItemTest extends ContextTest { */ } - @Test public void completeTest() throws IOException { ObjectMapper mapper = new ObjectMapper(); @@ -85,7 +84,6 @@ public class ItemTest extends ContextTest { JsonNode licenseJsonNode = licences.get(0); String licenseID = licenseJsonNode.get(ID_KEY).asText(); - Map map = new HashMap<>(); map.put(NAME_KEY, NAME_VALUE); map.put(TITLE_KEY, TITLE_VALUE); @@ -98,7 +96,6 @@ public class ItemTest extends ContextTest { tags.add(tag); map.put(TAGS_KEY, tags); - List> extras = new ArrayList<>(); Map type = new HashMap<>(); type.put(KEY_KEY, TYPE_KEY_VALUE); @@ -134,11 +131,11 @@ public class ItemTest extends ContextTest { Assert.assertTrue(gotTitle.compareTo(TITLE_VALUE) == 0); boolean privateValue = jsonNode.get(PRIVATE_KEY).asBoolean(); - Assert.assertTrue(privateValue==PRIVATE_VALUE); + Assert.assertTrue(privateValue == PRIVATE_VALUE); String gotLicenseID = jsonNode.get(LICENSE_ID_KEY).asText(); Assert.assertTrue(gotLicenseID.compareTo(licenseID) == 0); - }catch (Throwable e) { + } catch(Throwable e) { item.delete(NAME_VALUE, true); throw e; } @@ -154,8 +151,22 @@ public class ItemTest extends ContextTest { } @Test - public void safeTest() throws IOException { + public void listOnVOTest() throws Exception { + ContextTest.setContextByName("/gcube/devNext"); + Item item = new Item(); + String itemsString = item.list(10, 0, "bionym"); + logger.debug("Got list {}", itemsString); + + /* + ObjectMapper mapper = new ObjectMapper(); + JavaType listType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, String.class); + List items = mapper.readValue(itemsString, listType); + */ + } + + @Test + public void safeTest() throws Exception { ObjectMapper mapper = new ObjectMapper(); JavaType listType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, String.class); @@ -181,7 +192,7 @@ public class ItemTest extends ContextTest { Item item = new Item(); String itemsString = item.list(200, 0); List items = mapper.readValue(itemsString, listType); - while(items.size()>0) { + while(items.size() > 0) { for(String itemName : items) { item.purge(itemName); Thread.sleep(50); diff --git a/src/test/resources/.gitignore b/src/test/resources/.gitignore new file mode 100644 index 0000000..a8e4366 --- /dev/null +++ b/src/test/resources/.gitignore @@ -0,0 +1 @@ +/token.properties diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml new file mode 100644 index 0000000..4da43d9 --- /dev/null +++ b/src/test/resources/logback-test.xml @@ -0,0 +1,19 @@ + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n + + + + + + + + + + + + \ No newline at end of file