From d9fe526386386e5d1998862825bdb1db1eaae702 Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Thu, 23 Nov 2017 15:25:16 +0000 Subject: [PATCH] Refs #10238: Refactor Context Port Type Task-Url: https://support.d4science.org/issues/10238 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@158787 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../context/ContextManagement.java | 23 ++++++++++++++++++- .../context/ContextManagementTest.java | 11 +++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java index 6069500..8b42713 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java @@ -3,6 +3,7 @@ package org.gcube.informationsystem.resourceregistry.context; import java.util.Iterator; import java.util.UUID; +import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.gcube.informationsystem.model.AccessType; @@ -38,10 +39,12 @@ public class ContextManagement extends EntityManagement { protected String name; private void init() { - forceAdmin = true; + this.forceAdmin = true; this.ignoreStartWithKeys.add(Context.PARENT_PROPERTY); this.ignoreStartWithKeys.add(Context.CHILDREN_PROPERTY); + + this.erType = Context.NAME; } public ContextManagement() { @@ -337,5 +340,23 @@ public class ContextManagement extends EntityManagement { return true; } + + @Override + public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException { + JSONArray jsonArray = new JSONArray(); + Iterable iterable = orientGraph.getVerticesOfClass(erType, polymorphic); + for(Vertex vertex : iterable){ + ContextManagement contextManagement = new ContextManagement(); + contextManagement.setElement(vertex); + try { + JSONObject jsonObject = contextManagement.serializeAsJson(); + jsonArray.put(jsonObject); + }catch (ResourceRegistryException e) { + logger.error("Unable to correctly serialize {}. It will be excluded from results. {}", + vertex.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE); + } + } + return jsonArray.toString(); + } } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java index 8d6f6f5..7be948d 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java @@ -378,6 +378,17 @@ public class ContextManagementTest { delete(contextA1); logger.debug("The DB should be now clean"); } + + @Test + public void testGetAll() throws Exception { + ContextManagement contextManagement = new ContextManagement(); + String all = contextManagement.all(false); + logger.debug(all); + List contexts = ISMapper.unmarshalList(Context.class, all); + for(Context context : contexts){ + logger.debug(ISMapper.marshal(context)); + } + } // @Test public void createDevContext() throws Exception {