Pagination and Sorting

The objects related to pagination and sorting available in commercewebservicescommons and commerceservices extensions have been deprecated. The replacement objects can be found in the webservicescommons and platform extensions.

Data Structures

The objects in webservicescommons extension are intended only as output objects. Because their format differs from the one provided by the commercewebservicescommons extension, some of the existing webservices provide a new version for the endpoints to allow migration.

The objects in the platform are used as input for the facade/service layer and output from these layers.

Data Flow

The data flow is as follows:

  1. A request is made with sorting/pagination parameters:
    GET /users?pageSize=10&
    currentPage=1&
    sort=description,name:desc
  2. The controller creates a new SearchPageData object by creating List<SortData> and PaginationData objects, which is done by using the de.hybris.platform.webservicescommons.pagination.WebPaginationUtils interface for a call to the facade/service.

    The facade/service uses the de.hybris.platform.servicelayer.search.paginated.PaginatedFlexibleSearchService or de.hybris.platform.servicelayer.search.paginated.dao.PaginatedGenericDao interfaces, which support the new pagination and sorting objects.

  3. The facade/service returns the SearchPageData object.
  4. The controller uses the WebPaginationUtils / data mapper / converter to generate the SearchpageWsDto and returns it.

Using SearchPageWsDTO

The SearchPageWsDto<Result> is intended as a helper for creating output from a controller, but it should not be used directly.

Follow the steps below to make sure the SearchPageWsDTO is used properly:
  1. Create a dedicated subclass in yourextension-beans.xml file.
    <bean class="ywebservicespackage.dto.UsersPageWsDTO" extends="de.hybris.platform.webservicescommons.dto.SearchPageWsDTO&lt;ywebservicespackage.dto.UserWsDTO>" >
  2. Create a mapper configuration for Orika.
    <bean parent="fieldSetLevelMapping" id="usersPageWsDTOFieldSetLevelMapping">
        <property name="dtoClass" value="ywebservicespackage.dto.UsersPageWsDTO"/>
        <property name="levelMapping">
            <map>
                <entry key="BASIC" value="pagination(BASIC),sorts(BASIC),results(BASIC)"/>
                <entry key="DEFAULT" value="pagination(DEFAULT),sorts(DEFAULT),results(DEFAULT)"/>
                <entry key="FULL" value="pagination(FULL),sorts(FULL),results(FULL)"/>
            </map>
        </property>
    </bean>
  3. Return your subclass from the controller.
    public UsersPageWsDTO getUsersWithPagination(
        @RequestParam(required = false, defaultValue = DEFAULT_FIELD_SET) final String fields,
        @RequestParam final Map<String, String> params)
        {
            final SearchPageData<?> pageData = webPaginationUtils.buildSearchPageData(params);
     
            final SearchPageData<UserData> users = sampleFacades.getUsers(pageData);
     
            return dataMapper.map(users, UsersPageWsDTO.class, fields);
        }

For an example of using the SearchPageWsDTO in such a way, see ywebservices extension.