Search in sources :

Example 1 with SaveDocument

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

the class Mailbox method createDocument.

public Document createDocument(OperationContext octxt, int folderId, ParsedDocument pd, MailItem.Type type, int flags, MailItem parent, CustomMetadata custom, boolean indexing) throws IOException, ServiceException {
    StoreManager sm = StoreManager.getInstance();
    StagedBlob staged = sm.stage(pd.getBlob(), this);
    SaveDocument redoRecorder = new SaveDocument(mId, pd.getDigest(), pd.getSize(), folderId, flags);
    boolean success = false;
    try {
        long start = System.currentTimeMillis();
        beginTransaction("createDoc", octxt, redoRecorder);
        SaveDocument redoPlayer = (octxt == null ? null : (SaveDocument) octxt.getPlayer());
        int itemId = getNextItemId(redoPlayer == null ? ID_AUTO_INCREMENT : redoPlayer.getMessageId());
        String uuid = redoPlayer == null ? UUIDUtil.generateUUID() : redoPlayer.getUuid();
        Document doc;
        switch(type) {
            case DOCUMENT:
                doc = Document.create(itemId, uuid, getFolderById(folderId), pd.getFilename(), pd.getContentType(), pd, custom, flags, parent);
                break;
            case WIKI:
                doc = WikiItem.create(itemId, uuid, getFolderById(folderId), pd.getFilename(), pd, null);
                break;
            default:
                throw MailServiceException.INVALID_TYPE(type.toString());
        }
        redoRecorder.setMessageId(itemId);
        redoRecorder.setUuid(doc.getUuid());
        redoRecorder.setDocument(pd);
        redoRecorder.setItemType(type);
        redoRecorder.setDescription(pd.getDescription());
        redoRecorder.setFlags(doc.getFlagBitmask());
        // Get the redolog data from the mailbox blob.  This is less than ideal in the
        // HTTP store case because it will result in network access, and possibly an
        // extra write to local disk.  If this becomes a problem, we should update the
        // ParsedDocument constructor to take a DataSource instead of an InputStream.
        MailboxBlob mailboxBlob = doc.setContent(staged, pd);
        redoRecorder.setMessageBodyInfo(new MailboxBlobDataSource(mailboxBlob), mailboxBlob.getSize());
        if (indexing) {
            index.add(doc);
        }
        success = true;
        long elapsed = System.currentTimeMillis() - start;
        ZimbraLog.mailbox.debug("createDocument elapsed=" + elapsed);
        return doc;
    } catch (IOException ioe) {
        throw ServiceException.FAILURE("error writing document blob", ioe);
    } finally {
        endTransaction(success);
        sm.quietDelete(staged);
    }
}
Also used : StagedBlob(com.zimbra.cs.store.StagedBlob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) MailboxBlobDataSource(com.zimbra.cs.store.MailboxBlobDataSource) SaveDocument(com.zimbra.cs.redolog.op.SaveDocument) IOException(java.io.IOException) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) IndexDocument(com.zimbra.cs.index.IndexDocument) SaveDocument(com.zimbra.cs.redolog.op.SaveDocument) 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

IndexDocument (com.zimbra.cs.index.IndexDocument)1 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)1 ParsedDocument (com.zimbra.cs.mime.ParsedDocument)1 CreateMountpoint (com.zimbra.cs.redolog.op.CreateMountpoint)1 RefreshMountpoint (com.zimbra.cs.redolog.op.RefreshMountpoint)1 SaveDocument (com.zimbra.cs.redolog.op.SaveDocument)1 MailboxBlob (com.zimbra.cs.store.MailboxBlob)1 MailboxBlobDataSource (com.zimbra.cs.store.MailboxBlobDataSource)1 StagedBlob (com.zimbra.cs.store.StagedBlob)1 StoreManager (com.zimbra.cs.store.StoreManager)1 IOException (java.io.IOException)1