Search in sources :

Example 1 with PageItems

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"));
}
Also used : Pagination(com.liferay.apio.architect.pagination.Pagination) Page(com.liferay.apio.architect.pagination.Page) PageItems(com.liferay.apio.architect.pagination.PageItems) Test(org.junit.Test)

Example 2 with PageItems

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);
}
Also used : FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) PageItems(com.liferay.apio.architect.pagination.PageItems) Folder(com.liferay.portal.kernel.repository.model.Folder)

Example 3 with PageItems

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);
}
Also used : Path(com.liferay.apio.architect.uri.Path) JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) MockFormCreator.createForm(com.liferay.apio.architect.test.util.form.MockFormCreator.createForm) RequestInfo(com.liferay.apio.architect.request.RequestInfo) Collection(java.util.Collection) PageItems(com.liferay.apio.architect.pagination.PageItems) Path(com.liferay.apio.architect.uri.Path) Operation(com.liferay.apio.architect.operation.Operation) PageMessageMapper(com.liferay.apio.architect.message.json.PageMessageMapper) List(java.util.List) PageWriter(com.liferay.apio.architect.writer.PageWriter) HttpHeaders(javax.ws.rs.core.HttpHeaders) Pagination(com.liferay.apio.architect.pagination.Pagination) Gson(com.google.gson.Gson) RootModel(com.liferay.apio.architect.test.util.model.RootModel) Page(com.liferay.apio.architect.pagination.Page) POST(com.liferay.apio.architect.operation.Method.POST) Optional(java.util.Optional) MockWriterUtil.getRequestInfo(com.liferay.apio.architect.test.util.writer.MockWriterUtil.getRequestInfo) Collections(java.util.Collections) RootModel(com.liferay.apio.architect.test.util.model.RootModel) Gson(com.google.gson.Gson) Page(com.liferay.apio.architect.pagination.Page) Operation(com.liferay.apio.architect.operation.Operation) RequestInfo(com.liferay.apio.architect.request.RequestInfo) MockWriterUtil.getRequestInfo(com.liferay.apio.architect.test.util.writer.MockWriterUtil.getRequestInfo) Pagination(com.liferay.apio.architect.pagination.Pagination) PageItems(com.liferay.apio.architect.pagination.PageItems)

Aggregations

PageItems (com.liferay.apio.architect.pagination.PageItems)3 Page (com.liferay.apio.architect.pagination.Page)2 Pagination (com.liferay.apio.architect.pagination.Pagination)2 Gson (com.google.gson.Gson)1 JsonObject (com.google.gson.JsonObject)1 PageMessageMapper (com.liferay.apio.architect.message.json.PageMessageMapper)1 POST (com.liferay.apio.architect.operation.Method.POST)1 Operation (com.liferay.apio.architect.operation.Operation)1 RequestInfo (com.liferay.apio.architect.request.RequestInfo)1 MockFormCreator.createForm (com.liferay.apio.architect.test.util.form.MockFormCreator.createForm)1 RootModel (com.liferay.apio.architect.test.util.model.RootModel)1 MockWriterUtil.getRequestInfo (com.liferay.apio.architect.test.util.writer.MockWriterUtil.getRequestInfo)1 Path (com.liferay.apio.architect.uri.Path)1 PageWriter (com.liferay.apio.architect.writer.PageWriter)1 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)1 Folder (com.liferay.portal.kernel.repository.model.Folder)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1