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

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

Introduction

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

Prototype

int getNumber();

Source Link

Document

Returns the number of the current Slice .

Usage

From source file:org.jtalks.jcommune.model.dao.search.hibernate.TopicHibernateSearchDaoTest.java

@Test
public void testFullPhraseSearchPageNumberTooBig() {
    Topic expectedTopic = PersistedObjectsFactory.getDefaultTopic();
    expectedTopic.setTitle(TOPIC_CONTENT);

    saveAndFlushIndexes(Arrays.asList(expectedTopic));
    configureMocks(TOPIC_CONTENT, TOPIC_CONTENT);

    PageRequest pageRequest = new PageRequest("1000", 50);
    Page<Topic> searchResultPage = topicSearchDao.searchByTitleAndContent(TOPIC_CONTENT, pageRequest,
            Arrays.asList(expectedTopic.getBranch().getId()));

    Assert.assertEquals(searchResultPage.getNumber(), 1);
    Assert.assertTrue(searchResultPage.hasContent(), "Search result must not be empty.");
    for (Topic topic : searchResultPage.getContent()) {
        Assert.assertEquals(expectedTopic.getTitle(), topic.getTitle(),
                "Content from the index should be the same as in the database.");
    }/*from w  ww .java 2  s  .c om*/
}

From source file:org.jtalks.jcommune.web.controller.TopicController.java

/**
 * Displays to user a list of messages from the topic with pagination
 *
 * @param topicId the id of selected Topic
 * @param page    page//from  w ww  . j a  v  a  2s .c om
 * @return {@code ModelAndView}
 * @throws NotFoundException when topic or branch not found
 */
@RequestMapping(value = "/topics/{topicId}", method = RequestMethod.GET)
public ModelAndView showTopicPage(WebRequest request, @PathVariable(TOPIC_ID) Long topicId,
        @RequestParam(value = "page", defaultValue = "1", required = false) String page)
        throws NotFoundException {
    JCUser currentUser = userService.getCurrentUser();
    Topic topic = topicFetchService.get(topicId);

    topicFetchService.checkViewTopicPermission(topic.getBranch().getId());
    Page<Post> postsPage = postService.getPosts(topic, page);

    if (request.checkNotModified(topic.getLastModificationPostDate().getMillis())) {
        return null;
    }
    PostDto postDto = new PostDto();
    PostDraft draft = topic.getDraftForUser(currentUser);
    if (draft != null) {
        postDto = PostDto.getDtoFor(draft);
    }
    lastReadPostService.markTopicPageAsRead(topic, postsPage.getNumber());
    return new ModelAndView("topic/postList").addObject("viewList", locationService.getUsersViewing(topic))
            .addObject("usersOnline", sessionRegistry.getAllPrincipals()).addObject("postsPage", postsPage)
            .addObject("topic", topic).addObject(POST_DTO, postDto)
            .addObject("subscribed", topic.getSubscribers().contains(currentUser))
            .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getForumBreadcrumb(topic));
}

From source file:org.springframework.data.neo4j.aspects.support.FinderTest.java

private void assertPage(Page<Person> page0, int pageNumber, int totalPages, final int totalElements,
        Person... people) {//from  ww w. ja  v  a  2s.c  o  m
    assertEquals("content count", people.length, page0.getNumberOfElements());
    assertEquals("page number", pageNumber, page0.getNumber());
    assertEquals("page size", 2, page0.getSize());
    assertEquals("total elements", totalElements, page0.getTotalElements());
    assertEquals("page count", totalPages, page0.getTotalPages());
    assertEquals("next page", pageNumber < totalPages - 1, page0.hasNextPage());
    assertEquals("previous page", pageNumber > 0, page0.hasPreviousPage());
    assertEquals("page content", asList(people), page0.getContent());
}

From source file:pl.edu.pwr.szlagor.masterthesis.linguisticsummary.semantic.integrator.integrator.job.reader.SemanticRepositoryItemReader.java

/**
 * Performs the actual reading of a page via the repository.
 * Available for overriding as needed.//from  w w  w.j a  va2  s.  com
 *
 * @return the list of items that make up the page
 * @throws Exception
 */
@SuppressWarnings("unchecked")
protected List<T> doPageRead() throws Exception {
    if (page < endPage) {
        Pageable pageRequest = sort != null ? new PageRequest(page, pageSize, sort)
                : new PageRequest(page, pageSize);

        MethodInvoker invoker = createMethodInvoker(repository, methodName);

        List<Object> parameters = new ArrayList<Object>();

        if (arguments != null && arguments.size() > 0) {
            parameters.addAll(arguments);
        }

        parameters.add(pageRequest);

        invoker.setArguments(parameters.toArray());

        Page<T> curPage = (Page<T>) doInvoke(invoker);
        System.out.println("current Page no.:" + curPage.getNumber() + " of total: " + curPage.getTotalPages());
        return curPage.getContent();
    } else {
        return Collections.emptyList();
    }
}