use of org.activityinfo.store.query.output.RowBasedJsonWriter in project activityinfo by bedatadriven.
the class QueryResource method queryRows.
@POST
@Path("rows")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Executes a query over a set of forms in row format")
public Response queryRows(QueryModel model) {
ColumnSetBuilder builder = backend.newQueryBuilder();
final ColumnSet columnSet = builder.build(model);
final StreamingOutput output = outputStream -> {
RowBasedJsonWriter writer = new RowBasedJsonWriter(outputStream, Charsets.UTF_8);
writer.write(columnSet);
writer.flush();
};
return Response.ok(output).type(MediaType.APPLICATION_JSON_TYPE).build();
}
use of org.activityinfo.store.query.output.RowBasedJsonWriter in project activityinfo by bedatadriven.
the class MySqlCatalogIntegrationTest method testActivity.
@Test
public void testActivity() throws IOException {
QueryModel model = new QueryModel(activityFormClass(33));
model.selectField("date1");
model.selectField("date2");
model.selectExpr("Partner.name");
FormTree formTree = new FormTreeBuilder(catalog).queryTree(activityFormClass(33));
FormTreePrettyPrinter.print(formTree);
FormClass formClass = catalog.getForm(activityFormClass(33)).get().getFormClass();
for (FormField field : formClass.getFields()) {
if (field.getType() instanceof QuantityType) {
model.selectField(field.getId()).as("I" + CuidAdapter.getLegacyIdFromCuid(field.getId()));
}
}
Stopwatch stopwatch = Stopwatch.createStarted();
ColumnSet columnSet = columnSetBuilder.build(model);
System.out.println("Query executed in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
assertThat(columnSet.getNumRows(), equalTo(652));
StringWriter stringWriter = new StringWriter();
RowBasedJsonWriter writer = new RowBasedJsonWriter(stringWriter);
writer.write(columnSet);
System.out.println(stringWriter.toString());
}
use of org.activityinfo.store.query.output.RowBasedJsonWriter in project activityinfo by bedatadriven.
the class FormResource method queryRows.
@GET
@NoCache
@Path("query/rows")
@Produces(MediaType.APPLICATION_JSON)
public Response queryRows(@Context UriInfo uriInfo) {
final ColumnSet columnSet = query(uriInfo);
LOGGER.info("Query completed with " + columnSet.getNumRows() + " rows.");
final StreamingOutput output = outputStream -> {
RowBasedJsonWriter writer = new RowBasedJsonWriter(outputStream, Charsets.UTF_8);
writer.write(columnSet);
writer.flush();
};
return Response.ok(output).type(JSON_CONTENT_TYPE).build();
}
Aggregations