DocumentResource { @POST @Path("/bulk") @Consumes(MediaType.APPLICATION_JSON) @Timed @ApiOperation("Save list of documents") public Response saveDocuments(@PathParam("table") String table, @Valid final List<Document> documents) { Map<String, List<Document>> tableVsDocuments = getTableVsDocuments(table, documents); for(Map.Entry<String, List<Document>> entry : CollectionUtils.nullSafeSet(tableVsDocuments.entrySet())) { queryStore.save(entry.getKey(), entry.getValue()); } return Response.created(URI.create("/" + table)) .build(); } @Inject  DocumentResource(QueryStore queryStore, TableTranslator tableTranslator); @POST @Consumes(MediaType.APPLICATION_JSON) @Timed @ApiOperation("Save Document") Response saveDocument(@PathParam("table") String table, @Valid final Document document); @POST @Path("/bulk") @Consumes(MediaType.APPLICATION_JSON) @Timed @ApiOperation("Save list of documents") Response saveDocuments(@PathParam("table") String table, @Valid final List<Document> documents); @GET @Path("/{id}") @Timed @ApiOperation("Get Document") Response getDocument(@PathParam("table") final String table, @PathParam("id") @NotNull final String id); @GET @Timed @ApiOperation("Get Documents") Response getDocuments(@PathParam("table") final String table, @QueryParam("id") @NotNull final List<String> ids);  }
@Test public void testSaveDocuments() throws Exception { List<Document> documents = new ArrayList<Document>(); String id1 = UUID.randomUUID() .toString(); Document document1 = new Document(id1, System.currentTimeMillis(), getMapper().getNodeFactory() .objectNode() .put("D", "data")); String id2 = UUID.randomUUID() .toString(); Document document2 = new Document(id2, System.currentTimeMillis(), getMapper().getNodeFactory() .objectNode() .put("D", "data")); documents.add(document1); documents.add(document2); Entity<List<Document>> listEntity = Entity.json(documents); resources.client() .target(String.format("/v1/document/%s/bulk", TestUtils.TEST_TABLE_NAME)) .request() .post(listEntity); getElasticsearchConnection().refresh(ElasticsearchUtils.getIndices(TestUtils.TEST_TABLE_NAME)); compare(document1, getQueryStore().get(TestUtils.TEST_TABLE_NAME, id1)); compare(document2, getQueryStore().get(TestUtils.TEST_TABLE_NAME, id2)); }