use of org.activityinfo.model.formTree.LookupKey in project activityinfo by bedatadriven.
the class LookupViewModel method select.
public void select(LookupKey lookupKey, String keyChoice) {
Map<LookupKey, String> newSelectedKeys = new HashMap<>();
for (Map.Entry<LookupKey, Observable<Optional<String>>> entry : selectedKeys.entrySet()) {
Optional<String> selectedKey = entry.getValue().get();
if (selectedKey.isPresent()) {
newSelectedKeys.put(entry.getKey(), selectedKey.get());
}
}
newSelectedKeys.put(lookupKey, keyChoice);
// Clear the child choices
clearChildChoices(lookupKey, newSelectedKeys);
model.updateIfNotEqual(new LookupModel(newSelectedKeys));
}
use of org.activityinfo.model.formTree.LookupKey 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));
}
use of org.activityinfo.model.formTree.LookupKey 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.LookupKey in project activityinfo by bedatadriven.
the class EffectiveTableModel method addKeyColumns.
private void addKeyColumns(List<EffectiveTableColumn> columns, FormTree.Node node) {
LookupKeySet lookupKeySet = new LookupKeySet(formTree, node.getField());
Map<LookupKey, FormulaNode> formulas = lookupKeySet.getKeyFormulas(node.getFieldId());
for (LookupKey lookupKey : lookupKeySet.getLookupKeys()) {
ImmutableTableColumn tableColumn = ImmutableTableColumn.builder().id(node.getFieldId().asString() + "_k" + lookupKey.getKeyIndex()).formula(formulas.get(lookupKey).toString()).label(lookupKey.getKeyLabel()).build();
columns.add(new EffectiveTableColumn(formTree, tableColumn));
}
}
use of org.activityinfo.model.formTree.LookupKey in project activityinfo by bedatadriven.
the class KeyMatrix method findKeyLabels.
/**
* For a given (observable) record reference, find the string labels for each of its
* {@link LookupKey}s.
*/
public Observable<Map<LookupKey, String>> findKeyLabels(RecordRef ref) {
return keyColumns.transform(columns -> {
Map<LookupKey, String> labels = new HashMap<>();
int rowIndex = findRowIndex(columns, ref);
if (rowIndex != -1) {
for (LookupKey lookupKey : keyFormulas.keySet()) {
ColumnView keyColumn = columns.getColumnView(keyColumn(lookupKey));
labels.put(lookupKey, keyColumn.getString(rowIndex));
}
}
return labels;
});
}
Aggregations