Search in sources :

Example 1 with ModifyContact

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

the class Mailbox method modifyContact.

public void modifyContact(OperationContext octxt, int contactId, ParsedContact pc) throws ServiceException {
    StoreManager sm = StoreManager.getInstance();
    StagedBlob staged = null;
    if (pc.hasAttachment()) {
        // write the contact content directly to the mailbox's blob staging area
        InputStream is = null;
        try {
            staged = sm.stage(is = pc.getContentStream(), pc.getSize(), this);
        } catch (IOException ioe) {
            throw ServiceException.FAILURE("could not save contact blob", ioe);
        } finally {
            ByteUtil.closeStream(is);
        }
    }
    ModifyContact redoRecorder = new ModifyContact(mId, contactId, pc);
    boolean success = false;
    try {
        beginTransaction("modifyContact", octxt, redoRecorder);
        Contact con = getContactById(contactId);
        if (!checkItemChangeID(con)) {
            throw MailServiceException.MODIFY_CONFLICT();
        }
        try {
            // setContent() calls reanalyze(), which also updates the contact fields even when there is no blob
            con.setContent(staged, pc);
        } catch (IOException ioe) {
            throw ServiceException.FAILURE("could not save contact blob", ioe);
        }
        index.add(con);
        success = true;
    } finally {
        endTransaction(success);
        sm.quietDelete(staged);
    }
}
Also used : ModifyContact(com.zimbra.cs.redolog.op.ModifyContact) StagedBlob(com.zimbra.cs.store.StagedBlob) Rfc822ValidationInputStream(com.zimbra.common.mime.Rfc822ValidationInputStream) CopyInputStream(com.zimbra.common.util.CopyInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) StoreManager(com.zimbra.cs.store.StoreManager) ModifyContact(com.zimbra.cs.redolog.op.ModifyContact) ParsedContact(com.zimbra.cs.mime.ParsedContact) CreateContact(com.zimbra.cs.redolog.op.CreateContact)

Aggregations

Rfc822ValidationInputStream (com.zimbra.common.mime.Rfc822ValidationInputStream)1 CopyInputStream (com.zimbra.common.util.CopyInputStream)1 ParsedContact (com.zimbra.cs.mime.ParsedContact)1 CreateContact (com.zimbra.cs.redolog.op.CreateContact)1 ModifyContact (com.zimbra.cs.redolog.op.ModifyContact)1 StagedBlob (com.zimbra.cs.store.StagedBlob)1 StoreManager (com.zimbra.cs.store.StoreManager)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1