Class Query
- java.lang.Object
-
- com.sodius.oslc.server.process.query.Query
-
public class Query extends Object
Provides information on an OSLC query made with a HTTP request. The query is defined with some query parameters (e.g.oslc.where
) and some paging information. This class helps at producing aResponseInfoCollection
with the fetched resources and a reference for the next page, if any.- Since:
- 3.6.0
-
-
Constructor Summary
Constructors Constructor Description Query(HttpServletRequest request, QueryParameters parameters, int defaultPageSize, int maxPageSize)
Creates a query instance with the given request parameters and desired paging information.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> ResponseInfoCollection<T>
createResponseInfo(Collection<T> resources)
Returns aResponseInfoCollection
for the given resources, with a undetermined total number of resources.<T> ResponseInfoCollection<T>
createResponseInfo(Collection<T> resources, Integer totalCount)
Returns aResponseInfoCollection
for the given resources, with a known total number of resources.int
getPage()
Return the page index that is requested, for which resources are to fetch.int
getPageSize()
Returns the size of page to use, which is the desired number of resources to fetch.int
getPageStartIndex()
Returns the index of the first resource to fetch with this query.QueryParameters
getParameters()
Returns the parsed query parameters.
-
-
-
Constructor Detail
-
Query
public Query(HttpServletRequest request, QueryParameters parameters, int defaultPageSize, int maxPageSize)
Creates a query instance with the given request parameters and desired paging information.The query will provide paging information that combines what is requested by the client, with the
oslc.pageSize
parameter, and the page size recommended by the application.This query assume a
"page"
request parameter is used to indicate which page index is requested. If absent, it assumes the first page is requested.- Parameters:
request
- the HTTP requestparameters
- the query parameters parsed form the HTTP requestdefaultPageSize
- the default size of a pagemaxPageSize
- the maximum size of a page- Throws:
NullPointerException
- if request or parameters is nullNumberFormatException
- if the"page"
request parameter is present but is not a valid integerIllegalArgumentException
- if the"pageSize"
is not a positive integer
-
-
Method Detail
-
getParameters
public QueryParameters getParameters()
Returns the parsed query parameters.- Returns:
- the parsed query parameters
-
getPage
public int getPage()
Return the page index that is requested, for which resources are to fetch.- Returns:
- the requested page index
-
getPageSize
public int getPageSize()
Returns the size of page to use, which is the desired number of resources to fetch. This page size is the one requested with theoslc.pageSize
parameter, or the default size recommended by the application if the parameter is absent, but limited to the maximum size in the constructor.- Returns:
- the page size
-
getPageStartIndex
public int getPageStartIndex()
Returns the index of the first resource to fetch with this query. This index is the number of resources yet responded by previous pages of the query. When searching for an ordered list of resources matching the query filter, all resources below that index are to ignore and not to include in the response.- Returns:
- the index of the first resource to fetch with the query
-
createResponseInfo
public <T> ResponseInfoCollection<T> createResponseInfo(Collection<T> resources)
Returns aResponseInfoCollection
for the given resources, with a undetermined total number of resources.If the total number of resources can be determined by the application, prefer using
createResponseInfo(Collection, Integer)
so that the client has more information.The
ResponseInfoCollection
contains a reference to a next page if the number of fetched resources is greater than (or equal to) the desired page size, as this method assumes a next page may contain additional resources in this case.- Type Parameters:
T
- the type of resources in the response- Parameters:
resources
- the resources fetched in this page with the query- Returns:
- the response info collection
- Throws:
NullPointerException
- if resources is null
-
createResponseInfo
public <T> ResponseInfoCollection<T> createResponseInfo(Collection<T> resources, Integer totalCount)
Returns aResponseInfoCollection
for the given resources, with a known total number of resources.The
ResponseInfoCollection
contains a reference to a next page if thestart index
and number of fetched resources is lower than the total number of resources.- Type Parameters:
T
- the type of resources in the response- Parameters:
resources
- the resources fetched in this page with the querytotalCount
- the known total number of resources in the application for this query filter, across all pages- Returns:
- the response info collection
- Throws:
NullPointerException
- if resources is null
-
-