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;
}
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();
}
}
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;
}
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;
}
}
}
}
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();
}
Aggregations