List of usage examples for org.springframework.data.domain Pageable getPageSize
int getPageSize();
From source file:org.dspace.app.rest.converter.DiscoverFacetResultsConverter.java
private SearchFacetEntryRest convertFacetEntry(final String facetName, final DiscoverResult searchResult, final DiscoveryConfiguration configuration, final Pageable page) { DiscoverySearchFilterFacet field = configuration.getSidebarFacet(facetName); SearchFacetEntryRest facetEntryRest = new SearchFacetEntryRest(facetName); List<DiscoverResult.FacetResult> facetResults = searchResult.getFacetResult(field); if (!facetResults.isEmpty()) { facetEntryRest.setFacetType(facetResults.get(0).getFieldType()); }//from w ww . j a va 2s . c o m facetEntryRest.setFacetLimit(field.getFacetLimit()); //We requested one extra facet value. Check if that value is present to indicate that there are more results facetEntryRest.setHasMore(facetResults.size() > page.getPageSize()); return facetEntryRest; }
From source file:org.dspace.app.rest.model.hateoas.FacetsResource.java
private void embedFacetResults(SearchResultsRest data, Pageable page) { int i = 0;/*from w ww . j a v a 2 s. c om*/ for (SearchFacetEntryRest searchFacetEntryRest : CollectionUtils.emptyIfNull(data.getFacets())) { if (i >= page.getOffset() && i < page.getOffset() + page.getPageSize()) { facetResources.add(new SearchFacetEntryResource(searchFacetEntryRest, data)); } } embedResource("facets", facetResources); }
From source file:org.dspace.app.rest.repository.BrowseEntryLinkRepository.java
public Page<BrowseEntryRest> listBrowseEntries(HttpServletRequest request, String browseName, Pageable pageable, String projection) throws BrowseException, SQLException { // FIXME this should be bind automatically and available as method // argument//from www .j av a 2 s .c o m String scope = null; if (request != null) { scope = request.getParameter("scope"); } Context context = obtainContext(); BrowseEngine be = new BrowseEngine(context); BrowserScope bs = new BrowserScope(context); DSpaceObject scopeObj = null; if (scope != null) { UUID uuid = UUID.fromString(scope); scopeObj = communityService.find(context, uuid); if (scopeObj == null) { scopeObj = collectionService.find(context, uuid); } } // process the input, performing some inline validation final BrowseIndex bi; if (StringUtils.isNotEmpty(browseName)) { bi = BrowseIndex.getBrowseIndex(browseName); } else { bi = null; } if (bi == null) { throw new IllegalArgumentException("Unknown browse index"); } if (!bi.isMetadataIndex()) { throw new IllegalStateException("The requested browse haven't metadata entries"); } // set up a BrowseScope and start loading the values into it bs.setBrowseIndex(bi); Sort sort = null; if (pageable != null) { sort = pageable.getSort(); } if (sort != null) { Iterator<Order> orders = sort.iterator(); while (orders.hasNext()) { bs.setOrder(orders.next().getDirection().name()); } } // bs.setFilterValue(value != null?value:authority); // bs.setFilterValueLang(valueLang); // bs.setJumpToItem(focus); // bs.setJumpToValue(valueFocus); // bs.setJumpToValueLang(valueFocusLang); // bs.setStartsWith(startsWith); if (pageable != null) { bs.setOffset(pageable.getOffset()); bs.setResultsPerPage(pageable.getPageSize()); } // bs.setEtAl(etAl); // bs.setAuthorityValue(authority); if (scopeObj != null) { bs.setBrowseContainer(scopeObj); } BrowseInfo binfo = be.browse(bs); Pageable pageResultInfo = new PageRequest((binfo.getStart() - 1) / binfo.getResultsPerPage(), binfo.getResultsPerPage()); Page<BrowseEntryRest> page = new PageImpl<String[]>(Arrays.asList(binfo.getStringResults()), pageResultInfo, binfo.getTotal()).map(converter); page.forEach(new Consumer<BrowseEntryRest>() { @Override public void accept(BrowseEntryRest t) { t.setBrowseIndex(bixConverter.convert(bi)); } }); return page; }
From source file:org.dspace.app.rest.repository.BrowseItemLinkRepository.java
public Page<ItemRest> listBrowseItems(HttpServletRequest request, String browseName, Pageable pageable, String projection) throws BrowseException, SQLException { //FIXME these should be bind automatically and available as method arguments String scope = null;//from w ww.j a v a 2 s . co m String filterValue = null; String filterAuthority = null; if (request != null) { scope = request.getParameter("scope"); filterValue = request.getParameter("filterValue"); filterAuthority = request.getParameter("filterAuthority"); } Context context = obtainContext(); BrowseEngine be = new BrowseEngine(context); BrowserScope bs = new BrowserScope(context); DSpaceObject scopeObj = null; if (scope != null) { UUID uuid = UUID.fromString(scope); scopeObj = communityService.find(context, uuid); if (scopeObj == null) { scopeObj = collectionService.find(context, uuid); } } // process the input, performing some inline validation BrowseIndex bi = null; if (StringUtils.isNotEmpty(browseName)) { bi = BrowseIndex.getBrowseIndex(browseName); } if (bi == null) { throw new IllegalArgumentException("Unknown browse index"); } if (!bi.isItemIndex() && (filterAuthority == null && filterValue == null)) { throw new IllegalStateException( "The requested browse doesn't provide direct access to items you must specify a filter"); } if (!bi.isMetadataIndex() && (filterAuthority != null || filterValue != null)) { throw new IllegalStateException("The requested browse doesn't support filtering"); } // set up a BrowseScope and start loading the values into it bs.setBrowseIndex(bi); Sort sort = null; if (pageable != null) { sort = pageable.getSort(); } if (sort != null) { Iterator<Order> orders = sort.iterator(); while (orders.hasNext()) { Order order = orders.next(); bs.setOrder(order.getDirection().name()); String sortBy; if (!StringUtils.equals("default", order.getProperty())) { sortBy = order.getProperty(); } else { sortBy = bi.getDefaultOrder(); } try { SortOption so = SortOption.getSortOption(sortBy); if (so != null) { bs.setSortBy(so.getNumber()); } } catch (SortException e) { throw new RuntimeException(e.getMessage(), e); } } } if (filterValue != null || filterAuthority != null) { bs.setFilterValue(filterValue); bs.setAuthorityValue(filterAuthority); bs.setBrowseLevel(1); } // bs.setFilterValueLang(valueLang); // bs.setJumpToItem(focus); // bs.setJumpToValue(valueFocus); // bs.setJumpToValueLang(valueFocusLang); // bs.setStartsWith(startsWith); if (pageable != null) { bs.setOffset(pageable.getOffset()); bs.setResultsPerPage(pageable.getPageSize()); } if (scopeObj != null) { bs.setBrowseContainer(scopeObj); } // For second level browses on metadata indexes, we need to adjust the default sorting if (bi != null && bi.isMetadataIndex() && bs.isSecondLevel() && bs.getSortBy() <= 0) { bs.setSortBy(1); } BrowseInfo binfo = be.browse(bs); Pageable pageResultInfo = new PageRequest((binfo.getStart() - 1) / binfo.getResultsPerPage(), binfo.getResultsPerPage()); Page<ItemRest> page = new PageImpl<Item>(binfo.getBrowseItemResults(), pageResultInfo, binfo.getTotal()) .map(converter); return page; }
From source file:org.dspace.app.rest.repository.CollectionRestRepository.java
@Override public Page<CollectionRest> findAll(Context context, Pageable pageable) { List<Collection> it = null; List<Collection> collections = new ArrayList<Collection>(); int total = 0; try {/*from w ww . jav a2s . com*/ total = cs.countTotal(context); it = cs.findAll(context, pageable.getPageSize(), pageable.getOffset()); for (Collection c : it) { collections.add(c); } } catch (SQLException e) { throw new RuntimeException(e.getMessage(), e); } Page<CollectionRest> page = new PageImpl<Collection>(collections, pageable, total).map(dsoConverter); return page; }
From source file:org.dspace.app.rest.repository.CommunityRestRepository.java
@Override public Page<CommunityRest> findAll(Context context, Pageable pageable) { List<Community> it = null; List<Community> communities = new ArrayList<Community>(); int total = 0; try {// w ww. ja v a 2s . co m total = cs.countTotal(context); it = cs.findAll(context, pageable.getPageSize(), pageable.getOffset()); for (Community c : it) { communities.add(c); } } catch (SQLException e) { throw new RuntimeException(e.getMessage(), e); } Page<CommunityRest> page = new PageImpl<Community>(communities, pageable, total).map(dsoConverter); return page; }
From source file:org.dspace.app.rest.repository.EPersonRestRepository.java
@Override public Page<EPersonRest> findAll(Context context, Pageable pageable) { List<EPerson> epersons = null; int total = 0; try {/*from w ww . j a v a 2 s. c o m*/ if (!authorizeService.isAdmin(context)) { throw new RESTAuthorizationException( "The EPerson collection endpoint is reserved to system administrators"); } total = es.countTotal(context); epersons = es.findAll(context, EPerson.ID, pageable.getPageSize(), pageable.getOffset()); } catch (SQLException e) { throw new RuntimeException(e.getMessage(), e); } Page<EPersonRest> page = new PageImpl<EPerson>(epersons, pageable, total).map(converter); return page; }
From source file:org.dspace.app.rest.repository.EPersonRestRepository.java
/** * Find the epersons matching the query q parameter. The search is delegated to the * {@link EPersonService#search(Context, String, int, int)} method * * @param q//from w w w . j av a 2s . com * is the *required* query string * @param pageable * contains the pagination information * @return a Page of EPersonRest instances matching the user query */ @SearchRestMethod(name = "byName") public Page<EPersonRest> findByName(@Parameter(value = "q", required = true) String q, Pageable pageable) { List<EPerson> epersons = null; int total = 0; try { Context context = obtainContext(); epersons = es.search(context, q, pageable.getOffset(), pageable.getOffset() + pageable.getPageSize()); total = es.searchResultCount(context, q); } catch (SQLException e) { throw new RuntimeException(e.getMessage(), e); } Page<EPersonRest> page = new PageImpl<EPerson>(epersons, pageable, total).map(converter); return page; }
From source file:org.dspace.app.rest.repository.ItemRestRepository.java
@Override @PreAuthorize("hasAuthority('ADMIN')") public Page<ItemRest> findAll(Context context, Pageable pageable) { Iterator<Item> it = null; List<Item> items = new ArrayList<Item>(); int total = 0; try {/*from w w w . j a v a 2s . co m*/ total = is.countTotal(context); it = is.findAll(context, pageable.getPageSize(), pageable.getOffset()); while (it.hasNext()) { Item i = it.next(); items.add(i); } } catch (SQLException e) { throw new RuntimeException(e.getMessage(), e); } Page<ItemRest> page = new PageImpl<Item>(items, pageable, total).map(dsoConverter); return page; }
From source file:org.dspace.app.rest.repository.SubmissionUploadRestRepository.java
@Override public Page<SubmissionUploadRest> findAll(Context context, Pageable pageable) { List<SubmissionConfig> subConfs = new ArrayList<SubmissionConfig>(); subConfs = submissionConfigReader.getAllSubmissionConfigs(pageable.getPageSize(), pageable.getOffset()); List<SubmissionUploadRest> results = new ArrayList<>(); for (SubmissionConfig config : subConfs) { for (int i = 0; i < config.getNumberOfSteps(); i++) { SubmissionStepConfig step = config.getStep(i); if (SubmissionStepConfig.UPLOAD_STEP_NAME.equals(step.getType())) { UploadConfiguration uploadConfig = uploadConfigurationService.getMap().get(step.getId()); if (uploadConfig != null) { try { results.add(convert(context, uploadConfig)); } catch (Exception e) { log.error(e.getMessage(), e); }// w w w . jav a2 s .co m } } } } return new PageImpl<SubmissionUploadRest>(results, pageable, results.size()); }