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
This commit is contained in:
Luca Frosini 2017-11-23 15:25:16 +00:00
parent bdf17da9aa
commit d9fe526386
2 changed files with 33 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package org.gcube.informationsystem.resourceregistry.context;
import java.util.Iterator; import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.gcube.informationsystem.model.AccessType; import org.gcube.informationsystem.model.AccessType;
@ -38,10 +39,12 @@ public class ContextManagement extends EntityManagement<Context> {
protected String name; protected String name;
private void init() { private void init() {
forceAdmin = true; this.forceAdmin = true;
this.ignoreStartWithKeys.add(Context.PARENT_PROPERTY); this.ignoreStartWithKeys.add(Context.PARENT_PROPERTY);
this.ignoreStartWithKeys.add(Context.CHILDREN_PROPERTY); this.ignoreStartWithKeys.add(Context.CHILDREN_PROPERTY);
this.erType = Context.NAME;
} }
public ContextManagement() { public ContextManagement() {
@ -337,5 +340,23 @@ public class ContextManagement extends EntityManagement<Context> {
return true; return true;
} }
@Override
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
JSONArray jsonArray = new JSONArray();
Iterable<Vertex> 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();
}
} }

View File

@ -378,6 +378,17 @@ public class ContextManagementTest {
delete(contextA1); delete(contextA1);
logger.debug("The DB should be now clean"); 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<Context> contexts = ISMapper.unmarshalList(Context.class, all);
for(Context context : contexts){
logger.debug(ISMapper.marshal(context));
}
}
// @Test // @Test
public void createDevContext() throws Exception { public void createDevContext() throws Exception {