IndexResource extends AbstractSubResource { @POST @Path("/{indexName}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Consumes({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.indices.object.post", absolute = true) public Response postIndex(@PathParam("graphname") final String graphName, @PathParam("indexName") final String indexName, final JSONObject json) { this.setRequestObject(json); return this.postIndex(graphName, indexName); } IndexResource();  IndexResource(final UriInfo ui, final HttpServletRequest req, final RexsterApplication ra); @OPTIONS Response optionsAllIndices(); @GET @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.indices.collection.get", absolute = true) Response getAllIndices(@PathParam("graphname") final String graphName); @OPTIONS @Path("/{indexName}") Response optionsElementsFromIndex(); @GET @Path("/{indexName}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON}) @Timed(name = "http.rest.indices.object.get", absolute = true) Response getElementsFromIndex(@PathParam("graphname") final String graphName, @PathParam("indexName") final String indexName); @GET @Path("/{indexName}") @Produces({RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.indices.object.get", absolute = true) Response getElementsFromIndexRexsterTypedJson(@PathParam("graphname") final String graphName, @PathParam("indexName") final String indexName); @OPTIONS @Path("/{indexName}/count") @Timed(name = "http.rest.indices.count.get", absolute = true) Response optionsIndexCount(); @GET @Path("/{indexName}/count") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.indices.count.get", absolute = true) Response getIndexCount(@PathParam("graphname") final String graphName, @PathParam("indexName") final String indexName); @DELETE @Path("/{indexName}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Consumes({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.indices.object.delete", absolute = true) Response deleteIndex(@PathParam("graphname") final String graphName, @PathParam("indexName") final String indexName, final JSONObject json); @DELETE @Path("/{indexName}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.indices.object.delete", absolute = true) Response deleteIndex(@PathParam("graphname") final String graphName, @PathParam("indexName") final String indexName); @POST @Path("/{indexName}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Consumes({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.indices.object.post", absolute = true) Response postIndex(@PathParam("graphname") final String graphName, @PathParam("indexName") final String indexName, final JSONObject json); @POST @Path("/{indexName}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.indices.object.post", absolute = true) Response postIndex(@PathParam("graphname") final String graphName, @PathParam("indexName") final String indexName); @PUT @Path("/{indexName}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Consumes({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.indices.object.put", absolute = true) Response putElementInIndex(@PathParam("graphname") final String graphName, @PathParam("indexName") final String indexName, final JSONObject json); @PUT @Path("/{indexName}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.indices.object.put", absolute = true) Response putElementInIndex(@PathParam("graphname") final String graphName, @PathParam("indexName") final String indexName);  }
@Test(expected = WebApplicationException.class) public void postIndexIdxKeysNotAnArray() { final HashMap<String, Object> parameters = new HashMap<String, Object>(); parameters.put("class", "vertex"); parameters.put("keys", "name"); final IndexResource resource = constructIndexResource(true, parameters).getResource(); resource.postIndex(graphName, "index-name-0"); }
@Test public void postIndexNewVertexIndex() { final HashMap<String, Object> parameters = new HashMap<String, Object>(); parameters.put("class", "vertex"); parameters.put("keys", "[name]"); final IndexResource resource = constructIndexResource(true, parameters).getResource(); resource.postIndex(graphName, "index-name-100"); final Index idx = ((IndexableGraph) this.toyGraph).getIndex("index-name-100", Vertex.class); Assert.assertNotNull(idx); }
@Test public void postIndexNewEdgeIndex() { final HashMap<String, Object> parameters = new HashMap<String, Object>(); parameters.put("class", "edge"); parameters.put("keys", "[weight]"); final IndexResource resource = constructIndexResource(true, parameters).getResource(); resource.postIndex(graphName, "index-name-100"); final Index idx = ((IndexableGraph) this.toyGraph).getIndex("index-name-100", Edge.class); Assert.assertNotNull(idx); }
@Test(expected = WebApplicationException.class) public void postIndexAlreadyExists() { final HashMap<String, Object> parameters = new HashMap<String, Object>(); parameters.put("class", "vertex"); parameters.put("keys", "[name]"); final IndexResource resource = constructIndexResource(true, parameters).getResource(); resource.postIndex(graphName, "index-name-1"); }
@Test(expected = WebApplicationException.class) public void putElementInIndexBadClass() { final HashMap<String, Object> parameters = new HashMap<String, Object>(); parameters.put("class", "nonsense"); parameters.put("key", "name"); parameters.put("value", "marko"); parameters.put("id", "1"); final IndexResource resource = constructIndexResource(true, parameters).getResource(); resource.postIndex(graphName, "index-name-1"); }