Class Filter
- All Implemented Interfaces:
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:
Example of filtering by outputs:Filter.equal("inputs.Customer.value", endCustomerId)
If you use a filter for dates, the date values must be string formatted by the ISO format.Filter.equal("outputs.EndCustomer.result", endCustomerId)
The property is the name of a field, for example "sku", "label" or "attribute3". Some
methods that use the filter, for example api.find(), also accept the name configured for a field, such as
the label of an attributeX column. Other methods do not.
Create filters with the static methods of this class, for example equal(String, Object),
in(String, Collection) or and(Filter...). Then pass them to a data-reading method such as
api.find(),
api.stream() or
api.count().
Logics can use the Filter class without an import.
Example:
def filters = [
Filter.equal("name", "ListPrices"),
Filter.equal("sku", sku),
Filter.lessOrEqual("attribute1", 200)
]
def prices = api.find("PX", *filters)
- Author:
- dwolverton
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intprotected intThe type of comparison to do between the property and the value.protected StringThe name of the property to filter on.static final StringProperty string representing the root entity of the search.protected ObjectThe value to compare the property with. -
Constructor Summary
ConstructorsConstructorDescriptionFilter()Not intended for public use.Creates a filter that uses the == operator.Creates a filter with the given property, value and operator.Not intended for use in logics. -
Method Summary
Modifier and TypeMethodDescriptionvoidUsed with OP_OR and OP_AND filters.static FilterCreate a new Filter using the ALL operator.static FilterCreates a filter that matches every row of a query.static FilterCreate a new Filter using the AND operator.static FilterCreate a new Filter using a custom JPQL/HQL expression.static FilterCreate a new Filter using a custom JPQL/HQL expression.static Filtercustom(String expression, Collection<?> values) Create a new Filter using a custom JPQL/HQL expression.static FilterCreate a new Filter using the == operator.booleanCompares this filter with another object.intReturns the type of comparison this filter does, as one of theOP_*constants of this class.Returns the name of the property to filter on.getValue()Returns the value to compare the property with.Collection<?> Returns the value as a Collection, converting if necessary.List<?> Returns the value as a List, converting if necessary.static FiltergreaterOrEqual(String property, Object value) Create a new Filter using the >= operator.static FiltergreaterThan(String property, Object value) Create a new Filter using the > operator.inthashCode()static FilterCreate a new Filter using the ILIKE operator.static FilterCreate a new Filter using the IN operator.static Filterin(String property, Collection<?> value) Create a new Filter using the IN operator.static FilterCreate a new Filter using the IS EMPTY operator.static booleanNot intended for use in logics.static FilterisNotEmpty(String property) Create a new Filter using the IS NOT EMPTY operator.static FilterCreate a new Filter using the IS NOT NULL operator.static FilterCreate a new Filter using the IS NULL operator.booleanbooleanbooleanbooleanbooleanbooleanstatic FilterlessOrEqual(String property, Object value) Create a new Filter using the <= operator.static FilterCreate a new Filter using the < operator.static FilterCreate a new Filter using the LIKE operator.booleanmatches(MatcherContext context) Not intended for public use.booleanThe method verifies if thisFilterwould successfully match the provided combination of values.static FilterCreates a filter that matches no row of a query.static FilterCreate a new Filter using the NONE operator.static FilterCreate a new Filter using the NOT operator.static FilterCreate a new Filter using the !static FilterCreate a new Filter using the NOT IN operator.static FilternotIn(String property, Collection<?> value) Create a new Filter using the NOT IN operator.static FilterCreate a new Filter using the OR operator.static FilterreconstructFromMap(Map<String, ?> filterAsMap) Not intended for use in logics.voidUsed with OP_OR and OP_AND filters.voidsetOperator(int operator) Sets the type of comparison this filter does.voidsetProperty(String property) Sets the name of the property to filter on.voidSets the value to compare the property with.static FilterCreate a new Filter using the SOME operator.Not intended for public use.toString()
-
Field Details
-
ROOT_ENTITY
Property string representing the root entity of the search. This is just the empty string ("").- See Also:
-
property
The name of the property to filter on. It may be nested. Examples:"name", "dateOfBirth", "employee.age", "employee.spouse.job.title" -
value
The value to compare the property with. Should be of a compatible type with the property. Examples:"Fred", new Date(), 45 -
operator
protected int operatorThe 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
- See Also:
-
OP_EQUAL
public static final int OP_EQUAL- See Also:
-
OP_NOT_EQUAL
public static final int OP_NOT_EQUAL- See Also:
-
OP_LESS_THAN
public static final int OP_LESS_THAN- See Also:
-
OP_GREATER_THAN
public static final int OP_GREATER_THAN- See Also:
-
OP_LESS_OR_EQUAL
public static final int OP_LESS_OR_EQUAL- See Also:
-
OP_GREATER_OR_EQUAL
public static final int OP_GREATER_OR_EQUAL- See Also:
-
OP_LIKE
public static final int OP_LIKE- See Also:
-
OP_ILIKE
public static final int OP_ILIKE- See Also:
-
OP_IN
public static final int OP_IN- See Also:
-
OP_NOT_IN
public static final int OP_NOT_IN- See Also:
-
OP_NULL
public static final int OP_NULL- See Also:
-
OP_NOT_NULL
public static final int OP_NOT_NULL- See Also:
-
OP_EMPTY
public static final int OP_EMPTY- See Also:
-
OP_NOT_EMPTY
public static final int OP_NOT_EMPTY- See Also:
-
OP_AND
public static final int OP_AND- See Also:
-
OP_OR
public static final int OP_OR- See Also:
-
OP_NOT
public static final int OP_NOT- See Also:
-
OP_SOME
public static final int OP_SOME- See Also:
-
OP_ALL
public static final int OP_ALL- See Also:
-
OP_NONE
public static final int OP_NONE- See Also:
-
OP_CUSTOM
public static final int OP_CUSTOM- See Also:
-
-
Constructor Details
-
Filter
public Filter()Not intended for public use. This constructor exists for JSON deserialization. Use the static methods of this class, such asequal(String, Object), instead. -
Filter
Creates a filter with the given property, value and operator. In logics, use the static methods of this class, such asequal(String, Object)orin(String, Collection), instead. They set the operator for you.- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- Value to be compared with content of the given columnoperator- One of theOP_*constants of this class, for exampleOP_EQUAL
-
Filter
Creates a filter that uses the == operator. In logics, useequal(String, Object)instead.- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- Value to be compared with content of the given column
-
Filter
Not intended for use in logics. Useapi.filterFromMap()instead.Creates a filter from its map form, with the keys
property,valueandoperator. Nested sub-filters are not converted.- See Also:
-
-
Method Details
-
reconstructFromMap
Not intended for use in logics. Useapi.filterFromMap()instead.Creates a filter from its map form, with the keys
property,valueandoperator, including the nested sub-filters of AND, OR, NOT, SOME, ALL and NONE filters.- See Also:
-
isFilter
Not intended for use in logics. Useapi.filterFromMap()instead.Checks whether a map is the map form of a filter, that is, whether it contains the keys
property,valueandoperator.- See Also:
-
equal
Create a new Filter using the == operator.In
api.find()andapi.stream(),Filter.equal("attribute1", null)is turned intoFilter.isNull("attribute1"). Other methods, for exampleapi.findLookupTableValues(), do not do this, and the filter then matches no rows. To match empty values, useisNull(String).- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- Value to be compared with content of the given column.- Returns:
- the new filter
-
lessThan
Create a new Filter using the < operator.- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- Value to be compared with content of the given column.- Returns:
- the new filter
-
greaterThan
Create a new Filter using the > operator.- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- Value to be compared with content of the given column.- Returns:
- the new filter
-
lessOrEqual
Create a new Filter using the <= operator.- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- Value to be compared with content of the given column.- Returns:
- the new filter
-
greaterOrEqual
Create a new Filter using the >= operator.- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- Value to be compared with content of the given column.- Returns:
- the new filter
-
in
Create a new Filter using the IN operator. The filter matches when the column contains one of the values.The collection can contain any number of values. In
api.find(), an empty collection matches no rows.Example:
def skus = ["MB-0001", "MB-0002", "MB-0003"] def products = api.find("P", Filter.in("sku", skus))- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- Collection of values to be compared with content of the given column- Returns:
- the new filter
- See Also:
-
in
Create a new Filter using the IN operator.This takes a variable number of parameters. Any number of values can be specified.
Example:
def products = api.find("P", Filter.in("sku", "MB-0001", "MB-0002"))- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- Values to be compared with content of the given column- Returns:
- the new filter
- See Also:
-
notIn
Create a new Filter using the NOT IN operator. The filter matches when the column contains none of the values.The collection can contain any number of values. In
api.find(), an empty collection matches all rows.- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- Collection of values to be compared with content of the given column- Returns:
- the new filter
- See Also:
-
notIn
Create a new Filter using the NOT IN operator.This takes a variable number of parameters. Any number of values can be specified.
- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- Values to be compared with content of the given column- Returns:
- the new filter
- See Also:
-
like
Create a new Filter using the LIKE operator. The value is an SQL LIKE pattern, in which%stands for any sequence of characters. To ignore case, useilike(String, String).Example:
def products = api.find("P", Filter.like("label", "Mouse%"))- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- SQL LIKE pattern to be compared with content of the given column- Returns:
- the new filter
- See Also:
-
ilike
Create a new Filter using the ILIKE operator. It works likelike(String, String), but ignores case.Example:
def products = api.find("P", Filter.ilike("label", "%mouse%"))- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- SQL LIKE pattern to be compared with content of the given column- Returns:
- the new filter
- See Also:
-
notEqual
Create a new Filter using the != operator.In a database query, rows where the column is null do not match this filter, because the database treats null as an unknown value. To include them, combine this filter with
isNull(String).Example:
def filter = Filter.or( Filter.isNull("attribute1"), Filter.notEqual("attribute1", "A") )- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"value- Value to be compared with content of the given column- Returns:
- the new filter
- See Also:
-
isNull
Create a new Filter using the IS NULL operator.- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"- Returns:
- the new filter
- See Also:
-
isNotNull
Create a new Filter using the IS NOT NULL operator.- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"- Returns:
- the new filter
- See Also:
-
isEmpty
Create a new Filter using the IS EMPTY operator. This filter is not supported in the Analytics module (PA).The filter matches a null value, an empty string, or a collection without elements.
- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"- Returns:
- the new filter
- See Also:
-
isNotEmpty
Create a new Filter using the IS NOT EMPTY operator. This filter is not supported in the Analytics module (PA).The filter matches a value that is not null and not an empty string, or a collection with at least one element.
- Parameters:
property- Name of the property to filter on, for example"sku"or"attribute3"- Returns:
- the new filter
- See Also:
-
and
Create a new Filter using the AND operator.This takes a variable number of parameters. Any number of
Filters can be specified.Example:
def filter = Filter.and( Filter.equal("attribute1", "Accessories"), Filter.greaterOrEqual("attribute2", 100) ) def products = api.find("P", filter)- Parameters:
filters- Filters that must all match- Returns:
- the new filter
- See Also:
-
or
Create a new Filter using the OR operator.This takes a variable number of parameters. Any number of
Filters can be specified.Example:
def filter = Filter.or( Filter.equal("label", "Jack"), Filter.and( Filter.equal("label", "Jill"), Filter.like("attribute1", "%Chicago%") ) )- Parameters:
filters- Filters of which at least one must match- Returns:
- the new filter
- See Also:
-
not
Create a new Filter using the NOT operator.Example:
def filter = Filter.not(Filter.ilike("label", "test%"))- Parameters:
filter- Filter that must not match- Returns:
- the new filter
-
some
Create a new Filter using the SOME operator. This filter is not supported in the Analytics module (PA).The property is a collection of the searched object, for example the roles of a user. The filter matches when at least one element of the collection matches the given filter, which refers to the properties of that element. The property cannot be a nested path such as
"businessRoles.roles". Nest the filters instead, as in the example. The SOME, ALL and NONE filters cannot be used in anapi.find()call that returns distinct values only.Example:
def users = api.find("U", 0, "loginName", Filter.some("businessRoles", Filter.some("roles", Filter.equal("uniqueName", "CUSTOM_FORM_ADMIN"))) )- Parameters:
property- Name of the collection propertyfilter- Filter that at least one element of the collection must match- Returns:
- the new filter
- See Also:
-
all
Create a new Filter using the ALL operator. This filter is not supported in the Analytics module (PA).The filter matches when every element of the collection matches the given filter. A collection without elements matches. The restrictions of
some(String, Filter)apply.Example:
def users = api.find("U", 0, "loginName", Filter.all("roles", Filter.equal("uniqueName", "CUSTOM_FORM_ADMIN")))- Parameters:
property- Name of the collection propertyfilter- Filter that every element of the collection must match- Returns:
- the new filter
- See Also:
-
none
Create a new Filter using the NONE operator. This is equivalent to NOT SOME. This filter is not supported in the Analytics module (PA).The restrictions of
some(String, Filter)apply.Example:
def users = api.find("U", 0, "loginName", Filter.none("roles", Filter.equal("uniqueName", "DASHBOARD_RO")))- Parameters:
property- Name of the collection propertyfilter- Filter that no element of the collection may match- Returns:
- the new filter
- See Also:
-
custom
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- Returns:
- the new filter
-
custom
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 expressionvalues- one or more values to fill in the numbered placeholders in the expression- Returns:
- the new filter
-
custom
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 expressionvalues- one or more values to fill in the numbered placeholders in the expression- Returns:
- the new filter
-
alwaysMatch
Creates a filter that matches every row of a query. Use it where a filter is required but the query must not be restricted, for example when an optional condition is not set.Example:
def filter = category ? Filter.equal("attribute1", category) : Filter.alwaysMatch() def products = api.find("P", filter)- Returns:
- a Filter that alwaysMatch
- Since:
- 9.3 - Hurricane
- See Also:
-
neverMatch
Creates a filter that matches no row of a query.- Returns:
- a Filter that neverMatch
- Since:
- 9.3 - Hurricane
- See Also:
-
add
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.- Parameters:
filter- Filter to add- See Also:
-
remove
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.- Parameters:
filter- Filter to remove- See Also:
-
getProperty
Returns the name of the property to filter on.- Returns:
- the name of the property, for example
"sku"or"employee.age" - See Also:
-
setProperty
Sets the name of the property to filter on. It may be nested.- Parameters:
property- Name of the property, for example"sku"or"employee.age"- See Also:
-
getValue
Returns the value to compare the property with. For AND and OR filters, the value is the list of sub-filters. For NOT, SOME, ALL and NONE filters, it is the sub-filter.- Returns:
- the value of this filter
- See Also:
-
setValue
Sets the value to compare the property with. The value should be of a type compatible with the property.- Parameters:
value- Value to compare the property with, for example"Fred", a date or45- See Also:
-
getOperator
public int getOperator()Returns the type of comparison this filter does, as one of theOP_*constants of this class.- Returns:
- the operator, for example
OP_EQUAL - See Also:
-
setOperator
public void setOperator(int operator) Sets the type of comparison this filter does.- Parameters:
operator- One of theOP_*constants of this class, for exampleOP_EQUAL- See Also:
-
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 isnull,nullwill be returned.- Returns:
- the value as a list, or
nullif the value isnull - See Also:
-
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 isnull,nullwill be returned.- Returns:
- the value as a collection, or
nullif the value isnull - See Also:
-
isTakesSingleValue
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
public boolean isTakesListOfValues()- Returns:
- true if the operator should have a list of values specified.
IN, NOT_IN
-
isTakesNoValue
public boolean isTakesNoValue()- Returns:
- true if the operator does not require a value to be specified.
NULL, NOT_NULL, EMPTY, NOT_EMPTY, CUSTOM
-
isTakesSingleSubFilter
public boolean isTakesSingleSubFilter()- Returns:
- true if the operator should have a single Filter specified for
the value.
NOT, ALL, SOME, NONE
-
isTakesListOfSubFilters
public boolean isTakesListOfSubFilters()- Returns:
- true if the operator should have a list of Filters specified for
the value.
AND, OR
-
isTakesNoProperty
public boolean isTakesNoProperty()- Returns:
- true if the operator does not require a property to be specified.
AND, OR, NOT
-
hashCode
public int hashCode() -
equals
Compares this filter with another object. Two filters are equal when they have the same operator, property and value. -
matches
The method verifies if thisFilterwould 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 withand(Filter...),or(Filter...), etc:def filter = Filter.or( Filter.notIn("field1", "a", "b"), Filter.ilike("field2", "hey%") ) // returns false filter.matches([field1: "a"]) // returns true filter.matches([field1: "a", field2: "heyo"]) -
matches
public boolean matches(MatcherContext context) Not intended for public use. Usematches(Map)instead. -
toString
-
toQueryString
Not intended for public use. Returns this filter as a condition string in an SQL-like syntax, as the application uses it internally.- Returns:
- the condition string
-