IndexResource extends AbstractSubResource { @GET @Path("/{indexName}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON}) @Timed(name = "http.rest.indices.object.get", absolute = true) public Response getElementsFromIndex(@PathParam("graphname") final String graphName, @PathParam("indexName") final String indexName) { return this.getElementsFromIndex(graphName, indexName, false); } 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 public void getElementsFromIndexAll() { final HashMap<String, Object> parameters = new HashMap<String, Object>(); parameters.put("key", "field"); parameters.put("value", "X"); final IndexResource resource = constructIndexResource(true, parameters).getResource(); final Response response = resource.getElementsFromIndex(graphName, "index-name-9"); Assert.assertNotNull(response); Assert.assertEquals(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.TOTAL_SIZE)); Assert.assertEquals(4, json.optInt(Tokens.TOTAL_SIZE)); Assert.assertTrue(json.has(Tokens.QUERY_TIME)); final JSONArray results = json.optJSONArray(Tokens.RESULTS); Assert.assertEquals(4, results.length()); final List<String> foundIds = new ArrayList<String>(); for (int ix = 0; ix < results.length(); ix++) { foundIds.add(results.optJSONObject(ix).optString(Tokens._ID)); } Assert.assertTrue(foundIds.contains("1")); Assert.assertTrue(foundIds.contains("2")); Assert.assertTrue(foundIds.contains("4")); Assert.assertTrue(foundIds.contains("6")); }
@Test public void getElementsFromIndexAllOffset() { final HashMap<String, Object> parameters = new HashMap<String, Object>(); parameters.put("key", "field"); parameters.put("value", "X"); parameters.put(Tokens.REXSTER + "." + Tokens.OFFSET_START, "1"); parameters.put(Tokens.REXSTER + "." + Tokens.OFFSET_END, "3"); final IndexResource resource = constructIndexResource(true, parameters).getResource(); final Response response = resource.getElementsFromIndex(graphName, "index-name-9"); Assert.assertNotNull(response); Assert.assertEquals(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.TOTAL_SIZE)); Assert.assertEquals(4, json.optInt(Tokens.TOTAL_SIZE)); Assert.assertTrue(json.has(Tokens.QUERY_TIME)); final JSONArray results = json.optJSONArray(Tokens.RESULTS); Assert.assertEquals(2, results.length()); final List<String> foundIds = new ArrayList<String>(); for (int ix = 0; ix < results.length(); ix++) { foundIds.add(results.optJSONObject(ix).optString(Tokens._ID)); } Assert.assertTrue(foundIds.contains("1")); Assert.assertTrue(foundIds.contains("6")); }