use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class AbstractHibernateCurator method listAll.
@SuppressWarnings("unchecked")
@Transactional
public Page<List<E>> listAll(PageRequest pageRequest, boolean postFilter) {
Page<List<E>> resultsPage;
if (postFilter) {
// Create a copy of the page request with just the order and sort by values.
// Since we are filtering after the results are returned, we don't want
// to send the page or page size values in.
PageRequest orderAndSortByPageRequest = null;
if (pageRequest != null) {
orderAndSortByPageRequest = new PageRequest();
orderAndSortByPageRequest.setOrder(pageRequest.getOrder());
orderAndSortByPageRequest.setSortBy(pageRequest.getSortBy());
}
resultsPage = listAll(orderAndSortByPageRequest);
// Set the pageRequest to the correct object here.
resultsPage.setPageRequest(pageRequest);
} else {
resultsPage = listAll(pageRequest);
}
return resultsPage;
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class EntitlementResourceTest method getAllEntitlementsForConsumer.
@Test
public void getAllEntitlementsForConsumer() {
PageRequest req = new PageRequest();
req.setPage(1);
req.setPerPage(10);
Owner owner = TestUtil.createOwner();
Consumer consumer = TestUtil.createConsumer(owner);
Pool pool = TestUtil.createPool(owner, TestUtil.createProduct());
Entitlement e = TestUtil.createEntitlement(owner, consumer, pool, null);
e.setId("getAllEntitlementsForConsumer");
List<Entitlement> entitlements = new ArrayList<>();
entitlements.add(e);
Page<List<Entitlement>> page = new Page<>();
page.setPageData(entitlements);
EntitlementDTO entitlementDTO = new EntitlementDTO();
entitlementDTO.setId("getAllEntitlementsForConsumer");
when(consumerCurator.findByUuid(eq(consumer.getUuid()))).thenReturn(consumer);
when(entitlementCurator.listByConsumer(isA(Consumer.class), anyString(), isA(EntitlementFilterBuilder.class), isA(PageRequest.class))).thenReturn(page);
when(modelTranslator.translate(isA(Entitlement.class), eq(EntitlementDTO.class))).thenReturn(entitlementDTO);
List<EntitlementDTO> result = entResource.listAllForConsumer(consumer.getUuid(), null, null, req);
assertEquals(1, result.size());
assertEquals("getAllEntitlementsForConsumer", result.get(0).getId());
}
Aggregations