Search in sources :

Example 1 with FormTree

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));
                }
            }
        }
    }
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceType(org.activityinfo.model.type.ReferenceType)

Example 2 with FormTree

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);
    }
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) CssFloatLayoutContainer(com.sencha.gxt.widget.core.client.container.CssFloatLayoutContainer) SubFormKind(org.activityinfo.model.form.SubFormKind) FormTree(org.activityinfo.model.formTree.FormTree)

Example 3 with FormTree

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));
}
Also used : FormulaValidator(org.activityinfo.analysis.FormulaValidator) FormTree(org.activityinfo.model.formTree.FormTree) FormClass(org.activityinfo.model.form.FormClass) TestBatchFormClassProvider(org.activityinfo.model.formTree.TestBatchFormClassProvider) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) Test(org.junit.Test)

Example 4 with FormTree

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"))));
}
Also used : FormMetadataProvider(org.activityinfo.model.formTree.FormMetadataProvider) RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) FormMetadata(org.activityinfo.model.form.FormMetadata) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) TestingFormStore(org.activityinfo.ui.client.store.TestingFormStore) FormStore(org.activityinfo.ui.client.store.FormStore) Test(org.junit.Test)

Example 5 with FormTree

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));
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) LookupKeySet(org.activityinfo.model.formTree.LookupKeySet) FormulaNode(org.activityinfo.model.formula.FormulaNode) FormTree(org.activityinfo.model.formTree.FormTree) LookupKey(org.activityinfo.model.formTree.LookupKey) FormField(org.activityinfo.model.form.FormField) Test(org.junit.Test)

Aggregations

FormTree (org.activityinfo.model.formTree.FormTree)55 Test (org.junit.Test)35 ResourceId (org.activityinfo.model.resource.ResourceId)12 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)10 FormClass (org.activityinfo.model.form.FormClass)9 ColumnSet (org.activityinfo.model.query.ColumnSet)9 QueryModel (org.activityinfo.model.query.QueryModel)8 ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)8 PastedTable (org.activityinfo.ui.client.component.importDialog.model.source.PastedTable)8 FormField (org.activityinfo.model.form.FormField)7 RecordRef (org.activityinfo.model.type.RecordRef)7 LookupKeySet (org.activityinfo.model.formTree.LookupKeySet)6 FormulaNode (org.activityinfo.model.formula.FormulaNode)6 ReferenceType (org.activityinfo.model.type.ReferenceType)6 LookupKey (org.activityinfo.model.formTree.LookupKey)5 ValidatedRowTable (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable)5 Optional (com.google.common.base.Optional)4 ColumnView (org.activityinfo.model.query.ColumnView)4 Nullable (javax.annotation.Nullable)3 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)3