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