@GET @Produces(MediaType.APPLICATION_JSON) @Path(value = "/{integrationId}") public List<Exchange> getLogs( @PathParam("integrationId") String integrationId, @QueryParam("from") String from, @QueryParam("limit") Integer requestedLimit ) throws IOException { String path = "/logs/exchanges/" + integrationId; int limit = 10; if( requestedLimit != null ) { limit = requestedLimit; } if( limit > 1000 ) { limit = 1000; // max out to 1000 per request. } GetOptions options = new GetOptions() .order(GetOptions.Order.DESC) // reverse the order since we want most recent exchanges first. .startAfter(from).limitToFirst(limit); // allow paging byte[] data = jsondb.getAsByteArray(path, options); if( data == null ) { return new ArrayList<>(); } return toAPIAPITxLogEntryList(Json.mapper().readTree(data)); }
@Test public void testGetStartAfter() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().startAfter("user3")); assertThat(json).isEqualTo("{\"user4\":\"test 4\",\"user5\":\"test 5\",\"user6\":\"test 6\"}"); }
@Test public void testGetStartAfter() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().startAfter("user3")); assertThat(json).isEqualTo("{\"user4\":\"test 4\",\"user5\":\"test 5\",\"user6\":\"test 6\"}"); }
@Test public void testGetStartAfterWithDESC() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().startAfter("user3").order(GetOptions.Order.DESC)); assertThat(json).isEqualTo("{\"user2\":\"test 2\",\"user1\":\"test 1\"}"); }
@Test public void testGetStartAfterWithDESC() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3", "user4", "test 4", "user5", "test 5", "user6", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().startAfter("user3").order(GetOptions.Order.DESC)); assertThat(json).isEqualTo("{\"user2\":\"test 2\",\"user1\":\"test 1\"}"); }
if (o.startAfter() != null) { String startAfter = validateKey(o.startAfter()); if (o.order() == GetOptions.Order.DESC) { sql.append(" and path <= :startAfter");
if (o.startAfter() != null) { String startAfter = validateKey(o.startAfter()); if (o.order() == GetOptions.Order.DESC) { sql.append(" and path <= :startAfter");