Esempio n. 1
0
 @RequestMapping(value = "search", method = RequestMethod.GET)
 @ResponseBody
 public String search(
     @RequestParam("recipientType") String recipientType,
     @RequestParam(required = false) Long recipientId,
     PageParam pageParam) {
   Pageable pageable = pageParam.getPageable(Share.class);
   Page<Share> page = null;
   if (recipientId == null) {
     page = shareService2.findAll(currentUserId(), recipientType, pageable);
   } else {
     page = shareService2.findAll(currentUserId(), recipientType, recipientId, pageable);
   }
   return Gsons.filterByFields(ShareDto.Brief.class, pageParam.getFields())
       .toJson(PageDto.of(page, ShareDto.toBrief));
 }
Esempio n. 2
0
 @RequestMapping(method = RequestMethod.GET)
 @ResponseBody
 public String page(@RequestParam(required = false) String q, PageParam pageParam) {
   List<SearchFilter> filters =
       StringUtils.isEmpty(q) ? new ArrayList<SearchFilter>() : SearchFilter.parseQuery(q);
   filters.add(new SearchFilter("creator.id", Operator.EQ, currentUserId()));
   filters.add(new SearchFilter("status", Operator.EQ, Share.Status.CREATED));
   Page<Share> page = shareService2.findAll(filters, pageParam.getPageable(Share.class));
   return Gsons.filterByFields(ShareDto.Brief.class, pageParam.getFields())
       .toJson(PageDto.of(page, ShareDto.toBrief));
 }
Esempio n. 3
0
  @RequestMapping(method = RequestMethod.POST)
  @ResponseBody
  public String create(@Valid CreateRequest createRequest) {
    File file = fileService.find(createRequest.fileId);
    if (file == null) {
      throw new RestException(ErrorCode.FILE_NOT_FOUND);
    }
    // 判断操作人员是否有权限
    if (!file.getOwner().getId().equals(currentUserId())) {
      throw new RestException(ErrorCode.FORBIDDEN);
    }
    // 执行分享操作
    List<ShareRecipient> recipients = Lists.newArrayList();
    for (String recipient : createRequest.recipients) {
      ShareRecipient tmp = ShareDto.dtoToRecipient.apply(recipient);
      if (tmp != null) {
        recipients.add(tmp);
      }
    }
    Share share =
        shareService2.createShare(
            currentUser(), file, recipients, createRequest.shareHeadVersion, createRequest.message);

    // 推送消息
    String message =
        new StringBuilder()
            .append(getUserPrincipal().getUserName())
            .append("给您分享了文件")
            .append(file.getIsDir() ? "夹:" : ":")
            .append(file.getName())
            .toString();
    for (ReceivedShare receivedShare : receivedShareService.findAll(share)) {
      try {
        sendNotif(
            new Notification(
                NotifType.SHARE_CREATE,
                message,
                ReceivedShareDto.toNotify.apply(receivedShare),
                ImmutableList.<Long>of(receivedShare.getRecipient().getId())));
      } catch (Exception e) {
        _logger.error(null, e);
      }
    }
    return gson().toJson(ShareDto.toBrief.apply(share));
  }