Search in sources :

Example 6 with FormTreeBuilder

use of org.activityinfo.model.formTree.FormTreeBuilder in project activityinfo by bedatadriven.

the class FormResource method buildDefaultQueryModel.

private QueryModel buildDefaultQueryModel() {
    QueryModel queryModel;
    FormTreeBuilder treeBuilder = new FormTreeBuilder(backend.getStorage());
    FormTree tree = treeBuilder.queryTree(formId);
    queryModel = new DefaultQueryBuilder(tree).build();
    return queryModel;
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) QueryModel(org.activityinfo.model.query.QueryModel) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) JsonFormTreeBuilder(org.activityinfo.model.formTree.JsonFormTreeBuilder)

Example 7 with FormTreeBuilder

use of org.activityinfo.model.formTree.FormTreeBuilder in project activityinfo by bedatadriven.

the class NodeMatcherTest method tree.

private FormTree tree() {
    if (rootFormClass == null) {
        throw new IllegalStateException("Root FormClass is unset");
    }
    FormClassProvider provider = new FormClassProvider() {

        @Override
        public FormClass getFormClass(ResourceId formId) {
            if (rootFormClass.getId().equals(formId)) {
                return rootFormClass;
            }
            FormClass formClass = formClasses.get(formId);
            if (formClass == null) {
                throw new IllegalArgumentException(formId.toString());
            }
            return formClass;
        }
    };
    FormTreeBuilder builder = new FormTreeBuilder(provider);
    return builder.queryTree(rootFormClass.getId());
}
Also used : FormClassProvider(org.activityinfo.model.formTree.FormClassProvider) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder)

Example 8 with FormTreeBuilder

use of org.activityinfo.model.formTree.FormTreeBuilder in project activityinfo by bedatadriven.

the class BatchingFormTreeBuilder method queryTrees.

public Map<ResourceId, FormTree> queryTrees(Collection<ResourceId> rootFormIds) {
    // Fetch Required FormClasses in batches
    Set<ResourceId> toFetch = Sets.newHashSet();
    toFetch.addAll(rootFormIds);
    while (!toFetch.isEmpty()) {
        // First round: fetch root form classes
        List<FormClass> fetched = fetchFormClasses(toFetch);
        toFetch.clear();
        // Find newly referenced forms
        for (FormClass formClass : fetched) {
            if (formClass.isSubForm()) {
                if (!formCache.containsKey(formClass.getParentFormId().get())) {
                    toFetch.add(formClass.getParentFormId().get());
                }
            }
            for (FormField formField : formClass.getFields()) {
                if (formField.getType() instanceof ReferenceType) {
                    ReferenceType refType = (ReferenceType) formField.getType();
                    for (ResourceId refFormId : refType.getRange()) {
                        if (!formCache.containsKey(refFormId)) {
                            toFetch.add(refFormId);
                        }
                    }
                } else if (formField.getType() instanceof SubFormReferenceType) {
                    SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
                    if (!formCache.containsKey(subFormType.getClassId())) {
                        toFetch.add(subFormType.getClassId());
                    }
                }
            }
        }
    }
    // Now assemble trees
    Map<ResourceId, FormTree> treeMap = new HashMap<>();
    FormTreeBuilder builder = new FormTreeBuilder(new FormClassProvider() {

        @Override
        public FormClass getFormClass(ResourceId formId) {
            return formCache.get(formId);
        }
    });
    for (ResourceId rootFormId : rootFormIds) {
        treeMap.put(rootFormId, builder.queryTree(rootFormId));
    }
    return treeMap;
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ReferenceType(org.activityinfo.model.type.ReferenceType) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormClassProvider(org.activityinfo.model.formTree.FormClassProvider) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField)

Example 9 with FormTreeBuilder

use of org.activityinfo.model.formTree.FormTreeBuilder in project activityinfo by bedatadriven.

the class FormTreeBuilderTest method buildAndLoadBlankSubform.

@Test
public void buildAndLoadBlankSubform() {
    List<TestForm> testForms = Lists.newArrayList();
    GenericForm generic = new GenericForm();
    BlankSubForm blank = new BlankSubForm(generic);
    testForms.add(generic);
    testForms.add(blank);
    TestFormMetadataProvider provider = new TestFormMetadataProvider(testForms);
    FormTreeBuilder builder = new FormTreeBuilder(provider);
    // Build the form tree, and attempt to fetch the blank sub form
    FormTree tree = builder.queryTree(generic.getFormId());
    tree.getFormClass(blank.getFormId());
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) Test(org.junit.Test)

Example 10 with FormTreeBuilder

use of org.activityinfo.model.formTree.FormTreeBuilder in project activityinfo by bedatadriven.

the class SchemaCsvWriterV3Test method importSurveyForm.

@Test
public void importSurveyForm() {
    PastedTable pastedTable = new PastedTable(expectedSurveyExport);
    SchemaImporterV3 importer = new SchemaImporterV3(database.getId(), null, null);
    assertTrue("columns found", importer.parseColumns(pastedTable));
    boolean success = importer.processRows();
    for (SafeHtml warning : importer.getWarnings()) {
        System.out.println(warning);
    }
    assertTrue(success);
    List<FormClass> formClasses = importer.toSave();
    formClassProvider.addAll(formClasses);
    FormTreeBuilder treeBuilder = new FormTreeBuilder(formClassProvider);
    FormTreePrettyPrinter prettyPrinter = new FormTreePrettyPrinter();
    for (FormClass formClass : formClasses) {
        if (!formClass.isSubForm()) {
            prettyPrinter.printTree(treeBuilder.queryTree(formClass.getId()));
        }
    }
}
Also used : SchemaImporterV3(org.activityinfo.ui.client.page.config.design.importer.SchemaImporterV3) PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) FormClass(org.activityinfo.model.form.FormClass) FormTreePrettyPrinter(org.activityinfo.model.formTree.FormTreePrettyPrinter) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) Test(org.junit.Test)

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