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