Class FilterHelper


  • public class FilterHelper
    extends Object
    Helper class for working RSQL filter mechanisms
    Author:
    Jeff Fischer
    • Method Detail

      • getLinkedFieldInformation

        public static Optional<FilterHelper.LinkField> getLinkedFieldInformation​(@NonNull
                                                                                 Class<?> rootType,
                                                                                 @NonNull
                                                                                 String selector)
        If a Link annotated field is targeted by the selector, return information about the link.
        Parameters:
        rootType - The type of the containing repository domain
        selector - The selector from RSQL targeting a projection field that is buried in the entity referenced via the Link annotated field.
        Returns:
        Information about the link
      • transform

        @NonNull
        public static cz.jirutka.rsql.parser.ast.Node transform​(@Nullable
                                                                cz.jirutka.rsql.parser.ast.Node filters,
                                                                @NonNull
                                                                TrackableRepository<Trackable> repository,
                                                                @NonNull
                                                                List<RsqlQueryTransformer> rsqlQueryTransformers)
        Transforms filters from properties that target a projection into ones that apply to a backing repository provider domain object
        Parameters:
        filters - RSQL filters targeting a projection domain
        repository - A TrackableRepository form which to glean entity information for the transformation
        rsqlQueryTransformers - Customizes a RSQL query before it is passed on to the repository layer
        Returns:
        null if filters is null, otherwise an RSQL query suitable for targeting a repository domain object.
        See Also:
        RsqlQueryTransformer
      • transform

        @NonNull
        public static cz.jirutka.rsql.parser.ast.Node transform​(@NonNull
                                                                cz.jirutka.rsql.parser.ast.Node filters,
                                                                @NonNull
                                                                com.broadleafcommerce.common.extension.DomainTypeAware domainAware,
                                                                @NonNull
                                                                List<RsqlQueryTransformer> rsqlQueryTransformers)
        Transforms filters from properties that target a projection into ones that apply to a backing repository provider domain object
        Parameters:
        filters - RSQL filters targeting a projection domain
        domainAware - A DomainTypeAware form which to glean entity information for the transformation
        rsqlQueryTransformers - Customizes a RSQL query before it is passed on to the repository layer
        Returns:
        null if filters is null, otherwise an RSQL query suitable for targeting a repository domain object.
        See Also:
        RsqlQueryTransformer
      • filterByNameAndFilters

        @NonNull
        public static cz.jirutka.rsql.parser.ast.Node filterByNameAndFilters​(@Nullable
                                                                             cz.jirutka.rsql.parser.ast.Node filters,
                                                                             @Nullable
                                                                             String name,
                                                                             @Nullable
                                                                             FilterParser<cz.jirutka.rsql.parser.ast.Node> parser)
        A convenience method that acts as a shortcut to filterByFieldAndFilters(Node, String, String, FilterParser) with "name" supplied as the field argument.
        Parameters:
        filters - (optional) Node filters
        name - (optional) the search string that will be used to filter by name
        parser - (optional) the parser that can be used to build a Node for filtering by name. If null, name will be ignored.
        Returns:
        the "AND"-ed combination of filters and a contains-ignoring-case filter on the name field
      • filterByFieldAndFilters

        @NonNull
        public static cz.jirutka.rsql.parser.ast.Node filterByFieldAndFilters​(@Nullable
                                                                              cz.jirutka.rsql.parser.ast.Node filters,
                                                                              @Nullable
                                                                              String fieldName,
                                                                              @Nullable
                                                                              String searchString,
                                                                              @Nullable
                                                                              FilterParser<cz.jirutka.rsql.parser.ast.Node> parser)
        Produces a Node that is the "AND"-ed combination of filters and a contains-ignoring-case filter on fieldName with searchString.

        If searchString and filters are both empty (or effectively not present), EmptyNode will be returned.

        If filters is provided and searchString is empty, filters will be returned as-is.

        If searchString is provided and filters is empty (or effectively not present), a Node for filtering fieldName by searchString will be built and returned.

        If searchString and filters are both provided, both will be combined and returned in an AndNode.

        Parameters:
        filters - (optional) Node filters
        fieldName - the name of the field against which a contains-ignoring-case filter should be built with searchString as an argument. Required if searchString is supplied.
        searchString - (optional) the search string that will be used to filter fieldName
        parser - (optional) the parser that can be used to build a Node for fieldName/searchString. If null, searchString will be ignored.
        Returns:
        the "AND"-ed combination of filters and a contains-ignoring-case filter on fieldName with searchString
      • filterByFieldAndFiltersIn

        @NonNull
        public static cz.jirutka.rsql.parser.ast.Node filterByFieldAndFiltersIn​(@Nullable
                                                                                cz.jirutka.rsql.parser.ast.Node filters,
                                                                                @NonNull
                                                                                String fieldName,
                                                                                @Nullable
                                                                                List<String> searchList,
                                                                                @NonNull
                                                                                FilterParser<cz.jirutka.rsql.parser.ast.Node> parser)
        Produces a Node that is the "AND"-ed combination of filters and a in filter on fieldName with searchString.

        If searchLList and filters are both empty (or effectively not present), EmptyNode will be returned.

        If filters is provided and searchList is empty, filters will be returned as-is.

        If searchList is provided and filters is empty (or effectively not present), a Node for filtering fieldName by searchList will be built and returned.

        If searchList and filters are both provided, both will be combined and returned in an AndNode.

        Parameters:
        filters - (optional) Node filters
        fieldName - the name of the field against which a contains-ignoring-case filter should be built with searchList as an argument. Required if searchString is supplied.
        searchList - (optional) the search string that will be used to filter fieldName
        parser - the parser that can be used to build a Node for fieldName/searchList. If null, searchList will be ignored.
        Returns:
        the "AND"-ed combination of filters and a contains-ignoring-case filter on fieldName with searchList