Example usage for org.springframework.data.domain Pageable getPageSize

List of usage examples for org.springframework.data.domain Pageable getPageSize

Introduction

In this page you can find the example usage for org.springframework.data.domain Pageable getPageSize.

Prototype

int getPageSize();

Source Link

Document

Returns the number of items to be returned.

Usage

From source file:org.dspace.app.rest.repository.WorkspaceItemRestRepository.java

@Override
public Page<WorkspaceItemRest> findAll(Context context, Pageable pageable) {
    List<WorkspaceItem> witems = null;
    int total = 0;
    try {//  ww w.  ja  va2  s . co  m
        total = wis.countTotal(context);
        witems = wis.findAll(context, pageable.getPageSize(), pageable.getOffset());
    } catch (SQLException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    Page<WorkspaceItemRest> page = new PageImpl<WorkspaceItem>(witems, pageable, total).map(converter);
    return page;
}

From source file:org.dspace.app.rest.repository.WorkspaceItemRestRepository.java

@SearchRestMethod(name = "findBySubmitter")
public Page<WorkspaceItemRest> findBySubmitter(@Parameter(value = "uuid", required = true) UUID submitterID,
        Pageable pageable) {
    List<WorkspaceItem> witems = null;
    int total = 0;
    try {//from w  w  w  . java2 s . c  o m
        Context context = obtainContext();
        EPerson ep = epersonService.find(context, submitterID);
        witems = wis.findByEPerson(context, ep, pageable.getPageSize(), pageable.getOffset());
        total = wis.countByEPerson(context, ep);
    } catch (SQLException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    Page<WorkspaceItemRest> page = new PageImpl<WorkspaceItem>(witems, pageable, total).map(converter);
    return page;
}

From source file:org.dspace.app.rest.RestResourceController.java

private <ID extends Serializable> ResourceSupport findRelInternal(HttpServletRequest request,
        String apiCategory, String model, ID uuid, String rel, Pageable page, PagedResourcesAssembler assembler,
        String projection) {//  w w  w.j  a  va2  s  .c  o m
    checkModelPluralForm(apiCategory, model);
    DSpaceRestRepository<RestModel, ID> repository = utils.getResourceRepository(apiCategory, model);
    Class<RestModel> domainClass = repository.getDomainClass();

    LinkRest linkRest = utils.getLinkRest(rel, domainClass);

    if (linkRest != null) {
        LinkRestRepository linkRepository = utils.getLinkResourceRepository(apiCategory, model,
                linkRest.name());
        Method linkMethod = repositoryUtils.getLinkMethod(linkRest.method(), linkRepository);

        if (linkMethod == null) {
            // TODO custom exception
            throw new RuntimeException(
                    "Method for relation " + rel + " not found: " + linkRest.name() + ":" + linkRest.method());
        } else {
            try {
                Page<? extends Serializable> pageResult = (Page<? extends RestModel>) linkMethod
                        .invoke(linkRepository, request, uuid, page, projection);
                Link link = linkTo(this.getClass(), apiCategory, English.plural(model)).slash(uuid).slash(rel)
                        .withSelfRel();
                PagedResources<? extends ResourceSupport> result = assembler
                        .toResource(pageResult.map(linkRepository::wrapResource), link);
                return result;
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
    }
    RestModel modelObject = repository.findOne(uuid);
    DSpaceResource result = repository.wrapResource(modelObject, rel);
    if (result.getLink(rel) == null) {
        // TODO create a custom exception
        throw new ResourceNotFoundException(rel + "undefined for " + model);
    } else if (result.getEmbedded().get(rel) instanceof EmbeddedPage) {
        // this is a very inefficient scenario. We have an embedded list
        // already fully retrieved that we need to limit with pagination
        // parameter. BTW change the default sorting is not implemented at
        // the current stage and could be overcompex to implement
        // if we really want to implement pagination we should implement a
        // link repository so to fall in the previous block code
        EmbeddedPage ep = (EmbeddedPage) result.getEmbedded().get(rel);
        List<? extends RestModel> fullList = ep.getFullList();
        if (fullList == null || fullList.size() == 0)
            return null;
        int start = page.getOffset();
        int end = (start + page.getPageSize()) > fullList.size() ? fullList.size()
                : (start + page.getPageSize());
        DSpaceRestRepository<RestModel, ?> resourceRepository = utils
                .getResourceRepository(fullList.get(0).getCategory(), fullList.get(0).getType());
        PageImpl<RestModel> pageResult = new PageImpl(fullList.subList(start, end), page, fullList.size());
        return assembler.toResource(pageResult.map(resourceRepository::wrapResource));
    } else {
        ResourceSupport resu = (ResourceSupport) result.getEmbedded().get(rel);
        return resu;
    }
}

From source file:org.dspace.app.rest.utils.DiscoverQueryBuilder.java

private DiscoverQuery addFacetingForFacets(Context context, DSpaceObject scope, String prefix,
        DiscoverQuery queryArgs, DiscoveryConfiguration discoveryConfiguration, String facetName, Pageable page)
        throws InvalidSearchFacetException {

    DiscoverySearchFilterFacet facet = discoveryConfiguration.getSidebarFacet(facetName);
    if (facet != null) {
        queryArgs.setFacetMinCount(1);//w  w  w . j  av a  2 s .  c  o m
        int pageSize = Math.min(pageSizeLimit, page.getPageSize());

        fillFacetIntoQueryArgs(context, scope, prefix, queryArgs, facet, pageSize);

    } else {
        throw new InvalidSearchFacetException(facetName + " is not a valid search facet");
    }

    return queryArgs;
}

From source file:org.dspace.app.rest.utils.DiscoverQueryBuilder.java

private void configurePagination(Pageable page, DiscoverQuery queryArgs) {
    if (page != null) {
        queryArgs.setMaxResults(Math.min(pageSizeLimit, page.getPageSize()));
        queryArgs.setStart(page.getOffset());
    } else {//from w  ww. j av a2  s  .  c o m
        queryArgs.setMaxResults(pageSizeLimit);
        queryArgs.setStart(0);
    }
}

From source file:org.dspace.app.rest.utils.Utils.java

public <T> Page<T> getPage(List<T> fullContents, Pageable pageable) {
    int total = fullContents.size();
    List<T> pageContent = null;
    if (pageable.getOffset() > total) {
        throw new PaginationException(total);
    } else {//from   www  .j  a v a 2  s.c  o  m
        if (pageable.getOffset() + pageable.getPageSize() > total) {
            pageContent = fullContents.subList(pageable.getOffset(), total);
        } else {
            pageContent = fullContents.subList(pageable.getOffset(),
                    pageable.getOffset() + pageable.getPageSize());
        }
        return new PageImpl<T>(pageContent, pageable, total);
    }
}

From source file:org.eclipse.hawkbit.repository.jpa.JpaTargetManagement.java

@Override
public Slice<Target> findTargetsAllOrderByLinkedDistributionSet(final Pageable pageable,
        final Long orderByDistributionId, final FilterParams filterParams) {
    final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    final CriteriaQuery<JpaTarget> query = cb.createQuery(JpaTarget.class);
    final Root<JpaTarget> targetRoot = query.from(JpaTarget.class);

    // select case expression to retrieve the case value as a column to be
    // able to order based on
    // this column, installed first,...
    final Expression<Object> selectCase = cb.selectCase()
            .when(cb.equal(targetRoot.get(JpaTarget_.installedDistributionSet).get(JpaDistributionSet_.id),
                    orderByDistributionId), 1)
            .when(cb.equal(targetRoot.get(JpaTarget_.assignedDistributionSet).get(JpaDistributionSet_.id),
                    orderByDistributionId), 2)
            .otherwise(100);/*from  www.  ja  v  a2 s .c o  m*/
    // multiselect statement order by the select case and controllerId
    query.distinct(true);
    // build the specifications and then to predicates necessary by the
    // given filters
    final Predicate[] specificationsForMultiSelect = specificationsToPredicate(
            buildSpecificationList(filterParams), targetRoot, query, cb);

    // if we have some predicates then add it to the where clause of the
    // multiselect
    if (specificationsForMultiSelect.length > 0) {
        query.where(specificationsForMultiSelect);
    }
    // add the order to the multi select first based on the selectCase
    query.orderBy(cb.asc(selectCase), cb.desc(targetRoot.get(JpaTarget_.id)));
    // the result is a Object[] due the fact that the selectCase is an extra
    // column, so it cannot
    // be mapped directly to a Target entity because the selectCase is not a
    // attribute of the
    // Target entity, the the Object array contains the Target on the first
    // index (case of the
    // multiselect order) of the array and
    // the 2nd contains the selectCase int value.
    final int pageSize = pageable.getPageSize();
    final List<JpaTarget> resultList = entityManager.createQuery(query).setFirstResult(pageable.getOffset())
            .setMaxResults(pageSize + 1).getResultList();
    final boolean hasNext = resultList.size() > pageSize;
    return new SliceImpl<>(Collections.unmodifiableList(resultList), pageable, hasNext);
}

From source file:org.jbb.members.web.base.logic.MemberSearchCriteriaFactory.java

private Pageable includeSortingToPageable(SearchMemberForm form, Pageable pageable) {
    return PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(),
            Direction.fromString(form.getSortDirection()), form.getSortByField());
}

From source file:org.opentestsystem.shared.progman.client.ProgramManagementClient.java

private static Map<String, String> getPageableParams(final Pageable pageable) {
    Map<String, String> params = Maps.newHashMap();
    params.put("page.page", "");
    params.put("page.size", "");
    params.put("page.sort", "");
    params.put("page.sort.dir", "");

    if (pageable != null) {
        params.put("page.page", Integer.toString(pageable.getPageNumber()));
        params.put("page.size", Integer.toString(pageable.getPageSize()));
        if (pageable.getSort() != null && pageable.getSort().iterator().hasNext()) {
            Order firstOrder = pageable.getSort().iterator().next();
            params.put("page.sort", firstOrder.getProperty());
            params.put("page.sort.dir", firstOrder.getDirection().name());
        }// w  ww  .  j a  va 2  s . com
    }

    return params;
}

From source file:org.springframework.batch.admin.web.BatchFileController.java

@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)/*from w  ww  .  j  ava  2 s  .c  o  m*/
public PagedResources<FileInfoResource> list(Pageable pageable, PagedResourcesAssembler<FileInfo> assembler)
        throws IOException {

    List<FileInfo> files = fileService.getFiles(pageable.getOffset(), pageable.getPageSize());

    return assembler.toResource(new PageImpl<FileInfo>(files, pageable, fileService.countFiles()),
            fileInfoResourceAssembler);
}