Search in sources :

Example 1 with StringArrayColumnView

use of org.activityinfo.model.query.StringArrayColumnView in project activityinfo by bedatadriven.

the class AddDateFunction method columnApply.

@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
    ColumnView dateView = arguments.get(0);
    ColumnView daysView = arguments.get(1);
    String[] result = new String[dateView.numRows()];
    for (int i = 0; i < dateView.numRows(); i++) {
        LocalDate date = LocalDate.parse(dateView.getString(i));
        int days = (int) daysView.getDouble(i);
        result[i] = date.plusDays(days).toString();
    }
    return new StringArrayColumnView(result);
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) StringArrayColumnView(org.activityinfo.model.query.StringArrayColumnView) LocalDate(org.activityinfo.model.type.time.LocalDate) StringArrayColumnView(org.activityinfo.model.query.StringArrayColumnView)

Example 2 with StringArrayColumnView

use of org.activityinfo.model.query.StringArrayColumnView in project activityinfo by bedatadriven.

the class DateFunction method columnApply.

@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
    ColumnView year = arguments.get(0);
    ColumnView month = arguments.get(1);
    ColumnView day = arguments.get(2);
    String[] dates = new String[numRows];
    for (int i = 0; i < numRows; i++) {
        dates[i] = apply(year.getDouble(i), month.getDouble(i), day.getDouble(i)).toString();
    }
    return new StringArrayColumnView(dates);
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) StringArrayColumnView(org.activityinfo.model.query.StringArrayColumnView) StringArrayColumnView(org.activityinfo.model.query.StringArrayColumnView)

Example 3 with StringArrayColumnView

use of org.activityinfo.model.query.StringArrayColumnView 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

ColumnView (org.activityinfo.model.query.ColumnView)3 StringArrayColumnView (org.activityinfo.model.query.StringArrayColumnView)3 FormClass (org.activityinfo.model.form.FormClass)1 FormField (org.activityinfo.model.form.FormField)1 FormMetadataProviderStub (org.activityinfo.model.formTree.FormMetadataProviderStub)1 FormTree (org.activityinfo.model.formTree.FormTree)1 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1 ReferenceType (org.activityinfo.model.type.ReferenceType)1 LocalDate (org.activityinfo.model.type.time.LocalDate)1 Connection (org.activityinfo.observable.Connection)1 FormSource (org.activityinfo.store.query.shared.FormSource)1 Test (org.junit.Test)1