Search in sources :

Example 11 with FormTreeBuilder

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());
}
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 12 with FormTreeBuilder

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

Example 13 with FormTreeBuilder

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

Example 14 with FormTreeBuilder

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));
}
Also used : FormStorageProvider(org.activityinfo.store.spi.FormStorageProvider) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder)

Example 15 with FormTreeBuilder

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);
    }
}
Also used : FormPermissions(org.activityinfo.model.form.FormPermissions) ColumnView(org.activityinfo.model.query.ColumnView) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) FormulaNode(org.activityinfo.model.formula.FormulaNode) FormTree(org.activityinfo.model.formTree.FormTree)

Aggregations

FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)16 FormTree (org.activityinfo.model.formTree.FormTree)10 FormClass (org.activityinfo.model.form.FormClass)7 Test (org.junit.Test)7 JsonFormTreeBuilder (org.activityinfo.model.formTree.JsonFormTreeBuilder)5 ResourceId (org.activityinfo.model.resource.ResourceId)4 JsonValue (org.activityinfo.json.JsonValue)3 FormField (org.activityinfo.model.form.FormField)3 FormClassProvider (org.activityinfo.model.formTree.FormClassProvider)3 ColumnSet (org.activityinfo.model.query.ColumnSet)2 ColumnView (org.activityinfo.model.query.ColumnView)2 QueryModel (org.activityinfo.model.query.QueryModel)2 ReferenceType (org.activityinfo.model.type.ReferenceType)2 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)2 Stopwatch (com.google.common.base.Stopwatch)1 Gson (com.google.gson.Gson)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1