Search in sources :

Example 1 with EnumColumnView

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());
    }
}
Also used : FormulaSyntaxException(org.activityinfo.model.formula.diagnostic.FormulaSyntaxException) EnumColumnView(org.activityinfo.model.query.EnumColumnView) ColumnView(org.activityinfo.model.query.ColumnView) BooleanColumnView(org.activityinfo.model.query.BooleanColumnView) EnumColumnView(org.activityinfo.model.query.EnumColumnView)

Example 2 with EnumColumnView

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()));
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) NullFormScanCache(org.activityinfo.store.query.shared.NullFormScanCache) ColumnView(org.activityinfo.model.query.ColumnView) EnumColumnView(org.activityinfo.model.query.EnumColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Aggregations

ColumnView (org.activityinfo.model.query.ColumnView)2 EnumColumnView (org.activityinfo.model.query.EnumColumnView)2 FormulaSyntaxException (org.activityinfo.model.formula.diagnostic.FormulaSyntaxException)1 BooleanColumnView (org.activityinfo.model.query.BooleanColumnView)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1 QueryModel (org.activityinfo.model.query.QueryModel)1 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)1 NullFormScanCache (org.activityinfo.store.query.shared.NullFormScanCache)1 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)1 Test (org.junit.Test)1