static List<UberData> extractLinksAndContent(PagedResources<?> resources) { List<UberData> collectionOfResources = extractLinksAndContent((Resources<?>) resources); if (resources.getMetadata() != null ) { collectionOfResources.add(new UberData() .withName("page") .withData(Arrays.asList( new UberData() .withName("number") .withValue(resources.getMetadata().getNumber()), new UberData() .withName("size") .withValue(resources.getMetadata().getSize()), new UberData() .withName("totalElements") .withValue(resources.getMetadata().getTotalElements()), new UberData() .withName("totalPages") .withValue(resources.getMetadata().getTotalPages())))); } return collectionOfResources; }
final int currentPage = (int) resources.getMetadata().getNumber(); final int totalPages = (int) resources.getMetadata().getTotalPages();
public ExtendedPageMetadata toExtendedPageMetadata(long skipCount, PagedResources.PageMetadata basePageMetadata) { long totalPages = basePageMetadata.getTotalPages(); int skipCountRemainder = Math.toIntExact(skipCount % basePageMetadata.getSize()); if (skipCountRemainder != 0) { // exclude the first page, which has a different size than other pages int firstPageSize = skipCountRemainder; long totalElementsNotInTheFirstPage = basePageMetadata.getTotalElements() - firstPageSize; // then calculate the number of pages other than the first one and increment it by one (the first page) totalPages = new PagedResources.PageMetadata(basePageMetadata.getSize(), basePageMetadata.getNumber(), totalElementsNotInTheFirstPage).getTotalPages() + 1; } return new ExtendedPageMetadata(skipCount, basePageMetadata.getSize(), basePageMetadata.getNumber(), basePageMetadata.getTotalElements(), totalPages ); }
public AlfrescoPageMetadata toAlfrescoPageMetadata(PagedResources.PageMetadata basePageMetadata, long count) { long skipCount = basePageMetadata.getNumber() * basePageMetadata.getSize(); if (basePageMetadata instanceof ExtendedPageMetadata) { skipCount = ((ExtendedPageMetadata) basePageMetadata).getSkipCount(); } // the page number starts from zero, so it's necessary to increment by one before comparing with total pages return new AlfrescoPageMetadata(skipCount, basePageMetadata.getSize(), count, basePageMetadata.getTotalPages() > basePageMetadata.getNumber() + 1, basePageMetadata.getTotalElements()); } }