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

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

Introduction

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

Prototype

boolean hasContent();

Source Link

Document

Returns whether the Slice has content at all.

Usage

From source file:org.wallride.web.controller.admin.user.UserSelect2Controller.java

@RequestMapping(value = "/{language}/users/select")
public @ResponseBody List<DomainObjectSelect2Model> select(@PathVariable String language,
        @RequestParam(required = false) String keyword) {
    UserSearchForm form = new UserSearchForm();
    form.setKeyword(keyword);//w w  w  .  j av  a  2s . com
    Page<User> users = userService.getUsers(form.toUserSearchRequest());

    List<DomainObjectSelect2Model> results = new ArrayList<>();
    if (users.hasContent()) {
        for (User user : users) {
            DomainObjectSelect2Model model = new DomainObjectSelect2Model(user.getId(), user.toString());
            results.add(model);
        }
    }
    return results;
}

From source file:org.wallride.web.controller.admin.post.PostSelectController.java

@RequestMapping(value = "/{language}/posts/select")
public @ResponseBody List<DomainObjectSelect2Model> select(@PathVariable String language,
        @RequestParam(required = false) String keyword) {
    PostSearchRequest request = new PostSearchRequest(language).withStatus(Post.Status.PUBLISHED)
            .withKeyword(keyword);/*from  ww  w .j  a  v  a2s.  c o  m*/
    Page<Post> posts = postService.getPosts(request, new PageRequest(0, 30));

    List<DomainObjectSelect2Model> results = new ArrayList<>();
    if (posts.hasContent()) {
        for (Post post : posts) {
            DomainObjectSelect2Model model = new DomainObjectSelect2Model(post);
            results.add(model);
        }
    }
    return results;
}

From source file:org.wallride.web.controller.admin.category.CategorySelectController.java

@RequestMapping(value = "/{language}/categories/select")
public @ResponseBody List<DomainObjectSelect2Model> select(@PathVariable String language,
        @RequestParam(required = false) String keyword) {
    CategorySearchForm form = new CategorySearchForm();
    form.setKeyword(keyword);/*from w w  w.  java2 s. c o  m*/
    form.setLanguage(language);
    Page<Category> categories = categoryService.getCategories(form.toCategorySearchRequest());

    List<DomainObjectSelect2Model> results = new ArrayList<>();
    if (categories.hasContent()) {
        for (Category category : categories) {
            DomainObjectSelect2Model model = new DomainObjectSelect2Model(category.getId(), category.getName());
            results.add(model);
        }
    }
    return results;
}

From source file:cn.guoyukun.spring.jpa.plugin.serivce.BaseMovableService.java

private Integer findNextWeight() {
    Searchable searchable = Searchable.newSearchable().setPage(0, 1).addSort(Sort.Direction.DESC, "weight");
    Page<M> page = findAll(searchable);

    if (!page.hasContent()) {
        return stepLength;
    }/*from  ww  w  .  j  a v  a  2 s .  com*/

    return page.getContent().get(0).getWeight() + stepLength;
}

From source file:com.trenako.results.PaginatedListsTests.java

@Test
public void shouldPaginateListOfValuesForFirstPage() {
    Page<String> page = PaginatedLists.paginate(values(50), paging(1, 10));

    assertNotNull(page);//  ww  w . j ava 2  s.com
    assertFalse("With a previous page", page.hasPreviousPage());
    assertTrue("Without a next page", page.hasNextPage());
    assertTrue("Without content", page.hasContent());

    assertEquals(50, page.getTotalElements());
    assertEquals(10, page.getContent().size());
    assertEquals("item1", page.getContent().get(0));
    assertEquals("item10", page.getContent().get(9));
}

From source file:com.trenako.results.PaginatedListsTests.java

@Test
public void shouldPaginateListOfValuesForLastPage() {
    Page<String> page = PaginatedLists.paginate(values(50), paging(5, 10));

    assertNotNull(page);/* w w w .ja  v  a 2s. co  m*/
    assertFalse("With a next page", page.hasNextPage());
    assertTrue("Without a previous page", page.hasPreviousPage());
    assertTrue("Without content", page.hasContent());

    assertEquals(50, page.getTotalElements());
    assertEquals(10, page.getContent().size());
    assertEquals("item41", page.getContent().get(0));
    assertEquals("item50", page.getContent().get(9));
}

From source file:com.trenako.results.PaginatedListsTests.java

@Test
public void shouldPaginateListOfValuesForLastPageWhenIncomplete() {
    Page<String> page = PaginatedLists.paginate(values(47), paging(5, 10));

    assertNotNull(page);//from   w  w  w .ja v  a2s .  c o m
    assertFalse("With a next page", page.hasNextPage());
    assertTrue("Without a previous page", page.hasPreviousPage());
    assertTrue("Without content", page.hasContent());

    assertEquals(47, page.getTotalElements());
    assertEquals(7, page.getContent().size());
    assertEquals("item41", page.getContent().get(0));
    assertEquals("item47", page.getContent().get(6));
}

From source file:com.trenako.results.PaginatedListsTests.java

@Test
public void shouldPaginateListOfValuesForPageInBetween() {
    Page<String> page = PaginatedLists.paginate(values(50), paging(3, 10));

    assertNotNull(page);//ww w.j a  va 2s  . c  om
    assertTrue("Without a next page", page.hasNextPage());
    assertTrue("Without a previous page", page.hasPreviousPage());
    assertTrue("Without content", page.hasContent());

    assertEquals(50, page.getTotalElements());
    assertEquals(10, page.getContent().size());
    assertEquals("item21", page.getContent().get(0));
    assertEquals("item30", page.getContent().get(9));
}

From source file:cn.guoyukun.spring.jpa.plugin.serivce.BaseMovableService.java

public M findPreByWeight(Integer weight) {
    Pageable pageable = new PageRequest(0, 1);
    Map<String, Object> searchParams = Maps.newHashMap();
    searchParams.put("weight_lt", weight);
    Sort sort = new Sort(Sort.Direction.DESC, "weight");
    Page<M> page = findAll(Searchable.newSearchable(searchParams).addSort(sort).setPage(pageable));

    if (page.hasContent()) {
        return page.getContent().get(0);
    }//w w w.ja v  a  2s .c  o m
    return null;
}