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 {