Java Code Examples for org.springframework.data.domain.Page#getContent()

The following examples show how to use org.springframework.data.domain.Page#getContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EkmKnowledgeMasterRepositoryImpl.java    From youkefu with Apache License 2.0 6 votes vote down vote up
@Override
public List<EkmKnowledgeMaster> findByOrgiAndDatastatus(String orgi, boolean datastatus) {
	
	BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
	BoolQueryBuilder bq = QueryBuilders.boolQuery() ; 
	bq.must(QueryBuilders.termQuery("datastatus", datastatus)) ;
	bq.must(QueryBuilders.termQuery("orgi", orgi)) ;
	boolQueryBuilder.must(bq); 
	
	NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).withPageable(new PageRequest(0, 100000)) ;
	Page<EkmKnowledgeMaster> knowledgeList = null ;
	if(elasticsearchTemplate.indexExists(EkmKnowledgeMaster.class)){
		knowledgeList = elasticsearchTemplate.queryForPage(searchQueryBuilder.build() , EkmKnowledgeMaster.class ) ;
    }
	
	return knowledgeList.getContent();
}
 
Example 2
Source File: EkmKnowledgeMasterRepositoryImpl.java    From youkefu with Apache License 2.0 6 votes vote down vote up
@Override
public List<EkmKnowledgeMaster> findByOrgi(String orgi) {

	BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
	BoolQueryBuilder bq = QueryBuilders.boolQuery() ; 
	bq.must(QueryBuilders.termQuery("orgi", orgi)) ;
	boolQueryBuilder.must(bq); 
	
	NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).withPageable(new PageRequest(0, 100000)) ;
	Page<EkmKnowledgeMaster> knowledgeList = null ;
	if(elasticsearchTemplate.indexExists(EkmKnowledgeMaster.class)){
		knowledgeList = elasticsearchTemplate.queryForPage(searchQueryBuilder.build() , EkmKnowledgeMaster.class ) ;
    }
	
	return knowledgeList.getContent();
}
 
Example 3
Source File: AuditResource.java    From flair-engine with Apache License 2.0 5 votes vote down vote up
/**
 * GET  /audits : get a page of AuditEvents between the fromDate and toDate.
 *
 * @param fromDate the start of the time period of AuditEvents to get
 * @param toDate the end of the time period of AuditEvents to get
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of AuditEvents in body
 */
@GetMapping(params = {"fromDate", "toDate"})
public ResponseEntity<List<AuditEvent>> getByDates(
    @RequestParam(value = "fromDate") LocalDate fromDate,
    @RequestParam(value = "toDate") LocalDate toDate,
    @ApiParam Pageable pageable) {

    Page<AuditEvent> page = auditEventService.findByDates(
        fromDate.atStartOfDay(ZoneId.systemDefault()).toInstant(),
        toDate.atStartOfDay(ZoneId.systemDefault()).plusDays(1).toInstant(),
        pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/management/audits");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 4
Source File: AuditResource.java    From jhipster-online with Apache License 2.0 5 votes vote down vote up
/**
 * {@code GET  /audits} : get a page of {@link AuditEvent} between the {@code fromDate} and {@code toDate}.
 *
 * @param fromDate the start of the time period of {@link AuditEvent} to get.
 * @param toDate the end of the time period of {@link AuditEvent} to get.
 * @param pageable the pagination information.
 * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of {@link AuditEvent} in body.
 */
@GetMapping(params = {"fromDate", "toDate"})
public ResponseEntity<List<AuditEvent>> getByDates(
    @RequestParam(value = "fromDate") LocalDate fromDate,
    @RequestParam(value = "toDate") LocalDate toDate,
    Pageable pageable) {

    Instant from = fromDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
    Instant to = toDate.atStartOfDay(ZoneId.systemDefault()).plusDays(1).toInstant();

    Page<AuditEvent> page = auditEventService.findByDates(from, to, pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page);
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 5
Source File: ChnlZhihuSearchService.java    From albert with MIT License 5 votes vote down vote up
public List<ChnlZhihuSearch> search(ZhihuSearchParam param) {
	SearchQuery searchQuery = new NativeSearchQueryBuilder()
		    .withQuery(createQuery(param))
		    .withFilter(createFilter(param))
		    .withSort(addSort(param))
		    .withPageable(new PageRequest(param.getI() - 1, param.getS()))
		    .build();
	
	Page<ChnlZhihuSearch> page = elasticsearchTemplate.queryForPage(searchQuery, ChnlZhihuSearch.class);
	
	param.setTotalNum((int)page.getTotalElements());
	
	return page.getContent();
}
 
Example 6
Source File: PointsResource.java    From 21-points with Apache License 2.0 5 votes vote down vote up
/**
 * GET  /points : get all the points.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of points in body
 */
@GetMapping("/points")
@Timed
public ResponseEntity<List<Points>> getAllPoints(Pageable pageable) {
    log.debug("REST request to get a page of Points");
    Page<Points> page;
    if (SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN)) {
        page = pointsRepository.findAllByOrderByDateDesc(pageable);
    } else {
        page = pointsRepository.findByUserIsCurrentUser(pageable);
    }
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/points");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 7
Source File: EntryResource.java    From jhipster-microservices-example with Apache License 2.0 5 votes vote down vote up
/**
 * SEARCH  /_search/entries?query=:query : search for the entry corresponding
 * to the query.
 *
 * @param query the query of the entry search
 * @param pageable the pagination information
 * @return the result of the search
 */
@GetMapping("/_search/entries")
@Timed
public ResponseEntity<List<Entry>> searchEntries(@RequestParam String query, @ApiParam Pageable pageable) {
    log.debug("REST request to search for a page of Entries for query {}", query);
    Page<Entry> page = entrySearchRepository.search(queryStringQuery(query), pageable);
    HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, "/api/_search/entries");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 8
Source File: SpringDataWithSecurityIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenAppUser_whenLoginSuccessful_shouldReadMyPagedTweets() {
    AppUser appUser = userRepository.findByUsername("[email protected]");
    Authentication auth = new UsernamePasswordAuthenticationToken(new AppUserPrincipal(appUser), null, DummyContentUtil.getAuthorities());
    SecurityContextHolder.getContext()
        .setAuthentication(auth);
    Page<Tweet> page = null;
    do {
        page = tweetRepository.getMyTweetsAndTheOnesILiked(PageRequest.of(page != null ? page.getNumber() + 1 : 0, 5));
        for (Tweet twt : page.getContent()) {
            isTrue((twt.getOwner() == appUser.getUsername()) || (twt.getLikes()
                .contains(appUser.getUsername())), "I do not have any Tweets");
        }
    } while (page.hasNext());
}
 
Example 9
Source File: ClearController.java    From logistics-back with MIT License 5 votes vote down vote up
/**
 * 杂费结算  select
 */
@RequestMapping(value = "/selectAllExtraClear", method = RequestMethod.GET)
public Result selectAllExtraClear(@RequestParam("pageNum") int pageNum, @RequestParam("limit") int limit) {
	Pageable pageable = PageRequest.of(pageNum-1, limit);
	Page<ExtraClear> page = clearService.selectAllExtraClearByPage(pageable);
	Result result = new Result(200, "SUCCESS", (int) page.getTotalElements(), page.getContent());
	return result;
}
 
Example 10
Source File: ArticleService.java    From wallride with Apache License 2.0 5 votes vote down vote up
@Cacheable(value = WallRideCacheConfiguration.ARTICLE_CACHE)
public SortedSet<Article> getLatestArticles(String language, Post.Status status, int size) {
	ArticleSearchRequest request = new ArticleSearchRequest()
			.withLanguage(language)
			.withStatus(status);

	Pageable pageable = new PageRequest(0, size);
	Page<Article> page = articleRepository.search(request, pageable);
	return new TreeSet<>(page.getContent());
}
 
Example 11
Source File: NewsServiceImpl.java    From spring-backend-boilerplate with Apache License 2.0 5 votes vote down vote up
@Override
public String getImageFileObjectId(News news) {
	if (news == null) {
		return null;
	}
	Page<FileObject> fileObjects = fileObjectRepository.findByBizId(news.getId(), new PageRequest(0, 1));
	if (fileObjects.getContent() != null && !fileObjects.getContent().isEmpty()) {
		return fileObjects.getContent().get(0).getId();
	}
	return null;
}
 
Example 12
Source File: WeightResource.java    From 21-points with Apache License 2.0 5 votes vote down vote up
/**
 * GET  /weights : get all the weights.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of weights in body
 */
@GetMapping("/weights")
@Timed
public ResponseEntity<List<Weight>> getAllWeights(Pageable pageable) {
    log.debug("REST request to get a page of Weights");
    Page<Weight> page;
    if (SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN)) {
        page = weightRepository.findAllByOrderByTimestampDesc(pageable);
    } else {
        page = weightRepository.findByUserIsCurrentUser(pageable);
    }
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/weights");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 13
Source File: CommentServiceImpl.java    From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public PagedResponse<Comment> getAllComments(Long postId, int page, int size) {
	AppUtils.validatePageNumberAndSize(page, size);
	Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, "createdAt");

	Page<Comment> comments = commentRepository.findByPostId(postId, pageable);

	return new PagedResponse<Comment>(comments.getContent(), comments.getNumber(), comments.getSize(),
			comments.getTotalElements(), comments.getTotalPages(), comments.isLast());
}
 
Example 14
Source File: AuditResource.java    From cubeai with Apache License 2.0 5 votes vote down vote up
/**
 * GET  /audits : get a page of AuditEvents between the fromDate and toDate.
 *
 * @param fromDate the start of the time period of AuditEvents to get
 * @param toDate the end of the time period of AuditEvents to get
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of AuditEvents in body
 */
@GetMapping(params = {"fromDate", "toDate"})
public ResponseEntity<List<AuditEvent>> getByDates(
    @RequestParam(value = "fromDate") LocalDate fromDate,
    @RequestParam(value = "toDate") LocalDate toDate,
    Pageable pageable) {

    Page<AuditEvent> page = auditEventService.findByDates(
        fromDate.atStartOfDay(ZoneId.systemDefault()).toInstant(),
        toDate.atStartOfDay(ZoneId.systemDefault()).plusDays(1).toInstant(),
        pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/management/audits");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 15
Source File: RaceDataResource.java    From gpmr with Apache License 2.0 5 votes vote down vote up
/**
 * GET  /race-data : get all the raceData.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of raceData in body
 * @throws URISyntaxException if there is an error to generate the pagination HTTP headers
 */
@RequestMapping(value = "/race-data",
    method = RequestMethod.GET,
    produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<RaceData>> getAllRaceData(Pageable pageable)
    throws URISyntaxException {
    log.debug("REST request to get a page of RaceData");
    Page<RaceData> page = raceDataRepository.findAll(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/race-data");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 16
Source File: CosmosTemplateIT.java    From spring-data-cosmosdb with MIT License 5 votes vote down vote up
@Test
public void testFindAllWithTwoPagesAndVerifySortOrder() {
    final Person testPerson4 = new Person("id_4", "barney", NEW_LAST_NAME, HOBBIES, ADDRESSES);
    final Person testPerson5 = new Person("id_5", "fred", NEW_LAST_NAME, HOBBIES, ADDRESSES);

    cosmosTemplate.insert(TEST_PERSON_2,
            new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_2)));
    cosmosTemplate.insert(TEST_PERSON_3,
            new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_3)));
    cosmosTemplate.insert(testPerson4,
            new PartitionKey(personInfo.getPartitionKeyFieldValue(testPerson4)));
    cosmosTemplate.insert(testPerson5,
            new PartitionKey(personInfo.getPartitionKeyFieldValue(testPerson5)));

    final Sort sort = Sort.by(Sort.Direction.ASC, "firstName");
    final PageRequest pageRequest = new CosmosPageRequest(0, PAGE_SIZE_3, null, sort);

    final Page<Person> firstPage = cosmosTemplate.findAll(pageRequest, Person.class,
        containerName);

    assertThat(firstPage.getContent().size()).isEqualTo(3);
    validateNonLastPage(firstPage, firstPage.getContent().size());

    final List<Person> firstPageResults = firstPage.getContent();
    assertThat(firstPageResults.get(0).getFirstName()).isEqualTo(testPerson4.getFirstName());
    assertThat(firstPageResults.get(1).getFirstName()).isEqualTo(FIRST_NAME);
    assertThat(firstPageResults.get(2).getFirstName()).isEqualTo(testPerson5.getFirstName());

    final Page<Person> secondPage = cosmosTemplate.findAll(firstPage.getPageable(), Person.class,
        containerName);

    assertThat(secondPage.getContent().size()).isEqualTo(2);
    validateLastPage(secondPage, secondPage.getContent().size());

    final List<Person> secondPageResults = secondPage.getContent();
    assertThat(secondPageResults.get(0).getFirstName()).isEqualTo(NEW_FIRST_NAME);
    assertThat(secondPageResults.get(1).getFirstName()).isEqualTo(NEW_FIRST_NAME);
}
 
Example 17
Source File: ShadowSocksSerivceImpl.java    From ShadowSocks-Share with Apache License 2.0 4 votes vote down vote up
/**
 * 3. 查询 SS 信息
 */
@Override
public List<ShadowSocksEntity> findAll(Pageable pageable) {
	Page<ShadowSocksEntity> entities = shadowSocksRepository.findAll(pageable);
	return entities.getContent();
}
 
Example 18
Source File: PagingSortingIT.java    From spring-data-hazelcast with Apache License 2.0 4 votes vote down vote up
@Test
public void paging() {
    int PAGE_0 = 0;
    int PAGE_2 = 2;
    int SIZE_5 = 5;
    int SIZE_20 = 20;

    PageRequest thirdPageOf5Request = PageRequest.of(PAGE_2, SIZE_5);
    Page<Person> thirdPageOf5Response = this.personRepository.findAll(thirdPageOf5Request);
    assertThat("11 onwards returned", thirdPageOf5Response, notNullValue());

    List<Person> thirdPageOf5Content = thirdPageOf5Response.getContent();
    assertThat("11-15 returned", thirdPageOf5Content.size(), equalTo(5));

    Pageable fourthPageOf5Request = thirdPageOf5Response.nextPageable();
    Page<Person> fourthPageOf5Response = this.personRepository.findAll(fourthPageOf5Request);
    assertThat("16 onwards returned", fourthPageOf5Response, notNullValue());

    List<Person> fourthPageOf5Content = fourthPageOf5Response.getContent();
    assertThat("16-20 returned", fourthPageOf5Content.size(), equalTo(5));

    PageRequest firstPageOf20Request = PageRequest.of(PAGE_0, SIZE_20);
    Page<Person> firstPageOf20Response = this.personRepository.findAll(firstPageOf20Request);
    assertThat("1 onwards returned", firstPageOf20Response, notNullValue());

    List<Person> firstPageOf20Content = firstPageOf20Response.getContent();
    assertThat("1-20 returned", firstPageOf20Content.size(), equalTo(20));

    assertThat("11th", thirdPageOf5Content.get(0), equalTo(firstPageOf20Content.get(10)));
    assertThat("12th", thirdPageOf5Content.get(1), equalTo(firstPageOf20Content.get(11)));
    assertThat("13th", thirdPageOf5Content.get(2), equalTo(firstPageOf20Content.get(12)));
    assertThat("14th", thirdPageOf5Content.get(3), equalTo(firstPageOf20Content.get(13)));
    assertThat("15th", thirdPageOf5Content.get(4), equalTo(firstPageOf20Content.get(14)));
    assertThat("16th", fourthPageOf5Content.get(0), equalTo(firstPageOf20Content.get(15)));
    assertThat("17th", fourthPageOf5Content.get(1), equalTo(firstPageOf20Content.get(16)));
    assertThat("18th", fourthPageOf5Content.get(2), equalTo(firstPageOf20Content.get(17)));
    assertThat("19th", fourthPageOf5Content.get(3), equalTo(firstPageOf20Content.get(18)));
    assertThat("20th", fourthPageOf5Content.get(4), equalTo(firstPageOf20Content.get(19)));

    Set<String> ids = new TreeSet<>();
    firstPageOf20Content.forEach(person -> ids.add(person.getId()));

    assertThat("20 different years", ids.size(), equalTo(20));
}
 
Example 19
Source File: PostServiceImpl.java    From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 3 votes vote down vote up
@Override
public PagedResponse<Post> getAllPosts(int page, int size) {
	validatePageNumberAndSize(page, size);

	Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, CREATED_AT);

	Page<Post> posts = postRepository.findAll(pageable);

	List<Post> content = posts.getNumberOfElements() == 0 ? Collections.emptyList() : posts.getContent();

	return new PagedResponse<>(content, posts.getNumber(), posts.getSize(), posts.getTotalElements(),
			posts.getTotalPages(), posts.isLast());
}
 
Example 20
Source File: ConvertedDatatablesData.java    From springlets with Apache License 2.0 2 votes vote down vote up
/**
 * Create a response for datatables with data obtained from a previous request.
 *
 * @param data the data to show
 * @param recordsTotal the total number of available data
 * @param draw counts datatables requests. It must be sent by datatables value
 * in the data request.
 * @param conversionService to convert the data values to String
 */
public ConvertedDatatablesData(Page<T> data, Long recordsTotal, Integer draw,
    ConversionService conversionService) {
  this(data.getContent(), recordsTotal, data.getTotalElements(), draw, conversionService, null,
      DEFAULT_PROPERTY_SEPARATOR);
}