Search in sources :

Example 6 with ColumnSet

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();
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) ColumnJsonWriter(org.activityinfo.store.query.output.ColumnJsonWriter) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) JsonFormTreeBuilder(org.activityinfo.model.formTree.JsonFormTreeBuilder) GeoAreaType(org.activityinfo.model.type.geo.GeoAreaType) ResourceId.valueOf(org.activityinfo.model.resource.ResourceId.valueOf) UserDatabaseMeta(org.activityinfo.model.database.UserDatabaseMeta) WKBReader(com.vividsolutions.jts.io.WKBReader) PermissionsEnforcer(org.activityinfo.store.query.server.PermissionsEnforcer) org.activityinfo.model.form(org.activityinfo.model.form) NotFoundException(com.sun.jersey.api.NotFoundException) Level(java.util.logging.Level) HashSet(java.util.HashSet) Operation(io.swagger.v3.oas.annotations.Operation) SQLException(java.sql.SQLException) ResourceId(org.activityinfo.model.resource.ResourceId) Optional(com.google.common.base.Optional) Geometry(com.vividsolutions.jts.geom.Geometry) RecordRef(org.activityinfo.model.type.RecordRef) JsonValue(org.activityinfo.json.JsonValue) FormTreePrettyPrinter(org.activityinfo.model.formTree.FormTreePrettyPrinter) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) RecordLockSet(org.activityinfo.model.database.RecordLockSet) InvalidUpdateException(org.activityinfo.store.query.server.InvalidUpdateException) PrintWriter(java.io.PrintWriter) Charsets(com.google.common.base.Charsets) ParseException(com.vividsolutions.jts.io.ParseException) StringWriter(java.io.StringWriter) Set(java.util.Set) javax.ws.rs.core(javax.ws.rs.core) Logger(java.util.logging.Logger) String.format(java.lang.String.format) FormStorage(org.activityinfo.store.spi.FormStorage) RecordLock(org.activityinfo.model.database.RecordLock) List(java.util.List) javax.ws.rs(javax.ws.rs) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Tag(io.swagger.v3.oas.annotations.tags.Tag) XlsFormBuilder(org.activityinfo.io.xlsform.XlsFormBuilder) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) InjectParam(com.sun.jersey.api.core.InjectParam) FormTree(org.activityinfo.model.formTree.FormTree) RowBasedJsonWriter(org.activityinfo.store.query.output.RowBasedJsonWriter) ColumnJsonWriter(org.activityinfo.store.query.output.ColumnJsonWriter) ColumnSet(org.activityinfo.model.query.ColumnSet)

Example 7 with ColumnSet

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();
}
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 8 with ColumnSet

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();
}
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 9 with ColumnSet

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());
}
Also used : EffectiveTableModel(org.activityinfo.analysis.table.EffectiveTableModel) XlsTableWriter(org.activityinfo.io.xls.XlsTableWriter) TableViewModel(org.activityinfo.analysis.table.TableViewModel) OutputStream(java.io.OutputStream) ColumnSet(org.activityinfo.model.query.ColumnSet) GeneratedResource(org.activityinfo.server.generated.GeneratedResource) EffectiveTableModel(org.activityinfo.analysis.table.EffectiveTableModel) TableModel(org.activityinfo.model.analysis.TableModel) ExportResult(org.activityinfo.model.job.ExportResult)

Example 10 with ColumnSet

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

Aggregations

ColumnSet (org.activityinfo.model.query.ColumnSet)50 QueryModel (org.activityinfo.model.query.QueryModel)42 Test (org.junit.Test)28 ColumnView (org.activityinfo.model.query.ColumnView)24 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)14 FormTree (org.activityinfo.model.formTree.FormTree)12 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)12 ResourceId (org.activityinfo.model.resource.ResourceId)10 FormClass (org.activityinfo.model.form.FormClass)7 NullFormScanCache (org.activityinfo.store.query.shared.NullFormScanCache)7 Nullable (javax.annotation.Nullable)6 Charsets (com.google.common.base.Charsets)5 Operation (io.swagger.v3.oas.annotations.Operation)5 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)5 ColumnModel (org.activityinfo.model.query.ColumnModel)5 RowBasedJsonWriter (org.activityinfo.store.query.output.RowBasedJsonWriter)5 PrintWriter (java.io.PrintWriter)4 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)4 FormField (org.activityinfo.model.form.FormField)4 RecordRef (org.activityinfo.model.type.RecordRef)4