use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class FormResource method buildDefaultQueryModel.
private QueryModel buildDefaultQueryModel() {
QueryModel queryModel;
FormTreeBuilder treeBuilder = new FormTreeBuilder(backend.getStorage());
FormTree tree = treeBuilder.queryTree(formId);
queryModel = new DefaultQueryBuilder(tree).build();
return queryModel;
}
use of org.activityinfo.model.query.QueryModel 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.QueryModel 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.QueryModel 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)));
}
use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class ResourceLocatorAdaptorTest method deleteLocation.
@Test
public void deleteLocation() {
ResourceId instanceToDelete = CuidAdapter.locationInstanceId(1);
assertResolves(locator.remove(CuidAdapter.locationFormClass(1), instanceToDelete));
QueryModel queryModel = new QueryModel(CuidAdapter.locationFormClass(1));
queryModel.selectResourceId().as("id");
ColumnSet columnSet = assertResolves(locator.queryTable(queryModel));
ColumnView idColumn = columnSet.getColumnView("id");
for (int i = 0; i < idColumn.numRows(); i++) {
if (idColumn.getString(i).equals(instanceToDelete.asString())) {
throw new AssertionError();
}
}
}
Aggregations