Search in sources :

Example 11 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 12 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 13 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 14 with Metadata

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

the class InstanceData method encodeMetadata.

Metadata encodeMetadata() {
    Metadata meta = new Metadata();
    meta.put(FN_RECURRENCE_ID_Z, mRecurIdZ);
    if (mDtStart != null)
        meta.put(FN_DTSTART, mDtStart.longValue());
    if (mDuration != null)
        meta.put(FN_DURATION, mDuration.longValue());
    if (mAlarmAt != null)
        meta.put(FN_ALARM_AT, mAlarmAt.longValue());
    if (mTZOffset != null)
        meta.put(FN_TZOFFSET, mTZOffset.longValue());
    meta.put(FN_PARTSTAT, mPartStat);
    meta.put(FN_FREEBUSY_ACTUAL, mFreeBusyActual);
    meta.put(FN_PERCENT_COMPLETE, mPercentComplete);
    return meta;
}
Also used : Metadata(com.zimbra.cs.mailbox.Metadata)

Example 15 with Metadata

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

the class FileStore method saveCalendarData.

static void saveCalendarData(int mboxId, CalendarData calData) throws ServiceException {
    File file = getCalFolderFile(mboxId, calData.getFolderId());
    try {
        FileUtil.ensureDirExists(file.getParentFile());
    } catch (IOException e) {
        throw ServiceException.FAILURE("Unable to create directory " + file.getParentFile().getAbsolutePath(), e);
    }
    Metadata meta = new Metadata();
    meta.put(FN_VERSION, CURRENT_VERSION);
    meta.put(FN_MODSEQ, calData.getModSeq());
    meta.put(FN_CALDATA, calData.encodeMetadata());
    String encoded = meta.toString();
    saveToFile(file, encoded);
}
Also used : Metadata(com.zimbra.cs.mailbox.Metadata) IOException(java.io.IOException) File(java.io.File)

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