T - A placeholder for the type expected in the response, avoiding the requirement to cast responses. This is not
linked to the Type set on a request so a ClassCastException is possible if the type is set
incorrectly.public class ServiceSearchRequestBuilder<T> extends Object implements SearchRequestBuilder<T>
A builder used to construct generic ServiceSearchRequest instances that may be used against any search resource.
This provides methods for setting filters, pagination and sorting parameters, and column selection on the request. These
are all sent as querystring parameters, so be aware that using the withAddedParam(String, String) method can
overwrite values set by other methods.
Resource-specific search request builders are included in the accompanying services package; these provide dedicated methods for each column in that search and enums respresenting the columns.
| Modifier and Type | Field and Description |
|---|---|
static String |
COLUMNS_PARAM |
static String |
FIRST_RESULT_COLUMN |
static String |
PAGE_SIZE_COLUMN |
static String |
SORT_PARAM |
| Modifier and Type | Method and Description |
|---|---|
ServiceSearchRequest<T> |
build()
Constructs the immutable request instance for execution.
|
protected Method |
getMethod() |
protected Map<String,String> |
getParams() |
protected String |
getPath() |
protected Type |
getResponseType() |
protected String |
getRuid() |
protected ServiceName |
getService() |
protected ServiceSearchRequestBuilder<T> |
getThis() |
static <T> ServiceSearchRequestBuilder<T> |
newSearchRequest(ServiceName service,
String path,
Class<T> responseType)
Creates a new search request builder configured with the URL to call and expected response type.
|
static <T> ServiceSearchRequestBuilder<T> |
newSearchRequest(ServiceName service,
String path,
Type responseType)
Creates a new search request builder configured with the URL to call and expected response type.
|
ServiceSearchRequestBuilder<T> |
withAddedColumn(String column)
Adds a column to be included in search results.
|
ServiceSearchRequestBuilder<T> |
withAddedFilter(String column,
String value)
Add an additional column value filter to be applied to the search.
|
ServiceSearchRequestBuilder<T> |
withAddedFilters(Map<String,String> filters)
Add additional column value filters to be applied to the search, preserving previous filters set on this builder.
|
B |
withAddedParam(String name,
String value)
Add an additional unencoded querystring parameter to be added to the request, preserving the existing set but
overwriting any param with the same name.
|
B |
withAddedParams(Map<String,String> params)
Add additional unencoded querystring parameters to be added to the request, preserving the existing set but
overwriting any param with the same names.
|
ServiceSearchRequestBuilder<T> |
withAddedSort(String column,
SortDirection direction)
Add an additional column sort to be applied to the search.
|
ServiceSearchRequestBuilder<T> |
withColumns(List<String> columns)
Sets the columns to be included in search results, replacing any previously set.
|
ServiceSearchRequestBuilder<T> |
withColumns(String... columns)
Sets the columns to be included in search results, replacing any previously set.
|
ServiceSearchRequestBuilder<T> |
withFilters(Map<String,String> filters)
Set the column value filters to be applied to the search, replacing any previous filters set on this builder.
|
ServiceSearchRequestBuilder<T> |
withFirstResult(Integer firstResult)
Sets the first result to return, allowing paging through large result sets.
|
ServiceSearchRequestBuilder<T> |
withPage(Integer pageSize,
Integer firstResult)
Set paging parameters in one call.
|
ServiceSearchRequestBuilder<T> |
withPageSize(Integer pageSize)
Sets the number of results to return per page, allowing paging through large result sets.
|
B |
withParams(Map<String,String> params)
Add querystring parameters to the request, replacing any previously set.
|
B |
withPath(String path)
Set the path of the Brightpearl resource within the service provided to
withService(ServiceName). |
B |
withResponseType(Type responseType)
Set the generic type token representing the expected type of the response element in the JSON response body.
|
B |
withRuid(String ruid)
Set a unique identifier for the request.
|
B |
withService(ServiceName service)
Returns the name of the Brightpearl service that contains the resource to be called.
|
ServiceSearchRequestBuilder<T> |
withSorts(Map<String,SortDirection> sorts)
Set the sort columns and directions, replacing any previously added.
|
public static final String COLUMNS_PARAM
public static final String PAGE_SIZE_COLUMN
public static final String FIRST_RESULT_COLUMN
public static final String SORT_PARAM
protected ServiceSearchRequestBuilder<T> getThis()
public static <T> ServiceSearchRequestBuilder<T> newSearchRequest(ServiceName service, String path, Class<T> responseType)
T - Placeholder for the response type, used to avoid casting of responses.service - Brightpearl service that contains the resource.path - Path to the search resource, for example '/product-search'.responseType - Type of search result expected. In many cases this will be a different class to that used for
resource GET requests; it must have a flat structure with fields corresponding to column names.public static <T> ServiceSearchRequestBuilder<T> newSearchRequest(ServiceName service, String path, Type responseType)
T - Placeholder for the response type, used to avoid casting of responses. Responses are parsed into the type defined by responseType, not this type parameter.service - Brightpearl service that contains the resource.path - Path to the search resource, for example '/product-search'.responseType - Type of search result expected. In many cases this will be a different class to that used for
resource GET requests; it must have a flat structure with fields corresponding to column names.public ServiceSearchRequest<T> build()
build in interface SearchRequestBuilder<T>public ServiceSearchRequestBuilder<T> withAddedFilter(String column, String value)
column - name of column to filter on.value - value of filter.public ServiceSearchRequestBuilder<T> withAddedFilters(Map<String,String> filters)
filters - map of filters (column name to filter string) to be applied.public ServiceSearchRequestBuilder<T> withFilters(Map<String,String> filters)
filters - Map of filters (column name to filter string) to be applied.public ServiceSearchRequestBuilder<T> withAddedSort(String column, SortDirection direction)
column - Name of the column to sort by.direction - Direction to sort in.public ServiceSearchRequestBuilder<T> withSorts(Map<String,SortDirection> sorts)
Map implementation
that preserves insertion order, for example LinkedHashMap.sorts - Map of column name to sort direction.public ServiceSearchRequestBuilder<T> withPage(Integer pageSize, Integer firstResult)
pageSize - Number of results per page.firstResult - Position of first result to return.public ServiceSearchRequestBuilder<T> withPageSize(Integer pageSize)
pageSize - Number of results per page.public ServiceSearchRequestBuilder<T> withFirstResult(Integer firstResult)
firstResult - Position of the first result to return.public ServiceSearchRequestBuilder<T> withAddedColumn(String column)
column - Columns to be included in the results.public ServiceSearchRequestBuilder<T> withColumns(String... columns)
columns - Columns to be included in the results.public ServiceSearchRequestBuilder<T> withColumns(List<String> columns)
columns - Columns to be included in the results.public B withRuid(String ruid)
Note this RUID is applied only to the first request built by this builder; if you call build() more than
once, the second and subsequent requests will have randomly generated IDs unless you also call this method
between each invocation.
ruid - the custom unique identifier to use.public B withService(ServiceName service)
service - service containing the target resource.public B withPath(String path)
withService(ServiceName). For example, for
the product GET API, this would be '/product'.path - the path to be set.public B withResponseType(Type responseType)
Type is used instead of Class to provide support for deserialising
generic types e.g. collections and maps, however this does mean the type is not guaranteed to match the type token
T, which is used to avoid casting responses.responseType - the type to set.public B withAddedParam(String name, String value)
name - parameter name.value - parameter value.public B withAddedParams(Map<String,String> params)
params - map of querystring params.public B withParams(Map<String,String> params)
params - map of querystring params.protected String getRuid()
protected ServiceName getService()
protected Method getMethod()
protected String getPath()
protected Type getResponseType()
Copyright © 2014. All Rights Reserved.