Class Filter

java.lang.Object
sailpoint.tools.xml.AbstractXmlObject
sailpoint.object.Filter
All Implemented Interfaces:
Serializable, sailpoint.tools.xml.IXmlEqualable<Filter>, sailpoint.tools.xml.PersistentXmlObject
Direct Known Subclasses:
Filter.CompositeFilter, Filter.LeafFilter

public abstract class Filter extends sailpoint.tools.xml.AbstractXmlObject implements Serializable, sailpoint.tools.xml.IXmlEqualable<Filter>
A Filter is an abstract class that is used to express boolean logical expressions. The static methods on this class should be considered the public API as they are the most straight-forward to use when constructing query filters. Note that Filter.toExpression() can be fed back into Filter.compile(String) to reconstruct a filter.

The inner classes are public, but are typically only used in an SPI to convert Filters into consumer-specific queries (for example - an LDAP filter string).

See Also:
  • Constructor Details

    • Filter

      public Filter()
  • Method Details

    • clone

      public static Filter clone(Filter src)
      Perform a shallow copy of a filter. Here "shallow" means that the structure of the filter is cloned, but not the values used in the leaf filters. This is intended for use by query optimizers that might need to change the structure of the filter as well as do name mapping, but do not need to touch the values. Some values used in filters are not currently XML serializable but even if it were, cloning the values to do query optimization is expensive and best avoided.
    • compile

      public static Filter compile(String filter) throws sailpoint.tools.Parser.ParseException
      Compile a filter from its String representation.
      Parameters:
      filter - The filter string.
      Returns:
      The Filter that is compiled from the given string.
      Throws:
      sailpoint.tools.Parser.ParseException - If the format of the filter is incorrect.
      See Also:
    • fromExample

      public static Filter fromExample(Object o) throws sailpoint.tools.GeneralException
      Create a Filter from an example object. This will return an AND filter that compares equality for each non-null property on the given object. Null is returned if the given object does not have any non-null properties.
      Parameters:
      o - The object for which to create the Filter.
      Returns:
      An AND filter that compares equality for each non-null property on the given object. Null is returned if the given object does not have any non-null properties.
      Throws:
      sailpoint.tools.GeneralException - If there is a problem reading the properties from the given object.
    • eq

      public static Filter eq(String propertyName, Object value) throws IllegalArgumentException
      Check that the given property is equal to the given value.
      Throws:
      IllegalArgumentException
    • ne

      public static Filter ne(String propertyName, Object value) throws IllegalArgumentException
      Check that the given property is not equal to the given value.
      Throws:
      IllegalArgumentException
    • lt

      public static Filter lt(String propertyName, Object value) throws IllegalArgumentException
      Check that the given property is less than the given value.
      Throws:
      IllegalArgumentException
    • gt

      public static Filter gt(String propertyName, Object value) throws IllegalArgumentException
      Check that the given property is greater than the given value.
      Throws:
      IllegalArgumentException
    • le

      public static Filter le(String propertyName, Object value) throws IllegalArgumentException
      Check that the given property is less than or equal to the given value.
      Throws:
      IllegalArgumentException
    • ge

      public static Filter ge(String propertyName, Object value) throws IllegalArgumentException
      Check that the given property is greater than or equal to the given value.
      Throws:
      IllegalArgumentException
    • in

      public static Filter in(String propertyName, Collection<?> value) throws IllegalArgumentException
      Check that the given single-valued property has a value within the given set of values.
      Throws:
      IllegalArgumentException
    • containsAll

      public static Filter containsAll(String propertyName, Collection value)
      Check that the given multi-valued property contains all of the given values.
    • like

      public static Filter like(String propertyName, Object value)
      Check that the given string property contains the given value as a substring.
    • like

      public static Filter like(String propertyName, Object value, Filter.MatchMode matchMode)
      Check that the given string property contains the given value according to the given match mode.
    • notnull

      public static Filter notnull(String propertyName)
      Check that the given property is not null.
    • isnull

      public static Filter isnull(String propertyName)
      Check that the given property is null.
    • isempty

      public static Filter isempty(String propertyName)
      Check that the given multi-valued property is empty.
    • join

      public static Filter join(String property, String joinProperty)
      Join the given property to the requested fully-qualified join property. As an example, if you are filtering Cars based on engine size but do not have a direct reference to the engine, the filter might look like this: Filter engineJoin = Filter.join("car.engineModel", "Engine.model"); Filter engineSize = Filter.gt("Engine.size", 289); Filter engineCheck = Filter.and(engineJoin, engineSize);
      Parameters:
      property - The property on entity being filter to join through. For example, "identity".
      joinProperty - The fully-qualified property name to join to. For example, "Identity.name".
    • collectionCondition

      public static Filter collectionCondition(String collectionProperty, Filter compoundFilter)
      Check that the given collection (multi-valued) property has elements that match the given compoundFilter. The property names in the compound filter should be rooted from the collectionProperty.

      Example 1: Check to see if a Car's front doors both have power locks. // Note that these properties assume that they are rooted at the "doors" // property rather than the Car. Filter driverSide = Filter.and(Filter.eq("position", "frontDriver"), Filter.eq("powerLock", true)); Filter passengerSide = Filter.and(Filter.eq("position", "frontPassenger"), Filter.eq("powerLock", true)); Filter.collectionCondition("doors", Filter.and(driverSide, passengerSide));

      Example 2: Check to see if either of a Car's front doors have power locks. // Note that these properties assume that they are rooted at the "doors" // property rather than the Car. Filter driverSide = Filter.and(Filter.eq("position", "frontDriver"), Filter.eq("powerLock", true)); Filter passengerSide = Filter.and(Filter.eq("position", "frontPassenger"), Filter.eq("powerLock", true)); Filter.collectionCondition("doors", Filter.or(driverSide, passengerSide));

      Parameters:
      collectionProperty - The collection (multi-valued) property to check the elements on.
      compoundFilter - The composite filter (for example - AND or OR) that will filter the elements.
      Returns:
      A Filter that checks that the given collection property has elements that match the given compoundFilter.
      Throws:
      IllegalArgumentException - If the compoundFilter is not an AND or OR.
    • subquery

      public static Filter subquery(String property, Class<?> subqueryClass, String subqueryProperty, Filter subqueryFilter)
      Perform a subquery where the given property on the current class is found in a subquery over the given subquery class/property/filter. For example, if you want to find all Identities that have risky roles named after them, you would do the following: Filter.subquery("firstname", Bundle.class, "name", Filter.gt("riskScoreWeight", 500)); This turns into a query looking for Identities with a first name in the result set of role names with risk scores greater than 500. In pseudo SQL, this would look like:
         select *
           from Identity
          where firstname in (select name from Bundle where riskScoreWeight > 500)
       
      Note that a similar effect can be achieved by using Filter.join(), but this allows performing multiple subqueries on the same table, whereas a joined table can only be joined once.
      Parameters:
      property - The property on the query class to compared in against the results of the subquery.
      subqueryClass - The class to query over in the subquery.
      subqueryProperty - The property on the subquery class to compare against.
      subqueryFilter - The possibly-null filter to apply to the subquery.
      Returns:
      A subquery filter.
    • and

      public static Filter and(Filter filter1, Filter filter2)
      Combine the given filters with an AND conjunction.
    • and

      public static Filter and(List<Filter> children)
      Combine the given filters with an AND conjunction.
    • and

      public static Filter and(Filter... children)
      Combine the given filters with an AND conjunction.
    • or

      public static Filter or(Filter filter1, Filter filter2)
      Combine the given filters with an OR conjunction.
    • or

      public static Filter or(List<Filter> children)
      Combine the given filters with an OR conjunction.
    • or

      public static Filter or(Filter... children)
      Combine the given filters with an OR conjunction.
    • not

      public static Filter not(Filter filter)
      Negate the given filter.
    • ignoreCase

      public static Filter ignoreCase(Filter filter)
      Apply case-insensitivity to the given filter.
    • getValueEscapeStyle

      public Filter.ValueEscapeStyle getValueEscapeStyle()
    • setValueEscapeStyle

      public void setValueEscapeStyle(Filter.ValueEscapeStyle valueEscapeStyle)
    • accept

      public abstract void accept(Filter.FilterVisitor visitor) throws sailpoint.tools.GeneralException
      Throws:
      sailpoint.tools.GeneralException
    • getExpression

      public abstract String getExpression()
    • getExpression

      public String getExpression(boolean readable)
      Parameters:
      readable - Specify expression for machine for human readable language
      Returns:
      String expression
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • contentEquals

      public boolean contentEquals(Filter other)
      Specified by:
      contentEquals in interface sailpoint.tools.xml.IXmlEqualable<Filter>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object