Example usage for org.springframework.data.domain PageImpl PageImpl

List of usage examples for org.springframework.data.domain PageImpl PageImpl

Introduction

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

Prototype

public PageImpl(List<T> content, Pageable pageable, long total) 

Source Link

Document

Constructor of PageImpl .

Usage

From source file:com.github.obiteaaron.common.data.FixPageImpl.java

@Override
public <S> Page<S> map(Converter<? super T, ? extends S> converter) {
    return new PageImpl<S>(getConvertedContent(converter), getPageable(), total);
}

From source file:com.jiwhiz.rest.author.AuthorBlogCommentRestControllerTest.java

@Test
public void getCommentPostsByBlogPostId_ShouldReturnAllCommentPostsForBlog() throws Exception {
    UserAccount user = getTestLoggedInUserWithAuthorRole();
    when(userAccountServiceMock.getCurrentUser()).thenReturn(user);

    BlogPost blog = new BlogPost(user, "My Test Blog", "Hello!", "TEST");
    blog.setId(BLOG_ID);//from   ww  w. ja va2s.c  o m
    when(blogPostRepositoryMock.findOne(BLOG_ID)).thenReturn(blog);

    when(commentPostRepositoryMock.findByBlogPostOrderByCreatedTimeDesc(any(BlogPost.class),
            any(Pageable.class))).thenReturn(
                    new PageImpl<CommentPost>(getTestUserCommentPostList(), new PageRequest(0, 10), 1));

    mockMvc.perform(get(API_ROOT + URL_AUTHOR_BLOGS_BLOG_COMMENTS, BLOG_ID)).andExpect(status().isOk())
            .andExpect(content().contentType(MediaTypes.HAL_JSON))
            .andExpect(jsonPath("$._embedded.commentPostList", hasSize(2)))
            .andExpect(jsonPath("$._embedded.commentPostList[0].id", is(COMMENTS_1_ID)))
            .andExpect(jsonPath("$._embedded.commentPostList[0].content", is(COMMENTS_1_CONTENT)))
            .andExpect(jsonPath("$._embedded.commentPostList[1].id", is(COMMENTS_2_ID)))
            .andExpect(jsonPath("$._embedded.commentPostList[1].content", is(COMMENTS_2_CONTENT)))
            .andExpect(jsonPath("$._links.self.templated", is(true)))
            .andExpect(jsonPath("$._links.self.href", endsWith(BLOG_ID + "/comments{?page,size,sort}")));
}

From source file:it.f2informatica.core.gateway.mongodb.ConsultantRepositoryGatewayMongoDB.java

@Override
public Page<ConsultantModel> findAllConsultants(Pageable pageable) {
    Page<Consultant> consultantPage = consultantRepository.findAll(pageable);
    return new PageImpl<>(consultantToModelConverter.convertList(consultantPage.getContent()), pageable,
            consultantPage.getTotalElements());
}

From source file:io.pivotal.strepsirrhini.chaosloris.docs.DocumentationUtilities.java

static <T> Page<T> page(Pageable pageable, LongFunction<T> function) {
    return new PageImpl<>(LongStream.range(pageable.getOffset(), pageable.getOffset() + pageable.getPageSize())
            .mapToObj(function).collect(Collectors.toList()), pageable, 12);
}

From source file:io.curly.advisor.command.ReviewHystrixCommands.java

private Page<Review> defaultFindAllByArtifact(Pageable pageable, String artifact) {
    log.warn("Requested reviews for artifact {} on page {} but fell back", artifact, pageable.getPageNumber());
    return new PageImpl<>(Collections.<Review>emptyList(), pageable, 0);
}

From source file:org.openlmis.fulfillment.service.PageDto.java

@Override
public <S> Page<S> map(Converter<? super T, ? extends S> converter) {
    checkNotNull(converter);//from w ww .java  2 s  . c  o  m

    List<S> result = content.stream().map(converter::convert).collect(Collectors.toList());
    Pageable pageable = new PageRequest(number, size, sort);
    Page<S> page = new PageImpl<>(result, pageable, totalElements);

    return new PageDto<>(page);
}

From source file:org.venice.piazza.common.hibernate.dao.deployment.DeploymentDaoImpl.java

public Page<DeploymentEntity> getDeploymentListByDeploymentId(String keyword, Pagination pagination) {
    // Query/*from w  w w  . j  a v a 2s  . co m*/
    String queryString = String.format(KEYWORD_DEPLOYMENT_ID_QUERY,
            Direction.fromString(pagination.getOrder()));
    Query query = entityManager.createNativeQuery(queryString, DeploymentEntity.class);
    query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword));
    query.setParameter(2, pagination.getSortBy());
    query.setParameter(3, pagination.getPerPage());
    query.setParameter(4, pagination.getPage() * pagination.getPerPage());
    List<DeploymentEntity> results = query.getResultList();
    // Count
    query = entityManager.createNativeQuery(KEYWORD_DEPLOYMENT_ID_QUERY_COUNT);
    query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword));
    long count = ((BigInteger) query.getSingleResult()).longValue();
    return new PageImpl<DeploymentEntity>(results, null, count);
}

From source file:org.oncoblocks.centromere.mongodb.CentromereMongoRepository.java

/**
 * {@link RepositoryOperations#findAll}/*from w w w .  j  ava 2  s  . c  o m*/
 */
public Page<T> find(Iterable<QueryCriteria> queryCriterias, Pageable pageable) {
    Criteria criteria = MongoQueryUtils.getQueryFromQueryCriteria(queryCriterias);
    Query query = new Query();
    if (criteria != null) {
        query.addCriteria(criteria);
    }
    List<T> entities = mongoOperations.find(query.with(pageable), metadata.getJavaType());
    long count = count(queryCriterias);
    return new PageImpl<>(entities, pageable, count);
}

From source file:me.doshou.admin.monitor.web.controller.JPAQLExecutorController.java

@PageableDefaults(pageNumber = 0, value = 10)
@RequestMapping(value = "/ql", method = RequestMethod.POST)
public String executeQL(final @RequestParam("ql") String ql, final Model model, final Pageable pageable) {

    model.addAttribute("sessionFactory", HibernateUtils.getSessionFactory(em));

    try {/*from  w w w  .  ja  va 2s  .co m*/
        new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() {
            @Override
            public Void doInTransaction(TransactionStatus status) {
                //1?ql
                try {
                    Query query = em.createQuery(ql);
                    int updateCount = query.executeUpdate();
                    model.addAttribute("updateCount", updateCount);
                    return null;
                } catch (Exception e) {
                }
                //2 ?ql
                String findQL = ql;
                String alias = QueryUtils.detectAlias(findQL);
                if (StringUtils.isEmpty(alias)) {
                    Pattern pattern = Pattern.compile("^(.*\\s*from\\s+)(.*)(\\s*.*)",
                            Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
                    findQL = pattern.matcher(findQL).replaceFirst("$1$2 o $3");
                }
                String countQL = QueryUtils.createCountQueryFor(findQL);
                Query countQuery = em.createQuery(countQL);
                Query findQuery = em.createQuery(findQL);
                findQuery.setFirstResult(pageable.getOffset());
                findQuery.setMaxResults(pageable.getPageSize());

                Page page = new PageImpl(findQuery.getResultList(), pageable,
                        (Long) countQuery.getSingleResult());

                model.addAttribute("resultPage", page);
                return null;
            }
        });
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        model.addAttribute(Constants.ERROR, sw.toString());
    }

    return showQLForm();
}