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);
}
}
Aggregations