Skip to content
Browse files

Key Indices for edges.

  • Loading branch information...
1 parent 343d74b commit 36d435ffe5b545fc508ecb5f59df010e513d8b61 @spmallette spmallette committed May 16, 2012
View
33 rexster-server/src/main/java/com/tinkerpop/rexster/EdgeResource.java
@@ -79,20 +79,35 @@ public Response getAllEdgesRexsterTypedJson(@PathParam("graphname") String graph
return this.getAllEdges(graphName, true);
}
- private Response getAllEdges(String graphName, boolean showTypes) {
+ private Response getAllEdges(final String graphName, final boolean showTypes) {
- RexsterApplicationGraph rag = this.getRexsterApplicationGraph(graphName);
+ final RexsterApplicationGraph rag = this.getRexsterApplicationGraph(graphName);
+ final Graph graph = rag.getGraph();
- JSONObject theRequestObject = this.getRequestObject();
- Long start = RequestObjectHelper.getStartOffset(theRequestObject);
- Long end = RequestObjectHelper.getEndOffset(theRequestObject);
- List<String> returnKeys = RequestObjectHelper.getReturnKeys(this.getRequestObject());
+ final JSONObject theRequestObject = this.getRequestObject();
+ final Long start = RequestObjectHelper.getStartOffset(theRequestObject);
+ final Long end = RequestObjectHelper.getEndOffset(theRequestObject);
+ final List<String> returnKeys = RequestObjectHelper.getReturnKeys(this.getRequestObject());
+ String key = null;
+ Object value = null;
+
+ Object temp = theRequestObject.opt(Tokens.KEY);
+ if (null != temp)
+ key = temp.toString();
+
+ temp = theRequestObject.opt(Tokens.VALUE);
+ if (null != temp)
+ value = ElementHelper.getTypedPropertyValue(temp.toString());
+
+ final boolean filtered = key != null && value != null;
+
boolean wasInSection = false;
long counter = 0l;
try {
- JSONArray edgeArray = new JSONArray();
- for (Edge edge : rag.getGraph().getEdges()) {
+ final JSONArray edgeArray = new JSONArray();
+ final Iterable<Edge> edges = filtered ? graph.getEdges(key, value) : graph.getEdges();
+ for (Edge edge : edges) {
if (counter >= start && counter < end) {
wasInSection = true;
edgeArray.put(GraphSONFactory.createJSONElement(edge, returnKeys, showTypes));
@@ -109,7 +124,7 @@ private Response getAllEdges(String graphName, boolean showTypes) {
} catch (JSONException ex) {
logger.error(ex);
- JSONObject error = generateErrorObjectJsonFail(ex);
+ final JSONObject error = generateErrorObjectJsonFail(ex);
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(error).build());
}
View
32 rexster-server/src/test/java/com/tinkerpop/rexster/EdgeResourceTest.java
@@ -2,7 +2,9 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.blueprints.KeyIndexableGraph;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
@@ -57,6 +59,36 @@ public void getAllEdgesNoOffset() {
}
@Test
+ public void getEdgesKeyIndexed() {
+ KeyIndexableGraph graph = TinkerGraphFactory.createTinkerGraph();
+ graph.createKeyIndex("weight", Edge.class);
+
+ final RexsterApplicationGraph rag = new RexsterApplicationGraph("graph", graph);
+ final RexsterApplication ra = this.mockery.mock(RexsterApplication.class);
+
+ final UriInfo uri = this.mockery.mock(UriInfo.class);
+
+ final HttpServletRequest httpServletRequest = this.mockery.mock(HttpServletRequest.class);
+
+ final HashMap<String, String> parameters = new HashMap<String, String>();
+ parameters.put(Tokens.KEY, "weight");
+ parameters.put(Tokens.VALUE, "(f,0.4)");
+
+ this.mockery.checking(new Expectations() {{
+ allowing(httpServletRequest).getParameterMap();
+ will(returnValue(parameters));
+ allowing(ra).getApplicationGraph(with(any(String.class)));
+ will(returnValue(rag));
+ allowing(uri).getAbsolutePath();
+ will(returnValue(requestUriPath));
+ }});
+
+ EdgeResource resource = new EdgeResource(uri, httpServletRequest, ra);
+ assertEdgesOkResponseJsonStructure(2, 2, resource.getAllEdges("graph"));
+ }
+
+
+ @Test
public void getAllEdgesNoResults() {
final int numberOfEdges = 0;
EdgeResource resource = this.constructMockGetAllEdgesScenario(numberOfEdges);

0 comments on commit 36d435f

Please sign in to comment.
Something went wrong with that request. Please try again.