Search in sources :

Example 6 with FormTree

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

the class LookupKeySetTest method overlappingHierarchies.

/**
 * For classical location types especially, a reference field's range might include multiple forms,
 * such as [province, territory, health zone].
 *
 * This means that the user can <i>either</i> select a province, <i>or</i> a territory, <i>or</i>
 * a health zone.
 *
 * In this case, you also have a hierarchy
 * <pre>
 *               Province.Name
 *                 ^         ^
 *                 |         |
 *     Territory.Name     Health Zone.Name
 *        ^
 *        |
 *     Sector.Name
 * </pre>
 *
 * But the record reference depends on which fields are completed. If only province is completed,
 * then the selected record is from province. Otherwise from territory, etc.
 */
@Test
public void overlappingHierarchies() {
    TestingStorageProvider catalog = setup.getCatalog();
    LocaliteForm localiteForm = catalog.getLocaliteForm();
    FormTree formTree = setup.getFormTree(localiteForm.getFormId());
    LookupKeySet lookupKeySet = new LookupKeySet(formTree, localiteForm.getAdminField());
    // The resulting key set should only include 3 keys, not 6
    // because the three different forms in the range overlap
    assertThat(lookupKeySet.getLookupKeys(), hasSize(3));
    assertThat(lookupKeySet.getKey(0).getKeyLabel(), equalTo("Province Name"));
    assertThat(lookupKeySet.getKey(1).getKeyLabel(), equalTo("Territory Name"));
    assertThat(lookupKeySet.getKey(2).getKeyLabel(), equalTo("Zone de Sante Name"));
    // We need the relationships between the forms
    ResourceId provinceId = catalog.getProvince().getFormId();
    ResourceId territoryId = catalog.getTerritory().getFormId();
    assertThat(lookupKeySet.getAncestorForms(provinceId), hasSize(0));
    assertThat(lookupKeySet.getAncestorForms(territoryId), contains(provinceId));
    // Formulas...
    for (LookupKey lookupKey : lookupKeySet.getLeafKeys()) {
        System.out.println(lookupKey.getKeyLabel() + " => " + lookupKey.getKeyFormulas());
    }
}
Also used : LookupKeySet(org.activityinfo.model.formTree.LookupKeySet) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) LookupKey(org.activityinfo.model.formTree.LookupKey) Test(org.junit.Test)

Example 7 with FormTree

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

the class OperationFiltersTest method simpleRootFieldTest.

@Test
public void simpleRootFieldTest() {
    NfiForm nfiForm = setup.getCatalog().getNfiForm();
    FormTree formTree = setup.getCatalog().getFormTree(nfiForm.getFormId());
    FormPermissions permissions = new FormPermissions.Builder().allowFilteredView(nfiForm.getVillageField().getId() + " == 'g12345'").allowFilteredEdit(nfiForm.getVillageField().getId() + "=='g12345'").build();
    PermissionFilters filters = new PermissionFilters(formTree, permissions);
    assertThat(filters.getReferenceBaseFilter(nfiForm.getVillageField().getId()).get().asExpression(), equalTo("[_id] == \"g12345\""));
}
Also used : FormPermissions(org.activityinfo.model.form.FormPermissions) FormTree(org.activityinfo.model.formTree.FormTree) NfiForm(org.activityinfo.store.testing.NfiForm) Test(org.junit.Test)

Example 8 with FormTree

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

the class LookupViewModelTest method overlappingHierarchies.

@Test
public void overlappingHierarchies() {
    LocaliteForm locationForm = catalog.getLocaliteForm();
    FormTree formTree = catalog.getFormTree(locationForm.getFormId());
    LookupViewModel viewModel = new LookupViewModel(setup.getFormStore(), formTree, locationForm.getAdminField());
    assertThat(viewModel.getLookupKeys(), hasSize(3));
    LookupKeyViewModel province = viewModel.getLookupKeys().get(0);
    assertThat(province.getKeyLabel(), equalTo("Province Name"));
    // The second level should now reflect these choices
    LookupKeyViewModel territory = viewModel.getLookupKeys().get(1);
    assertThat(territory.getKeyLabel(), equalTo("Territory Name"));
    // We also have a third level -- Health Zone or "Zone de Sante" which
    // is related to province, but NOT territory.
    LookupKeyViewModel healthZone = viewModel.getLookupKeys().get(2);
    assertThat(healthZone.getKeyLabel(), equalTo("Zone de Sante Name"));
    // Connect to the lists
    Connection<List<String>> provinceList = setup.connect(province.getChoices());
    Connection<List<String>> territoryList = setup.connect(territory.getChoices());
    Connection<List<String>> zoneList = setup.connect(healthZone.getChoices());
    // Connect to the selection
    Connection<Set<RecordRef>> selection = setup.connect(viewModel.getSelectedRecords());
    // Initially... no selection
    assertThat(selection.assertLoaded().isEmpty(), equalTo(true));
    // Initially the root level should have all choices (16)
    assertThat(provinceList.assertLoaded(), hasSize(catalog.getProvince().getCount()));
    // Select a province.
    viewModel.select(province.getLookupKey(), province.getChoices().get().get(2));
    // Choosing just a province is a valid selection, so we should now have a value
    assertThat(selection.assertLoaded(), hasSize(1));
    // ..and the options available to the second level
    territoryList.assertChanged();
    System.out.println(territoryList.assertLoaded());
    assertThat(territoryList.assertLoaded(), hasSize(7));
    System.out.println(territoryList.assertLoaded());
    // Select a territory
    viewModel.select(territory.getLookupKey(), territoryList.assertLoaded().get(2));
    zoneList.assertChanged();
    // No we should still have only one selected record, but this time
    // territory and not province because province is a parent of territory.
    RecordRef territoryRef = new RecordRef(catalog.getTerritory().getFormId(), ResourceId.valueOf("c23"));
    assertThat(selection.assertLoaded(), contains(territoryRef));
    // We should ALSO be able to select a Zone de Sante
    viewModel.select(healthZone.getLookupKey(), zoneList.assertLoaded().get(5));
    RecordRef zoneRef = new RecordRef(catalog.getHealthZone().getFormId(), ResourceId.valueOf("c165"));
    assertThat(selection.assertLoaded(), containsInAnyOrder(territoryRef, zoneRef));
}
Also used : ColumnSet(org.activityinfo.model.query.ColumnSet) FormTree(org.activityinfo.model.formTree.FormTree) RecordRef(org.activityinfo.model.type.RecordRef) Test(org.junit.Test)

Example 9 with FormTree

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

the class LookupViewModelTest method overlappingHierarchiesInitialSelection.

@Test
public void overlappingHierarchiesInitialSelection() {
    LocaliteForm locationForm = catalog.getLocaliteForm();
    FormTree formTree = catalog.getFormTree(locationForm.getFormId());
    LookupViewModel viewModel = new LookupViewModel(setup.getFormStore(), formTree, locationForm.getAdminField());
    RecordRef territoryRef = new RecordRef(catalog.getTerritory().getFormId(), ResourceId.valueOf("c23"));
    Connection<Optional<String>> province = setup.connect(viewModel.getLookupKeys().get(0).getSelectedKey());
    Connection<Optional<String>> territory = setup.connect(viewModel.getLookupKeys().get(1).getSelectedKey());
    Connection<Optional<String>> healthZone = setup.connect(viewModel.getLookupKeys().get(2).getSelectedKey());
    // Initially the key value labels should be empty
    assertThat(province.assertLoaded().isPresent(), equalTo(false));
    assertThat(territory.assertLoaded().isPresent(), equalTo(false));
    assertThat(healthZone.assertLoaded().isPresent(), equalTo(false));
    // If the initial selection is a territory then the province and territory labels should be loaded
    viewModel.setInitialSelection(Collections.singleton(territoryRef));
    assertThat(province.assertLoaded().get(), equalTo("Province 11"));
    assertThat(territory.assertLoaded().get(), equalTo("Territory 24"));
    assertThat(healthZone.assertLoaded().isPresent(), equalTo(false));
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) Optional(com.google.common.base.Optional) RecordRef(org.activityinfo.model.type.RecordRef) Test(org.junit.Test)

Example 10 with FormTree

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

the class FieldTreeBuilderTest method subForms.

@Test
public void subForms() {
    FormSource formStore = new FormSourceSyncImpl(new TestingStorageProvider(), 1);
    FormTree tree = formStore.getFormTree(ReferralSubForm.FORM_ID).waitFor();
    TreeStore<MeasureTreeNode> treeStore = new TreeStore<>(MeasureTreeNode::getId);
    FieldTreeBuilder builder = new FieldTreeBuilder(tree, treeStore);
    try {
        builder.build(tree);
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("===== FormTree === ");
    FormTreePrettyPrinter.print(tree);
    System.out.println();
    System.out.println("===== TreeStore === ");
    prettyPrint(treeStore);
}
Also used : TreeStore(com.sencha.gxt.data.shared.TreeStore) FormTree(org.activityinfo.model.formTree.FormTree) TestingStorageProvider(org.activityinfo.store.testing.TestingStorageProvider) FormSourceSyncImpl(org.activityinfo.store.query.server.FormSourceSyncImpl) FormSource(org.activityinfo.store.query.shared.FormSource) 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