Class Filter

Object
Filter
All Implemented Interfaces:
Serializable

public class Filter extends Object implements Serializable

A Filter is used by the Search class to specify a restriction on what results should be returned in the search. For example, if a filter Filter.equal("name","Paul") were added to the search, only objects with the property "name" equal to the string "Paul" would be returned.

Nested properties can also be specified, for example Filter.greaterThan("employee.age",65).

Nested properties of corresponding JSON structure can be also used for filtering. It applies to objects containing inputs and outputs (typically Quotes, Rebate Agreements, Claims, Contracts, and Sales Compensations).
Note: We recommend using these nested filter properties instead of fetching the entire item (to get inputs/outputs) in your logic.

Example of filtering by inputs:


     Filter.equal("inputs.Customer.value", endCustomerId)
 
Example of filtering by outputs:

     Filter.equal("outputs.EndCustomer.result", endCustomerId)
 
If you use a filter for dates, the date values must be string formatted by the ISO format.
Author:
dwolverton
See Also:
  • Field Details Link icon

    • ROOT_ENTITY Link icon

      public static final String ROOT_ENTITY
      Property string representing the root entity of the search. This is just the empty string ("").
      See Also:
    • property Link icon

      protected String property
      The name of the property to filter on. It may be nested. Examples: "name", "dateOfBirth", "employee.age", "employee.spouse.job.title"
    • value Link icon

      protected Object value
      The value to compare the property with. Should be of a compatible type with the property. Examples: "Fred", new Date(), 45
    • operator Link icon

      protected int operator
      The type of comparison to do between the property and the value. The options are limited to the integer constants on this class: OP_EQAUL, OP_NOT_EQUAL, OP_LESS_THAN, OP_GREATER_THAN, LESS_OR_EQUAL, OP_GREATER_OR_EQUAL, OP_IN, OP_NOT_IN, OP_LIKE, OP_ILIKE, OP_NULL, OP_NOT_NULL, OP_EMPTY, OP_NOT_EMPTY, OP_SOME, OP_ALL, OP_NONE, OP_AND, OP_OR, OP_NOT .
    • DELIMITER Link icon

      public static final String DELIMITER
      See Also:
    • OP_EQUAL Link icon

      public static final int OP_EQUAL
      See Also:
    • OP_NOT_EQUAL Link icon

      public static final int OP_NOT_EQUAL
      See Also:
    • OP_LESS_THAN Link icon

      public static final int OP_LESS_THAN
      See Also:
    • OP_GREATER_THAN Link icon

      public static final int OP_GREATER_THAN
      See Also:
    • OP_LESS_OR_EQUAL Link icon

      public static final int OP_LESS_OR_EQUAL
      See Also:
    • OP_GREATER_OR_EQUAL Link icon

      public static final int OP_GREATER_OR_EQUAL
      See Also:
    • OP_LIKE Link icon

      public static final int OP_LIKE
      See Also:
    • OP_ILIKE Link icon

      public static final int OP_ILIKE
      See Also:
    • OP_IN Link icon

      public static final int OP_IN
      See Also:
    • OP_NOT_IN Link icon

      public static final int OP_NOT_IN
      See Also:
    • OP_NULL Link icon

      public static final int OP_NULL
      See Also:
    • OP_NOT_NULL Link icon

      public static final int OP_NOT_NULL
      See Also:
    • OP_EMPTY Link icon

      public static final int OP_EMPTY
      See Also:
    • OP_NOT_EMPTY Link icon

      public static final int OP_NOT_EMPTY
      See Also:
    • OP_AND Link icon

      public static final int OP_AND
      See Also:
    • OP_OR Link icon

      public static final int OP_OR
      See Also:
    • OP_NOT Link icon

      public static final int OP_NOT
      See Also:
    • OP_SOME Link icon

      public static final int OP_SOME
      See Also:
    • OP_ALL Link icon

      public static final int OP_ALL
      See Also:
    • OP_NONE Link icon

      public static final int OP_NONE
      See Also:
    • OP_CUSTOM Link icon

      public static final int OP_CUSTOM
      See Also:
  • Constructor Details Link icon

    • Filter Link icon

      public Filter()
    • Filter Link icon

      public Filter(String property, Object value, int operator)
    • Filter Link icon

      public Filter(String property, Object value)
    • Filter Link icon

      public Filter(Map<String,?> filterAsMap)
  • Method Details Link icon

    • reconstructFromMap Link icon

      public static Filter reconstructFromMap(Map<String,?> filterAsMap)
    • isFilter Link icon

      public static boolean isFilter(Map<String,?> filter)
    • equal Link icon

      public static Filter equal(String property, Object value)
      Create a new Filter using the == operator.
      Parameters:
      property - Name of the column to be used for filtering - it could be either the system name (e.g. "sku", "label", "attribute3") or the Name given during the configuration of column (only for the "attributeX" columns)
      value - Value to be compared with content of the given column.
      Returns:
    • lessThan Link icon

      public static Filter lessThan(String property, Object value)
      Create a new Filter using the < operator.
      Parameters:
      property - Name of the column to be used for filtering - it could be either the system name (e.g. "sku", "label", "attribute3") or the Name given during the configuration of column (only for the "attributeX" columns)
      value - Value to be compared with content of the given column.
      Returns:
    • greaterThan Link icon

      public static Filter greaterThan(String property, Object value)
      Create a new Filter using the > operator.
      Parameters:
      property - Name of the column to be used for filtering - it could be either the system name (e.g. "sku", "label", "attribute3") or the Name given during the configuration of column (only for the "attributeX" columns)
      value - Value to be compared with content of the given column.
      Returns:
    • lessOrEqual Link icon

      public static Filter lessOrEqual(String property, Object value)
      Create a new Filter using the <= operator.
      Parameters:
      property - Name of the column to be used for filtering - it could be either the system name (e.g. "sku", "label", "attribute3") or the Name given during the configuration of column (only for the "attributeX" columns)
      value - Value to be compared with content of the given column.
      Returns:
    • greaterOrEqual Link icon

      public static Filter greaterOrEqual(String property, Object value)
      Create a new Filter using the >= operator.
      Parameters:
      property - Name of the column to be used for filtering - it could be either the system name (e.g. "sku", "label", "attribute3") or the Name given during the configuration of column (only for the "attributeX" columns)
      value - Value to be compared with content of the given column.
      Returns:
    • in Link icon

      public static Filter in(String property, Collection<?> value)
      Create a new Filter using the IN operator.

      This takes a variable number of parameters. Any number of values can be specified.

    • in Link icon

      public static Filter in(String property, Object... value)
      Create a new Filter using the IN operator.

      This takes a variable number of parameters. Any number of values can be specified.

    • notIn Link icon

      public static Filter notIn(String property, Collection<?> value)
      Create a new Filter using the NOT IN operator.

      This takes a variable number of parameters. Any number of values can be specified.

    • notIn Link icon

      public static Filter notIn(String property, Object... value)
      Create a new Filter using the NOT IN operator.

      This takes a variable number of parameters. Any number of values can be specified.

    • like Link icon

      public static Filter like(String property, String value)
      Create a new Filter using the LIKE operator.
    • ilike Link icon

      public static Filter ilike(String property, String value)
      Create a new Filter using the ILIKE operator.
    • notEqual Link icon

      public static Filter notEqual(String property, Object value)
      Create a new Filter using the != operator.
    • isNull Link icon

      public static Filter isNull(String property)
      Create a new Filter using the IS NULL operator.
    • isNotNull Link icon

      public static Filter isNotNull(String property)
      Create a new Filter using the IS NOT NULL operator.
    • isEmpty Link icon

      public static Filter isEmpty(String property)
      Create a new Filter using the IS EMPTY operator.
    • isNotEmpty Link icon

      public static Filter isNotEmpty(String property)
      Create a new Filter using the IS NOT EMPTY operator.
    • and Link icon

      public static Filter and(Filter... filters)
      Create a new Filter using the AND operator.

      This takes a variable number of parameters. Any number of Filters can be specified.

    • or Link icon

      public static Filter or(Filter... filters)
      Create a new Filter using the OR operator.

      This takes a variable number of parameters. Any number of Filters can be specified.

    • not Link icon

      public static Filter not(Filter filter)
      Create a new Filter using the NOT operator.
    • some Link icon

      public static Filter some(String property, Filter filter)
      Create a new Filter using the SOME operator.
    • all Link icon

      public static Filter all(String property, Filter filter)
      Create a new Filter using the ALL operator.
    • none Link icon

      public static Filter none(String property, Filter filter)
      Create a new Filter using the NONE operator. This is equivalent to NOT SOME.
    • custom Link icon

      public static Filter custom(String expression)

      Create a new Filter using a custom JPQL/HQL expression. This can be any valid where-clause type expression. Reference properties by wrapping them with curly braces ({}).

      Here are some examples:

      
       // Referencing a property in a custom expression
       Filter.custom("{serialNumber} like '%4780%'");
       Filter.custom("{RebateCategory} like ?1", "%Promotional%");
       // comparing two properties
       Filter.custom("{attribute10} < {attribute34}");
       Filter.custom("{parent.spotCount} > {spotCount} + 4");
       // A constant
       Filter.custom("1 = 1");
       // A function
       Filter.custom("{dueDate} > current_date()");
       // A subquery
       Filter.custom(" AND {clicId} IN (SELECT id FROM Quote WHERE workflowStatus = 3 or workflowStatus = 4)") // draft = 0, submitted = 1, denied = 2, approved = 3, no_approval_required = 4, withdrawn = 5, invalidated = 6;
       Filter.custom(" {claimId} IN (SELECT id FROM Claims WHERE workflowStatus = 1 or workflowStatus = 3 or workflowStatus = 4");
       Filter.custom("{sku} IN (SELECT sku FROM PX30 WHERE attribute6 NOT IN ('NA', 'Custom')");
       
      Parameters:
      expression - JPQL/HQL where-clause expression
    • custom Link icon

      public static Filter custom(String expression, Object... values)

      Create a new Filter using a custom JPQL/HQL expression. This can be any valid where-clause type expression. Reference properties by wrapping them with curly braces ({}). The expression can also contain place holders for the Filter values; these are indicated by JPQL-style positional parameters (i.e. a question mark (?) followed by a number indicating the parameter order, starting with one).

      Here are some examples:

      
       // Referencing a property in a custom expression
       Filter.custom("{serialNumber} like ?1", "%4780%");
       // comparing two properties
       Filter.custom("{parent.spotCount} + ?1 > {spotCount} + ?2", 0, 4);
       // A constant
       Filter.custom("?1 = ?2", 1, 1);
       // A function
       Filter.custom("?1 > current_date()", someDate);
       // A subquery
       Filter.custom("{id} in (select pc.cat_id from popular_cats pc where pc.color = ?1)", "blue");
       
      Parameters:
      expression - JPQL/HQL where-clause expression
      values - one or more values to fill in the numbered placeholders in the expression
    • custom Link icon

      public static Filter custom(String expression, Collection<?> values)

      Create a new Filter using a custom JPQL/HQL expression. This can be any valid where-clause type expression. Reference properties by wrapping them with curly braces ({}). The expression can also contain place holders for the Filter values; these are indicated by JPQL-style positional parameters (i.e. a question mark (?) followed by a number indicating the parameter order, starting with one).

      Here are some examples:

      
       // Referencing a property in a custom expression
       Filter.custom("{serialNumber} like ?1", Collections.singleton("%4780%"));
       // comparing two properties
       Filter.custom("{parent.spotCount} + ?1 > {spotCount} + ?2", Arrays.asList(0, 4));
       // A constant
       Filter.custom("?1 = ?2", Arrays.asList(1, 1));
       // A function
       Filter.custom("?1 > current_date()", Collections.singleton(someDate));
       // A subquery
       Filter.custom("{id} in (select pc.cat_id from popular_cats pc where pc.color = ?1)", Collections.singleton("blue"));
       
      Parameters:
      expression - JPQL/HQL where-clause expression
      values - one or more values to fill in the numbered placeholders in the expression
    • alwaysMatch Link icon

      public static Filter alwaysMatch()
      Returns:
      a Filter that alwaysMatch
    • neverMatch Link icon

      public static Filter neverMatch()
      Returns:
      a Filter that neverMatch
    • add Link icon

      public void add(Filter filter)
      Used with OP_OR and OP_AND filters. These filters take a collection of filters as their value. This method adds a filter to that list.
    • remove Link icon

      public void remove(Filter filter)
      Used with OP_OR and OP_AND filters. These filters take a collection of filters as their value. This method removes a filter from that list.
    • getProperty Link icon

      public String getProperty()
    • setProperty Link icon

      public void setProperty(String property)
    • getValue Link icon

      public Object getValue()
    • setValue Link icon

      public void setValue(Object value)
    • getOperator Link icon

      public int getOperator()
    • setOperator Link icon

      public void setOperator(int operator)
    • getValuesAsList Link icon

      public List<?> getValuesAsList()
      Returns the value as a List, converting if necessary. If the value is a List, it will be returned directly. If it is any other Collection type or if it is an Array, an ArrayList will be returned with all the same elements. If the value is any other non-null value, a List containing just that one value will be returned. If it is null, null will be returned.
    • getValuesAsCollection Link icon

      public Collection<?> getValuesAsCollection()
      Returns the value as a Collection, converting if necessary. If the value is a Collection, it will be returned directly. If it is an Array, an ArrayList will be returned with all the same elements. If the value is any other non-null value, a Set containing just that one value will be returned. If it is null, null will be returned.
      Returns:
    • isTakesSingleValue Link icon

      public boolean isTakesSingleValue()
      Returns:
      true if the operator should have a single value specified.

      EQUAL, NOT_EQUAL, LESS_THAN, LESS_OR_EQUAL, GREATER_THAN, GREATER_OR_EQUAL, LIKE, ILIKE

    • isTakesListOfValues Link icon

      public boolean isTakesListOfValues()
      Returns:
      true if the operator should have a list of values specified.

      IN, NOT_IN

    • isTakesNoValue Link icon

      public boolean isTakesNoValue()
      Returns:
      true if the operator does not require a value to be specified.

      NULL, NOT_NULL, EMPTY, NOT_EMPTY, CUSTOM

    • isTakesSingleSubFilter Link icon

      public boolean isTakesSingleSubFilter()
      Returns:
      true if the operator should have a single Filter specified for the value.

      NOT, ALL, SOME, NONE

    • isTakesListOfSubFilters Link icon

      public boolean isTakesListOfSubFilters()
      Returns:
      true if the operator should have a list of Filters specified for the value.

      AND, OR

    • isTakesNoProperty Link icon

      public boolean isTakesNoProperty()
      Returns:
      true if the operator does not require a property to be specified.

      AND, OR, NOT

    • hashCode Link icon

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals Link icon

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • matches Link icon

      public boolean matches(Map<String,Object> values)
      The method verifies if this Filter would successfully match the provided combination of values.

      For example, the following code would return true:

      
           Filter.equal("myField", 5).matches([myField: 5])
       

      And the following would return false:

      
           Filter.in("myField", 3, 4).matches([myField: 5])
       

      Of course, composite Filters can be used with and(Filter...), or(Filter...), etc:

      
           def filter = Filter.or(
               Filter.notIn("field1", "a", "b"),
               Filter.ilike("field2", "hey%")
           )
           // returns false
           filter.matches([field1: "a"])
           // retunrs true
           filter.matches([field1: "a", field2: "heyo"])
       
      Parameters:
      values - A Map of values for the fields being referenced in this Filter.
      Returns:
      true if the Filter matches for the values in values.
    • matches Link icon

      public boolean matches(MatcherContext context)
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object
    • toQueryString Link icon

      public String toQueryString()