Java Code Examples for org.springframework.data.domain.Page#map()
The following examples show how to use
org.springframework.data.domain.Page#map() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemberSignRecordControler.java From ZTuoExchange_framework with MIT License | 6 votes |
@RequiresPermissions("activity:member-sign-record:page-query") @GetMapping("page-query") public MessageResult pageQuery(MemberSignRecordScreen screen, PageModel pageModel) { Page<MemberSignRecord> source = service.findAllScreen(screen, pageModel); Page<MemberSignRecordVO> page = source.map(x -> MemberSignRecordVO.getMemberSignRecordVO(x)); return success(page); }
Example 2
Source File: SheetServiceImpl.java From halo with GNU General Public License v3.0 | 6 votes |
@Override public Page<SheetListVO> convertToListVo(Page<Sheet> sheetPage) { Assert.notNull(sheetPage, "Sheet page must not be null"); // Get all sheet id List<Sheet> sheets = sheetPage.getContent(); Set<Integer> sheetIds = ServiceUtils.fetchProperty(sheets, Sheet::getId); // key: sheet id, value: comment count Map<Integer, Long> sheetCommentCountMap = sheetCommentService.countByPostIds(sheetIds); return sheetPage.map(sheet -> { SheetListVO sheetListVO = new SheetListVO().convertFrom(sheet); sheetListVO.setCommentCount(sheetCommentCountMap.getOrDefault(sheet.getId(), 0L)); sheetListVO.setFullPath(buildFullPath(sheet)); return sheetListVO; }); }
Example 3
Source File: PermissionController.java From ueboot with BSD 3-Clause "New" or "Revised" License | 5 votes |
@RequiresPermissions("ueboot:permission:read") @RequestMapping(value = "/page", method = RequestMethod.POST) public Response<Page<PermissionResp>> page(@PageableDefault(value = 15, sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable, @RequestBody(required = false) PermissionFindReq req) { Page<Permission> entities = permissionService.findBy(pageable); Page<PermissionResp> body = entities.map(entity -> { PermissionResp resp = new PermissionResp(); BeanUtils.copyProperties(entity, resp); return resp; }); return new Response<>(body); }
Example 4
Source File: PhotoServiceImpl.java From halo with GNU General Public License v3.0 | 5 votes |
@Override public Page<PhotoDTO> pageDtosBy(Pageable pageable, PhotoQuery photoQuery) { Assert.notNull(pageable, "Page info must not be null"); // List all Page<Photo> photoPage = photoRepository.findAll(buildSpecByQuery(photoQuery), pageable); // Convert and return return photoPage.map(photo -> new PhotoDTO().convertFrom(photo)); }
Example 5
Source File: TaskDefinitionController.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * Return a page-able list of {@link TaskDefinitionResource} defined tasks. * * @param pageable page-able collection of {@code TaskDefinitionResource} * @param search optional findByTaskNameContains parameter * @param manifest optional manifest flag to indicate whether the latest task execution requires task manifest update * @param assembler assembler for the {@link TaskDefinition} * @return a list of task definitions */ @RequestMapping(value = "", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public PagedModel<TaskDefinitionResource> list(Pageable pageable, @RequestParam(required = false) String search, @RequestParam(required = false) boolean manifest, PagedResourcesAssembler<TaskExecutionAwareTaskDefinition> assembler) { final Page<TaskDefinition> taskDefinitions; if (search != null) { taskDefinitions = repository.findByTaskNameContains(search, pageable); } else { taskDefinitions = repository.findAll(pageable); } final java.util.HashMap<String, TaskDefinition> taskDefinitionMap = new java.util.HashMap<>(); for (TaskDefinition taskDefinition : taskDefinitions) { taskDefinitionMap.put(taskDefinition.getName(), taskDefinition); } final List<TaskExecution> taskExecutions; if (!taskDefinitionMap.isEmpty()) { taskExecutions = this.explorer.getLatestTaskExecutionsByTaskNames( taskDefinitionMap.keySet().toArray(new String[taskDefinitionMap.size()])); } else { taskExecutions = null; } final Page<TaskExecutionAwareTaskDefinition> taskExecutionAwareTaskDefinitions = taskDefinitions .map(new TaskDefinitionConverter(taskExecutions)); PagedModel<TaskDefinitionResource> taskDefinitionResources = assembler.toModel(taskExecutionAwareTaskDefinitions, new Assembler(manifest)); // Classify the composed task elements by iterating through the task definitions that are part of this page. updateComposedTaskElement(taskDefinitionResources.getContent()); return taskDefinitionResources; }
Example 6
Source File: PostController.java From spring-boot-react-blog with Apache License 2.0 | 5 votes |
@GetMapping(value = "/posts") public ResponseEntity<List<PostDto>> getPostList(Pageable pageable) { log.debug("REST request to get Posts : {}", pageable); Page<Post> posts = postService.findAllByOrderByCreatedDateDescPageable(pageable); Page<PostDto> postDto = posts.map(post -> new PostDto((post))); return new ResponseEntity<>(postDto.getContent(), HttpStatus.OK); }
Example 7
Source File: OrganizationController.java From ueboot with BSD 3-Clause "New" or "Revised" License | 5 votes |
@RequiresPermissions("ueboot:organization:read") @RequestMapping(value = "/page", method = RequestMethod.POST) public Response<Page<OrganizationResp>> page(@PageableDefault(value = 15, sort = { "id" }, direction = Sort.Direction.DESC) Pageable pageable, @RequestBody(required = false) OrganizationFindReq req){ Page<Organization> entities = organizationService.findBy(pageable); Page<OrganizationResp> body = entities.map(entity -> { OrganizationResp resp = new OrganizationResp(); BeanUtils.copyProperties(entity, resp); return resp; }); return new Response<>(body); }
Example 8
Source File: UserRoleController.java From ueboot with BSD 3-Clause "New" or "Revised" License | 5 votes |
@RequiresPermissions("ueboot:userRole:read") @PostMapping(value = "/page") public Response<Page<UserRoleResp>> page(@PageableDefault(value = 15, sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable, @RequestBody(required = false) UserRoleFindReq req) { Page<UserRole> entities = userRoleService.findBy(pageable); Page<UserRoleResp> body = entities.map(entity -> { UserRoleResp resp = new UserRoleResp(); BeanUtils.copyProperties(entity, resp); return resp; }); return new Response<>(body); }
Example 9
Source File: RoleController.java From ueboot with BSD 3-Clause "New" or "Revised" License | 5 votes |
@RequiresPermissions("ueboot:role:read") @PostMapping(value = "/page") public Response<Page<RoleResp>> page(@PageableDefault(value = 15, sort = {"id"}, direction = Sort.Direction.ASC) Pageable pageable, @RequestBody(required = false) RoleFindReq req) { Page<Role> entities = roleService.findByName(pageable, req != null ? req.getName() : ""); Page<RoleResp> body = entities.map(entity -> { RoleResp resp = new RoleResp(); BeanUtils.copyProperties(entity, resp); return resp; }); return new Response<>(body); }
Example 10
Source File: WithdrawController.java From ZTuoExchange_framework with MIT License | 5 votes |
/** * 提现地址分页信息 * @param user * @param pageNo * @param pageSize * @param unit * @return */ @RequestMapping("address/page") public MessageResult addressPage(@SessionAttribute(SESSION_MEMBER) AuthMember user, int pageNo, int pageSize, String unit) { Page<MemberAddress> page = memberAddressService.pageQuery(pageNo, pageSize, user.getId(), unit); Page<ScanMemberAddress> scanMemberAddresses = page.map(x -> ScanMemberAddress.toScanMemberAddress(x)); MessageResult result = MessageResult.success(); result.setData(scanMemberAddresses); return result; }
Example 11
Source File: MemberSignRecordControler.java From ZTuoExchange_framework with MIT License | 5 votes |
@RequiresPermissions("activity:member-sign-record:page-query") @GetMapping("page-query") public MessageResult pageQuery(MemberSignRecordScreen screen, PageModel pageModel) { Page<MemberSignRecord> source = service.findAllScreen(screen, pageModel); Page<MemberSignRecordVO> page = source.map(x -> MemberSignRecordVO.getMemberSignRecordVO(x)); return success(page); }
Example 12
Source File: WithdrawController.java From ZTuoExchange_framework with MIT License | 5 votes |
/** * 提币记录 * @param user * @param page * @param pageSize * @return */ @GetMapping("record") public MessageResult pageWithdraw(@SessionAttribute(SESSION_MEMBER) AuthMember user, int page, int pageSize) { MessageResult mr = new MessageResult(0, "success"); Page<WithdrawRecord> records = withdrawApplyService.findAllByMemberId(user.getId(), page, pageSize); records.map(x -> ScanWithdrawRecord.toScanWithdrawRecord(x)); mr.setData(records); return mr; }
Example 13
Source File: WithdrawController.java From ZTuoExchange_framework with MIT License | 5 votes |
/** * 提现地址分页信息 * @param user * @param pageNo * @param pageSize * @param unit * @return */ @RequestMapping("address/page") public MessageResult addressPage(@SessionAttribute(SESSION_MEMBER) AuthMember user, int pageNo, int pageSize, String unit) { Page<MemberAddress> page = memberAddressService.pageQuery(pageNo, pageSize, user.getId(), unit); Page<ScanMemberAddress> scanMemberAddresses = page.map(x -> ScanMemberAddress.toScanMemberAddress(x)); MessageResult result = MessageResult.success(); result.setData(scanMemberAddresses); return result; }
Example 14
Source File: SignController.java From ZTuoExchange_framework with MIT License | 5 votes |
@RequiresPermissions("activity:sign:page-query") @GetMapping("page-query") public MessageResult pageQuery(SignScreen screen, PageModel pageModel) { Page<Sign> source = service.findAllScreen(screen, pageModel); Page<SignVO> page = source.map(x -> SignVO.getSignVO(x)); return success(page); }
Example 15
Source File: PostServiceImpl.java From docs-manage with MIT License | 5 votes |
@Override public Result getPostPage(PostQuery postQuery, Pageable pageable) { Page<Post> postPage; if (StringUtils.isBlank(postQuery.getKeyword())) { postQuery.setKeyword("%%"); } else { postQuery.setKeyword("%" + postQuery.getKeyword() + "%"); } if (StringUtils.isNotBlank(postQuery.getTagName())) { List<Long> postIds = postTagRepository.findAllByTagName(postQuery.getTagName()) .stream().map(PostTag::getPostId).collect(Collectors.toList()); if (ValidateUtils.idValid(postQuery.getCateId())) { postPage = postRepository.findAllByTitleLikeAndCateIdAndIdIsIn(postQuery.getKeyword(), postQuery.getCateId(), postIds, pageable); } else { postPage = postRepository.findAllByTitleLikeAndIdIsIn(postQuery.getKeyword(), postIds, pageable); } } else if (ValidateUtils.idValid(postQuery.getCateId())) { postPage = postRepository.findAllByTitleLikeAndCateId(postQuery.getKeyword(), postQuery.getCateId(), pageable); } else { postPage = postRepository.findAllByTitleLike(postQuery.getKeyword(), pageable); } Page<PostVO> postVOPage = postPage == null ? null : postPage.map(post -> { PostVO postVO = new PostVO(); BeanUtils.copyProperties(post, postVO); postVO.setId(post.getId()); postVO.setCreateAt(post.getCreatedAt()); postVO.setLastModifiedAt(post.getLastModifiedAt()); postVO.setTags(postTagRepository.findAllByPostId(post.getId()).stream().map(PostTag::getTagName).collect(Collectors.toList())); return postVO; }); return Result.ok(postVOPage); }
Example 16
Source File: BaseCommentServiceImpl.java From halo with GNU General Public License v3.0 | 4 votes |
@Override public Page<BaseCommentWithParentVO> pageWithParentVoBy(Integer postId, Pageable pageable) { Assert.notNull(postId, "Post id must not be null"); Assert.notNull(pageable, "Page info must not be null"); log.debug("Getting comment list view of post: [{}], page info: [{}]", postId, pageable); // List all the top comments (Caution: This list will be cleared) Page<COMMENT> commentPage = baseCommentRepository.findAllByPostIdAndStatus(postId, CommentStatus.PUBLISHED, pageable); // Get all comments List<COMMENT> comments = commentPage.getContent(); // Get all comment parent ids Set<Long> parentIds = ServiceUtils.fetchProperty(comments, COMMENT::getParentId); // Get all parent comments List<COMMENT> parentComments = baseCommentRepository.findAllByIdIn(parentIds, pageable.getSort()); // Convert to comment map (Key: comment id, value: comment) Map<Long, COMMENT> parentCommentMap = ServiceUtils.convertToMap(parentComments, COMMENT::getId); Map<Long, BaseCommentWithParentVO> parentCommentVoMap = new HashMap<>(parentCommentMap.size()); // Convert to comment page return commentPage.map(comment -> { // Convert to with parent vo BaseCommentWithParentVO commentWithParentVO = new BaseCommentWithParentVO().convertFrom(comment); // Get parent comment vo from cache BaseCommentWithParentVO parentCommentVo = parentCommentVoMap.get(comment.getParentId()); if (parentCommentVo == null) { // Get parent comment COMMENT parentComment = parentCommentMap.get(comment.getParentId()); if (parentComment != null) { // Convert to parent comment vo parentCommentVo = new BaseCommentWithParentVO().convertFrom(parentComment); // Cache the parent comment vo parentCommentVoMap.put(parentComment.getId(), parentCommentVo); } } // Set parent commentWithParentVO.setParent(parentCommentVo == null ? null : parentCommentVo.clone()); return commentWithParentVO; }); }
Example 17
Source File: PostServiceImpl.java From halo with GNU General Public License v3.0 | 4 votes |
@Override public Page<PostDetailVO> convertToDetailVo(Page<Post> postPage) { Assert.notNull(postPage, "Post page must not be null"); return postPage.map(this::convertToDetailVo); }
Example 18
Source File: BasePostServiceImpl.java From halo with GNU General Public License v3.0 | 4 votes |
@Override public Page<BasePostMinimalDTO> convertToMinimal(Page<POST> postPage) { Assert.notNull(postPage, "Post page must not be null"); return postPage.map(this::convertToMinimal); }
Example 19
Source File: AdvertiseService.java From ZTuoExchange_framework with MIT License | 4 votes |
public Page<ScanAdvertise> paginationQuery(int pageNo, int pageSize, String country, String payMode, AdvertiseType advertiseType, Currency currency) { Sort.Order order1 = new Sort.Order(Sort.Direction.ASC, "price"); Sort.Order order2 = new Sort.Order(Sort.Direction.DESC, "id"); Sort sort = new Sort(order1, order2); PageRequest pageRequest = new PageRequest(pageNo, pageSize, sort); Specification<Advertise> specification = (root, criteriaQuery, criteriaBuilder) -> { Path<String> country1 = root.get("country"); Path<String> payMode1 = root.get("payMode"); Path<AdvertiseType> advertiseType1 = root.get("advertiseType"); Path<Long> currency1 = root.get("coin").get("id"); Path<CommonStatus> status1 = root.get("status"); Predicate predicate1 = criteriaBuilder.like(payMode1, "%" + payMode + "%"); Predicate predicate2 = criteriaBuilder.equal(country1, country); Predicate predicate3 = criteriaBuilder.equal(advertiseType1, advertiseType); Predicate predicate4 = criteriaBuilder.equal(currency1, currency); Predicate predicate5 = criteriaBuilder.equal(status1, CommonStatus.NORMAL); if (country == null && payMode == null) { return criteriaBuilder.and(predicate3, predicate4, predicate5); } else if (country != null && payMode == null) { return criteriaBuilder.and(predicate2, predicate3, predicate4, predicate5); } else if (country == null && payMode != null) { return criteriaBuilder.and(predicate1, predicate3, predicate4, predicate5); } else { return criteriaBuilder.and(predicate1, predicate2, predicate3, predicate4, predicate5); } }; Page<Advertise> page = advertiseDao.findAll(specification, pageRequest); //todo:得到市场价 BigDecimal markerprice = BigDecimal.TEN; Page<ScanAdvertise> page1 = page.map((Advertise advertise) -> { Member member = advertise.getMember(); return ScanAdvertise.builder() .advertiseId(advertise.getId()) .coinId(advertise.getCoin().getId()) .coinName(advertise.getCoin().getName()) .coinNameCn(advertise.getCoin().getNameCn()) .createTime(advertise.getCreateTime()) .maxLimit(advertise.getMaxLimit()) .minLimit(advertise.getMinLimit()) .memberName(member.getUsername()) .payMode(advertise.getPayMode()) .unit(advertise.getCoin().getUnit()) .remainAmount(advertise.getRemainAmount()) .transactions(member.getTransactions()) .price(advertise.getPriceType().equals(PriceType.REGULAR) ? advertise.getPrice() : markerprice.multiply(advertise.getPremiseRate().divide(new BigDecimal(100)).add(BigDecimal.ONE))) .build(); }); return page1; }
Example 20
Source File: BasePostServiceImpl.java From halo with GNU General Public License v3.0 | 4 votes |
@Override public Page<BasePostSimpleDTO> convertToSimple(Page<POST> postPage) { Assert.notNull(postPage, "Post page must not be null"); return postPage.map(this::convertToSimple); }