List of usage examples for org.springframework.data.domain Page map
<U> Page<U> map(Function<? super T, ? extends U> converter);
From source file:com.accenture.banking.resource.OfficeController.java
/** * This method returns all paged Offices * /* ww w . j a v a 2 s . co m*/ * @return Page<Office> */ // http://localhost:8081/offices/?page=2&size=1&sort=id @RequestMapping(value = "/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) Page<OfficeDto> list(Pageable pageable) { Page<Office> offices = officeService.listAllByPage(pageable); Page<OfficeDto> dtoPage = offices.map(new Converter<Office, OfficeDto>() { public OfficeDto convert(Office office) { OfficeDto dto = dtoBuilder.buildOfficeDto(office); return dto; } }); return dtoPage; }
From source file:com.netflix.genie.core.jpa.services.JpaApplicationServiceImpl.java
/** * {@inheritDoc}// w w w . ja va2s . c o m */ @Override @Transactional(readOnly = true) public Page<Application> getApplications(final String name, final String user, final Set<ApplicationStatus> statuses, final Set<String> tags, final String type, final Pageable page) { log.debug("Called"); @SuppressWarnings("unchecked") final Page<ApplicationEntity> applicationEntities = this.applicationRepo .findAll(JpaApplicationSpecs.find(name, user, statuses, tags, type), page); return applicationEntities.map(ApplicationEntity::getDTO); }
From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImpl.java
/** * {@inheritDoc}/*from www. j a v a 2 s . com*/ */ @Override @Transactional(readOnly = true) public Page<Command> getCommands(final String name, final String user, final Set<CommandStatus> statuses, final Set<String> tags, final Pageable page) { log.debug("Called"); @SuppressWarnings("unchecked") final Page<CommandEntity> commandEntities = this.commandRepo .findAll(JpaCommandSpecs.find(name, user, statuses, tags), page); return commandEntities.map(CommandEntity::getDTO); }
From source file:com.netflix.genie.core.jpa.services.JpaClusterServiceImpl.java
/** * {@inheritDoc}//ww w.j a v a2 s . c o m */ @Override @Transactional(readOnly = true) public Page<Cluster> getClusters(final String name, final Set<ClusterStatus> statuses, final Set<String> tags, final Date minUpdateTime, final Date maxUpdateTime, final Pageable page) { log.debug("called"); @SuppressWarnings("unchecked") final Page<ClusterEntity> clusterEntities = this.clusterRepo .findAll(JpaClusterSpecs.find(name, statuses, tags, minUpdateTime, maxUpdateTime), page); return clusterEntities.map(ClusterEntity::getDTO); }
From source file:com.example.ekanban.service.ProductService.java
public Page<ProductDto> findPageBySubCategory(SubCategory subCategory, Pageable pageable) { logger.debug("findPageBySubCategory()"); Page<Product> page = productRepository.findBySubCategory(subCategory, pageable); page.forEach(p -> {//from w w w .jav a2 s . co m Hibernate.initialize(p.getSectionList()); Hibernate.initialize(p.getSupplierList()); }); return page.map(converter); }
From source file:com.thinkbiganalytics.feedmgr.service.feed.DefaultFeedManagerFeedService.java
public Page<FeedSummary> getFeedSummaryData(Pageable pageable, String filter) { return metadataAccess.read(() -> { this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_FEEDS); Page<Feed> domainFeeds = feedProvider.findPage(pageable, filter); return domainFeeds.map(d -> feedModelTransform.domainToFeedSummary(d)); });//ww w . ja v a 2 s.c o m }
From source file:com.thinkbiganalytics.feedmgr.service.feed.DefaultFeedManagerFeedService.java
public Page<FeedMetadata> getFeeds(Pageable pageable, String filter) { return metadataAccess.read(() -> { this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_FEEDS); Page<Feed> domainFeeds = feedProvider.findPage(pageable, filter); return domainFeeds.map(d -> feedModelTransform.domainToFeedMetadata(d)); });// w w w. j ava 2 s .com }
From source file:org.dspace.app.rest.RestResourceController.java
private <ID extends Serializable> ResourceSupport findRelInternal(HttpServletRequest request, String apiCategory, String model, ID uuid, String rel, Pageable page, PagedResourcesAssembler assembler, String projection) {/*from www .jav a 2 s .c om*/ checkModelPluralForm(apiCategory, model); DSpaceRestRepository<RestModel, ID> repository = utils.getResourceRepository(apiCategory, model); Class<RestModel> domainClass = repository.getDomainClass(); LinkRest linkRest = utils.getLinkRest(rel, domainClass); if (linkRest != null) { LinkRestRepository linkRepository = utils.getLinkResourceRepository(apiCategory, model, linkRest.name()); Method linkMethod = repositoryUtils.getLinkMethod(linkRest.method(), linkRepository); if (linkMethod == null) { // TODO custom exception throw new RuntimeException( "Method for relation " + rel + " not found: " + linkRest.name() + ":" + linkRest.method()); } else { try { Page<? extends Serializable> pageResult = (Page<? extends RestModel>) linkMethod .invoke(linkRepository, request, uuid, page, projection); Link link = linkTo(this.getClass(), apiCategory, English.plural(model)).slash(uuid).slash(rel) .withSelfRel(); PagedResources<? extends ResourceSupport> result = assembler .toResource(pageResult.map(linkRepository::wrapResource), link); return result; } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException(e.getMessage(), e); } } } RestModel modelObject = repository.findOne(uuid); DSpaceResource result = repository.wrapResource(modelObject, rel); if (result.getLink(rel) == null) { // TODO create a custom exception throw new ResourceNotFoundException(rel + "undefined for " + model); } else if (result.getEmbedded().get(rel) instanceof EmbeddedPage) { // this is a very inefficient scenario. We have an embedded list // already fully retrieved that we need to limit with pagination // parameter. BTW change the default sorting is not implemented at // the current stage and could be overcompex to implement // if we really want to implement pagination we should implement a // link repository so to fall in the previous block code EmbeddedPage ep = (EmbeddedPage) result.getEmbedded().get(rel); List<? extends RestModel> fullList = ep.getFullList(); if (fullList == null || fullList.size() == 0) return null; int start = page.getOffset(); int end = (start + page.getPageSize()) > fullList.size() ? fullList.size() : (start + page.getPageSize()); DSpaceRestRepository<RestModel, ?> resourceRepository = utils .getResourceRepository(fullList.get(0).getCategory(), fullList.get(0).getType()); PageImpl<RestModel> pageResult = new PageImpl(fullList.subList(start, end), page, fullList.size()); return assembler.toResource(pageResult.map(resourceRepository::wrapResource)); } else { ResourceSupport resu = (ResourceSupport) result.getEmbedded().get(rel); return resu; } }
From source file:org.jbb.members.impl.base.DefaultMemberService.java
@Override public Page<MemberRegistrationAware> getAllMembersWithCriteria(MemberSearchCriteria criteria) { Validate.notNull(criteria);//from w w w . java 2s . c o m Page<MemberEntity> resultPage = memberRepository.findAll(specificationCreator.createSpecification(criteria), criteria.getPageRequest()); return resultPage.map(memberEntity -> (MemberRegistrationAware) memberEntity); }