Package org.jtalks.jcommune.model.entity

Examples of org.jtalks.jcommune.model.entity.PrivateMessage


        verify(pmDao, times(1)).delete(any(PrivateMessage.class));
    }

    @Test(expectedExceptions = NotFoundException.class)
    public void testDeleteNotFound() throws NotFoundException {
        PrivateMessage message1 = new PrivateMessage(user, user, null, null);
        message1.setStatus(PrivateMessageStatus.DRAFT);

        PrivateMessage message2 = new PrivateMessage(user, user, null, null);
        message2.setStatus(PrivateMessageStatus.DRAFT);

        when(pmDao.get(1L)).thenReturn(message1);
        when(pmDao.get(2L)).thenReturn(message2);
        when(pmDao.isExist(1L)).thenReturn(true);
        when(pmDao.isExist(2L)).thenReturn(true);
View Full Code Here


     * {@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;
    }
View Full Code Here

    public void saveDraft(long id, String recipient, String title, String body, JCUser userFrom)
            throws NotFoundException {

        JCUser userTo = recipient != null ? userService.getByUsername(recipient) : null;

        PrivateMessage pm = new PrivateMessage(userTo, userFrom, title, body);
        pm.setId(id);
        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());

    }
View Full Code Here

     */
    @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;
    }
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    @PreAuthorize("hasPermission(#id, 'PRIVATE_MESSAGE', 'GeneralPermission.READ')")
    public PrivateMessage get(Long id) throws NotFoundException {
        PrivateMessage pm = super.get(id);
        if (!hasCurrentUserAccessToPM(pm)) {
            throw new NotFoundException(String.format("current user has no right to read pm %s with id %d",
                    userService.getCurrentUser(), id));
        }
        if (this.ifMessageShouldBeMarkedAsRead(pm)) {
            pm.setRead(true);
            this.getDao().saveOrUpdate(pm);
            userDataCache.decrementNewMessageCountFor(pm.getUserTo().getUsername());
        }
        return pm;
    }
View Full Code Here

        JCUser currentUser = userService.getCurrentUser();

        String result = "inbox";
        for (Long id : ids) {

            PrivateMessage message = this.get(id);

            switch (message.getStatus()) {
                case DRAFT:
                    this.getDao().delete(message);
                    result = "drafts";
                    break;
                case DELETED_FROM_INBOX:
                    this.getDao().delete(message);
                    result = "outbox";
                    break;
                case DELETED_FROM_OUTBOX:
                    this.getDao().delete(message);
                    result = "inbox";
                    break;
                case SENT:
                    if (currentUser.equals(message.getUserFrom())) {
                        message.setStatus(PrivateMessageStatus.DELETED_FROM_OUTBOX);
                        result = "outbox";
                    } else {
                        message.setStatus(PrivateMessageStatus.DELETED_FROM_INBOX);
                        result = "inbox";
                    }
                    break;
                default:
                    break;
View Full Code Here

    private long ID = 1L;
    PrivateMessage pm;
   
    @BeforeMethod
    public void init() {
        pm = new PrivateMessage(user,user, TITLE, BODY);
        pm.setId(ID);
    }
View Full Code Here

        PersistedObjectsFactory.setSession(session);
    }

    @Test
    public void testSave() {
        PrivateMessage pm = getSavedPm();
        assertNotSame(pm.getId(), 0, "Id not created");

        session.evict(pm);
        PrivateMessage result = (PrivateMessage) session.get(PrivateMessage.class, pm.getId());

        assertReflectionEquals(pm, result);
    }
View Full Code Here

        assertReflectionEquals(pm, result);
    }

    @Test(expectedExceptions = DataIntegrityViolationException.class)
    public void testSavePostWithDateNotNullViolation() {
        PrivateMessage pm = new PrivateMessage(author, recipient, "", "");
        dao.saveOrUpdate(pm);
    }
View Full Code Here

        dao.saveOrUpdate(pm);
    }

    @Test
    public void testGet() {
        PrivateMessage pm = getSavedPm();

        PrivateMessage result = dao.get(pm.getId());

        assertNotNull(result);
        assertEquals(result.getId(), pm.getId());
    }
View Full Code Here

TOP

Related Classes of org.jtalks.jcommune.model.entity.PrivateMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.