use of com.liferay.apio.architect.pagination.PageItems in project com-liferay-apio-architect by liferay.
the class URLCreatorTest method testCreateCollectionPageURL.
@Test
public void testCreateCollectionPageURL() {
Pagination pagination = Mockito.mock(Pagination.class);
Mockito.when(pagination.getItemsPerPage()).thenReturn(30);
Mockito.when(pagination.getPageNumber()).thenReturn(1);
PageItems<String> pageItems = new PageItems<>(emptyList(), 0);
Page page = new Page<>("", pageItems, pagination, null);
String firstPageURL = URLCreator.createCollectionPageURL("www.liferay.com", page, PageType.FIRST);
assertThat(firstPageURL, is("www.liferay.com?page=1&per_page=30"));
}
use of com.liferay.apio.architect.pagination.PageItems in project com-liferay-apio-architect by liferay.
the class MediaObjectNestedCollectionResource method _getPageItems.
private PageItems<FileEntry> _getPageItems(Pagination pagination, Long folderId) throws PortalException {
Folder folder = _dlAppService.getFolder(folderId);
List<FileEntry> dlFileEntries = _dlAppService.getFileEntries(folder.getGroupId(), folder.getFolderId(), pagination.getStartPosition(), pagination.getEndPosition());
int count = _dlAppService.getFileEntriesCount(folder.getGroupId(), folder.getFolderId());
return new PageItems<>(dlFileEntries, count);
}
use of com.liferay.apio.architect.pagination.PageItems in project com-liferay-apio-architect by liferay.
the class MockPageWriter method write.
/**
* Writes a Collection of {@link RootModel}, with the hierarchy of embedded
* models and multiple fields.
*
* @param httpHeaders the request's {@code HttpHeaders}
* @param pageMessageMapper the {@link PageMessageMapper} to use for writing
* the JSON object
*/
public static JsonObject write(HttpHeaders httpHeaders, PageMessageMapper<RootModel> pageMessageMapper) {
RequestInfo requestInfo = getRequestInfo(httpHeaders);
Collection<RootModel> items = Arrays.asList(() -> "1", () -> "2", () -> "3");
PageItems<RootModel> pageItems = new PageItems<>(items, 9);
Pagination pagination = new Pagination(3, 2);
Path path = new Path("name", "id");
List<Operation> operations = Collections.singletonList(new Operation(createForm("c", "p"), POST, "create-operation"));
Page<RootModel> page = new Page<>("root", pageItems, pagination, path, operations);
PageWriter<RootModel> pageWriter = PageWriter.create(builder -> builder.page(page).pageMessageMapper(pageMessageMapper).pathFunction(MockWriterUtil::identifierToPath).resourceNameFunction(__ -> Optional.of("models")).representorFunction(MockWriterUtil::getRepresentorOptional).requestInfo(requestInfo).singleModelFunction(MockWriterUtil::getSingleModel).build());
return new Gson().fromJson(pageWriter.write(), JsonObject.class);
}
Aggregations