use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class PageRequestFilter method filter.
@Override
public void filter(ContainerRequestContext requestContext) {
PageRequest p = null;
MultivaluedMap<String, String> params = requestContext.getUriInfo().getQueryParameters();
String page = params.getFirst(PageRequest.PAGE_PARAM);
String perPage = params.getFirst(PageRequest.PER_PAGE_PARAM);
String order = params.getFirst(PageRequest.ORDER_PARAM);
String sortBy = params.getFirst(PageRequest.SORT_BY_PARAM);
if (page != null || perPage != null || order != null || sortBy != null) {
p = new PageRequest();
if (order == null) {
p.setOrder(PageRequest.DEFAULT_ORDER);
} else {
p.setOrder(readOrder(order));
}
/* We'll leave it to the curator layer to figure out what to sort by if
* sortBy is null. */
p.setSortBy(sortBy);
try {
if (page == null && perPage != null) {
p.setPage(PageRequest.DEFAULT_PAGE);
p.setPerPage(readInteger(perPage));
} else if (page != null && perPage == null) {
p.setPage(readInteger(page));
p.setPerPage(PageRequest.DEFAULT_PER_PAGE);
} else {
p.setPage(readInteger(page));
p.setPerPage(readInteger(perPage));
}
} catch (NumberFormatException nfe) {
I18n i18n = this.i18nProvider.get();
throw new BadRequestException(i18n.tr("offset and limit parameters" + " must be positive integers"), nfe);
}
}
ResteasyProviderFactory.pushContext(PageRequest.class, p);
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class PageRequestFilterTest method testNoAnything.
@Test
public void testNoAnything() throws Exception {
mockReq = MockHttpRequest.create("GET", "http://localhost/candlepin/status");
when(mockRequestContext.getUriInfo()).thenReturn(mockReq.getUri());
interceptor.filter(mockRequestContext);
PageRequest p = ResteasyProviderFactory.getContextData(PageRequest.class);
assertNull(p);
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class PageRequestFilterTest method testBothLimitAndPage.
@Test
public void testBothLimitAndPage() throws Exception {
mockReq = MockHttpRequest.create("GET", "http://localhost/candlepin/status?per_page=10&page=4");
when(mockRequestContext.getUriInfo()).thenReturn(mockReq.getUri());
interceptor.filter(mockRequestContext);
PageRequest p = ResteasyProviderFactory.getContextData(PageRequest.class);
assertEquals(Integer.valueOf(10), p.getPerPage());
assertEquals(Integer.valueOf(4), p.getPage());
assertEquals(PageRequest.DEFAULT_ORDER, p.getOrder());
assertNull(p.getSortBy());
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class ConsumerResourceIntegrationTest method testConsumerCannotListWithUuidsAndOtherParameters.
@Test(expected = BadRequestException.class)
public void testConsumerCannotListWithUuidsAndOtherParameters() {
Consumer consumer = TestUtil.createConsumer(standardSystemType, owner);
consumerCurator.create(consumer);
setupAdminPrincipal("admin");
securityInterceptor.enable();
List<String> uuidList = new ArrayList<>();
uuidList.add(consumer.getUuid());
consumerResource.list("username", toSet("typeLabel"), owner.getKey(), uuidList, null, null, new PageRequest());
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class EntitlementResourceTest method getAllEntitlements.
@Test
public void getAllEntitlements() {
PageRequest req = new PageRequest();
req.setPage(1);
req.setPerPage(10);
Entitlement e = TestUtil.createEntitlement();
e.setId("getEntitlementList");
List<Entitlement> entitlements = new ArrayList<>();
entitlements.add(e);
Page<List<Entitlement>> page = new Page<>();
page.setPageData(entitlements);
EntitlementDTO entitlementDTO = new EntitlementDTO();
entitlementDTO.setId("getEntitlementList");
when(entitlementCurator.listAll(isA(EntitlementFilterBuilder.class), isA(PageRequest.class))).thenReturn(page);
when(modelTranslator.translate(isA(Entitlement.class), eq(EntitlementDTO.class))).thenReturn(entitlementDTO);
List<EntitlementDTO> result = entResource.listAllForConsumer(null, null, null, req);
assertEquals(1, result.size());
assertEquals("getEntitlementList", result.get(0).getId());
}
Aggregations