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