/** * Create and persist one single message. * * @param status message status. * @return saved pm. */ public static PrivateMessage createAndSaveMessage(PrivateMessageStatus status, JCUser userTo, JCUser userFrom) { PrivateMessage pm = new PrivateMessage(userTo, userFrom, "Message title", "Private message body"); pm.setStatus(status); persist(pm); return pm; }
"Message title", "Private message body"); if (i % 2 == 0) { pm.setStatus(PrivateMessageStatus.SENT); } else { pm.setStatus(PrivateMessageStatus.NEW); "Message title", "Private message body"); if (i % 2 == 0) { pm.setStatus(PrivateMessageStatus.DELETED_FROM_OUTBOX); } else { pm.setStatus(PrivateMessageStatus.DELETED_FROM_INBOX); PrivateMessage pm = new PrivateMessage(userTo, userFrom, "Message title", "Private message body"); pm.setStatus(PrivateMessageStatus.DRAFT); messages.add(pm); persist(pm);
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#userFrom.id, 'USER', 'ProfilePermission.SEND_PRIVATE_MESSAGES')") public PrivateMessage sendMessage(String title, String body, JCUser recipient, JCUser userFrom) { PrivateMessage pm = new PrivateMessage(recipient, userFrom, title, body); pm.setRead(false); pm.setStatus(PrivateMessageStatus.SENT); this.getDao().saveOrUpdate(pm); userDataCache.incrementNewMessageCountFor(recipient.getUsername()); securityService.createAclBuilder().grant(GeneralPermission.READ).to(recipient).on(pm).flush(); securityService.createAclBuilder().grant(GeneralPermission.READ).to(userFrom).on(pm).flush(); if (isSendNotificationMessage(recipient)) { mailService.sendReceivedPrivateMessageNotification(recipient, pm); } logger.debug("Private message to user {} was sent. Message id={}", recipient.getUsername(), pm.getId()); return pm; }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#userFrom.id, 'USER', 'ProfilePermission.SEND_PRIVATE_MESSAGES')") public void saveDraft(long id, JCUser userTo, String title, String body, JCUser userFrom) { PrivateMessage pm; if (this.getDao().isExist(id)) { pm = this.getDao().get(id); pm.setUserTo(userTo); pm.setTitle(title); pm.setBody(body); } else { pm = new PrivateMessage(userTo, userFrom, title, body); pm.setStatus(PrivateMessageStatus.DRAFT); } this.getDao().saveOrUpdate(pm); JCUser user = userService.getCurrentUser(); securityService.createAclBuilder().grant(GeneralPermission.READ).to(user).on(pm).flush(); securityService.createAclBuilder().grant(GeneralPermission.WRITE).to(user).on(pm).flush(); logger.debug("Updated private message draft. Message id={}", pm.getId()); }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#userFrom.id, 'USER', 'ProfilePermission.SEND_PRIVATE_MESSAGES')") public PrivateMessage sendDraft(long id, String title, String body, JCUser recipient, JCUser userFrom) throws NotFoundException { PrivateMessage pm = new PrivateMessage(recipient, userFrom, title, body); pm.setId(id); pm.setRead(false); pm.setStatus(PrivateMessageStatus.SENT); this.getDao().saveOrUpdate(pm); userDataCache.incrementNewMessageCountFor(recipient.getUsername()); securityService.deleteFromAcl(pm); securityService.createAclBuilder().grant(GeneralPermission.READ).to(recipient).on(pm).flush(); securityService.createAclBuilder().grant(GeneralPermission.READ).to(userFrom).on(pm).flush(); if (isSendNotificationMessage(recipient)) { mailService.sendReceivedPrivateMessageNotification(recipient, pm); } logger.debug("Private message(was draft) to user {} was sent. Message id={}", recipient.getUsername(), pm.getId()); return pm; }