Search in sources :

Example 1 with ReferenceValue

use of org.activityinfo.model.type.ReferenceValue in project activityinfo by bedatadriven.

the class ReferenceFieldWidget method init.

@Override
public void init(FieldValue value) {
    ReferenceValue referenceValue = (ReferenceValue) value;
    RecordRef recordRef = referenceValue.getOnlyReference();
    viewModel.setInitialSelection(referenceValue.getReferences());
}
Also used : ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef)

Example 2 with ReferenceValue

use of org.activityinfo.model.type.ReferenceValue in project activityinfo by bedatadriven.

the class ReferenceFieldWidget method onSelection.

private void onSelection(SelectionEvent<String> event) {
    LOGGER.info("onSelection: " + event.getSelectedItem());
    viewModel.getSelectedRecords().once().then(new AsyncCallback<Set<RecordRef>>() {

        @Override
        public void onFailure(Throwable caught) {
        }

        @Override
        public void onSuccess(Set<RecordRef> result) {
            if (result.isEmpty()) {
                fieldUpdater.update(FieldInput.EMPTY);
            } else {
                fieldUpdater.update(new FieldInput(new ReferenceValue(result)));
            }
        }
    });
}
Also used : Set(java.util.Set) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) FieldInput(org.activityinfo.ui.client.input.model.FieldInput)

Example 3 with ReferenceValue

use of org.activityinfo.model.type.ReferenceValue in project activityinfo by bedatadriven.

the class LookupKeySetTest method labelTest.

@Test
public void labelTest() {
    NfiForm nfiForm = setup.getNfiForm();
    VillageForm villageForm = setup.getVillageForm();
    AdminLevelForm territoryForm = villageForm.getParentForm();
    AdminLevelForm provinceForm = territoryForm.getParentForm().get();
    Observable<Maybe<RecordTree>> nfiRecordTree = setup.getFormStore().getRecordTree(nfiForm.getRecordRef(0));
    Connection<Maybe<RecordTree>> nfiRecordTreeView = setup.connect(nfiRecordTree);
    RecordTree tree = nfiRecordTreeView.assertLoaded().get();
    LookupKeySet lookupKeySet = new LookupKeySet(tree.getFormTree(), tree.getFormTree().getRootField(nfiForm.getVillageField().getId()).getField());
    assertThat(lookupKeySet.getLookupKeys().size(), equalTo(3));
    ReferenceValue referenceValue = (ReferenceValue) tree.getRoot().get(nfiForm.getVillageField().getId());
    RecordRef villageRef = referenceValue.getOnlyReference();
    RecordTree villageTree = tree.subTree(villageRef);
    referenceValue = (ReferenceValue) villageTree.getRoot().get(villageForm.getAdminFieldId());
    RecordRef territoryRef = referenceValue.getOnlyReference();
    RecordTree territoryTree = villageTree.subTree(territoryRef);
    referenceValue = (ReferenceValue) territoryTree.getRoot().get(territoryForm.getParentFieldId());
    RecordRef provinceRef = referenceValue.getOnlyReference();
    Maybe<String> villageLabel = lookupKeySet.label(tree, villageRef);
    Maybe<String> territoryLabel = lookupKeySet.label(tree, territoryRef);
    Maybe<String> provinceLabel = lookupKeySet.label(tree, provinceRef);
    assertThat(villageLabel, equalTo(Maybe.of("Village 660")));
    assertThat(territoryLabel, equalTo(Maybe.of("Territory 85")));
    assertThat(provinceLabel, equalTo(Maybe.of("Province 11")));
}
Also used : RecordTree(org.activityinfo.model.formTree.RecordTree) Maybe(org.activityinfo.promise.Maybe) LookupKeySet(org.activityinfo.model.formTree.LookupKeySet) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) Test(org.junit.Test)

Example 4 with ReferenceValue

use of org.activityinfo.model.type.ReferenceValue in project activityinfo by bedatadriven.

the class RecordTreeLoaderTest method references.

@Test
public void references() {
    BioDataForm bioDataForm = setup.getBioDataForm();
    Observable<Maybe<RecordTree>> recordTree = setup.getFormStore().getRecordTree(bioDataForm.getRecordRef(0));
    Connection<Maybe<RecordTree>> recordTreeView = setup.connect(recordTree);
    RecordTree tree = recordTreeView.assertLoaded().get();
    LookupKeySet lookupKeySet = new LookupKeySet(tree.getFormTree(), tree.getFormTree().getRootField(BioDataForm.PROTECTION_CODE_FIELD_ID).getField());
    assertThat(lookupKeySet.getLookupKeys(), hasSize(1));
    ReferenceValue referenceValue = (ReferenceValue) tree.getRoot().get(BioDataForm.PROTECTION_CODE_FIELD_ID);
    RecordRef ref = referenceValue.getOnlyReference();
    assertThat(lookupKeySet.label(tree, ref), equalTo(Maybe.of("00667")));
}
Also used : RecordTree(org.activityinfo.model.formTree.RecordTree) Maybe(org.activityinfo.promise.Maybe) LookupKeySet(org.activityinfo.model.formTree.LookupKeySet) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) BioDataForm(org.activityinfo.store.testing.BioDataForm) Test(org.junit.Test)

Example 5 with ReferenceValue

use of org.activityinfo.model.type.ReferenceValue in project activityinfo by bedatadriven.

the class ReferenceFieldMapping method mapFieldValue.

public FieldValue mapFieldValue(int sourceIndex) {
    int keyIndex = sourceKeySet.getKeyIndexOfSourceRow(sourceIndex);
    ResourceId targetId = lookupTable.get().getTargetMatchId(keyIndex);
    ResourceId targetFormId = Iterables.getOnlyElement(((ReferenceType) targetReferenceField.getType()).getRange());
    return new ReferenceValue(new RecordRef(targetFormId, targetId));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef)

Aggregations

ReferenceValue (org.activityinfo.model.type.ReferenceValue)31 RecordRef (org.activityinfo.model.type.RecordRef)26 ResourceId (org.activityinfo.model.resource.ResourceId)17 Test (org.junit.Test)11 FormInstance (org.activityinfo.model.form.FormInstance)7 FieldValue (org.activityinfo.model.type.FieldValue)7 LocalDate (org.activityinfo.model.type.time.LocalDate)4 ResultSet (java.sql.ResultSet)3 OnDataSet (org.activityinfo.server.database.OnDataSet)3 ForeignKeyBuilder (org.activityinfo.store.query.server.join.ForeignKeyBuilder)3 ForeignKey (org.activityinfo.store.query.shared.columns.ForeignKey)3 SQLException (java.sql.SQLException)2 Set (java.util.Set)2 FormClass (org.activityinfo.model.form.FormClass)2 LookupKeySet (org.activityinfo.model.formTree.LookupKeySet)2 RecordTree (org.activityinfo.model.formTree.RecordTree)2 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)2 Maybe (org.activityinfo.promise.Maybe)2 ValidationResult (org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)2 BitSet (java.util.BitSet)1