KeyIndexResource extends AbstractSubResource { @GET @Path("/{clazz}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.key-indices.class.collection.get", absolute = true) public Response getIndexKeys(@PathParam("graphname") final String graphName, @PathParam("clazz") final String clazz) { final Class<? extends Element> keyClass; if (clazz.equals(Tokens.VERTEX)) { keyClass = Vertex.class; } else if (clazz.equals(Tokens.EDGE)) { keyClass = Edge.class; } else { throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build()); } final KeyIndexableGraph graph = this.getKeyIndexableGraph(graphName); final RexsterApplicationGraph rag = this.getRexsterApplicationGraph(graphName); try { final JSONArray keyArray = new JSONArray(); for (String key : graph.getIndexedKeys(keyClass)) { keyArray.put(key); } this.resultObject.put(Tokens.RESULTS, keyArray); this.resultObject.put(Tokens.QUERY_TIME, this.sh.stopWatch()); } catch (JSONException ex) { logger.error(ex); final JSONObject error = generateErrorObjectJsonFail(ex); throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build()); } finally { rag.tryCommit(); } return Response.ok(this.resultObject).build(); } KeyIndexResource();  KeyIndexResource(final UriInfo ui, final HttpServletRequest req, final RexsterApplication ra); @OPTIONS Response optionsKeyIndices(); @GET @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.key-indices.collection.get", absolute = true) Response getKeyIndices(@PathParam("graphname") final String graphName); @OPTIONS @Path("/{clazz}") Response optionsIndexKeys(); @GET @Path("/{clazz}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.key-indices.class.collection.get", absolute = true) Response getIndexKeys(@PathParam("graphname") final String graphName, @PathParam("clazz") final String clazz); @OPTIONS @Path("/{clazz}/{keyName}") Response optionsIndexKey(); @DELETE @Path("{clazz}/{keyName}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.key-indices.object.delete", absolute = true) Response deleteIndexKey(@PathParam("graphname") final String graphName, @PathParam("clazz") final String clazz, 
                                   @PathParam("keyName") final String keyName); @POST @Path("/{clazz}/{keyName}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.key-indices.class.object.post", absolute = true) Response postIndexKey(@PathParam("graphname") final String graphName, @PathParam("clazz") final String clazz,
                                 @PathParam("keyName") final String keyName);  }
@Test(expected = WebApplicationException.class) public void getIndexKeysNonIndexableGraph() { final KeyIndexResource resource = mockNonKeyIndexableGraph(); resource.getIndexKeys("graph", Tokens.VERTEX); }
@Test public void getIndexKeysVertex() { final KeyIndexResource resource = constructKeyIndexResourceWithToyGraph().getResource(); final Response response = resource.getIndexKeys(graphName, Tokens.VERTEX); Assert.assertNotNull(response); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Assert.assertNotNull(response.getEntity()); Assert.assertTrue(response.getEntity() instanceof JSONObject); final JSONObject json = (JSONObject) response.getEntity(); Assert.assertTrue(json.has(Tokens.QUERY_TIME)); Assert.assertTrue(json.has(Tokens.RESULTS)); final JSONArray jsonKeys = json.optJSONArray(Tokens.RESULTS); Assert.assertEquals(2, jsonKeys.length()); }
@Test public void getIndexKeysEdge() { final KeyIndexResource resource = constructKeyIndexResourceWithToyGraph().getResource(); final Response response = resource.getIndexKeys(graphName, Tokens.EDGE); Assert.assertNotNull(response); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Assert.assertNotNull(response.getEntity()); Assert.assertTrue(response.getEntity() instanceof JSONObject); final JSONObject json = (JSONObject) response.getEntity(); Assert.assertTrue(json.has(Tokens.QUERY_TIME)); Assert.assertTrue(json.has(Tokens.RESULTS)); final JSONArray jsonKeys = json.optJSONArray(Tokens.RESULTS); Assert.assertEquals(1, jsonKeys.length()); }