Search in sources :

Example 6 with FilterConfig

use of com.sencha.gxt.data.shared.loader.FilterConfig in project activityinfo by bedatadriven.

the class ColumnFilterParserTest method list.

@Test
public void list() {
    FilterConfig cfg = new FilterConfigBean();
    cfg.setType("list");
    cfg.setValue("Item1::Item2::Item3");
    assertThat(toFormula(A, cfg).asExpression(), equalTo("A.Item1 || A.Item2 || A.Item3"));
}
Also used : FilterConfigBean(com.sencha.gxt.data.shared.loader.FilterConfigBean) FilterConfig(com.sencha.gxt.data.shared.loader.FilterConfig) Test(org.junit.Test)

Example 7 with FilterConfig

use of com.sencha.gxt.data.shared.loader.FilterConfig in project activityinfo by bedatadriven.

the class ColumnFilterParserTest method string.

@Test
public void string() {
    FilterConfig cfg = new FilterConfigBean();
    cfg.setType("string");
    cfg.setComparison("contains");
    cfg.setValue("Bar");
    assertThat(toFormula(A, cfg).asExpression(), equalTo("ISNUMBER(SEARCH(\"Bar\", A))"));
}
Also used : FilterConfigBean(com.sencha.gxt.data.shared.loader.FilterConfigBean) FilterConfig(com.sencha.gxt.data.shared.loader.FilterConfig) Test(org.junit.Test)

Example 8 with FilterConfig

use of com.sencha.gxt.data.shared.loader.FilterConfig in project activityinfo by bedatadriven.

the class ColumnFilterParserTest method test.

@Test
public void test() {
    FilterConfig c = new FilterConfigBean();
    c.setComparison("on");
    c.setType("date");
    c.setValue("1505779200000");
    assertThat(toFormula(A, c).asExpression(), equalTo("A == DATE(2017, 9, 19)"));
}
Also used : FilterConfigBean(com.sencha.gxt.data.shared.loader.FilterConfigBean) FilterConfig(com.sencha.gxt.data.shared.loader.FilterConfig) Test(org.junit.Test)

Example 9 with FilterConfig

use of com.sencha.gxt.data.shared.loader.FilterConfig in project activityinfo by bedatadriven.

the class ColumnFilterParser method parseComparison.

private boolean parseComparison(FormulaNode node, Multimap<Integer, FilterConfig> result) {
    if (!(node instanceof FunctionCallNode)) {
        return false;
    }
    // Check that this is a binary
    FunctionCallNode callNode = (FunctionCallNode) node;
    if (callNode.getArgumentCount() != 2) {
        return false;
    }
    // Does this comparison involve one of our fields?
    Integer columnIndex = findColumnIndex(callNode.getArgument(0));
    if (columnIndex == null) {
        return false;
    }
    // Is it compared with a constant value?
    FieldValue value = parseLiteral(callNode.getArgument(1));
    if (value == null) {
        return false;
    }
    FilterConfig config;
    if (value instanceof Quantity) {
        config = numericFilter(callNode, (Quantity) value);
    } else if (value instanceof LocalDate) {
        config = dateFilter(callNode, (LocalDate) value);
    } else {
        return false;
    }
    result.put(columnIndex, config);
    return true;
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity) FilterConfig(com.sencha.gxt.data.shared.loader.FilterConfig) FieldValue(org.activityinfo.model.type.FieldValue) LocalDate(org.activityinfo.model.type.time.LocalDate)

Example 10 with FilterConfig

use of com.sencha.gxt.data.shared.loader.FilterConfig in project activityinfo by bedatadriven.

the class ColumnFilterParser method parseStringContains.

/**
 * Tries to parse an expression in the form ISNUMBER(SEARCH(substring, string))
 */
private boolean parseStringContains(FormulaNode node, Multimap<Integer, FilterConfig> result) {
    if (!(node instanceof FunctionCallNode)) {
        return false;
    }
    FunctionCallNode isNumberCall = ((FunctionCallNode) node);
    if (isNumberCall.getFunction() != IsNumberFunction.INSTANCE) {
        return false;
    }
    FormulaNode isNumberArgument = Formulas.simplify(isNumberCall.getArgument(0));
    if (!(isNumberArgument instanceof FunctionCallNode)) {
        return false;
    }
    FunctionCallNode searchCall = (FunctionCallNode) isNumberArgument;
    if (searchCall.getFunction() != SearchFunction.INSTANCE) {
        return false;
    }
    if (searchCall.getArgumentCount() != 2) {
        return false;
    }
    FieldValue substring = parseLiteral(searchCall.getArgument(0));
    if (!(substring instanceof HasStringValue)) {
        return false;
    }
    FormulaNode columnExpr = searchCall.getArgument(1);
    Integer columnIndex = columnMap.get(columnExpr);
    if (columnIndex == -1) {
        return false;
    }
    FilterConfig filterConfig = new FilterConfigBean();
    filterConfig.setType("string");
    filterConfig.setComparison("contains");
    filterConfig.setValue(((HasStringValue) substring).asString());
    result.put(columnIndex, filterConfig);
    return true;
}
Also used : FilterConfigBean(com.sencha.gxt.data.shared.loader.FilterConfigBean) HasStringValue(org.activityinfo.model.type.primitive.HasStringValue) FilterConfig(com.sencha.gxt.data.shared.loader.FilterConfig) FieldValue(org.activityinfo.model.type.FieldValue)

Aggregations

FilterConfig (com.sencha.gxt.data.shared.loader.FilterConfig)11 FilterConfigBean (com.sencha.gxt.data.shared.loader.FilterConfigBean)9 Test (org.junit.Test)6 FieldValue (org.activityinfo.model.type.FieldValue)2 FormulaNode (org.activityinfo.model.formula.FormulaNode)1 Quantity (org.activityinfo.model.type.number.Quantity)1 HasStringValue (org.activityinfo.model.type.primitive.HasStringValue)1 LocalDate (org.activityinfo.model.type.time.LocalDate)1