use of org.activityinfo.model.formTree.FormTreeBuilder 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.formTree.FormTreeBuilder in project activityinfo by bedatadriven.
the class MySqlCatalogTest method queryFormTree.
private FormTree queryFormTree(ResourceId classId) {
FormTreeBuilder builder = new FormTreeBuilder(catalog);
FormTree formTree = builder.queryTree(classId);
JsonValue formTreeObject = JsonFormTreeBuilder.toJson(formTree);
formTree = JsonFormTreeBuilder.fromJson(formTreeObject);
return formTree;
}
use of org.activityinfo.model.formTree.FormTreeBuilder in project activityinfo by bedatadriven.
the class MySqlCatalogTest method testReportingPeriod.
@Test
public void testReportingPeriod() {
FormTreeBuilder treeBuilder = new FormTreeBuilder(catalog);
FormTree formTree = treeBuilder.queryTree(CuidAdapter.reportingPeriodFormClass(3));
FormTreePrettyPrinter.print(formTree);
query(CuidAdapter.reportingPeriodFormClass(3), "rate", "date1", "date2", "site.partner", "site.partner.label", "site.location.label");
assertThat(column("date1"), hasValues("2009-01-01", "2009-02-01", "2009-03-01"));
}
use of org.activityinfo.model.formTree.FormTreeBuilder in project activityinfo by bedatadriven.
the class ActivityInfoClientAsyncStub method getFormTree.
@Override
public Promise<FormTree> getFormTree(ResourceId formId) {
FormStorageProvider newCatalog = newCatalog();
FormTreeBuilder treeBuilder = new FormTreeBuilder(newCatalog);
return Promise.resolved(treeBuilder.queryTree(formId));
}
use of org.activityinfo.model.formTree.FormTreeBuilder in project activityinfo by bedatadriven.
the class FormScanBatch method computePermissionFilter.
private Slot<TableFilter> computePermissionFilter(ResourceId formId) {
FormPermissions permissions = supervisor.getFormPermissions(formId);
if (!permissions.isVisible()) {
return new PendingSlot<>(TableFilter.NONE_SELECTED);
}
if (!permissions.hasVisibilityFilter()) {
return new PendingSlot<>(TableFilter.ALL_SELECTED);
}
// Otherwise apply per-record permissions
try {
FormTreeBuilder formTreeBuilder = new FormTreeBuilder(formClassProvider);
FormTree formTree = formTreeBuilder.queryTree(formId);
FormulaNode formula = FormulaParser.parse(permissions.getViewFilter());
QueryEvaluator evaluator = new QueryEvaluator(FilterLevel.NONE, formTree, this);
Slot<ColumnView> filterView = evaluator.evaluateExpression(formula);
return new MemoizedSlot<>(filterView, new Function<ColumnView, TableFilter>() {
@Override
public TableFilter apply(ColumnView columnView) {
return new TableFilter(columnView);
}
});
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to parse visibility filter", e);
LOGGER.severe("Error parsing visibility filter '" + permissions.getViewFilter() + " in form " + formId + ": " + e.getMessage() + ". " + "For security reasons, no results will be shown");
return new PendingSlot<>(TableFilter.NONE_SELECTED);
}
}
Aggregations