List of usage examples for org.springframework.data.domain Page hasContent
boolean hasContent();
From source file:io.springagora.store.rest.controllers.ProductRestController.java
/** * Internal helper method that correctly applies pagination rules for list * operations that support it. It won't throw any error in case of errors * during the parse of the page and size directives. Instead it will always * assume default values.//from www . j a v a2s . c o m * <p> * Once processed, pagination variables are sent to {@code IPaginatedFinder} * implementation received by the method, that can effectivelly fetch the page. * * @param page {@code String}. Current page being requested. * @param size {@code String}. Ammount of elements being fetched. * @param finder {@code IPaginatedFinder}. Finder to be executed. * * @return * A {@code Page} with all results for a given page, in a given range. * If problems ocurred during the conversion of page and size, it will * attempt to fetch the first page, with 10 results. * * @throws EntityNotFoundException * To be compliant with the RESTful API, if no results are found for a * given operation and page, then it will throw this exception that is * correctly converted to an API error by the framework. */ private static Page<Product> handleGeneralPagination(String page, String size, IPaginatedFinder<Product> finder) { // // Page and Size conversion. In case of problems, it won't throw any parse // errors, and will assume default values for both variables. // int pageNumber, sizeNumber; try { pageNumber = Integer.parseInt(page); sizeNumber = Integer.parseInt(size); } catch (NumberFormatException nfExp) { pageNumber = 0; sizeNumber = 10; } // // Invoke the finder callback, passing the correct paging parameters to // it. Following, the results are validated and returned, or the API error // is thrown in case of a null/empty page. // Page<Product> products = finder.executeFind(pageNumber, sizeNumber); if (products != null && products.hasContent()) { return products; } throw new EntityNotFoundException("Sorry, no products found."); }
From source file:net.maritimecloud.identityregistry.services.BaseServiceImpl.java
protected Page<T> filterResult(Page<T> data) { if (data != null && !data.hasContent()) { // If not authorized to see all we clean the object for sensitive data. if (!isAuthorized()) { logger.debug("Clearing Sensitive Fields"); for (T entity : data) { if (!entity.hasSensitiveFields()) { break; }//from w w w . j a v a 2 s .c o m entity.clearSensitiveFields(); } } } return data; }
From source file:com.xpeppers.phonedirectory.services.PhoneDirectoryServiceImpl.java
private Map<String, Object> datatableResponseAttributes(QueryParameters parameters, Page page) { final boolean hasContent = page.hasContent(); Map<String, Object> datatableAttributes = Maps.newHashMap(); datatableAttributes.put("sEcho", parameters.getEcho()); datatableAttributes.put("iTotalRecords", (hasContent) ? page.getTotalElements() : 0L); datatableAttributes.put("iTotalDisplayRecords", (hasContent) ? page.getTotalElements() : 0L); datatableAttributes.put("aaData", page.getContent()); return datatableAttributes; }
From source file:it.f2informatica.pagination.response.DatatablePaginationResponse.java
@Override public <T> Map<String, Object> generateResponseAttributes(QueryParameters queryParameters, Page<T> paginatedQueryResult) { final boolean hasContent = paginatedQueryResult.hasContent(); Map<String, Object> datatableAttributes = Maps.newHashMap(); datatableAttributes.put("sEcho", queryParameters.getEcho()); datatableAttributes.put("iTotalRecords", (hasContent) ? paginatedQueryResult.getTotalElements() : 0L); datatableAttributes.put("iTotalDisplayRecords", (hasContent) ? paginatedQueryResult.getTotalElements() : 0L); datatableAttributes.put("aaData", convertResultAsArray(paginatedQueryResult, queryParameters)); return datatableAttributes; }
From source file:it.f2informatica.pagination.response.DatatablePaginationResponse.java
private <T> Object[] convertResultAsArray(Page<T> paginatedQueryResult, QueryParameters parameters) { return paginatedQueryResult.hasContent() ? Iterables.toArray(transformDataRowOneByOne(parameters, paginatedQueryResult), Object.class) : ArrayUtils.EMPTY_OBJECT_ARRAY; }
From source file:net.maritimecloud.identityregistry.services.OrganizationServiceImpl.java
@Override protected Page<Organization> filterResult(Page<Organization> data) { if (data != null && !data.hasContent() && !accessControlUtil.hasRole("SITE_ADMIN")) { // If not authorized to see all we clean the object for sensitive data. boolean isAuthorized = isAuthorized(); for (Organization org : data) { if (!isAuthorized || !AccessControlUtil.hasAccessToOrg(org.getMrn())) { logger.debug("Clearing Sensitive Fields"); org.clearSensitiveFields(); }/* w w w .j av a 2s. c o m*/ } } return data; }
From source file:io.kahu.hawaii.util.pagination.PageMetadataWriter.java
@Override protected void writeJson(Page<?> page, JSONObject json) throws JSONException { json.put(TOTAL_ELEMENTS, page.getTotalElements()); if (!page.hasContent() && page.getTotalElements() > 0) { json.put(TOO_MANY_ELEMENTS, true); } else {/*from ww w . j a v a 2 s . c o m*/ json.put(SIZE, page.getSize()); json.put(TOTAL_PAGES, page.getTotalPages()); json.put(NUMBER, page.getNumber()); json.put(NUMBER_OF_ELEMENTS, page.getNumberOfElements()); } }
From source file:com.trenako.activities.ActivityStreamImpl.java
@Override public Iterable<Activity> recentActivity(int numberOfItems) { Pageable pageable = new PageRequest(0, numberOfItems, Direction.DESC, "recorded"); Page<Activity> results = repo.findAll(pageable); if (!results.hasContent()) { return Collections.emptyList(); }/*from w w w . j av a 2 s . c o m*/ return results.getContent(); }
From source file:org.openlmis.fulfillment.AuditLogInitializer.java
private void createSnapshots(PagingAndSortingRepository<?, ?> repository) { Pageable pageable = new PageRequest(DEFAULT_PAGE_NUMBER, 2000); while (true) { Page<?> page = repository.findAll(pageable); if (!page.hasContent()) { break; }/* w w w . ja v a 2 s .com*/ page.forEach(this::createSnapshot); pageable = pageable.next(); } }
From source file:org.wallride.web.controller.admin.tag.TagSelect2Controller.java
@RequestMapping(value = "/{language}/tags/select") public @ResponseBody List<DomainObjectSelect2Model> select(@PathVariable String language, @RequestParam(required = false) String keyword) { TagSearchForm form = new TagSearchForm(); form.setKeyword(keyword);//from w w w .j a v a2 s. c o m Page<Tag> tags = tagService.getTags(form.toTagSearchRequest()); List<DomainObjectSelect2Model> results = new ArrayList<>(); if (tags.hasContent()) { for (Tag tag : tags) { DomainObjectSelect2Model model = new DomainObjectSelect2Model(tag.getId(), tag.getName()); results.add(model); } } return results; }