Example usage for org.springframework.data.domain Page getContent

List of usage examples for org.springframework.data.domain Page getContent

Introduction

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

Prototype

List<T> getContent();

Source Link

Document

Returns the page content as List .

Usage

From source file:edu.zipcloud.cloudstreetmarket.api.services.StockProductServiceOnlineImpl.java

@Override
@Transactional//w  w  w  .j  a v  a2  s.  c o  m
public Page<StockProduct> gather(String indexId, String exchangeId, MarketId marketId, String startWith,
        Specification<StockProduct> spec, Pageable pageable) {

    Page<StockProduct> stocks = get(indexId, exchangeId, marketId, startWith, spec, pageable, false);

    if (AuthenticationUtil.userHasRole(Role.ROLE_OAUTH2)) {
        updateStocksAndQuotesFromYahoo(stocks.getContent().stream().collect(Collectors.toSet()));
        return get(indexId, exchangeId, marketId, startWith, spec, pageable, false);
    }

    return stocks;
}

From source file:org.jblogcms.core.comment.repository.CommentRepositoryItTest.java

@Test
@Transactional//www .  j a  v  a2 s . com
public void testFindFavoriteComments_returnOneComment() throws Exception {
    Page<Comment> comments = commentRepository.findFavoriteComments(ACCOUNT_2_ID, pageable);

    Assert.assertEquals(1, comments.getNumberOfElements());

    Assert.assertEquals(COMMENT_2_ID, comments.getContent().get(0).getId());
    Assert.assertEquals(COMMENT_2_TEXT, comments.getContent().get(0).getText());
    Assert.assertEquals(COMMENT_2_ACCOUNT_2_ID, comments.getContent().get(0).getAccount().getId());
    Assert.assertEquals(COMMENT_2_ACCOUNT_2_NAME, comments.getContent().get(0).getAccount().getName());
    Assert.assertEquals(COMMENT_2_POST_1_ID, comments.getContent().get(0).getPost().getId());
    Assert.assertEquals(COMMENT_2_POST_1_TITLE, comments.getContent().get(0).getPost().getTitle());
}

From source file:de.appsolve.padelcampus.api.controllers.ApiParticipantsController.java

@RequestMapping(method = GET, value = "options", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody//w  ww.ja v a 2s .  c om
public List<Option> getOptions(HttpServletRequest request, @RequestParam("q") String q,
        @RequestParam("type") EventType eventType) {
    Player user = sessionUtil.getUser(request);
    if (user == null) {
        return null;
    }
    List<Option> options = new ArrayList<>();
    if (!StringUtils.isEmpty(q)) {
        Page<? extends ParticipantI> page;
        switch (eventType) {
        case PullRoundRobin:
        case CommunityRoundRobin:
            page = playerDAO.findAllByFuzzySearch(q);
            break;
        default:
            page = teamDAO.findAllByFuzzySearch(q);
            break;
        }
        for (ParticipantI model : page.getContent()) {
            options.add(getOption(model));
        }
    }
    return options;
}

From source file:edu.zipcloud.cloudstreetmarket.core.services.StockProductServiceOfflineImpl.java

@Override
@Transactional/*w ww .java 2  s .  c om*/
public Page<StockProduct> gather(String userId, String indexId, String exchangeId, MarketId marketId,
        String startWith, Specification<StockProduct> spec, Pageable pageable) {

    Page<StockProduct> stocks = get(indexId, exchangeId, marketId, startWith, spec, pageable, false);

    if (AuthenticationUtil.userHasRole(Role.ROLE_OAUTH2)) {
        updateStocksAndQuotesFromYahoo(stocks.getContent().stream().collect(Collectors.toSet()));
        return get(indexId, exchangeId, marketId, startWith, spec, pageable, false);
    }

    return stocks;
}

From source file:com.restfiddle.controller.rest.NodeController.java

@RequestMapping(value = "/api/nodes/starred", method = RequestMethod.GET)
public @ResponseBody List<NodeDTO> findStarredNodes(
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "limit", required = false) Integer limit) {
    logger.debug("Finding starred nodes.");

    int pageNo = 0;
    if (page != null && page > 0) {
        pageNo = page;//from   ww  w  .  j  a  v  a  2  s.  com
    }

    int numberOfRecords = 10;
    if (limit != null && limit > 0) {
        numberOfRecords = limit;
    }
    Sort sort = new Sort(Direction.DESC, "lastModifiedDate");
    Pageable pageable = new PageRequest(pageNo, numberOfRecords, sort);

    Page<BaseNode> paginatedStarredNodes = nodeRepository.findStarredNodes(pageable);

    List<BaseNode> starredNodes = paginatedStarredNodes.getContent();
    long totalElements = paginatedStarredNodes.getTotalElements();

    List<NodeDTO> response = new ArrayList<NodeDTO>();
    for (BaseNode item : starredNodes) {
        response.add(EntityToDTO.toDTO(item));
    }

    System.out.println("totalElements : " + totalElements);
    return response;
}

From source file:org.jblogcms.core.comment.repository.CommentRepositoryItTest.java

@Test
@Transactional//from  ww w  .  jav a2 s  .c  o  m
public void testFindCommentsByAccountId_returnOneComment() throws Exception {
    Page<Comment> comments = commentRepository.findCommentsByAccountId(ACCOUNT_2_ID, pageable);

    Assert.assertEquals(1, comments.getNumberOfElements());

    Assert.assertEquals(COMMENT_2_ID, comments.getContent().get(0).getId());
    Assert.assertEquals(COMMENT_2_TEXT, comments.getContent().get(0).getText());
    Assert.assertEquals(COMMENT_2_ACCOUNT_2_ID, comments.getContent().get(0).getAccount().getId());
    Assert.assertEquals(COMMENT_2_ACCOUNT_2_NAME, comments.getContent().get(0).getAccount().getName());
    Assert.assertEquals(COMMENT_2_POST_1_ID, comments.getContent().get(0).getPost().getId());
    Assert.assertEquals(COMMENT_2_POST_1_TITLE, comments.getContent().get(0).getPost().getTitle());
}

From source file:com._4dconcept.springframework.data.marklogic.repository.support.RepositoryIntegrationTests.java

@Test
public void findAllWithPagination() {
    Page<Person> pageResult = repository.findAll(PageRequest.of(0, 2));
    assertThat(pageResult.getTotalElements(), is(3L));
    assertThat(pageResult.getTotalPages(), is(2));
    assertThat(pageResult.getContent(), hasSize(2));
}

From source file:net.sf.gazpachoquest.facades.impl.ResearchFacadeImpl.java

@Override
public PageDTO<ResearchDTO> findPaginated(Integer pageNumber, Integer size) {
    Page<Research> page = researchPermissionsAwareServiceImpl.findPaginated(pageNumber, size);
    PageDTO<ResearchDTO> pageDTO = new PageDTO<>();
    pageDTO.setNumber(page.getNumber() + 1);
    pageDTO.setSize(page.getSize());//from   w  ww  .  j  a va  2 s  .  c om
    pageDTO.setTotalPages(page.getTotalPages());
    pageDTO.setTotalElements(page.getTotalElements());

    for (Research research : page.getContent()) {
        ResearchDTO researchDTO = mapper.map(research, ResearchDTO.class);
        pageDTO.addElement(researchDTO);
    }
    return pageDTO;
}

From source file:org.openlmis.fulfillment.web.shipmentdraft.ShipmentDraftController.java

/**
 * Get shipment with request param.//ww w . j  a v a2  s . co m
 *
 * @param orderId order UUID (required).
 * @return a page of shipment drafts.
 */
@GetMapping
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public Page<ShipmentDraftDto> getShipmentDrafts(@RequestParam(required = false) UUID orderId,
        Pageable pageable) {
    XLOGGER.entry(orderId);
    Profiler profiler = new Profiler("GET_SHIPMENT_DRAFTS");
    profiler.setLogger(XLOGGER);

    profiler.start("VALIDATE");
    if (orderId == null) {
        throw new ValidationException(SHIPMENT_DRAFT_ORDER_REQUIRED);
    }

    Order order = orderRepository.findOne(orderId);
    if (order == null) {
        throw new ValidationException(SHIPMENT_DRAFT_ORDER_NOT_FOUND);
    }

    profiler.start(CHECK_RIGHTS);
    permissionService.canViewShipmentDraft(order);

    profiler.start("FIND_BY_ORDER_AND_BUILD_DTO");
    Page<ShipmentDraft> draftPage = repository.findByOrder(order, pageable);
    List<ShipmentDraftDto> draftDtos = draftDtoBuilder.build(draftPage.getContent());

    int numberOfElements = draftPage.getNumberOfElements();
    Page<ShipmentDraftDto> page = Pagination.getPage(draftDtos, pageable, numberOfElements);

    profiler.stop().log();
    XLOGGER.exit(page);
    return page;
}

From source file:org.jblogcms.core.comment.repository.CommentRepositoryItTest.java

@Test
@Transactional/*from ww w  . j  a v a  2  s.  c o m*/
public void testFindFavoriteComments_returnTwoComments() throws Exception {
    Page<Comment> comments = commentRepository.findFavoriteComments(ACCOUNT_1_ID, pageable);

    Assert.assertEquals(2, comments.getNumberOfElements());

    Assert.assertEquals(COMMENT_1_ID, comments.getContent().get(0).getId());
    Assert.assertEquals(COMMENT_1_TEXT, comments.getContent().get(0).getText());
    Assert.assertEquals(COMMENT_1_ACCOUNT_1_ID, comments.getContent().get(0).getAccount().getId());
    Assert.assertEquals(COMMENT_1_ACCOUNT_1_NAME, comments.getContent().get(0).getAccount().getName());
    Assert.assertEquals(COMMENT_1_POST_2_ID, comments.getContent().get(0).getPost().getId());
    Assert.assertEquals(COMMENT_1_POST_2_TITLE, comments.getContent().get(0).getPost().getTitle());

    Assert.assertEquals(COMMENT_2_ID, comments.getContent().get(1).getId());
    Assert.assertEquals(COMMENT_2_TEXT, comments.getContent().get(1).getText());
    Assert.assertEquals(COMMENT_2_ACCOUNT_2_ID, comments.getContent().get(1).getAccount().getId());
    Assert.assertEquals(COMMENT_2_ACCOUNT_2_NAME, comments.getContent().get(1).getAccount().getName());
    Assert.assertEquals(COMMENT_2_POST_1_ID, comments.getContent().get(1).getPost().getId());
    Assert.assertEquals(COMMENT_2_POST_1_TITLE, comments.getContent().get(1).getPost().getTitle());
}