Search in sources :

Example 1 with CustomMetadata

use of com.zimbra.cs.mailbox.MailItem.CustomMetadata in project zm-mailbox by Zimbra.

the class SetCustomData method deserializeData.

@Override
protected void deserializeData(RedoLogInput in) throws IOException {
    this.itemId = in.readInt();
    this.type = MailItem.Type.of(in.readByte());
    try {
        String extendedKey = in.readUTF();
        this.custom = new CustomMetadata(extendedKey, in.readUTF());
    } catch (ServiceException e) {
        mLog.warn("could not deserialize custom metadata for folder", e);
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) CustomMetadata(com.zimbra.cs.mailbox.MailItem.CustomMetadata)

Example 2 with CustomMetadata

use of com.zimbra.cs.mailbox.MailItem.CustomMetadata in project zm-mailbox by Zimbra.

the class SetCustomMetadata method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
    Element meta = request.getElement(MailConstants.E_METADATA);
    String section = meta.getAttribute(MailConstants.A_SECTION);
    section = section.trim();
    if (section.length() == 0 || section.length() > 36)
        throw ServiceException.INVALID_REQUEST("invalid length for custom metadata section name", null);
    CustomMetadata custom = new CustomMetadata(section);
    for (Element.KeyValuePair kvp : meta.listKeyValuePairs()) custom.put(kvp.getKey(), kvp.getValue());
    ItemId iid = new ItemId(request.getAttribute(MailConstants.A_ID), zsc);
    mbox.setCustomData(octxt, iid.getId(), MailItem.Type.UNKNOWN, custom);
    Element response = zsc.createElement(MailConstants.SET_METADATA_RESPONSE);
    response.addAttribute(MailConstants.A_ID, ifmt.formatItemId(iid));
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Mailbox(com.zimbra.cs.mailbox.Mailbox) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) ItemId(com.zimbra.cs.service.util.ItemId) CustomMetadata(com.zimbra.cs.mailbox.MailItem.CustomMetadata)

Example 3 with CustomMetadata

use of com.zimbra.cs.mailbox.MailItem.CustomMetadata in project zm-mailbox by Zimbra.

the class CreateFolder method deserializeData.

@Override
protected void deserializeData(RedoLogInput in) throws IOException {
    this.name = in.readUTF();
    this.parentId = in.readInt();
    if (getVersion().atLeast(1, 19)) {
        this.attrs = in.readByte();
    }
    this.defaultView = MailItem.Type.of(in.readByte());
    this.flags = in.readInt();
    if (getVersion().atLeast(1, 27)) {
        this.color = in.readLong();
    } else {
        this.color = in.readByte();
    }
    this.url = in.readUTF();
    this.folderId = in.readInt();
    if (getVersion().atLeast(1, 37)) {
        this.folderUuid = in.readUTF();
    }
    if (getVersion().atLeast(1, 39)) {
        if (in.readBoolean()) {
            if (getVersion().atLeast(1, 40)) {
                this.date = in.readLong();
            } else {
                this.date = ((long) in.readInt()) * 1000;
            }
        }
    }
    if (getVersion().atLeast(1, 41)) {
        String section = in.readUTF();
        if (section != null) {
            try {
                this.custom = new CustomMetadata(section, in.readUTF());
            } catch (ServiceException e) {
                mLog.warn("could not deserialize custom metadata for folder", e);
            }
        }
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) CustomMetadata(com.zimbra.cs.mailbox.MailItem.CustomMetadata)

Example 4 with CustomMetadata

use of com.zimbra.cs.mailbox.MailItem.CustomMetadata in project zm-mailbox by Zimbra.

the class FolderTest method create.

@Test
public void create() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    final String uuid = UUIDUtil.generateUUID();
    final String url = "https://www.google.com/calendar/dav/YOUREMAIL@DOMAIN.COM/user";
    final long date = ((System.currentTimeMillis() - Constants.MILLIS_PER_MONTH) / 1000) * 1000;
    Folder.FolderOptions fopt = new Folder.FolderOptions();
    fopt.setAttributes(Folder.FOLDER_DONT_TRACK_COUNTS);
    fopt.setColor((byte) 3);
    fopt.setCustomMetadata(new CustomMetadata("s", "d1:a1:be"));
    fopt.setDate(date);
    fopt.setDefaultView(MailItem.Type.CONTACT);
    fopt.setFlags(Flag.BITMASK_CHECKED);
    fopt.setUuid(uuid);
    // setting folder sync URL triggers an error in MockProvisioning; comment out for now
    //        fopt.setUrl(url);
    // create the folder and make sure all the options were applied
    Folder folder = mbox.createFolder(null, "test", Mailbox.ID_FOLDER_CONTACTS, fopt);
    Assert.assertEquals("correct name", "test", folder.getName());
    Assert.assertEquals("correct parent", Mailbox.ID_FOLDER_CONTACTS, folder.getFolderId());
    Assert.assertEquals("correct attributes", Folder.FOLDER_DONT_TRACK_COUNTS, folder.getAttributes());
    Assert.assertEquals("correct color", 3, folder.getColor());
    CustomMetadata custom = folder.getCustomData("s");
    Assert.assertNotNull("custom data set", custom);
    Assert.assertEquals("1 entry in custom data", 1, custom.size());
    Assert.assertEquals("correct custom data", "b", custom.get("a"));
    Assert.assertEquals("correct date", date, folder.getDate());
    Assert.assertEquals("correct view", MailItem.Type.CONTACT, folder.getDefaultView());
    Assert.assertEquals("correct flags", Flag.BITMASK_CHECKED, folder.getFlagBitmask());
    Assert.assertEquals("correct uuid", uuid, folder.getUuid());
    //        Assert.assertEquals("correct url", url, folder.getUrl());
    // check again after forcing a reload from disk, just in case
    mbox.purge(MailItem.Type.FOLDER);
    folder = mbox.getFolderById(null, folder.getId());
    Assert.assertEquals("correct name", "test", folder.getName());
    Assert.assertEquals("correct parent", Mailbox.ID_FOLDER_CONTACTS, folder.getFolderId());
    Assert.assertEquals("correct attributes", Folder.FOLDER_DONT_TRACK_COUNTS, folder.getAttributes());
    Assert.assertEquals("correct color", 3, folder.getColor());
    custom = folder.getCustomData("s");
    Assert.assertNotNull("custom data set", custom);
    Assert.assertEquals("1 entry in custom data", 1, custom.size());
    Assert.assertEquals("correct custom data", "b", custom.get("a"));
    Assert.assertEquals("correct date", date, folder.getDate());
    Assert.assertEquals("correct view", MailItem.Type.CONTACT, folder.getDefaultView());
    Assert.assertEquals("correct flags", Flag.BITMASK_CHECKED, folder.getFlagBitmask());
    Assert.assertEquals("correct uuid", uuid, folder.getUuid());
//        Assert.assertEquals("correct url", url, folder.getUrl());
}
Also used : CustomMetadata(com.zimbra.cs.mailbox.MailItem.CustomMetadata) Test(org.junit.Test)

Example 5 with CustomMetadata

use of com.zimbra.cs.mailbox.MailItem.CustomMetadata in project zm-mailbox by Zimbra.

the class CreateMessage method deserializeData.

@Override
protected void deserializeData(RedoLogInput in) throws IOException {
    mRcptEmail = in.readUTF();
    if (getVersion().atLeast(1, 4)) {
        mReceivedDate = in.readLong();
    } else {
        mReceivedDate = getTimestamp();
    }
    mShared = in.readBoolean();
    mDigest = in.readUTF();
    if (getVersion().atLeast(1, 42)) {
        mMsgSize = in.readLong();
    } else {
        mMsgSize = in.readInt();
    }
    mMsgId = in.readInt();
    mFolderId = in.readInt();
    mConvId = in.readInt();
    if (getVersion().atLeast(1, 5)) {
        mConvFirstMsgId = in.readInt();
    }
    if (getVersion().atLeast(1, 32)) {
        int mergeCount = in.readInt();
        mMergedConvIds = new ArrayList<Integer>(mergeCount);
        for (int i = 0; i < mergeCount; i++) {
            mMergedConvIds.add(in.readInt());
        }
    }
    mCalendarItemId = in.readInt();
    if (getVersion().atLeast(1, 1)) {
        mCalendarItemPartStat = in.readUTF();
    }
    mFlags = in.readInt();
    mNoICal = in.readBoolean();
    if (getVersion().atLeast(1, 33)) {
        mTags = in.readUTFArray();
    } else {
        mTagIds = in.readUTF();
    }
    mPath = in.readUTF();
    in.readShort();
    if (getVersion().atLeast(1, 25)) {
        String extendedKey = in.readUTF();
        if (extendedKey != null) {
            try {
                mExtendedData = new CustomMetadata(extendedKey, in.readUTF());
            } catch (ServiceException e) {
                mLog.warn("could not deserialize custom metadata for message", e);
            }
        }
    }
    mMsgBodyType = in.readByte();
    if (mMsgBodyType == MSGBODY_INLINE) {
        int dataLength = in.readInt();
        boolean inMemory = false;
        try {
            inMemory = dataLength <= StoreManager.getDiskStreamingThreshold();
        } catch (ServiceException e) {
        }
        // mData must be the last thing deserialized.  See comments in serializeData()
        if (inMemory) {
            byte[] data = new byte[dataLength];
            in.readFully(data, 0, dataLength);
            mData = new RedoableOpData(data);
        } else {
            long pos = in.getFilePointer();
            mData = new RedoableOpData(new File(in.getPath()), pos, dataLength);
            // Now that we have a stream to the data, skip to the next op.
            int numSkipped = in.skipBytes(dataLength);
            if (numSkipped != dataLength) {
                String msg = String.format("Attempted to skip %d bytes at position %d in %s, but actually skipped %d.", dataLength, pos, in.getPath(), numSkipped);
                throw new IOException(msg);
            }
        }
    // Blob data must be the last thing deserialized.  See comments in
    // serializeData().
    } else {
        in.readShort();
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) IOException(java.io.IOException) File(java.io.File) CustomMetadata(com.zimbra.cs.mailbox.MailItem.CustomMetadata)

Aggregations

CustomMetadata (com.zimbra.cs.mailbox.MailItem.CustomMetadata)8 ServiceException (com.zimbra.common.service.ServiceException)5 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)3 ItemId (com.zimbra.cs.service.util.ItemId)3 Element (com.zimbra.common.soap.Element)2 Mailbox (com.zimbra.cs.mailbox.Mailbox)2 OperationContext (com.zimbra.cs.mailbox.OperationContext)2 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 IOException (java.io.IOException)2 ZFolder (com.zimbra.client.ZFolder)1 ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 DbTag (com.zimbra.cs.db.DbTag)1 ImapMessage (com.zimbra.cs.imap.ImapMessage)1 MailItem (com.zimbra.cs.mailbox.MailItem)1 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)1 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)1 NormalizedTags (com.zimbra.cs.mailbox.Tag.NormalizedTags)1 TypedIdList (com.zimbra.cs.mailbox.util.TypedIdList)1