Search in sources :

Example 11 with QueryModel

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;
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) QueryModel(org.activityinfo.model.query.QueryModel) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) JsonFormTreeBuilder(org.activityinfo.model.formTree.JsonFormTreeBuilder)

Example 12 with 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();
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) Charsets(com.google.common.base.Charsets) ColumnJsonWriter(org.activityinfo.store.query.output.ColumnJsonWriter) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) StreamingOutput(javax.ws.rs.core.StreamingOutput) Operation(io.swagger.v3.oas.annotations.Operation) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Response(javax.ws.rs.core.Response) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) RowBasedJsonWriter(org.activityinfo.store.query.output.RowBasedJsonWriter) ColumnSet(org.activityinfo.model.query.ColumnSet) StreamingOutput(javax.ws.rs.core.StreamingOutput) RowBasedJsonWriter(org.activityinfo.store.query.output.RowBasedJsonWriter) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation)

Example 13 with QueryModel

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();
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) Charsets(com.google.common.base.Charsets) ColumnJsonWriter(org.activityinfo.store.query.output.ColumnJsonWriter) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) StreamingOutput(javax.ws.rs.core.StreamingOutput) Operation(io.swagger.v3.oas.annotations.Operation) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Response(javax.ws.rs.core.Response) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) RowBasedJsonWriter(org.activityinfo.store.query.output.RowBasedJsonWriter) ColumnJsonWriter(org.activityinfo.store.query.output.ColumnJsonWriter) ColumnSet(org.activityinfo.model.query.ColumnSet) StreamingOutput(javax.ws.rs.core.StreamingOutput) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation)

Example 14 with QueryModel

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)));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 15 with QueryModel

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();
        }
    }
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) Test(org.junit.Test)

Aggregations

QueryModel (org.activityinfo.model.query.QueryModel)59 ColumnSet (org.activityinfo.model.query.ColumnSet)40 Test (org.junit.Test)30 ColumnView (org.activityinfo.model.query.ColumnView)21 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)13 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)11 FormTree (org.activityinfo.model.formTree.FormTree)9 ResourceId (org.activityinfo.model.resource.ResourceId)9 FormClass (org.activityinfo.model.form.FormClass)7 Nullable (javax.annotation.Nullable)6 FormField (org.activityinfo.model.form.FormField)6 ColumnModel (org.activityinfo.model.query.ColumnModel)6 NullFormScanCache (org.activityinfo.store.query.shared.NullFormScanCache)6 QuantityType (org.activityinfo.model.type.number.QuantityType)5 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)4 RowBasedJsonWriter (org.activityinfo.store.query.output.RowBasedJsonWriter)4 Charsets (com.google.common.base.Charsets)3 Operation (io.swagger.v3.oas.annotations.Operation)3 FieldPath (org.activityinfo.model.formTree.FieldPath)3 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)3