Class 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 a ResponseInfoCollection with the fetched resources and a reference for the next page, if any.
    Since:
    3.6.0
    • 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 request
        parameters - the query parameters parsed form the HTTP request
        defaultPageSize - the default size of a page
        maxPageSize - the maximum size of a page
        Throws:
        NullPointerException - if request or parameters is null
        NumberFormatException - if the "page" request parameter is present but is not a valid int
    • 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 the oslc.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 a ResponseInfoCollection 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 a ResponseInfoCollection for the given resources, with a known total number of resources.

        The ResponseInfoCollection contains a reference to a next page if the start 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 query
        totalCount - 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