Search in sources :

Example 1 with SaveChat

use of com.zimbra.cs.redolog.op.SaveChat in project zm-mailbox by Zimbra.

the class Mailbox method updateChat.

public Chat updateChat(OperationContext octxt, ParsedMessage pm, int id) throws IOException, ServiceException {
    if (pm == null) {
        throw ServiceException.INVALID_REQUEST("null ParsedMessage when updating chat " + id + " in mailbox " + mId, null);
    }
    // write the chat content directly to the mailbox's blob staging area
    StoreManager sm = StoreManager.getInstance();
    StagedBlob staged;
    InputStream is = pm.getRawInputStream();
    try {
        staged = sm.stage(is, this);
    } finally {
        ByteUtil.closeStream(is);
    }
    String digest = staged.getDigest();
    int size = (int) staged.getSize();
    SaveChat redoRecorder = new SaveChat(mId, id, digest, size, -1, 0, null);
    boolean success = false;
    try {
        beginTransaction("saveChat", octxt, redoRecorder);
        SaveChat redoPlayer = (SaveChat) currentChange().getRedoPlayer();
        redoRecorder.setMessageBodyInfo(new ParsedMessageDataSource(pm), size);
        Chat chat = (Chat) getItemById(id, MailItem.Type.CHAT);
        if (!chat.isMutable()) {
            throw MailServiceException.IMMUTABLE_OBJECT(id);
        }
        if (!checkItemChangeID(chat)) {
            throw MailServiceException.MODIFY_CONFLICT();
        }
        // content changed, so we're obliged to change the IMAP uid
        int imapID = getNextItemId(redoPlayer == null ? ID_AUTO_INCREMENT : redoPlayer.getImapId());
        redoRecorder.setImapId(imapID);
        // update the content and increment the revision number
        chat.setContent(staged, pm);
        // NOTE: msg is now uncached (will this cause problems during commit/reindex?)
        index.add(chat);
        success = true;
        return chat;
    } finally {
        endTransaction(success);
        sm.quietDelete(staged);
    }
}
Also used : ParsedMessageDataSource(com.zimbra.cs.mime.ParsedMessageDataSource) StagedBlob(com.zimbra.cs.store.StagedBlob) Rfc822ValidationInputStream(com.zimbra.common.mime.Rfc822ValidationInputStream) CopyInputStream(com.zimbra.common.util.CopyInputStream) InputStream(java.io.InputStream) SaveChat(com.zimbra.cs.redolog.op.SaveChat) CreateChat(com.zimbra.cs.redolog.op.CreateChat) SaveChat(com.zimbra.cs.redolog.op.SaveChat) RefreshMountpoint(com.zimbra.cs.redolog.op.RefreshMountpoint) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) CreateMountpoint(com.zimbra.cs.redolog.op.CreateMountpoint) StoreManager(com.zimbra.cs.store.StoreManager)

Aggregations

Rfc822ValidationInputStream (com.zimbra.common.mime.Rfc822ValidationInputStream)1 CopyInputStream (com.zimbra.common.util.CopyInputStream)1 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)1 ParsedMessageDataSource (com.zimbra.cs.mime.ParsedMessageDataSource)1 CreateChat (com.zimbra.cs.redolog.op.CreateChat)1 CreateMountpoint (com.zimbra.cs.redolog.op.CreateMountpoint)1 RefreshMountpoint (com.zimbra.cs.redolog.op.RefreshMountpoint)1 SaveChat (com.zimbra.cs.redolog.op.SaveChat)1 StagedBlob (com.zimbra.cs.store.StagedBlob)1 StoreManager (com.zimbra.cs.store.StoreManager)1 InputStream (java.io.InputStream)1