List of usage examples for org.springframework.data.domain Page getSize
int getSize();
From source file:com.yqboots.web.thymeleaf.processor.element.PaginationElementProcessor.java
/** * Gets the link node of the previous page. * * @param page the pagination object * @param contextPath current context path of servlet * @return the node/* www.j a v a2 s . c o m*/ */ private Element getPreviousElement(final Page<?> page, final String contextPath) { final Element result = new Element("li"); String url; if (!page.hasPrevious()) { url = getPagedParams(contextPath, 0, page.getSize()); } else { url = getPagedParams(contextPath, page.getNumber() - 1, page.getSize()); } final Element a = new Element("a"); a.setAttribute("href", url); result.addChild(a); final Element icon = new Element("i"); icon.setAttribute("class", "glyphicon glyphicon-triangle-left"); a.addChild(icon); if (!page.hasPrevious()) { result.setAttribute("class", "disabled"); } return result; }
From source file:org.thingsplode.server.infrastructure.DeviceService.java
@Transactional public void setConfigurationForDevices(List<Configuration> configurations) { int pageIndex = 0; Page<Device> devicePage; do {//from w w w . j a v a 2s . c om devicePage = deviceRepo.findAll(new PageRequest(pageIndex, pageSize)); if (devicePage != null && devicePage.getSize() > 0) { devicePage.getContent().stream().forEach((d) -> { d.getConfiguration().clear(); }); deviceRepo.save(devicePage.getContent()); deviceRepo.flush(); devicePage.getContent().stream().forEach((d) -> { d.getConfiguration().addAll(configurations); }); deviceRepo.save(devicePage.getContent()); } pageIndex += 1; } while (devicePage != null && (!devicePage.isLast() || devicePage.getNumber() > 0)); }
From source file:com.yqboots.web.thymeleaf.processor.element.PaginationElementProcessor.java
/** * Gets the link node of the last page.//from w w w. j a v a2 s . c o m * * @param page the pagination object * @param contextPath current context path of servlet * @return the node */ private Element getLastElement(final Page<?> page, final String contextPath) { final Element result = new Element("li"); final Element a = new Element("a"); a.setAttribute("href", getPagedParams(contextPath, page.getTotalPages() - 1, page.getSize())); result.addChild(a); final Element icon = new Element("i"); icon.setAttribute("class", "glyphicon glyphicon-step-forward"); a.addChild(icon); if (page.isLast()) { result.setAttribute("class", "disabled"); } return result; }
From source file:com.expedia.seiso.web.assembler.ResourceAssembler.java
private PageMetadata toPageMetadata(Page<?> itemPage) { val pageSize = itemPage.getSize(); val pageNumber = itemPage.getNumber(); val totalItems = itemPage.getTotalElements(); return new PageMetadata(pageSize, pageNumber, totalItems); }
From source file:com.yqboots.web.thymeleaf.processor.element.PaginationElementProcessor.java
/** * Gets the link node of the next page.// w ww .j av a 2s . c om * * @param page the pagination object * @param contextPath current context path of servlet * @return the node */ private Element getNextElement(final Page<?> page, final String contextPath) { final Element result = new Element("li"); String url; if (!page.hasNext()) { int pageNumber = page.getTotalPages() - 1; url = getPagedParams(contextPath, pageNumber < 0 ? 0 : pageNumber, page.getSize()); } else { url = getPagedParams(contextPath, page.getNumber() + 1, page.getSize()); } final Element a = new Element("a"); a.setAttribute("href", url); result.addChild(a); final Element icon = new Element("i"); icon.setAttribute("class", "glyphicon glyphicon-triangle-right"); a.addChild(icon); if (!page.hasNext()) { result.setAttribute("class", "disabled"); } return result; }
From source file:midas.service.CustomerDuplicatesService.java
private DomainPage<CustomerDuplicates> mapToCustomerDuplicates(final Page<CustomerJpa> entities) { final List<CustomerDuplicates> domainList = new ArrayList<>(); for (CustomerJpa entity : entities) { CustomerDuplicates domain = mapper.map(entity, CustomerDuplicates.class); domain.setDuplicates(mapEntitiesToDomain(entity.getDuplicates())); domainList.add(domain);//from w w w. java 2s . c om } return new DomainPage<CustomerDuplicates>(entities.getNumber(), entities.getTotalPages(), entities.getSize(), domainList); }
From source file:com.rizki.mufrizal.belajar.spring.data.mongodb.service.impl.CategoryServiceImpl.java
@Override public TreeMap<String, Object> getCategories(Pageable pageable) { Page<Category> categories = categoryRepository.findAll(pageable); List<Category> categorys = new ArrayList<>(); for (Category category : categories) { category.setDepartment(departmentRepository.findOne(category.getDepartmentId())); categorys.add(category);//from ww w . j a v a2s . co m } TreeMap<String, Object> map = new TreeMap<>(); map.put("content", categorys); map.put("last", categories.isLast()); map.put("totalPages", categories.getTotalPages()); map.put("totalElements", categories.getTotalElements()); map.put("size", categories.getSize()); map.put("number", categories.getNumber()); map.put("sort", categories.getSort()); map.put("first", categories.isFirst()); map.put("numberOfElements", categories.getNumberOfElements()); return map; }
From source file:de.hska.ld.content.service.DocumentServiceIntegrationTest.java
@Test public void testGetDocumentTagsPage() { for (int i = 0; i < 21; i++) { tagService.save(newTag());/*from w w w.j a v a 2 s . c o m*/ } Page<Tag> tagPage = tagService.getTagsPage(0, 10, "DESC", "createdAt"); Assert.assertNotNull(tagPage); Assert.assertTrue(tagPage.getTotalElements() > 0); Assert.assertTrue(tagPage.getSize() == 10); Document document = documentService.save(newDocument()); documentService.addTag(document.getId(), tagPage.getContent().get(0).getId()); Page<Tag> documentTagsPage = documentService.getDocumentTagsPage(document.getId(), 0, 10, "DESC", "createdAt"); Assert.assertNotNull(documentTagsPage); Assert.assertTrue(documentTagsPage.getTotalElements() == 1); }
From source file:com.excilys.ebi.bank.web.controller.account.operations.OperationsTableConverter.java
@Override public OperationsTable convert(Page<Operation> source) { /*/* www. j ava 2 s . c o m*/ * For the brave souls who get this far: You are the chosen ones, the * valiant knights of programming who toil away, without rest, fixing * our most awful code. To you, true saviors, kings of men, I say this: * never gonna give you up, never gonna let you down, never gonna run * around and desert you. Never gonna make you cry, never gonna say * goodbye. Never gonna tell a lie and hurt you. */ OperationsTable table = new OperationsTable(); table.setNumber(source.getNumber()); table.setNumberOfElements(source.getNumberOfElements()); table.setSize(source.getSize()); table.setTotalElements(source.getTotalElements()); table.setTotalPages(source.getTotalPages()); table.setHasContent(source.hasContent()); table.setHasNextPage(source.hasNextPage()); table.setHasPreviousPage(source.hasPreviousPage()); table.setFirstPage(source.isFirstPage()); table.setLastPage(source.isLastPage()); table.setStartIndex(source.getTotalElements() > 0 ? source.getSize() * source.getNumber() + 1 : 0); table.setPageIndex(source.getTotalElements() > 0 ? source.getNumber() + 1 : 0); table.setEndIndex(source.getSize() * source.getNumber() + source.getNumberOfElements()); for (Operation operation : source.getContent()) { OperationsLine line = new OperationsLine(); line.setAmount(operation.getAmount()); line.setDate(operation.getDate().toString("MM/dd/yyyy")); line.setName(operation.getName()); line.setStatus(operation.getStatus().getId()); table.getLines().add(line); } for (int i = 0; i < source.getSize() - source.getNumberOfElements(); i++) { table.getEmptyLines().add(StringUtils.EMPTY); } return table; }
From source file:com.yqboots.web.thymeleaf.processor.element.PaginationElementProcessor.java
/** * Adds elements for steps./*ww w . j a v a 2s. c om*/ * * @param page the pagination object * @param contextPath current context path of servlet * @param container the container node of the element */ private void addStepElements(final Page<?> page, final String contextPath, final Element container) { for (int step = 0; step < DEFAULT_STEPS; step++) { // beyond total pages is not allowed if (page.getTotalPages() < step + 1) { continue; } String url; int stepValue; if ((page.getNumber() + DEFAULT_STEPS) <= page.getTotalPages()) { // calculate by page number url = getPagedParams(contextPath, page.getNumber() + step, page.getSize()); stepValue = page.getNumber() + step + 1; } else if (page.getTotalPages() < DEFAULT_STEPS && page.getTotalPages() >= step + 1) { // between step and DEFAULT_STEPS url = getPagedParams(contextPath, step, page.getSize()); stepValue = step + 1; } else { // calculate by totalPages url = getPagedParams(contextPath, page.getTotalPages() - DEFAULT_STEPS + step, page.getSize()); stepValue = page.getTotalPages() - DEFAULT_STEPS + step + 1; } final Element a = new Element("a"); a.setAttribute("href", url); a.addChild(new Text(Integer.toString(stepValue))); final Element li = new Element("li"); li.addChild(a); // set active if (page.getNumber() + 1 == stepValue) { li.setAttribute("class", "active"); } container.addChild(li); } }