Search in sources :

Example 96 with PageRequest

use of org.springframework.data.domain.PageRequest in project oc-explorer by devgateway.

the class PersonDashboardJpaRepositoryProvider method iterator.

/**
 * @see SortableDataProvider#iterator(long, long)
 */
@Override
public Iterator<UserDashboard> iterator(final long first, final long count) {
    int page = (int) ((double) first / WebConstants.PAGE_SIZE);
    Page<UserDashboard> findAll = userDashboardRepository.findDashboardsForPersonId(SecurityUtil.getCurrentAuthenticatedPerson().getId(), new PageRequest(page, WebConstants.PAGE_SIZE, translateSort()));
    return findAll.iterator();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) UserDashboard(org.devgateway.ocds.persistence.dao.UserDashboard)

Example 97 with PageRequest

use of org.springframework.data.domain.PageRequest in project uplace.es by Uplace.

the class UserServiceIntTest method assertThatAnonymousUserIsNotGet.

@Test
@Transactional
public void assertThatAnonymousUserIsNotGet() {
    user.setLogin(Constants.ANONYMOUS_USER);
    if (!userRepository.findOneByLogin(Constants.ANONYMOUS_USER).isPresent()) {
        userRepository.saveAndFlush(user);
    }
    final PageRequest pageable = new PageRequest(0, (int) userRepository.count());
    final Page<UserDTO> allManagedUsers = userService.getAllManagedUsers(pageable);
    assertThat(allManagedUsers.getContent().stream().noneMatch(user -> Constants.ANONYMOUS_USER.equals(user.getLogin()))).isTrue();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) UserDTO(com.arnaugarcia.uplace.service.dto.UserDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 98 with PageRequest

use of org.springframework.data.domain.PageRequest in project uplace.es by Uplace.

the class PaginationUtilUnitTest method generatePaginationHttpHeadersTest.

@Test
public void generatePaginationHttpHeadersTest() {
    String baseUrl = "/api/_search/example";
    List<String> content = new ArrayList<>();
    Page<String> page = new PageImpl<>(content, new PageRequest(6, 50), 400L);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, baseUrl);
    List<String> strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    String headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 4);
    String expectedData = "</api/_search/example?page=7&size=50>; rel=\"next\"," + "</api/_search/example?page=5&size=50>; rel=\"prev\"," + "</api/_search/example?page=7&size=50>; rel=\"last\"," + "</api/_search/example?page=0&size=50>; rel=\"first\"";
    assertEquals(expectedData, headerData);
    List<String> xTotalCountHeaders = headers.get("X-Total-Count");
    assertTrue(xTotalCountHeaders.size() == 1);
    assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(400L));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) HttpHeaders(org.springframework.http.HttpHeaders) PageRequest(org.springframework.data.domain.PageRequest) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 99 with PageRequest

use of org.springframework.data.domain.PageRequest in project zhcet-web by zhcet-amu.

the class NotificationReadingService method getNotifications.

public Page<NotificationRecipient> getNotifications(int page) {
    String userId = Auditor.getLoggedInUsername();
    PageRequest pageRequest = PageRequest.of(page - 1, PAGE_SIZE, Sort.Direction.DESC, "notification.sentTime");
    return notificationRecipientRepository.findByRecipientUserId(userId, pageRequest);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest)

Example 100 with PageRequest

use of org.springframework.data.domain.PageRequest in project zhcet-web by zhcet-amu.

the class NotificationReadingService method getFavoriteNotifications.

public Page<NotificationRecipient> getFavoriteNotifications(int page) {
    String userId = Auditor.getLoggedInUsername();
    PageRequest pageRequest = PageRequest.of(page - 1, PAGE_SIZE, Sort.Direction.DESC, "notification.sentTime");
    return notificationRecipientRepository.findByRecipientUserIdAndFavorite(userId, true, pageRequest);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest)

Aggregations

PageRequest (org.springframework.data.domain.PageRequest)106 Sort (org.springframework.data.domain.Sort)29 Pageable (org.springframework.data.domain.Pageable)25 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 Transactional (org.springframework.transaction.annotation.Transactional)9 UUID (java.util.UUID)8 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)7 ApiOperation (io.swagger.annotations.ApiOperation)7 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)6 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)6 List (java.util.List)6 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)5 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)5 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 PageImpl (org.springframework.data.domain.PageImpl)5