use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class LookupKeySetTest method overlappingHierarchiesKeyQuery.
@Test
public void overlappingHierarchiesKeyQuery() {
TestingStorageProvider catalog = setup.getCatalog();
LocaliteForm localiteForm = catalog.getLocaliteForm();
FormTree formTree = setup.getFormTree(localiteForm.getFormId());
LookupKeySet lookupKeySet = new LookupKeySet(formTree, localiteForm.getAdminField());
Map<LookupKey, FormulaNode> formulas = lookupKeySet.getKeyFormulas(localiteForm.getAdminField().getId());
QueryModel queryModel = new QueryModel(localiteForm.getFormId());
queryModel.selectResourceId().as("id");
queryModel.selectExpr(formulas.get(lookupKeySet.getKey(0))).as("province");
queryModel.selectExpr(formulas.get(lookupKeySet.getKey(1))).as("territory");
queryModel.selectExpr(formulas.get(lookupKeySet.getKey(2))).as("zs");
Connection<ColumnSet> table = setup.connect(setup.getFormStore().query(queryModel));
ColumnSet columnSet = table.assertLoaded();
ColumnView id = columnSet.getColumnView("id");
ColumnView province = columnSet.getColumnView("province");
ColumnView territory = columnSet.getColumnView("territory");
ColumnView zs = columnSet.getColumnView("zs");
// First row references a Zone de Sante
assertThat(id.getString(0), equalTo("c0"));
assertThat(province.getString(0), equalTo("Province 14"));
assertThat(territory.getString(0), nullValue());
assertThat(zs.getString(0), equalTo("Zone de Sante 56"));
// Second row references only a Province
assertThat(id.getString(1), equalTo("c1"));
assertThat(province.getString(1), equalTo("Province 8"));
assertThat(territory.getString(1), nullValue());
assertThat(zs.getString(1), nullValue());
// Fifth row references a territory
assertThat(id.getString(4), equalTo("c4"));
assertThat(province.getString(4), equalTo("Province 15"));
assertThat(territory.getString(4), equalTo("Territory 42"));
assertThat(zs.getString(4), nullValue());
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class LookupViewModelTest method nullKeys.
@Test
public void nullKeys() {
FormClass keyForm = new FormClass(ResourceId.valueOf("FORM1"));
keyForm.addField(ResourceId.valueOf("PROVINCE")).setLabel("Province").setKey(true).setRequired(true).setType(TextType.SIMPLE);
keyForm.addField(ResourceId.valueOf("SCHOOL")).setLabel("School").setKey(true).setRequired(true).setType(TextType.SIMPLE);
FormClass form = new FormClass(ResourceId.valueOf("FORM2"));
FormField referenceField = new FormField(ResourceId.generateFieldId(ReferenceType.TYPE_CLASS));
ReferenceType referenceType = new ReferenceType(Cardinality.SINGLE, ResourceId.valueOf("FORM1"));
referenceField.setType(referenceType);
form.addField(ResourceId.valueOf("PROJECT")).setLabel("Project name").setType(referenceType);
FormTreeBuilder treeBuilder = new FormTreeBuilder(new FormMetadataProviderStub(form, keyForm));
FormTree formTree = treeBuilder.queryTree(form.getId());
Map<String, ColumnView> columnSet = new HashMap<>();
columnSet.put("id", new StringArrayColumnView(Arrays.asList("R1", "R2", "R3", "R4")));
columnSet.put("k1", new StringArrayColumnView(Arrays.asList("PZ", null, "PA", "PA")));
columnSet.put("k2", new StringArrayColumnView(Arrays.asList("S1", "S2", null, "S3")));
FormSource formSource = EasyMock.createMock(FormSource.class);
EasyMock.expect(formSource.query(EasyMock.anyObject(QueryModel.class))).andReturn(Observable.just(new ColumnSet(3, columnSet))).anyTimes();
EasyMock.replay(formSource);
LookupViewModel viewModel = new LookupViewModel(formSource, formTree, referenceField);
LookupKeyViewModel provinceKey = viewModel.getLookupKeys().get(0);
assertThat(provinceKey.getChoices().get(), contains("PA", "PZ"));
viewModel.select(provinceKey.getLookupKey(), "PA");
LookupKeyViewModel schoolKey = viewModel.getLookupKeys().get(1);
Connection<List<String>> schoolChoices = new Connection<>(schoolKey.getChoices());
assertThat(schoolChoices.assertLoaded(), contains("S3"));
}
Aggregations