List of usage examples for org.springframework.data.domain PageImpl PageImpl
public PageImpl(List<T> content, Pageable pageable, long total)
From source file:com.ccserver.digital.controller.AdminControllerTest.java
@Test public void getAppListTest() { PageRequest page = new PageRequest(1, 1); List<CreditCardApplicationDTO> ccAppDTOList = new ArrayList<CreditCardApplicationDTO>(); CreditCardApplicationDTO ccApp = getCreditCardApplicationDTOMock(1L); ccAppDTOList.add(ccApp);/* w w w .j a v a2s .com*/ PageImpl<CreditCardApplicationDTO> pageDTO = new PageImpl<CreditCardApplicationDTO>(ccAppDTOList, page, 1); AdminSearchPageDTO adminSearchPageDTO = new AdminSearchPageDTO(1, pageDTO); Mockito.when(ccAppService.findBySearchText("aaa", page)).thenReturn(adminSearchPageDTO); // when ResponseEntity<?> application = controller.getAppList("aaa", page); // then Assert.assertEquals(HttpStatus.OK, application.getStatusCode()); Assert.assertEquals(1, ((AdminSearchPageDTO) application.getBody()).getCount()); }
From source file:com.wiiyaya.framework.provider.repository.BaseDaoImpl.java
@Override public Page<Tuple> findAllJFTuple(JFTuple joinFetch, Pageable pageable) { JPQLQuery countQuery = createQuery(); joinFetch.prepareQry(countQuery, false); Long total = countQuery.count(); List<Tuple> content = null; if (total > pageable.getOffset()) { JPQLQuery query = querydsl.applyPagination(pageable, createQuery()); content = joinFetch.prepareQry(query, true); } else {//from ww w. j av a 2 s . c o m content = Collections.<Tuple>emptyList(); } return new PageImpl<Tuple>(content, pageable, total); }
From source file:de.rahn.finances.services.securities.SecuritiesServiceMetricsAspectTest.java
/** * @throws Exception//from w w w .j a v a 2s . com */ @Before public void setUp() throws Exception { counters.clear(); gauges.clear(); AspectJProxyFactory factory = new AspectJProxyFactory(service); factory.addAspect(classUnderTests); serviceProxy = factory.getProxy(); testSecurity.setId(randomUUID().toString()); testSecurity.setIsin("DE0000000000"); testSecurity.setWkn("000000"); testSecurity.setSymbol("ABC"); testSecurity.setName("ABC AG"); testSecurity.setType(stock); List<Security> allSecurity = new ArrayList<>(); allSecurity.add(testSecurity); PageImpl<Security> page = new PageImpl<>(allSecurity, new PageRequest(0, 1), allSecurity.size()); when(service.getSecurities()).thenReturn(allSecurity); when(service.getSecurities(any(Pageable.class))).thenReturn(page); when(service.save(testSecurity)).thenReturn(testSecurity); when(service.save(null)).thenThrow(new SecurityNotFoundException("")); doAnswer(invocation -> { counters.add((String) invocation.getArguments()[0]); return null; }).when(counterService).increment(anyString()); doAnswer(invocation -> { gauges.add((String) invocation.getArguments()[0]); return null; }).when(gaugeService).submit(anyString(), anyDouble()); }
From source file:org.jblogcms.core.common.service.PostServiceToolImplTest.java
@Before public void setUp() throws Exception { post1.setId(POST_1_ID);// w w w . j av a 2s . c om post2.setId(POST_2_ID); post3.setId(POST_3_ID); Sort sort = new Sort(PAGEABLE_SORT); pageable = new PageRequest(PAGEABLE_PAGE, PAGEABLE_SIZE, sort); postPage = new PageImpl(postList, pageable, 3); postEmptyPage = new PageImpl(postEmptyList, pageable, 0); account.setId(ACCOUNT_ID); postRelation1.setAccount(account); postRelation1.setItem(post1); postRelation3.setAccount(account); postRelation3.setItem(post3); postRate1.setAccount(account); postRate1.setItem(post1); postRate3.setAccount(account); postRate3.setItem(post3); }
From source file:org.venice.piazza.common.hibernate.dao.job.JobDaoImpl.java
public Page<JobEntity> getJobListForUserAndStatus(String status, String userName, Pagination pagination) { // Query/*from www . ja va2s .c om*/ String queryString = String.format(USERNAME_AND_STATUS_JOB_QUERY, Direction.fromString(pagination.getOrder())); Query query = entityManager.createNativeQuery(queryString, JobEntity.class); query.setParameter(1, userName); query.setParameter(2, status); query.setParameter(3, pagination.getSortBy()); query.setParameter(4, pagination.getPerPage()); query.setParameter(5, pagination.getPage() * pagination.getPerPage()); List<JobEntity> results = query.getResultList(); // Count query = entityManager.createNativeQuery(USERNAME_AND_STATUS_JOB_QUERY_COUNT); query.setParameter(1, userName); query.setParameter(2, status); long count = ((BigInteger) query.getSingleResult()).longValue(); return new PageImpl<JobEntity>(results, null, count); }
From source file:cn.edu.zjnu.acm.judge.problem.ProblemStatusController.java
@GetMapping("/problemstatus") @SuppressWarnings("AssignmentToMethodParameter") public String status(HttpServletRequest request, @RequestParam("problem_id") long id, @PageableDefault(size = 20, sort = { "time", "memory", "code_length" }) Pageable pageable, Authentication authentication) { log.debug("{}", pageable); if (pageable.getPageSize() > 500) { pageable = new PageRequest(pageable.getPageNumber(), 500, pageable.getSort()); }//from w w w . j ava2 s. c om Problem problem = problemMapper.findOneNoI18n(id); if (problem == null) { throw new MessageException("No such problem", HttpStatus.NOT_FOUND); } final Long contestId = problem.getContest(); request.setAttribute("contestId", contestId); List<ScoreCount> list = problemMapper.groupByScore(id); ArrayList<String> scores = new ArrayList<>(list.size()); ArrayList<Long> counts = new ArrayList<>(list.size()); ArrayList<String> urls = new ArrayList<>(list.size()); for (ScoreCount scoreCount : list) { int score = scoreCount.getScore(); scores.add(ResultType.getShowsourceString(score)); counts.add(scoreCount.getCount()); urls.add(request.getContextPath() + "/status?problem_id=" + id + "&score=" + score); } List<Submission> bestSubmissions = submissionMapper.bestSubmission(id, pageable); long total = pageable.getOffset() + bestSubmissions.size() + (pageable.getPageSize() == bestSubmissions.size() ? 1 : 0); PageImpl<Submission> page = new PageImpl<>(bestSubmissions, pageable, total); boolean isAdmin = UserDetailService.isAdminLoginned(request); boolean isSourceBrowser = UserDetailService.isSourceBrowser(request); boolean canView = isAdmin || isSourceBrowser; request.setAttribute("page", page); request.setAttribute("sa", Arrays.asList(counts, scores, urls)); request.setAttribute("problem", problem); request.setAttribute("url", URLBuilder.fromRequest(request).replaceQueryParam("page").toString()); request.setAttribute("contestId", contestId); request.setAttribute("canView", canView); request.setAttribute("authentication", authentication); return "problems/status"; }
From source file:com.github.markserrano.jsonquery.jpa.service.FilterService.java
@Override public Page<T> readAndCount(String filter, Pageable page, Class<T> clazz, OrderSpecifier order, String joinChildField, Class<?> joinChildClass, List<String> childFields) { Map<String, String> filters = QueryUtil.createParentAndChildFilter(filter, childFields); BooleanBuilder parentBuilder = new JsonBooleanBuilder(clazz) .build(new JsonFilter(filters.get("parentFilter").toString())); BooleanBuilder joinChildBuilder = new JsonBooleanBuilder(joinChildClass) .build(new JsonFilter(filters.get("childFilter").toString())); Page<T> pageImpl = new PageImpl<T>( read(parentBuilder, page, clazz, order, joinChildBuilder, joinChildField, joinChildClass), page, count(parentBuilder, clazz, order, joinChildBuilder, joinChildField, joinChildClass)); return pageImpl; }
From source file:org.ow2.proactive.workflow_catalog.rest.service.repository.QueryDslWorkflowRevisionRepository.java
private Page<WorkflowRevision> findWorkflowRevisions(ListSubQuery<Long> workflowRevisionIds, QueryExpressionContext context, Pageable pageable) { JPAQuery query = new JPAQuery(entityManager).from(QWorkflowRevision.workflowRevision); query = query.where(qWorkflowRevision.id.in(workflowRevisionIds).and(context.getExpression())).distinct(); long count = query.count(); JPQLQuery paginatedQuery = super.getQuerydsl().applyPagination(pageable, query); return new PageImpl<>(paginatedQuery.list(qWorkflowRevision), pageable, count); }
From source file:org.oncoblocks.centromere.mongodb.GenericMongoRepository.java
/** * {@link RepositoryOperations#findAll}/*from ww w .j ava2s . c o m*/ */ public Page<T> findAll(Pageable pageable) { List<T> entities = mongoOperations.find(new Query().with(pageable), model); long count = count(); return new PageImpl<T>(entities, pageable, count); }
From source file:org.jblogcms.core.blog.service.BlogServiceImplTest.java
@Before public void setUp() throws Exception { blog1.setId(BLOG_1_ID);//from w w w. j a v a 2s . c o m blog1.setName(BLOG_1_NAME); blog1.setUrlName(BLOG_1_URL_NAME); blog2.setId(BLOG_2_ID); blog2.setName(BLOG_2_NAME); blog2.setUrlName(BLOG_2_URL_NAME); blog3.setId(BLOG_3_ID); blog3.setName(BLOG_3_NAME); blog3.setUrlName(BLOG_3_URL_NAME); existingBlog.setId(EXISTING_BLOG_ID); existingBlog.setName(EXISTING_BLOG_NAME); existingBlog.setUrlName(EXISTING_BLOG_URL_NAME); Sort sort = new Sort(PAGEABLE_SORT); pageable = new PageRequest(PAGEABLE_PAGE, PAGEABLE_SIZE, sort); blogs = new PageImpl(blogList, pageable, BLOGS_SIZE); }