List of usage examples for org.springframework.data.domain Page forEach
default void forEach(Consumer<? super T> action)
From source file:edu.cmu.cs.lti.discoursedb.api.browsing.controller.BrowsingRestController.java
@RequestMapping(value = { "/database/{databaseName}/discourses/{discourseId}/discoursePartTypes/{discoursePartType}", "/discourses/{discourseId}/discoursePartTypes" }, method = RequestMethod.GET) @ResponseBody//from w w w . ja v a 2 s. c o m PagedResources<Resource<BrowsingDiscoursePartResource>> discoursePartsByTypeAndDiscourse( @RequestParam(value = "page", defaultValue = "0") int page, @RequestParam(value = "size", defaultValue = "20") int size, @PathVariable("databaseName") String databaseName, @PathVariable("discourseId") Long discourseId, @PathVariable("discoursePartType") Optional<String> discoursePartType, @RequestParam(value = "annoType", defaultValue = "*") String annoType, HttpServletRequest hsr, HttpSession session) { registerDb(hsr, session, databaseName); PageRequest p = new PageRequest(page, size); Page<BrowsingDiscoursePartResource> repoResources = null; if (!discoursePartType.isPresent()) { repoResources = discoursePartRepository.findAllByDiscourse(discourseId, p) .map(dp -> new BrowsingDiscoursePartResource(dp, annoService)).map(bdpr -> { bdpr.filterAnnotations(annoType); bdpr.fillInUserInteractions(discoursePartInteractionRepository, annoService); return bdpr; }); } else { repoResources = discoursePartRepository .findAllByDiscourseAndType(discoursePartType.get(), discourseId, p) .map(dp -> new BrowsingDiscoursePartResource(dp, annoService)).map(bdpr -> { bdpr.filterAnnotations(annoType); bdpr.fillInUserInteractions(discoursePartInteractionRepository, annoService); return bdpr; }); } repoResources.forEach(bcr -> { if (bcr.getContainingDiscourseParts().size() > 1) { bcr._getContainingDiscourseParts().forEach((dpId, dpname) -> { bcr.add(makeLink("/browsing/database/" + databaseName + "/usersInDiscourseParts/" + dpId, "users in " + dpname)); bcr.add(makeLink("/browsing/database/" + databaseName + "/subDiscourseParts/" + dpId, dpname)); }); } //Link check = makeLink1Arg("/browsing/action/exportLightside","chk:Export to Lightside: no annotations", "parentDpId", Long.toString(bcr._getDpId())); //Link check2 = makeLink2Arg("/browsing/action/exportLightside","chk:Export to Lightside: with annotations", "withAnnotations", "true", "parentDpId", Long.toString(bcr._getDpId())); Link check = makeLightsideExportNameLink( "/browsing/action/database/" + databaseName + "/exportLightside", false, "chk:Export to Lightside, no annotations", bcr.getName(), Long.toString(bcr._getDpId())); Link check2 = makeLightsideExportNameLink( "/browsing/action/database/" + databaseName + "/exportLightside", true, "chk:Export to Lightside, with annotations", bcr.getName(), Long.toString(bcr._getDpId())); bcr.add(check); bcr.add(check2); Link check3 = makeBratExportNameLink("/browsing/action/database/" + databaseName + "/exportBratItem", "chk:Export to BRAT", bcr.getName(), Long.toString(bcr._getDpId())); bcr.add(check3); }); PagedResources<Resource<BrowsingDiscoursePartResource>> response = praDiscoursePartAssembler .toResource(repoResources); return response; }
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 w w w. j a v a2 s . co 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.eclipse.hawkbit.repository.jpa.JpaRolloutManagement.java
private void createAssignmentOfTargetsToGroup(final Page<Target> targets, final RolloutGroup group) { targets.forEach(target -> rolloutTargetGroupRepository.save(new RolloutTargetGroup(group, target))); }
From source file:org.egov.tl.service.TradeLicenseService.java
@ReadOnly public Page<SearchForm> searchTradeLicense(final SearchForm searchForm) { Pageable pageable = new PageRequest(searchForm.pageNumber(), searchForm.pageSize(), searchForm.orderDir(), searchForm.orderBy());/*from w ww. j a v a2s .c om*/ User currentUser = securityUtils.getCurrentUser(); Page<TradeLicense> licenses = searchTradeRepository.findAll(SearchTradeSpec.searchTrade(searchForm), pageable); List<SearchForm> searchResults = new ArrayList<>(); licenses.forEach(license -> searchResults.add(new SearchForm(license, currentUser, getOwnerName(license), licenseConfigurationService.getFeeCollectorRoles()))); return new PageImpl<>(searchResults, pageable, licenses.getTotalElements()); }