Search in sources :

Example 1 with LookupKey

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));
}
Also used : LookupModel(org.activityinfo.ui.client.lookup.model.LookupModel) LookupKey(org.activityinfo.model.formTree.LookupKey) Observable(org.activityinfo.observable.Observable)

Example 2 with LookupKey

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));
}
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)

Example 3 with LookupKey

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());
    }
}
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 4 with LookupKey

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));
    }
}
Also used : LookupKeySet(org.activityinfo.model.formTree.LookupKeySet) FormulaNode(org.activityinfo.model.formula.FormulaNode) LookupKey(org.activityinfo.model.formTree.LookupKey) ImmutableTableColumn(org.activityinfo.model.analysis.ImmutableTableColumn)

Example 5 with LookupKey

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;
    });
}
Also used : LookupKey(org.activityinfo.model.formTree.LookupKey) ColumnView(org.activityinfo.model.query.ColumnView)

Aggregations

LookupKey (org.activityinfo.model.formTree.LookupKey)8 LookupKeySet (org.activityinfo.model.formTree.LookupKeySet)6 FormTree (org.activityinfo.model.formTree.FormTree)5 FormulaNode (org.activityinfo.model.formula.FormulaNode)5 Test (org.junit.Test)5 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)2 ColumnView (org.activityinfo.model.query.ColumnView)2 ParsedFormula (org.activityinfo.analysis.ParsedFormula)1 ImmutableTableColumn (org.activityinfo.model.analysis.ImmutableTableColumn)1 FormField (org.activityinfo.model.form.FormField)1 SymbolNode (org.activityinfo.model.formula.SymbolNode)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1 QueryModel (org.activityinfo.model.query.QueryModel)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 TextType (org.activityinfo.model.type.primitive.TextType)1 Observable (org.activityinfo.observable.Observable)1 LookupModel (org.activityinfo.ui.client.lookup.model.LookupModel)1