use of org.activityinfo.model.formTree.FormTree in project activityinfo by bedatadriven.
the class FormForest method collectReferenced.
private void collectReferenced(FormTree tree, Iterable<FormTree.Node> parentFields, Set<ResourceId> visited, List<FormClass> list) {
for (FormTree.Node parentField : parentFields) {
if (parentField.getType() instanceof ReferenceType) {
for (ResourceId formId : parentField.getRange()) {
if (!visited.contains(formId)) {
visited.add(formId);
// depth first...
collectReferenced(tree, parentField.getChildren(formId), visited, list);
// now ourselves
list.add(tree.getFormClass(formId));
}
}
}
}
}
use of org.activityinfo.model.formTree.FormTree in project activityinfo by bedatadriven.
the class FormPanel method addSubForm.
private void addSubForm(FormTree formTree, FormTree.Node node) {
SubFormReferenceType subFormType = (SubFormReferenceType) node.getType();
FormTree subTree = formTree.subTree(subFormType.getClassId());
SubFormKind subFormKind = subTree.getRootFormClass().getSubFormKind();
if (subFormKind == SubFormKind.REPEATING) {
RepeatingSubFormPanel subPanel = new RepeatingSubFormPanel(formSource, node, subTree, inputHandler);
panel.add(subPanel, new CssFloatLayoutContainer.CssFloatData(1));
repeatingSubForms.add(subPanel);
} else {
KeyedSubFormPanel subPanel = new KeyedSubFormPanel(recordRef, formSource, node, subTree, inputHandler);
panel.add(subPanel, new CssFloatLayoutContainer.CssFloatData(1));
keyedSubFormPanels.add(subPanel);
}
}
use of org.activityinfo.model.formTree.FormTree in project activityinfo by bedatadriven.
the class FormulaValidatorTest method invalidFormSchema.
@Test
public void invalidFormSchema() {
FormClass formClass = new FormClass(ResourceId.valueOf("XYZ"));
formClass.addField(ResourceId.valueOf("F1")).setCode("A").setLabel("Field A1").setType(TextType.SIMPLE);
formClass.addField(ResourceId.valueOf("F2")).setCode("A").setLabel("Field A2").setType(TextType.SIMPLE);
TestBatchFormClassProvider formProvider = new TestBatchFormClassProvider();
formProvider.add(formClass);
FormTreeBuilder formTreeBuilder = new FormTreeBuilder(formProvider);
FormTree formTree = formTreeBuilder.queryTree(formClass.getId());
FormulaValidator validator = new FormulaValidator(formTree);
assertFalse(validator.validate(FormulaParser.parse("A")));
assertThat(validator.getErrors(), hasSize(1));
}
use of org.activityinfo.model.formTree.FormTree in project activityinfo by bedatadriven.
the class FormInputViewModelTest method hiddenSubForm.
/**
* Test the ViewModel for when the user does not have access to a referenced sub form.
*/
@Test
public void hiddenSubForm() {
FormClass parentForm = new FormClass(ResourceId.valueOf("PARENT_FORM"));
parentForm.addField(ResourceId.valueOf("F1")).setLabel("What is your name?").setType(TextType.SIMPLE);
parentForm.addField(ResourceId.valueOf("F2")).setLabel("What are your secrets?").setType(new SubFormReferenceType(ResourceId.valueOf("SECRET_FORM")));
FormTreeBuilder treeBuilder = new FormTreeBuilder(new FormMetadataProvider() {
@Override
public FormMetadata getFormMetadata(ResourceId formId) {
if (formId.equals(parentForm.getId())) {
return FormMetadata.of(1, parentForm, FormPermissions.owner());
} else {
return FormMetadata.forbidden(formId);
}
}
});
FormTree formTree = treeBuilder.queryTree(parentForm.getId());
FormStore formStore = EasyMock.createMock(FormStore.class);
EasyMock.replay(formStore);
FormInputViewModelBuilder viewModelBuilder = new FormInputViewModelBuilder(formStore, formTree, new TestingActivePeriodMemory());
FormInputViewModel viewModel = viewModelBuilder.build(new FormInputModel(new RecordRef(parentForm.getId(), ResourceId.valueOf("R1"))));
}
use of org.activityinfo.model.formTree.FormTree in project activityinfo by bedatadriven.
the class LookupKeySetTest method multipleTextKeysTest.
@Test
public void multipleTextKeysTest() {
TestingStorageProvider catalog = setup.getCatalog();
SimpleReferenceForm refForm = catalog.getSimpleReferenceForm();
MultipleTextKeysForm multTextKeyForm = catalog.getMultipleTextKeysForm();
FormField refField = refForm.getRefField();
CompoundExpr pathToKey1 = new CompoundExpr(refField.getId(), MultipleTextKeysForm.FIRST_TEXT_KEY_ID.asString());
CompoundExpr pathToKey2 = new CompoundExpr(refField.getId(), MultipleTextKeysForm.SECOND_TEXT_KEY_ID.asString());
FormTree formTree = catalog.getFormTree(multTextKeyForm.getFormId());
LookupKeySet lookupKeySet = new LookupKeySet(formTree, refField);
Map<LookupKey, FormulaNode> formulas = lookupKeySet.getKeyFormulas(refField.getId());
assertThat(formulas.values(), containsInAnyOrder(pathToKey1, pathToKey2));
}
Aggregations