Search in sources :

Example 1 with CreateChat

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

the class Mailbox method createChat.

public Chat createChat(OperationContext octxt, ParsedMessage pm, int folderId, int flags, String[] tags) throws IOException, ServiceException {
    if (pm == null) {
        throw ServiceException.INVALID_REQUEST("null ParsedMessage when adding chat to 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();
    CreateChat redoRecorder = new CreateChat(mId, digest, size, folderId, flags, tags);
    boolean success = false;
    try {
        beginTransaction("createChat", octxt, redoRecorder);
        Tag.NormalizedTags ntags = new Tag.NormalizedTags(this, tags);
        CreateChat redoPlayer = (octxt == null ? null : (CreateChat) octxt.getPlayer());
        redoRecorder.setMessageBodyInfo(new ParsedMessageDataSource(pm), size);
        int itemId = getNextItemId(redoPlayer == null ? ID_AUTO_INCREMENT : redoPlayer.getMessageId());
        Chat chat = Chat.create(itemId, getFolderById(folderId), pm, staged, false, flags, ntags);
        redoRecorder.setMessageId(chat.getId());
        MailboxBlob mblob = sm.link(staged, this, itemId, getOperationChangeID());
        markOtherItemDirty(mblob);
        // when we created the Chat, we used the staged locator/size/digest;
        // make sure that data actually matches the final blob in the store
        chat.updateBlobData(mblob);
        index.add(chat);
        success = true;
        return chat;
    } finally {
        endTransaction(success);
        sm.quietDelete(staged);
    }
}
Also used : StagedBlob(com.zimbra.cs.store.StagedBlob) NormalizedTags(com.zimbra.cs.mailbox.Tag.NormalizedTags) MailboxBlob(com.zimbra.cs.store.MailboxBlob) Rfc822ValidationInputStream(com.zimbra.common.mime.Rfc822ValidationInputStream) CopyInputStream(com.zimbra.common.util.CopyInputStream) InputStream(java.io.InputStream) 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) ParsedMessageDataSource(com.zimbra.cs.mime.ParsedMessageDataSource) CreateChat(com.zimbra.cs.redolog.op.CreateChat) NormalizedTags(com.zimbra.cs.mailbox.Tag.NormalizedTags) SaveChat(com.zimbra.cs.redolog.op.SaveChat) CreateChat(com.zimbra.cs.redolog.op.CreateChat) AlterItemTag(com.zimbra.cs.redolog.op.AlterItemTag) CreateTag(com.zimbra.cs.redolog.op.CreateTag) DbTag(com.zimbra.cs.db.DbTag)

Aggregations

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