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