Interface QueryRequest
- All Superinterfaces:
Request
There are four types of query request:
- default query: when neither a filter, expression or query ID are specified all resources will be returned
- query by filter: returns all resources which match the
QueryFilters
specified usingsetQueryFilter(QueryFilter)
- query by ID: returns all resources which match
the named prepared query specified using
setQueryId(String)
- query by expression: returns all resources
which match a native expression specified using
setQueryExpression(String)
. Note that this type of query should only be used in very rare cases since it introduces a tight coupling between the application and the underlying JSON resource. In addition, applications should take care to prevent users from directly accessing this form of query for security reasons.
In addition to the above mentioned query types queries may also be paged when a page size is found via getPageSize()
. Paged requests should be used in most cases when an unknown number of query results will be
returned.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The name of the field which specifies whether the query request is to return only the count of the results.static final String
The name of the field which contains the page size in the JSON representation.static final String
The name of the field which contains the paged results cookie in the JSON representation.static final String
The name of the field which contains the paged results offset in the JSON representation.static final String
The name of the field which contains the query expression in the JSON representation.static final String
The name of the field which contains the query filter in the JSON representation.static final String
The name of the field which contains the query ID in the JSON representation.static final String
The name of the field which contains the sort keys in the JSON representation.static final String
The name of the field which contains the policy used for calculating the total number of paged results.Fields inherited from interface org.forgerock.json.resource.Request
FIELD_ADDITIONAL_PARAMETERS, FIELD_FIELDS, FIELD_RESOURCE_PATH, FIELD_VALUE_ALL
-
Method Summary
Modifier and TypeMethodDescription<R,
P> R accept
(RequestVisitor<R, P> v, P p) Applies aRequestVisitor
to thisRequest
.Adds one or more fields which should be included with each JSON resource returned by this request.addField
(JsonPointer... fields) Adds one or more fields which should be included with each JSON resource returned by this request.addSortKey
(String... keys) Adds one or more sort keys which will be used for ordering the JSON resources returned by this query request.addSortKey
(SortKey... keys) Adds one or more sort keys which will be used for ordering the JSON resources returned by this query request.getAdditionalParameter
(String name) Returns the additional parameter which should be used to control the behavior of this action request.Returns the additional parameters which should be used to control the behavior of this action request.Returns the list of fields which should be included with each JSON resource returned by this request.Returns the opaque cookie which is used by the resource provider to track its position in the set of query results.int
Returns the zero-based index of the first resource which should be included in the query results.int
Returns the requested page results page size or0
if paged results are not required.Get the locale preference for the request.Returns the native query expression which will be used for processing the query request.Returns the query filter which will be used for selecting which JSON resources will be returned.Returns the query identifier for pre-defined queries.Returns the type of this request.Returns the non-null
path of the JSON resource to which this request should be targeted.Returns the non-null
path of the JSON resource to which this request should be targeted.Gets the requested API version of the resource.Returns the sort keys which should be used for ordering the JSON resources returned by this query request.Returns theCountPolicy
used to calculateQueryResponse.getTotalPagedResults()
.boolean
Return if the request should only return resource count.default boolean
Returns whether paged results are requested.setAdditionalParameter
(String name, String value) Sets an additional parameter which should be used to control the behavior of this action request.setCountOnly
(boolean countOnly) Sets whether the request was to only provide a count of the query results.setPagedResultsCookie
(String cookie) Sets the opaque cookie which is used by the resource provider to track its position in the set of query results.setPagedResultsOffset
(int offset) Sets the zero-based index of the first resource which should be included in the query results.setPageSize
(int size) Sets the requested page results page size or0
if paged results are not required.setPreferredLocales
(PreferredLocales preferredLocales) Set the locale preference for the request.setQueryExpression
(String expression) Sets the native query expression which will be used for processing the query request.setQueryFilter
(QueryFilter<JsonPointer> filter) Sets the query filter which will be used for selecting which JSON resources will be returned.setQueryId
(String id) Sets the query identifier for pre-defined queries.setResourcePath
(String path) Sets the non-null
path of the JSON resource to which this request should be targeted.setResourcePath
(ResourcePath path) Sets the non-null
path of the JSON resource to which this request should be targeted.setResourceVersion
(Version resourceVersion) Sets the requested API version of the resource.Sets the policy for calculating the total number of paged results.Return a JsonValue representation of this request.
-
Field Details
-
FIELD_PAGED_RESULTS_COOKIE
The name of the field which contains the paged results cookie in the JSON representation.- See Also:
-
FIELD_PAGED_RESULTS_OFFSET
The name of the field which contains the paged results offset in the JSON representation.- See Also:
-
FIELD_PAGE_SIZE
The name of the field which contains the page size in the JSON representation.- See Also:
-
FIELD_QUERY_EXPRESSION
The name of the field which contains the query expression in the JSON representation.- See Also:
-
FIELD_QUERY_FILTER
The name of the field which contains the query filter in the JSON representation.- See Also:
-
FIELD_QUERY_ID
The name of the field which contains the query ID in the JSON representation.- See Also:
-
FIELD_SORT_KEYS
The name of the field which contains the sort keys in the JSON representation.- See Also:
-
FIELD_TOTAL_PAGED_RESULTS_POLICY
The name of the field which contains the policy used for calculating the total number of paged results.- See Also:
-
FIELD_COUNT_ONLY
The name of the field which specifies whether the query request is to return only the count of the results.- See Also:
-
-
Method Details
-
accept
Description copied from interface:Request
Applies aRequestVisitor
to thisRequest
. -
addField
Description copied from interface:Request
Adds one or more fields which should be included with each JSON resource returned by this request. -
addField
Description copied from interface:Request
Adds one or more fields which should be included with each JSON resource returned by this request. -
addSortKey
Adds one or more sort keys which will be used for ordering the JSON resources returned by this query request.- Parameters:
keys
- The sort keys which will be used for ordering the JSON resources returned by this query request.- Returns:
- This query request.
- Throws:
UnsupportedOperationException
- If this query request does not permit changes to the sort keys.
-
addSortKey
Adds one or more sort keys which will be used for ordering the JSON resources returned by this query request.- Parameters:
keys
- The sort keys which will be used for ordering the JSON resources returned by this query request.- Returns:
- This query request.
- Throws:
IllegalArgumentException
- If one or more of the provided sort keys could not be parsed.UnsupportedOperationException
- If this query request does not permit changes to the sort keys.
-
getAdditionalParameter
Description copied from interface:Request
Returns the additional parameter which should be used to control the behavior of this action request.- Specified by:
getAdditionalParameter
in interfaceRequest
- Parameters:
name
- The name of the additional parameter.- Returns:
- The additional parameter which should be used to control the behavior of this action request
-
getAdditionalParameters
Description copied from interface:Request
Returns the additional parameters which should be used to control the behavior of this action request. The returned map may be modified if permitted by this action request.- Specified by:
getAdditionalParameters
in interfaceRequest
- Returns:
- The additional parameters which should be used to control the behavior of this action request (never
null
).
-
getFields
List<JsonPointer> getFields()Description copied from interface:Request
Returns the list of fields which should be included with each JSON resource returned by this request. The returned list may be modified if permitted by this query request. An empty list indicates that all fields should be included.NOTE: field filtering alters the structure of a JSON resource and MUST only be performed once while processing a request. It is therefore the responsibility of front-end implementations (e.g. HTTP listeners, Servlets, etc) to perform field filtering. Request handler and resource provider implementations SHOULD NOT filter fields, but MAY choose to optimise their processing in order to return a resource containing only the fields targeted by the field filters.
-
getPageSize
int getPageSize()Returns the requested page results page size or0
if paged results are not required. For all paged result requests other than the initial request, a cookie should be provided with the query request. SeegetPagedResultsCookie()
for more information.- Returns:
- The requested page results page size or
0
if paged results are not required. - See Also:
-
pagingRequested
default boolean pagingRequested()Returns whether paged results are requested.- Returns:
true
if paged results are requested,false
otherwise.- See Also:
-
getPagedResultsCookie
String getPagedResultsCookie()Returns the opaque cookie which is used by the resource provider to track its position in the set of query results. Paged results will be enabled if and only if the page size is non-zero.The cookie must be
null
in the initial query request sent by the client. For subsequent query requests the client must include the cookie returned with the previous query result, until the resource provider returns anull
cookie indicating that the final page of results has been returned.Note: Cookies and offsets are mutually exclusive.
- Returns:
- The opaque cookie which is used by the resource provider to track its position in the set of query
results, or
null
if paged results are not requested (when the page size is 0) or if the first page of results is being requested (when the page size is non-zero). - See Also:
-
getPagedResultsOffset
int getPagedResultsOffset()Returns the zero-based index of the first resource which should be included in the query results. An offset of 0 (default) will return the first resource in the collection. An offset of1
will return the second, and so on ...Note: Offsets and cookies are mutually exclusive. When a cookie is supplied only the default
0
offset is supported.Offset must be a zero-based integer denoting the number of records to skip. This is very similar to the
LIMIT
andSKIP
clauses in SQL databases.- Returns:
- The zero-based index within the result set of the first result which should be returned.
- See Also:
-
getPreferredLocales
PreferredLocales getPreferredLocales()Description copied from interface:Request
Get the locale preference for the request.- Specified by:
getPreferredLocales
in interfaceRequest
- Returns:
- The
PreferredLocales
instance for the request.
-
getQueryExpression
String getQueryExpression()Returns the native query expression which will be used for processing the query request. An example of a native query expression is a SQL statement.NOTE: the native query expression, query filter, and query ID parameters are mutually exclusive and only one of them may be specified.
- Returns:
- The native query expression which will be used for processing the query request, or
null
if another type of query is to be performed. - See Also:
-
getQueryFilter
QueryFilter<JsonPointer> getQueryFilter()Returns the query filter which will be used for selecting which JSON resources will be returned.NOTE: the native query expression, query filter, and query ID parameters are mutually exclusive and only one of them may be specified.
- Returns:
- The query filter which will be used for selecting which JSON resources will be returned, or
null
if another type of query is to be performed. - See Also:
-
getQueryId
String getQueryId()Returns the query identifier for pre-defined queries.NOTE: the native query expression, query filter, and query ID parameters are mutually exclusive and only one of them may be specified.
- Returns:
- The query identifier for pre-defined queries, or
null
if a pre-defined query is not to be used, ornull
if another type of query is to be performed. - See Also:
-
getRequestType
RequestType getRequestType()Description copied from interface:Request
Returns the type of this request.- Specified by:
getRequestType
in interfaceRequest
- Returns:
- The type of this request.
-
getResourcePath
String getResourcePath()Description copied from interface:Request
Returns the non-null
path of the JSON resource to which this request should be targeted. The resource path is relative and never begins or ends with a forward slash, but may be empty.NOTE: for resource provider implementations the resource path is relative to the current resource being accessed. See the description of
UriRouterContext
for more information.- Specified by:
getResourcePath
in interfaceRequest
- Returns:
- The non-
null
path of the JSON resource to which this request should be targeted, which may be the empty string.
-
getResourcePathObject
ResourcePath getResourcePathObject()Description copied from interface:Request
Returns the non-null
path of the JSON resource to which this request should be targeted. The resource path is relative and never begins or ends with a forward slash, but may be empty.NOTE: for resource provider implementations the resource path is relative to the current resource being accessed. See the description of
UriRouterContext
for more information.- Specified by:
getResourcePathObject
in interfaceRequest
- Returns:
- The non-
null
path of the JSON resource to which this request should be targeted, which may be the empty string.
-
getResourceVersion
Version getResourceVersion()Description copied from interface:Request
Gets the requested API version of the resource.- Specified by:
getResourceVersion
in interfaceRequest
- Returns:
- The requested API version of the resource.
-
getSortKeys
Returns the sort keys which should be used for ordering the JSON resources returned by this query request. The returned list may be modified if permitted by this query request.- Returns:
- The sort keys which should be used for ordering the JSON resources returned by this query request (never
null
).
-
getTotalPagedResultsPolicy
CountPolicy getTotalPagedResultsPolicy()Returns theCountPolicy
used to calculateQueryResponse.getTotalPagedResults()
.- Returns:
- The count policy.
- See Also:
-
isCountOnly
boolean isCountOnly()Return if the request should only return resource count.- Returns:
- whether the request should only return the resource count.
-
setAdditionalParameter
Description copied from interface:Request
Sets an additional parameter which should be used to control the behavior of this action request.- Specified by:
setAdditionalParameter
in interfaceRequest
- Parameters:
name
- The name of the additional parameter.value
- The additional parameter's value.- Returns:
- This request.
- Throws:
BadRequestException
- If this request does not permit the additional parameter to be set.
-
setPageSize
Sets the requested page results page size or0
if paged results are not required. For all paged result requests other than the initial request, a cookie should be provided with the query request. SeesetPagedResultsCookie(String)
for more information.- Parameters:
size
- The requested page results page size or0
if paged results are not required.- Returns:
- This query request.
- Throws:
UnsupportedOperationException
- If this query request does not permit changes to the page size.- See Also:
-
setPagedResultsCookie
Sets the opaque cookie which is used by the resource provider to track its position in the set of query results. Paged results will be enabled if and only if the page size is non-zero.The cookie must be
null
in the initial query request sent by the client. For subsequent query requests the client must include the cookie returned with the previous query result, until the resource provider returns anull
cookie indicating that the final page of results has been returned.When subsequent paged requests are being made no query parameters may be altered; doing so will result in undefined behavior. The only parameter that may be changed during paged requests is the page size.
- Parameters:
cookie
- The opaque cookie which is used by the resource provider to track its position in the set of query results.- Returns:
- This query request.
- Throws:
UnsupportedOperationException
- If this query request does not permit changes to the paged results cookie.- See Also:
-
setPagedResultsOffset
Sets the zero-based index of the first resource which should be included in the query results. An offset of 0 (default) will return the first resource in the collection. An offset of1
will return the second, and so on ...Note: Offsets and cookies are mutually exclusive. When a cookie is supplied only the default
0
offset is supported.Offset must be a zero-based integer denoting the number of records to skip. This is very similar to the
LIMIT
andSKIP
clauses in SQL databases.- Parameters:
offset
- The index within the result set of the first result which should be returned.- Returns:
- This query request.
- Throws:
UnsupportedOperationException
- If this query request does not permit changes to the paged results offset.- See Also:
-
setPreferredLocales
Description copied from interface:Request
Set the locale preference for the request.- Specified by:
setPreferredLocales
in interfaceRequest
- Parameters:
preferredLocales
- ThePreferredLocales
instance for the request.- Returns:
- This request.
-
setQueryExpression
Sets the native query expression which will be used for processing the query request. An example of a native query expression is a SQL statement.NOTE: the native query expression, query filter, and query ID parameters are mutually exclusive and only one of them may be specified.
- Parameters:
expression
- The native query expression which will be used for processing the query request, ornull
if another type of query is to be performed.- Returns:
- This query request.
- Throws:
UnsupportedOperationException
- If this query request does not permit changes to the query identifier.- See Also:
-
setQueryFilter
Sets the query filter which will be used for selecting which JSON resources will be returned.NOTE: the native query expression, query filter, and query ID parameters are mutually exclusive and only one of them may be specified.
- Parameters:
filter
- The query filter which will be used for selecting which JSON resources will be returned, ornull
if another type of query is to be performed.- Returns:
- This query request.
- Throws:
UnsupportedOperationException
- If this query request does not permit changes to the query filter.- See Also:
-
setQueryId
Sets the query identifier for pre-defined queries.NOTE: the native query expression, query filter, and query ID parameters are mutually exclusive and only one of them may be specified.
- Parameters:
id
- The query identifier for pre-defined queries, ornull
if another type of query is to be performed.- Returns:
- This query request.
- Throws:
UnsupportedOperationException
- If this query request does not permit changes to the query identifier.- See Also:
-
setResourcePath
Description copied from interface:Request
Sets the non-null
path of the JSON resource to which this request should be targeted. The resource path is relative and never begins or ends with a forward slash, but may be empty.NOTE: for resource provider implementations the resource path is relative to the current resource being accessed. See the description of
UriRouterContext
for more information.- Specified by:
setResourcePath
in interfaceRequest
- Parameters:
path
- The non-null
path of the JSON resource to which this request should be targeted, which may be the empty string.- Returns:
- This request.
-
setResourcePath
Description copied from interface:Request
Sets the non-null
path of the JSON resource to which this request should be targeted. The resource path is relative and never begins or ends with a forward slash, but may be empty.NOTE: for resource provider implementations the resource path is relative to the current resource being accessed. See the description of
UriRouterContext
for more information.- Specified by:
setResourcePath
in interfaceRequest
- Parameters:
path
- The non-null
path of the JSON resource to which this request should be targeted, which may be the empty string. The path should be URL-encoded.- Returns:
- This request.
-
setResourceVersion
Description copied from interface:Request
Sets the requested API version of the resource.- Specified by:
setResourceVersion
in interfaceRequest
- Parameters:
resourceVersion
- The requested API version of the resource.- Returns:
- This request.
-
setTotalPagedResultsPolicy
Sets the policy for calculating the total number of paged results. If no count policy is supplied or paged results are not requested a default ofCountPolicy.NONE
will be used. This will result in no count being performed and no overhead incurred.- Parameters:
policy
- The policy used to calculate total paged results- Returns:
- This query request.
- See Also:
-
setCountOnly
Sets whether the request was to only provide a count of the query results.- Parameters:
countOnly
- whether to return result count only.- Returns:
- this query request
-
toJsonValue
JsonValue toJsonValue()Description copied from interface:Request
Return a JsonValue representation of this request.- Specified by:
toJsonValue
in interfaceRequest
- Returns:
- this request as a JsonValue
-