Search in sources :

Example 1 with FormSource

use of org.activityinfo.store.query.shared.FormSource in project activityinfo by bedatadriven.

the class FieldTreeBuilderTest method subForms.

@Test
public void subForms() {
    FormSource formStore = new FormSourceSyncImpl(new TestingStorageProvider(), 1);
    FormTree tree = formStore.getFormTree(ReferralSubForm.FORM_ID).waitFor();
    TreeStore<MeasureTreeNode> treeStore = new TreeStore<>(MeasureTreeNode::getId);
    FieldTreeBuilder builder = new FieldTreeBuilder(tree, treeStore);
    try {
        builder.build(tree);
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("===== FormTree === ");
    FormTreePrettyPrinter.print(tree);
    System.out.println();
    System.out.println("===== TreeStore === ");
    prettyPrint(treeStore);
}
Also used : TreeStore(com.sencha.gxt.data.shared.TreeStore) FormTree(org.activityinfo.model.formTree.FormTree) TestingStorageProvider(org.activityinfo.store.testing.TestingStorageProvider) FormSourceSyncImpl(org.activityinfo.store.query.server.FormSourceSyncImpl) FormSource(org.activityinfo.store.query.shared.FormSource) Test(org.junit.Test)

Example 2 with FormSource

use of org.activityinfo.store.query.shared.FormSource 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"));
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) StringArrayColumnView(org.activityinfo.model.query.StringArrayColumnView) Connection(org.activityinfo.observable.Connection) ColumnSet(org.activityinfo.model.query.ColumnSet) ReferenceType(org.activityinfo.model.type.ReferenceType) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) FormTree(org.activityinfo.model.formTree.FormTree) FormClass(org.activityinfo.model.form.FormClass) FormSource(org.activityinfo.store.query.shared.FormSource) FormField(org.activityinfo.model.form.FormField) StringArrayColumnView(org.activityinfo.model.query.StringArrayColumnView) FormMetadataProviderStub(org.activityinfo.model.formTree.FormMetadataProviderStub) Test(org.junit.Test)

Aggregations

FormTree (org.activityinfo.model.formTree.FormTree)2 FormSource (org.activityinfo.store.query.shared.FormSource)2 Test (org.junit.Test)2 TreeStore (com.sencha.gxt.data.shared.TreeStore)1 FormClass (org.activityinfo.model.form.FormClass)1 FormField (org.activityinfo.model.form.FormField)1 FormMetadataProviderStub (org.activityinfo.model.formTree.FormMetadataProviderStub)1 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1 ColumnView (org.activityinfo.model.query.ColumnView)1 StringArrayColumnView (org.activityinfo.model.query.StringArrayColumnView)1 ReferenceType (org.activityinfo.model.type.ReferenceType)1 Connection (org.activityinfo.observable.Connection)1 FormSourceSyncImpl (org.activityinfo.store.query.server.FormSourceSyncImpl)1 TestingStorageProvider (org.activityinfo.store.testing.TestingStorageProvider)1