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:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java

@Test
public void gettingNonFirstPageWorksWithoutLimitBeingSet() {
    Page<Person> slice = repository.findByLastnameLike("Matthews", new PageRequest(1, 1));

    assertThat(slice.getContent(), hasSize(1));
    assertThat(slice.hasPrevious(), is(true));
    assertThat(slice.hasNext(), is(false));
}

From source file:nu.yona.server.analysis.service.ActivityServiceTest.java

@Test
public void getUserWeekActivityOverviews_noActivityPresent_resultsWithInactivity() {
    Page<WeekActivityOverviewDto> inactivityWeekOverviews = service.getUserWeekActivityOverviews(userId,
            new PageRequest(0, 5));

    // because the gambling goal was added with creation date two weeks ago, there are multiple weeks
    assertThat(inactivityWeekOverviews.getNumberOfElements(), equalTo(3));
    // the other goals were created today, so get the most recent (first) element
    WeekActivityOverviewDto inactivityWeekOverview = inactivityWeekOverviews.getContent().get(0);
    assertThat(inactivityWeekOverview.getWeekActivities().size(), equalTo(userAnonEntity.getGoals().size()));
    WeekActivityDto inactivityWeekForGambling = inactivityWeekOverview.getWeekActivities().stream()
            .filter(a -> a.getGoalId().equals(gamblingGoal.getId())).findAny().get();
    assertThat(inactivityWeekForGambling.getStartTime(),
            equalTo(getWeekStartTime(ZonedDateTime.now(userAnonZone))));
    // TODO: mock day activity in this week?
    // ZonedDateTime today = getDayStartTime(ZonedDateTime.now(userAnonZone));
    // int thisWeekNumberOfWeekDaysPast = today.getDayOfWeek() == DayOfWeek.SUNDAY ? 0 : today.getDayOfWeek().getValue();
    // assertThat(inactivityWeekForGambling.getDayActivities().size(), equalTo(1 + thisWeekNumberOfWeekDaysPast));
}

From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java

@Test
public void shouldNotLimitPagedQueryWhenPageRequestWithinBounds() {
    repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"),
            new Person("Bob-3", "Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan")));
    Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(0, 2));
    assertThat(result.getContent().size(), is(2));
}

From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java

@Test
public void shouldLimitPagedQueryWhenPageRequestExceedsUpperBoundary() {
    repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"),
            new Person("Bob-3", "Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan")));
    Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(1, 2));
    assertThat(result.getContent().size(), is(1));
}

From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java

@Test
public void shouldReturnEmptyWhenPageRequestedPageIsTotallyOutOfScopeForLimit() {
    repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"),
            new Person("Bob-3", "Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan")));
    Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(2, 2));
    assertThat(result.getContent().size(), is(0));
}

From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java

@Test
public void findByNestedPropertyInCollectionShouldFindMatchingDocuments() {
    Person p = new Person("Mary", "Poppins");
    Address adr = new Address("some", "2", "where");
    p.setAddress(adr);/*from   w  ww. j  a v a 2 s .c o m*/

    repository.save(p);

    Page<Person> result = repository.findByAddressIn(Arrays.asList(adr), new PageRequest(0, 10));

    assertThat(result.getContent(), hasSize(1));
}

From source file:com.olp.jpa.domain.docu.ut.service.DeptWebServiceImpl.java

@Override
@Transactional(readOnly = true)//from   ww  w  .  j a  v  a  2  s. c o m
public PageResponseBean<DeptBeanPub> doSimpleSearch(String keywords, Boolean fuzzy, Integer outputMode,
        PageRequestBean request) throws ServiceException {

    if (keywords == null || "".equals(keywords)) {
        ServiceException se = FaultUtil.makeServiceException(
                "Exception occured in simple search paged service ",
                new IllegalArgumentException("No search keyword found !"));
        throw se;
    }

    PageRequest req = JpaUtil.convert(request);

    Page<DepartmentBean> resp = null;
    PageResponseBean<DeptBeanPub> response = null;
    try {
        resp = service.findText(keywords, fuzzy, req);
        List<DepartmentBean> list1 = resp.getContent();
        List<DeptBeanPub> list2 = convert(list1, outputMode);

        response = JpaUtil.tranform(resp, list2);
    } catch (Throwable t) {
        ServiceException se = FaultUtil
                .makeServiceException("Exception occurred in simple search paged service", t);
        throw se;
    }

    return (response);
}

From source file:nu.yona.server.analysis.service.ActivityServiceTest.java

@Test
public void getUserDayActivityOverviews_noActivityPresent_resultsWithInactivity() {
    ZonedDateTime today = getDayStartTime(ZonedDateTime.now(userAnonZone));

    Page<DayActivityOverviewDto<DayActivityDto>> inactivityDayOverviews = service
            .getUserDayActivityOverviews(userId, new PageRequest(0, 3));

    // because the gambling goal was added with creation date two weeks ago, there are multiple days
    assertThat(inactivityDayOverviews.getNumberOfElements(), equalTo(3));
    // the other goals were created today, so get the most recent (first) element
    DayActivityOverviewDto<DayActivityDto> inactivityDayOverview = inactivityDayOverviews.getContent().get(0);
    assertThat(inactivityDayOverview.getDayActivities().size(), equalTo(userAnonEntity.getGoals().size()));
    DayActivityDto inactivityDayForGambling = inactivityDayOverview.getDayActivities().stream()
            .filter(a -> a.getGoalId().equals(gamblingGoal.getId())).findAny().get();
    assertThat(inactivityDayForGambling.getStartTime(), equalTo(today));
    assertThat(inactivityDayForGambling.getTotalActivityDurationMinutes().get(), equalTo(0));
    assertThat(inactivityDayForGambling.getTotalMinutesBeyondGoal(), equalTo(0));
}

From source file:com.olp.jpa.domain.docu.ut.service.EmpWebServiceImpl.java

@Override
@Transactional(readOnly = true)/*from   w ww  .  jav  a  2s.c o m*/
public PageResponseBean<EmpBeanPub> findAll(Integer outputMode, PageRequestBean request)
        throws ServiceException {

    PageRequest req = JpaUtil.convert(request);
    Page<EmployeeBean> resp = null;
    try {
        resp = service.findAll(req);
    } catch (Throwable t) {
        ServiceException se = FaultUtil.makeServiceException("Exception occurred in findAll paged service", t);
        throw se;
    }

    List<EmployeeBean> list1 = resp.getContent();
    List<EmpBeanPub> list2 = convert(list1, outputMode);

    PageResponseBean<EmpBeanPub> response = JpaUtil.tranform(resp, list2);

    return (response);
}

From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java

@Test
public void findUsingAnnotatedQueryOnDBRef() {
    operations.remove(new org.springframework.data.mongodb.core.query.Query(), User.class);

    User user = new User();
    user.setUsername("Terria");
    operations.save(user);/*  w  ww  . ja va  2  s . c  o  m*/

    alicia.setCreator(user);
    repository.save(alicia);

    Page<Person> result = repository.findByHavingCreator(new PageRequest(0, 100));

    assertThat(result.getNumberOfElements(), is(1));
    assertThat(result.getContent().get(0), is(alicia));
}