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

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

Introduction

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

Prototype

long getTotalElements();

Source Link

Document

Returns the total amount of elements.

Usage

From source file:com.th.jbp.web.vm.TrailerHeadVM.java

private void loadItems() {
    LOGGER.info("loadItems--> activePage : " + this.activePage);
    PageRequest pageRequest = new PageRequest(activePage, pageSize);
    Page<TrailerHeadM> page = trailerHeadService.lists(licensePlate, pageRequest);
    this.totalSize = Integer.parseInt(String.valueOf(page.getTotalElements()));
    this.records.clear();
    this.records.addAll(page.getContent());
}

From source file:com.github.markserrano.jsonquery.jpa.service.ParentEntityServiceTest.java

@Test
public void testReadAndCount_Jqgrid_DoubleCriteria_Empty() {
    String filter = "{\"groupOp\":\"AND\",\"rules\":" + "[{\"field\":\"id\",\"op\":\"gt\",\"data\":\"5\"},"
            + "{\"field\":\"store\",\"op\":\"ne\",\"data\":\"StoreC\"}]" + "}";

    BooleanBuilder builder = jsonBooleanBuilder.build(new JsonFilter(filter));

    Page<Parent> results = service.readAndCount(builder, new PageRequest(0, 3), Parent.class, orderSpecifier);

    Assert.assertNotNull(results);/*from  w w w .  j a v a  2 s  .com*/
    Assert.assertEquals(0, results.getTotalElements());
}

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

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

    assertNotNull(page);//from  ww w  .  ja va 2s  .  c om
    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  .  j av  a2 s.c o 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.j  av a 2 s.  c om
    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:it.f2informatica.core.gateway.mongodb.ConsultantRepositoryGatewayMongoDB.java

@Override
public Page<ConsultantModel> findAllConsultants(Pageable pageable) {
    Page<Consultant> consultantPage = consultantRepository.findAll(pageable);
    return new PageImpl<>(consultantToModelConverter.convertList(consultantPage.getContent()), pageable,
            consultantPage.getTotalElements());
}

From source file:com.github.markserrano.jsonquery.jpa.service.ParentEntityServiceTest.java

@Test
public void testReadAndCount_WhenNoFilterPresent() {
    String filter = QueryUtil.init();

    BooleanBuilder builder = jsonBooleanBuilder.build(new JsonFilter(filter));

    Page<Parent> results = service.readAndCount(builder, new PageRequest(0, 3), Parent.class, orderSpecifier);

    Assert.assertNotNull(results);//from  www  .ja  v a 2 s .c o m
    Assert.assertEquals(4, results.getTotalElements());
    Assert.assertEquals("StoreA", results.getContent().get(0).getStore());
    Assert.assertEquals("StoreB", results.getContent().get(1).getStore());
    Assert.assertEquals("StoreC", results.getContent().get(2).getStore());
}

From source file:com.github.markserrano.jsonquery.jpa.service.ParentEntityServiceTest.java

@Test
public void testReadAndCount_Jqgrid_DoubleCriteria() {
    String filter = "{\"groupOp\":\"AND\",\"rules\":" + "[{\"field\":\"id\",\"op\":\"gt\",\"data\":\"1\"},"
            + "{\"field\":\"store\",\"op\":\"ne\",\"data\":\"StoreC\"}]" + "}";

    BooleanBuilder builder = jsonBooleanBuilder.build(new JsonFilter(filter));

    Page<Parent> results = service.readAndCount(builder, new PageRequest(0, 3), Parent.class, orderSpecifier);

    Assert.assertNotNull(results);//  w  ww  .j a  va  2 s .c  o  m
    Assert.assertEquals(2, results.getTotalElements());
    Assert.assertEquals("StoreB", results.getContent().get(0).getStore());
    Assert.assertEquals("StoreD", results.getContent().get(1).getStore());
}

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

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

    assertNotNull(page);//  w w  w  .j  a v  a 2 s  . 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:com.epam.ta.reportportal.ws.converter.ProjectRelatedResourceAssembler.java

/**
 * Creates {@link com.epam.ta.reportportal.ws.model.Page} from {@link Page} DB query result
 *
 * @param content//from   w ww .j  av  a2s. com
 * @return
 */
public com.epam.ta.reportportal.ws.model.Page<R> toPagedResources(Page<T> content, final String project) {
    Assert.notNull(content);

    return new com.epam.ta.reportportal.ws.model.Page<R>(
            content.getContent().stream().map(c -> toResource(c, project)).collect(Collectors.toList()),
            new com.epam.ta.reportportal.ws.model.Page.PageMetadata(content.getSize(), content.getNumber() + 1,
                    content.getTotalElements(), content.getTotalPages()));
}