@QueryParam("callback") String callback ) { GetOptions options = new GetOptions(); if ("pretty".equals(print)) { options.prettyPrint(true); } else if ("silent".equals(print)) { if( jsondb.exists(path) ) { options.depth(1); if( callback!=null ) { contentType = APPLICATION_JAVASCRIPT; options.callback(callback);
@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 testGetStartAtEndAt() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "1", "user2:1", "2", "user2:2", "3", "user2:3", "4", "user4", "5" ))); String json = jsondb.getAsString("/test", new GetOptions().startAt("user2:").endAt("user2:")); assertThat(json).isEqualTo("{\"user2:1\":\"2\",\"user2:2\":\"3\",\"user2:3\":\"4\"}"); }
/* default */ JsonRecordConsumer(String base, OutputStream output, GetOptions options) throws IOException { this.base = base; this.output = output; try { this.options = options.clone(); } catch (CloneNotSupportedException e) { throw new IOException(e); } if (this.options.callback() != null) { String backack = this.options.callback() + "("; output.write(backack.getBytes(StandardCharsets.UTF_8)); } this.jg = new JsonFactory().createGenerator(output); if (options.prettyPrint()) { jg.useDefaultPrettyPrinter(); } }
o = options; } else { o = new GetOptions(); GetOptions.Order order = o.order(); if( order == null ) { order = GetOptions.Order.ASC; if( o.filter() == null ) { sql.append("select path,value,ovalue from jsondb where path LIKE :like"); } else { sql.append("SELECT path,value,ovalue FROM jsondb A INNER JOIN ("); SqlExpressionBuilder.create(this, o.filter(), baseDBPath).build(sql, binds); sql.append(") B ON A.path LIKE B.match_path||'%'"); if (o.startAfter() != null) { String startAfter = validateKey(o.startAfter()); if (o.order() == GetOptions.Order.DESC) { sql.append(" and path <= :startAfter"); binds.add(query -> { if (o.startAt() != null) { String startAt = validateKey(o.startAt()); if (o.order() == GetOptions.Order.DESC) { sql.append(" and path < :startAt"); binds.add(query -> { if (o.endAt() != null) { String endAt = validateKey(o.endAt());
@Test public void testGetMetricsForIntegration1() throws IOException { String json = jsondb.getAsString(JsonDBRawMetrics.path("intId1"), new GetOptions().prettyPrint(true)); Map<String,RawMetrics> metrics = Json.reader().forType(new TypeReference<Map<String,RawMetrics>>() {}).readValue(json); assertThat(metrics.size()).isEqualTo(3); assertThat(metrics.keySet()).contains("HISTORY1"); }
@Override public Set<String> fetchIds() { try { String json = jsondb.getAsString(getCollectionPath(), new GetOptions().depth(1)); if (json != null) { Map<String,Boolean> map = Json.reader().forType(new TypeReference<Map<String,Boolean>>() {}).readValue(json); return map.keySet() .stream().map(path -> path.substring(path.indexOf(':') + 1)).collect(Collectors.toSet()); } else { return Collections.<String>emptySet(); } } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException|IOException e) { throw SyndesisServerException.launderThrowable(e); } }
@Test public void testGetLimitDeeper() throws IOException { jsondb.update("/test", mapper.writeValueAsString(map( "user1/value", "test 1", "user2/value", "test 2", "user3/value", "test 3", "user4/value", "test 4", "user5/value", "test 5", "user6/value", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().limitToFirst(3)); assertThat(json).isEqualTo("{\"user1\":{\"value\":\"test 1\"},\"user2\":{\"value\":\"test 2\"},\"user3\":{\"value\":\"test 3\"}}"); }
@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 testGetEndAtWithDESC() 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().endAt("user3").order(GetOptions.Order.DESC)); assertThat(json).isEqualTo("{\"user6\":\"test 6\",\"user5\":\"test 5\",\"user4\":\"test 4\",\"user3\":\"test 3\"}"); }
@Test public void testGetEndBeforeWithDESC() 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().endBefore("user2").order(GetOptions.Order.DESC)); assertThat(json).isEqualTo("{\"user6\":\"test 6\",\"user5\":\"test 5\",\"user4\":\"test 4\",\"user3\":\"test 3\"}"); }
@Test public void testGetStartAtWithDESC() 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().startAt("user2").order(GetOptions.Order.DESC)); assertThat(json).isEqualTo("{\"user2\":\"test 2\",\"user1\":\"test 1\"}"); }
@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 testGetOrder() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "user1", "test 1", "user2", "test 2", "user3", "test 3" ))); // Default order is ASC String json = jsondb.getAsString("/test", new GetOptions()); assertThat(json).isEqualTo("{\"user1\":\"test 1\",\"user2\":\"test 2\",\"user3\":\"test 3\"}"); // Explicit ASC should give us the same. json = jsondb.getAsString("/test", new GetOptions().order(GetOptions.Order.ASC)); assertThat(json).isEqualTo("{\"user1\":\"test 1\",\"user2\":\"test 2\",\"user3\":\"test 3\"}"); // DESC ord should reverse the output order. json = jsondb.getAsString("/test", new GetOptions().order(GetOptions.Order.DESC)); assertThat(json).isEqualTo("{\"user3\":\"test 3\",\"user2\":\"test 2\",\"user1\":\"test 1\"}"); }
@Test public void testGetStartAt() 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().startAt("user4")); assertThat(json).isEqualTo("{\"user4\":\"test 4\",\"user5\":\"test 5\",\"user6\":\"test 6\"}"); }
@Test public void testGetEndBefore() 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().endBefore("user5")); assertThat(json).isEqualTo("{\"user1\":\"test 1\",\"user2\":\"test 2\",\"user3\":\"test 3\",\"user4\":\"test 4\"}"); }
@Test public void testGetEndAt() 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().endAt("user4")); assertThat(json).isEqualTo("{\"user1\":\"test 1\",\"user2\":\"test 2\",\"user3\":\"test 3\",\"user4\":\"test 4\"}"); }
@Test public void testGetCallback() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "name", "Hiram Chirino" ))); String json = jsondb.getAsString("/", new GetOptions().callback("myfunction")); assertThat(json).isEqualTo("myfunction({\"test\":{\"name\":\"Hiram Chirino\"}})"); }
if( this.options.limitToFirst() !=null ) { if( !newPath.get(0).equals(currentRootField) ) { this.entriesAdded++; currentRootField = newPath.get(0); if( this.entriesAdded > this.options.limitToFirst() ) { close(); return; if (this.options.depth()!=null && this.options.depth() < newPath.size() ) { shallowObjects.add(newPath.get(0)); return;
assertThat(jsondb.getAsString("/users", new GetOptions().filter( Filter.child("name", Op.EQ, "u2") ))).isEqualTo( "{\"u2\":{\"age\":10,\"name\":\"u2\"}}" ); assertThat(jsondb.getAsString("/users", new GetOptions().filter( Filter.child("name", Op.NEQ, "u2") ))).isEqualTo( "{\"u1\":{\"age\":9,\"name\":\"u1\"},\"u3\":{\"age\":21,\"name\":\"u3\"}}" ); assertThat(jsondb.getAsString("/users", new GetOptions().filter( Filter.child("name", Op.LT, "u2") ))).isEqualTo( "{\"u1\":{\"age\":9,\"name\":\"u1\"}}" ); assertThat(jsondb.getAsString("/users", new GetOptions().filter( Filter.child("name", Op.GT, "u2") ))).isEqualTo( "{\"u3\":{\"age\":21,\"name\":\"u3\"}}" ); assertThat(jsondb.getAsString("/users", new GetOptions().filter( Filter.child("name", Op.LTE, "u2") ))).isEqualTo( "{\"u1\":{\"age\":9,\"name\":\"u1\"},\"u2\":{\"age\":10,\"name\":\"u2\"}}" ); assertThat(jsondb.getAsString("/users", new GetOptions().filter( Filter.child("name", Op.GTE, "u2") ))).isEqualTo(