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);
}
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());
}
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));
}
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();
}
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();
}
Aggregations