use of org.activityinfo.model.query.EnumColumnView in project activityinfo by bedatadriven.
the class ComparisonOperator method columnApply.
@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
checkArity(arguments, 2);
ColumnView a = arguments.get(0);
ColumnView b = arguments.get(1);
if (a.numRows() != b.numRows()) {
throw new FormulaSyntaxException("Arguments must have the same number of rows");
}
if (a.getType() == ColumnType.NUMBER && b.getType() == ColumnType.NUMBER) {
return columnApplyNumber(a, b);
} else if (a.getType() == ColumnType.STRING && b.getType() == ColumnType.STRING) {
if (a instanceof EnumColumnView) {
return columnApplyEnum((EnumColumnView) a, b);
} else if (b instanceof EnumColumnView) {
return columnApplyEnum((EnumColumnView) b, a);
} else {
return columnApplyString(a, b);
}
} else {
throw new FormulaSyntaxException("Comparsion between incompatible types: " + a.getType() + ", " + b.getType());
}
}
use of org.activityinfo.model.query.EnumColumnView in project activityinfo by bedatadriven.
the class EnumerationQueryTest method enumIdTests.
@Test
public void enumIdTests() {
TestingStorageProvider catalog = new TestingStorageProvider();
ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
QueryModel queryModel = new QueryModel(EmptyForm.FORM_ID);
queryModel.selectField(EmptyForm.ENUM_FIELD_ID).as("emptyEnum");
queryModel.selectField(EmptyForm.POP_ENUM_FIELD_ID).as("populatedEnum");
ColumnSet columnSet = builder.build(queryModel);
ColumnView emptyEnum = columnSet.getColumnView("emptyEnum");
ColumnView populatedEnum = columnSet.getColumnView("populatedEnum");
// // Standard Enum Id Checks
// Null check on empty set first
assertThat(emptyEnum.get(0), equalTo(null));
assertThat(((EnumColumnView) emptyEnum).getId(0), equalTo(null));
// Value check on populated set
assertThat(populatedEnum.get(0).toString(), equalTo("One"));
assertThat(((EnumColumnView) populatedEnum).getId(0), equalTo(EmptyForm.ENUM_ONE_ID.asString()));
// // Selected Row Enum Id Checks
ColumnView emptySelectedRow = emptyEnum.select(new int[] { 0 });
ColumnView populatedSelectedRow = populatedEnum.select(new int[] { 0 });
// Null check on empty set first
assertThat(emptySelectedRow.get(0), equalTo(null));
assertThat(((EnumColumnView) emptySelectedRow).getId(0), equalTo(null));
// Value check on populated set
assertThat(populatedSelectedRow.get(0).toString(), equalTo("One"));
assertThat(((EnumColumnView) populatedSelectedRow).getId(0), equalTo(EmptyForm.ENUM_ONE_ID.asString()));
}
Aggregations