Search in sources :

Example 26 with QueryModel

use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.

the class AbstractMySqlTest method queryWhere.

protected final void queryWhere(ResourceId formClassId, List<String> fields, String filter) {
    QueryModel queryModel = new QueryModel(formClassId);
    queryModel.selectResourceId().as("_id");
    for (String field : fields) {
        queryModel.selectExpr(field).setId(field);
    }
    queryModel.setFilter(filter);
    query(queryModel);
}
Also used : QueryModel(org.activityinfo.model.query.QueryModel)

Example 27 with QueryModel

use of org.activityinfo.model.query.QueryModel 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());
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) StringWriter(java.io.StringWriter) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) Stopwatch(com.google.common.base.Stopwatch) ColumnSet(org.activityinfo.model.query.ColumnSet) RowBasedJsonWriter(org.activityinfo.store.query.output.RowBasedJsonWriter) QueryModel(org.activityinfo.model.query.QueryModel) FormField(org.activityinfo.model.form.FormField) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) Test(org.junit.Test)

Example 28 with QueryModel

use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.

the class MySqlCatalogTest method testNoColumns.

@Test
public void testNoColumns() {
    QueryModel queryModel = new QueryModel(CuidAdapter.activityFormClass(1));
    query(queryModel);
    assertThat(columnSet.getNumRows(), equalTo(3));
}
Also used : QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 29 with QueryModel

use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.

the class FormResource method getDefaultQueryModel.

@GET
@NoCache
@Path("query/defaultModel")
@Produces(MediaType.APPLICATION_JSON)
public Response getDefaultQueryModel() {
    assertVisible(formId);
    QueryModel queryModel = buildDefaultQueryModel();
    return Response.ok(queryModel.toJsonString()).type(JSON_CONTENT_TYPE).build();
}
Also used : QueryModel(org.activityinfo.model.query.QueryModel)

Example 30 with QueryModel

use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.

the class RootResource method getCountries.

@GET
@Path("/countries")
@JsonView(DTOViews.List.class)
@Produces(MediaType.APPLICATION_JSON)
public List<CountryDTO> getCountries() {
    QueryModel model = new QueryModel(CountryTable.FORM_CLASS_ID);
    model.selectField(CountryTable.CODE_FIELD_ID).as("code");
    model.selectField(CountryTable.NAME_FIELD_ID).as("name");
    return dispatcher.execute(new GetCountries()).getData();
}
Also used : GetCountries(org.activityinfo.legacy.shared.command.GetCountries) QueryModel(org.activityinfo.model.query.QueryModel) JsonView(org.codehaus.jackson.map.annotate.JsonView)

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