use of org.activityinfo.model.query.ColumnSet in project activityinfo by bedatadriven.
the class FormResource method queryColumns.
@GET
@NoCache
@Path("query/columns")
@Produces(MediaType.APPLICATION_JSON)
public Response queryColumns(@Context UriInfo uriInfo) {
final ColumnSet columnSet = query(uriInfo);
final StreamingOutput output = outputStream -> {
ColumnJsonWriter columnSetWriter = new ColumnJsonWriter(outputStream, Charsets.UTF_8);
columnSetWriter.write(columnSet);
columnSetWriter.flush();
};
return Response.ok(output).type(JSON_CONTENT_TYPE).build();
}
use of org.activityinfo.model.query.ColumnSet 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.model.query.ColumnSet in project activityinfo by bedatadriven.
the class QueryResource method queryColumns.
@POST
@Path("columns")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Executes a query over a set of forms in columnar format")
public Response queryColumns(QueryModel model) {
ColumnSetBuilder builder = backend.newQueryBuilder();
final ColumnSet columnSet = builder.build(model);
final StreamingOutput output = outputStream -> {
ColumnJsonWriter columnSetWriter = new ColumnJsonWriter(outputStream, Charsets.UTF_8);
columnSetWriter.write(columnSet);
columnSetWriter.flush();
};
return Response.ok(output).type(MediaType.APPLICATION_JSON_TYPE).build();
}
use of org.activityinfo.model.query.ColumnSet in project activityinfo by bedatadriven.
the class ExportFormExecutor method execute.
@Override
public ExportResult execute(ExportFormJob descriptor) throws IOException {
TableModel tableModel = descriptor.getTableModel();
GeneratedResource export = storageProvider.create(XlsTableWriter.EXCEL_MIME_TYPE, "Export.xls");
TableViewModel viewModel = new TableViewModel(formSource, tableModel);
EffectiveTableModel effectiveTableModel = viewModel.getEffectiveTable().waitFor();
ColumnSet columnSet = effectiveTableModel.getColumnSet().waitFor();
XlsTableWriter writer = new XlsTableWriter();
writer.addSheet(effectiveTableModel, columnSet);
try (OutputStream out = export.openOutputStream()) {
writer.write(out);
}
return new ExportResult(export.getDownloadUri());
}
use of org.activityinfo.model.query.ColumnSet in project activityinfo by bedatadriven.
the class ResourceLocatorAdaptorTest method siteDeletion.
@Test
public void siteDeletion() {
QueryModel query = new QueryModel(NFI_DIST_FORM_CLASS);
query.selectResourceId().as("id");
query.selectField(CuidAdapter.field(VILLAGE_CLASS, CuidAdapter.NAME_FIELD));
ColumnSet columnSet = assertResolves(locator.queryTable(query));
assertThat(columnSet.getNumRows(), equalTo(3));
final ResourceId firstRecordId = ResourceId.valueOf(columnSet.getColumnView("id").getString(0));
assertResolves(locator.remove(NFI_DIST_FORM_CLASS, firstRecordId));
columnSet = assertResolves(locator.queryTable(query));
// size is reduced
assertThat(columnSet.getNumRows(), equalTo(2));
assertThat(columnSet.getColumnView("id"), not(hasValue(firstRecordId)));
}
Aggregations