List of usage examples for org.springframework.data.domain Page getContent
List<T> getContent();
From source file:com.snowstore.pontus.endpoint.ReservationListEndpoint.java
public List<ReservationResp> queryQuoteContractListByApp(ReservationListReq reservationListReq) { try {//from w ww . ja v a 2 s. c o m QuoteContractForm form = new QuoteContractForm(); List<QuoteContractWorkFlow> workFlowList = new ArrayList<QuoteContractWorkFlow>(); workFlowList.add(Enums.QuoteContractWorkFlow.PENDING); workFlowList.add(Enums.QuoteContractWorkFlow.REJECT); dozerBeanMapper.map(reservationListReq, form); form.setCustomerId(Long.valueOf(customerService.getCustomerId(reservationListReq.getAccessToken()))); form.setWorkFlowList(workFlowList); Page<QuoteContract> page = quoteContractService.queryQuoteContractList(form); List<ReservationResp> resp = new ArrayList<ReservationListResp.ReservationResp>(); for (QuoteContract quoteContract : page.getContent()) { ReservationResp reservationResp = new ReservationResp(); reservationResp .setEndDate(Calendars.format(quoteContract.getContractEndDate(), Calendars.YYYY_MM_DD)); dozerBeanMapper.map(quoteContract, reservationResp); reservationResp.setReservationId(quoteContract.getId()); resp.add(reservationResp); } return resp; } catch (PontusServiceException e) { LOGGER.error("?", e); throw e; } catch (Exception e) { LOGGER.error("?", e); throw new PontusServiceException("?", e); } }
From source file:com.luna.common.repository.PageAndSortUserRepositoryIT.java
@Test public void testFindAllForPageAndSort() { for (int i = 0; i < 15; i++) { userRepository.save(createUser()); }/*w ww. ja v a 2 s. c o m*/ Sort.Order idAsc = new Sort.Order(Sort.Direction.ASC, "id"); Sort.Order usernameDesc = new Sort.Order(Sort.Direction.DESC, "username"); Sort sort = new Sort(idAsc, usernameDesc); PageRequest pageRequest = new PageRequest(1, 5, sort); Page<User> page = userRepository.findAll(pageRequest); assertEquals(pageRequest.getPageSize(), page.getNumberOfElements()); assertEquals(3, page.getTotalPages()); assertTrue(page.getContent().get(0).getId() < page.getContent().get(1).getId()); }
From source file:com.github.markserrano.jsonquery.jpa.service.ParentChildThingEntityServiceTest.java
@Test public void testReadAndCount_SingleCriteriaBy_ParentNonId_ThingNonId() { String filter = "{\"groupOp\":\"AND\",\"rules\":" + "[{\"field\":\"parent.store\",\"op\":\"ne\",\"data\":\"StoreB\"}," + "{\"field\":\"parent.thing.name\",\"op\":\"ne\",\"data\":\"Pencil\"}]" + "}"; BooleanBuilder builder = jsonBooleanBuilder.build(new JsonFilter(filter)); Page<Child> results = service.readAndCount(builder, new PageRequest(0, 3), Child.class, orderSpecifiers); Assert.assertNotNull(results);/* www. j a va2 s.c o m*/ Assert.assertEquals(4, results.getTotalElements()); Assert.assertEquals(3, results.getContent().size()); // paged at 3 records Assert.assertEquals("StoreA", results.getContent().get(0).getParent().getStore()); Assert.assertEquals("StoreA", results.getContent().get(1).getParent().getStore()); Assert.assertEquals("StoreA", results.getContent().get(2).getParent().getStore()); }
From source file:org.openlmis.fulfillment.service.PageDto.java
/** * Creates new instance based on data from {@link Page} instance. *///from w ww .ja va 2 s . co m public PageDto(Page<T> page) { this(checkNotNull(page).isLast(), page.isFirst(), page.getTotalPages(), page.getTotalElements(), page.getSize(), page.getNumber(), page.getNumberOfElements(), page.getSort(), checkNotNull(page.getContent())); }
From source file:midas.database.PopulateDatabase.java
@Test @Transactional//from www. j a v a 2s.c om public void testFindDuplicates() { CustomerJpa dupEntity = new CustomerJpa(); dupEntity.setFirstName("caio"); dupEntity.setLastName("amaral"); dupEntity = customerJpaRepo.save(dupEntity); CustomerJpa entity = new CustomerJpa(); entity.setFirstName("caio2"); entity.setLastName("amaral2"); entity.setDuplicates(Arrays.asList(dupEntity)); entity = customerJpaRepo.save(entity); entity = new CustomerJpa(); entity.setFirstName("caio3"); entity.setLastName("amaral3"); entity = customerJpaRepo.save(entity); PageRequest pageable = new PageRequest(0, 2); Page<CustomerJpa> findDuplicates = customerJpaRepo.findDuplicates(pageable); Assert.assertEquals(1l, findDuplicates.getTotalElements()); CustomerJpa customer = findDuplicates.getContent().get(0); Assert.assertEquals(2, customer.getId().intValue()); Assert.assertEquals(1, customer.getDuplicates().size()); Assert.assertEquals(1, customer.getDuplicates().get(0).getId().intValue()); }
From source file:org.ow2.proactive.workflow_catalog.rest.service.repository.QueryDslWorkflowRevisionRepositoryIntegrationTest.java
private void assertContainRightVariable(BucketMetadata bucket, Page<WorkflowRevision> result) { for (WorkflowRevision workflowRevision : result.getContent()) { assertThat(bucket.id).isEqualTo(findBucketIndex(workflowRevision)); }/*from ww w.ja va 2 s .co m*/ }
From source file:org.jblogcms.core.account.repository.AccountRepositoryItTest.java
@Test @Transactional/*from www . j av a 2 s. c om*/ public void testFindAccounts_returnAllAccounts() throws Exception { Page<Account> accounts = accountRepository.findAccounts(pageable); Assert.assertEquals(3, accounts.getTotalElements()); Assert.assertEquals(ACCOUNT_1_ID, accounts.getContent().get(0).getId()); Assert.assertEquals(ACCOUNT_1_EMAIL, accounts.getContent().get(0).getEmail()); Assert.assertEquals(ACCOUNT_2_ID, accounts.getContent().get(1).getId()); Assert.assertEquals(ACCOUNT_2_EMAIL, accounts.getContent().get(1).getEmail()); Assert.assertEquals(ACCOUNT_3_ID, accounts.getContent().get(2).getId()); Assert.assertEquals(ACCOUNT_3_EMAIL, accounts.getContent().get(2).getEmail()); }
From source file:com.github.markserrano.jsonquery.jpa.service.ParentChildThingEntityServiceTest.java
@Test public void testReadAndCount_SingleCriteriaBy_ParentNonId_ThingId() { String filter = "{\"groupOp\":\"AND\",\"rules\":" + "[{\"field\":\"parent.store\",\"op\":\"ne\",\"data\":\"StoreB\"}," + "{\"field\":\"parent.thing.id\",\"op\":\"ne\",\"data\":\"1\"}]" + "}"; BooleanBuilder builder = jsonBooleanBuilder.build(new JsonFilter(filter)); Page<Child> results = service.readAndCount(builder, new PageRequest(0, 3), Child.class, orderSpecifiers); Assert.assertNotNull(results);//from w w w. ja va2 s . com Assert.assertEquals(2, results.getTotalElements()); Assert.assertEquals("StoreC", results.getContent().get(0).getParent().getStore()); Assert.assertEquals("StoreD", results.getContent().get(1).getParent().getStore()); }
From source file:com.github.markserrano.jsonquery.jpa.service.ParentChildThingEntityServiceTest.java
@Test public void testReadAndCount_DoubleCriteriaBy_ForeignTable_FieldOtherThanId() { String filter = "{\"groupOp\":\"AND\",\"rules\":" + "[{\"field\":\"parent.store\",\"op\":\"ne\",\"data\":\"StoreB\"}," + "{\"field\":\"birthDate\",\"op\":\"lt\",\"data\":\"1995-10-01T00:00:00.000Z\"}]" + "}"; BooleanBuilder builder = jsonBooleanBuilder.build(new JsonFilter(filter)); Page<Child> results = service.readAndCount(builder, new PageRequest(0, 3), Child.class, orderSpecifiers); Assert.assertNotNull(results);/*w w w. j av a 2 s .c o m*/ Assert.assertEquals(2, results.getTotalElements()); Assert.assertEquals("StoreA", results.getContent().get(0).getParent().getStore()); Assert.assertEquals("StoreD", results.getContent().get(1).getParent().getStore()); }
From source file:com.jiwhiz.rest.site.WebsiteRestController.java
@RequestMapping(method = RequestMethod.GET, value = URL_SITE_LATEST_BLOG) @Transactional(readOnly = true)//from ww w .j av a 2 s . c om public HttpEntity<PublicBlogResource> getLatestBlogPost() throws ResourceNotFoundException { PageRequest request = new PageRequest(0, 1); Page<BlogPost> blogPosts = this.blogPostRepository.findByPublishedIsTrueOrderByPublishedTimeDesc(request); if (blogPosts.getContent().size() != 1) { return new ResponseEntity<>(HttpStatus.OK); } BlogPost blogPost = blogPosts.getContent().get(0); PublicBlogResource resource = publicBlogResourceAssembler.toResource(blogPost); return new ResponseEntity<>(resource, HttpStatus.OK); }