Class FilterQueryBuilder

java.lang.Object
net.amcintosh.freshbooks.models.builders.FilterQueryBuilder
All Implemented Interfaces:
QueryBuilder

public class FilterQueryBuilder extends Object implements QueryBuilder
Builder for making filtered list queries. Filters can be chained together.

     FreshBooksClient freshBooksClient = new FreshBooksClient.FreshBooksClientBuilder("some_client_id")
         .withAccessToken("some_token")
         .build();
     Clients clients = new Clients(freshBooksClient);

     FilterQueryBuilder filters = new FilterQueryBuilder();
     filters.inList("clientids", [123, 456]);
     assertEquals("&search[clientids][]=123&search[clientids][]=456", filters.build(ResourceType.ACCOUNTING_LIKE));

     FilterQueryBuilder filters = new FilterQueryBuilder();
     filters.like("email_like", "@freshbooks.com").boolean("active", false);
     assertEquals("&search[email_like]=@freshbooks.com&active=False", filters.build(ResourceType.ACCOUNTING_LIKE));

     ArrayList<QueryBuilder> builders = new ArrayList<QueryBuilder>();
     builders.add(filters);

     ClientList clientListResponse = clients.list(accountId, builders);
 
  • Constructor Details

    • FilterQueryBuilder

      public FilterQueryBuilder()
  • Method Details

    • addBetween

      public FilterQueryBuilder addBetween(String field, int min, int max)
      Filters results where the provided field is between two values. In general 'between' filters in FreshBooks end in a '_min' or '_max' (as in 'amount_min' or 'amount_max') or '_date' (as in 'start_date', 'end_date'). Thus for numerical values '_min' and '_max' will be appended to the 'field' value.

      Eg. 'addBetween("amount", 1, 10);' will result in a filter of '&search[amount_min]=1&search[amount_max]=10'.

      For '_date' fields, or non-standard between filters, they must be composed individually:

      Eg. 'addBetween("start_date", "2022-01-19");' will result in filters of '&search[start_date]=2022-01-19'.
      Parameters:
      field - The API response field to filter on
      min - The value the field should be greater than (or equal to)
      max - The value the field should be less than (or equal to)
      Returns:
      The FilterQueryBuilder instance.
    • addBetween

      public FilterQueryBuilder addBetween(String field, int value)
      Filters results where the provided field is either greater than or less than the value based on the filter field.

      Eg.
      • 'addBetween("amount_min", 1);' will result in a filter of '&search[amount_min]=1'.
      • 'addBetween("amount_max", 10);' will result in a filter of '&search[amount_max]=10'.
      Parameters:
      field - The API filter key
      value - The value the key should be compared to
      Returns:
      The FilterQueryBuilder instance.
    • addBetween

      public FilterQueryBuilder addBetween(String field, String value)
      Filters results where the provided field is either greater than or less than the value based on the filter field.
      Eg. 'addBetween("start_date", "2022-01-19");' will result in a filter of '&search[start_date]=2022-01-19'.
      Parameters:
      field - The API filter key
      value - The value the key should be compared to
      Returns:
      The FilterQueryBuilder instance.
    • addBoolean

      public FilterQueryBuilder addBoolean(String field, boolean value)
      Filters results where the field is equal to true or false.
      Eg. 'addBoolean("active", false);' will result in a filter of '&active=false'.
      Parameters:
      field - The API response field to filter on
      value - true or false
      Returns:
      The FilterQueryBuilder instance.
    • addDate

      public FilterQueryBuilder addDate(String field, LocalDate value)
      Filters for entries that come before or after a particular time, as specified by the field. Eg. "updated_since" on Time Entries will return time entries updated after the provided date.
      Eg. 'addDateTime("updated_since", LocalDate.now())' will yield '&updated_since=2022-01-28'.
      Parameters:
      field - The API response field to filter on
      value - The date object
      Returns:
      The FilterQueryBuilder instance.
    • addDateTime

      public FilterQueryBuilder addDateTime(String field, ZonedDateTime value)
      Filters for entries that come before or after a particular time, as specified by the field. Eg. "updated_since" on Time Entries will return time entries updated after the provided time.
      Eg. 'addDateTime("updated_since", ZonedDateTime.now())' will yield '&updated_since=2022-01-28T13:14:07'.
      Parameters:
      field - The API response field to filter on
      value - The timezone-aware date time object
      Returns:
      The FilterQueryBuilder instance.
    • addEquals

      public FilterQueryBuilder addEquals(String field, String value)
      Filters results where the field is equal to the provided value.
      Eg. 'addEquals("username", "Bob")' will yield '&search[username]=Bob' for an accounting-like resource and '&username=Bob' for a project-like resource.
      Parameters:
      field - The API response field to filter on
      value - The value the field should equal
      Returns:
      The FilterQueryBuilder instance.
    • addEquals

      public FilterQueryBuilder addEquals(String field, int value)
      Filters results where the field is equal to the provided value.
      Eg. 'addEquals("username", "Bob")' will yield '&search[username]=Bob' for an accounting-like resource and '&username=Bob' for a project-like resource.
      Parameters:
      field - The API response field to filter on
      value - The value the field should equal
      Returns:
      The FilterQueryBuilder instance.
    • addInList

      public FilterQueryBuilder addInList(String field, List<Integer> values)
    • addLike

      public FilterQueryBuilder addLike(String field, String value)
      Filters for a match contained within the field being searched. For example, "leaf" will Like-match "aleaf" and "leafy", but not "leav", and "leafs" would not Like-match "leaf".
      Eg. 'addLike("organization_like", "fresh")' will yield '&search[organization_like]=fresh'.
      Parameters:
      field - The API response field to filter on
      value - The value the field should equal
      Returns:
      The FilterQueryBuilder instance.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • build

      public String build(ResourceType resourceType)
      Build the query string parameters for the list. As different FreshBooks resources use different structure for filter parameters, a resource type is required.
      Specified by:
      build in interface QueryBuilder
      Parameters:
      resourceType - The resource type.
      Returns:
      The composed query string parameters.