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