Search in sources :

Example 21 with Metadata

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

the class PendingModifications method getOriginal.

private static Map<ModificationKey, Change> getOriginal(Mailbox mbox, Map<ModificationKeyMeta, ChangeMeta> map) throws ServiceException {
    if (map == null) {
        return null;
    }
    Map<ModificationKey, Change> ret = new LinkedHashMap<ModificationKey, Change>();
    Iterator<Entry<ModificationKeyMeta, ChangeMeta>> iter = map.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<ModificationKeyMeta, ChangeMeta> entry = iter.next();
        ModificationKey key = new ModificationKey(entry.getKey().accountId, entry.getKey().itemId);
        ChangeMeta changeMeta = entry.getValue();
        Object what = null;
        Object preModifyObj = null;
        if (changeMeta.whatType == ChangeMeta.ObjectType.MAILITEM) {
            Metadata meta = new Metadata(changeMeta.metaWhat);
            MailItem.UnderlyingData ud = new MailItem.UnderlyingData();
            ud.deserialize(meta);
            what = MailItem.constructItem(mbox, ud, true);
            if (what instanceof Folder) {
                Folder folder = ((Folder) what);
                folder.setParent(mbox.getFolderById(null, folder.getFolderId()));
            }
        } else if (changeMeta.whatType == ChangeMeta.ObjectType.MAILITEMTYPE) {
            what = MailItem.Type.of(changeMeta.metaWhat);
        } else if (changeMeta.whatType == ChangeMeta.ObjectType.MAILBOX) {
            mbox.refreshMailbox(null);
            what = mbox;
        } else {
            ZimbraLog.session.warn("Unexpected mailbox change type received : " + changeMeta.whatType);
            continue;
        }
        if (changeMeta.preModifyObjType == ChangeMeta.ObjectType.MAILITEM) {
            Metadata meta = new Metadata(changeMeta.metaPreModifyObj);
            MailItem.UnderlyingData ud = new MailItem.UnderlyingData();
            ud.deserialize(meta);
            preModifyObj = MailItem.constructItem(mbox, ud, true);
            if (preModifyObj instanceof Folder) {
                Folder folder = ((Folder) preModifyObj);
                folder.setParent(mbox.getFolderById(null, folder.getFolderId()));
            }
        } else if (changeMeta.preModifyObjType == ChangeMeta.ObjectType.MAILITEMTYPE) {
            preModifyObj = MailItem.Type.of(changeMeta.metaPreModifyObj);
        } else if (changeMeta.whatType == ChangeMeta.ObjectType.MAILBOX) {
            what = mbox;
        } else {
            ZimbraLog.session.warn("Unexpected mailbox change type received : " + changeMeta.whatType);
            continue;
        }
        Change change = new Change(what, changeMeta.metaWhy, preModifyObj);
        ret.put(key, change);
    }
    return ret;
}
Also used : Metadata(com.zimbra.cs.mailbox.Metadata) Folder(com.zimbra.cs.mailbox.Folder) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) MailItem(com.zimbra.cs.mailbox.MailItem)

Example 22 with Metadata

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

the class SetCalendarItem method deserializeData.

@Override
protected void deserializeData(RedoLogInput in) throws IOException {
    mFolderId = in.readInt();
    if (getVersion().atLeast(1, 0)) {
        in.readShort();
    }
    mCalendarItemId = in.readInt();
    if (getVersion().atLeast(1, 1)) {
        mCalendarItemPartStat = in.readUTF();
    }
    if (getVersion().atLeast(1, 2)) {
        mAttachmentIndexingEnabled = in.readBoolean();
    } else {
        mAttachmentIndexingEnabled = false;
    }
    if (getVersion().atLeast(1, 11)) {
        mFlags = in.readInt();
        if (getVersion().atLeast(1, 33)) {
            mTags = in.readUTFArray();
        } else {
            mTagBitmask = in.readLong();
        }
    }
    Invite tzmapInv = null;
    boolean hasDefaultInvite = true;
    if (getVersion().atLeast(1, 17)) {
        hasDefaultInvite = in.readBoolean();
    }
    try {
        if (hasDefaultInvite) {
            mDefaultInvite = deserializeSetCalendarItemData(in, mAttachmentIndexingEnabled);
            tzmapInv = mDefaultInvite.invite;
        }
        int numExceptions = in.readInt();
        if (numExceptions > 0) {
            mExceptions = new Mailbox.SetCalendarItemData[numExceptions];
            for (int i = 0; i < numExceptions; i++) {
                mExceptions[i] = deserializeSetCalendarItemData(in, mAttachmentIndexingEnabled);
                if (tzmapInv == null) {
                    tzmapInv = mExceptions[i].invite;
                }
            }
        }
    } catch (MessagingException ex) {
        ex.printStackTrace();
        throw new IOException("Cannot read serialized entry for SetCalendarItem" + ex.toString());
    }
    if (getVersion().atLeast(1, 15)) {
        int num = in.readInt();
        if (num > 10000 && !getVersion().atLeast(1, 24)) {
            // exception.
            throw new IOException("Replies count > 10000.  Looks like a corrupted pre-v1.24 redo entry.  Skipping");
        }
        if (num < 0) {
            // no replies list
            mReplies = null;
        } else {
            mReplies = new ArrayList<ReplyInfo>(num);
            TimeZoneMap tzMap = tzmapInv.getTimeZoneMap();
            for (int i = 0; i < num; i++) {
                String data = in.readUTF();
                try {
                    Metadata md = new Metadata(data);
                    ReplyInfo reply = ReplyInfo.decodeFromMetadata(md, tzMap);
                    mReplies.add(reply);
                } catch (ServiceException e) {
                    IOException ioe = new IOException("Cannot read serialized entry for ReplyInfo");
                    ioe.initCause(e);
                    throw ioe;
                }
            }
        }
    }
    if (getVersion().atLeast(1, 21)) {
        mNextAlarm = in.readLong();
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) MessagingException(javax.mail.MessagingException) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) Metadata(com.zimbra.cs.mailbox.Metadata) IOException(java.io.IOException) ReplyInfo(com.zimbra.cs.mailbox.CalendarItem.ReplyInfo) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 23 with Metadata

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

the class SetCalendarItem method deserializeSetCalendarItemData.

private Mailbox.SetCalendarItemData deserializeSetCalendarItemData(RedoLogInput in, boolean attachmentIndexingEnabled) throws IOException, MessagingException {
    Mailbox.SetCalendarItemData toRet = new Mailbox.SetCalendarItemData();
    int mboxId = getMailboxId();
    try {
        // keep this for backward compatibility with when SetCalendarItemData
        in.readBoolean();
        // used to have mForce field
        ICalTimeZone localTz = Util.decodeTimeZoneFromMetadata(new Metadata(in.readUTF()));
        toRet.invite = Invite.decodeMetadata(mboxId, new Metadata(in.readUTF()), null, localTz);
        boolean hasPm;
        if (getVersion().atLeast(1, 24)) {
            hasPm = in.readBoolean();
        } else {
            hasPm = true;
        }
        // If version is earlier than 1.24, we always have ParsedMessage array.
        if (hasPm) {
            long receivedDate = in.readLong();
            int dataLen = in.readInt();
            byte[] rawPmData = new byte[dataLen];
            in.readFully(rawPmData, 0, dataLen);
            InputStream is = new SharedByteArrayInputStream(rawPmData);
            MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), is);
            toRet.message = new ParsedMessage(mm, receivedDate, attachmentIndexingEnabled);
        }
    } catch (ServiceException ex) {
        ex.printStackTrace();
        throw new IOException("Cannot read serialized entry for CreateInvite " + ex.toString());
    }
    return toRet;
}
Also used : SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) InputStream(java.io.InputStream) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Metadata(com.zimbra.cs.mailbox.Metadata) IOException(java.io.IOException) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) MimeMessage(javax.mail.internet.MimeMessage) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Example 24 with Metadata

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

the class FixCalendarItemTZ method deserializeData.

@Override
protected void deserializeData(RedoLogInput in) throws IOException {
    mId = in.readInt();
    int numReplacements = in.readInt();
    if (numReplacements > 0) {
        mReplacementMap = new HashMap<String, ICalTimeZone>(numReplacements);
        for (int i = 0; i < numReplacements; i++) {
            String tzid = in.readUTF();
            String newTZMeta = in.readUTF();
            try {
                ICalTimeZone newTZ = null;
                if (newTZMeta != null)
                    newTZ = Util.decodeTimeZoneFromMetadata(new Metadata(newTZMeta));
                mReplacementMap.put(tzid, newTZ);
            } catch (ServiceException e) {
                IOException ioe = new IOException("Error deserializing timezone");
                ioe.initCause(e);
                throw ioe;
            }
        }
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) Metadata(com.zimbra.cs.mailbox.Metadata) IOException(java.io.IOException) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Example 25 with Metadata

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

the class DbScheduledTask method getEncodedMetadata.

private static String getEncodedMetadata(ScheduledTask task) {
    boolean hasProperties = false;
    Metadata metadata = new Metadata();
    Set<String> keys = task.getPropertyNames();
    for (String key : keys) {
        hasProperties = true;
        metadata.put(key, task.getProperty(key));
    }
    if (!hasProperties) {
        return null;
    }
    return metadata.toString();
}
Also used : Metadata(com.zimbra.cs.mailbox.Metadata)

Aggregations

Metadata (com.zimbra.cs.mailbox.Metadata)60 Mailbox (com.zimbra.cs.mailbox.Mailbox)16 ArrayList (java.util.ArrayList)15 ServiceException (com.zimbra.common.service.ServiceException)13 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)9 SQLException (java.sql.SQLException)9 IOException (java.io.IOException)8 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 OperationContext (com.zimbra.cs.mailbox.OperationContext)7 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)6 MailItem (com.zimbra.cs.mailbox.MailItem)5 HashMap (java.util.HashMap)5 ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)4 DataSource (com.zimbra.cs.account.DataSource)4 DbDataSource (com.zimbra.cs.db.DbDataSource)4 DataSourceItem (com.zimbra.cs.db.DbDataSource.DataSourceItem)4 Map (java.util.Map)4 Entry (java.util.Map.Entry)4 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)3