Search in sources :

Example 61 with PageRequest

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;
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) List(java.util.List) ArrayList(java.util.ArrayList) Transactional(com.google.inject.persist.Transactional)

Example 62 with PageRequest

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());
}
Also used : Owner(org.candlepin.model.Owner) EntitlementFilterBuilder(org.candlepin.model.EntitlementFilterBuilder) ArrayList(java.util.ArrayList) Page(org.candlepin.common.paging.Page) PageRequest(org.candlepin.common.paging.PageRequest) EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Aggregations

PageRequest (org.candlepin.common.paging.PageRequest)62 Test (org.junit.Test)54 List (java.util.List)35 ArrayList (java.util.ArrayList)32 LinkedList (java.util.LinkedList)26 Date (java.util.Date)14 Page (org.candlepin.common.paging.Page)13 Pool (org.candlepin.model.Pool)9 PoolFilterBuilder (org.candlepin.model.PoolFilterBuilder)7 Consumer (org.candlepin.model.Consumer)6 Owner (org.candlepin.model.Owner)5 EntitlementDTO (org.candlepin.dto.api.v1.EntitlementDTO)4 Entitlement (org.candlepin.model.Entitlement)4 Product (org.candlepin.model.Product)4 Transactional (com.google.inject.persist.Transactional)3 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)3 EntitlementFilterBuilder (org.candlepin.model.EntitlementFilterBuilder)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)2