use of com.zimbra.cs.mailbox.MailItem.Type in project zm-mailbox by Zimbra.
the class PagedDeleteTest method testRemoveBeforeAfterCutoff.
@Test
public void testRemoveBeforeAfterCutoff() {
TypedIdList tombstone = new TypedIdList();
tombstone.add(Type.MESSAGE, 3, "", 100);
tombstone.add(Type.MESSAGE, 4, "", 101);
tombstone.add(Type.APPOINTMENT, 1, "", 101);
tombstone.add(Type.APPOINTMENT, 5, "", 100);
tombstone.add(Type.APPOINTMENT, 9, "", 103);
tombstone.add(Type.MESSAGE, 2, "", 99);
tombstone.add(Type.MESSAGE, 22, "", 105);
tombstone.add(Type.MESSAGE, 24, "", 103);
tombstone.add(Type.MESSAGE, 28, "", 106);
PagedDelete pgDelete = new PagedDelete(tombstone, true);
pgDelete.removeBeforeCutoff(4, 101);
Collection<Integer> ids = pgDelete.getAllIds();
Assert.assertEquals(5, ids.size());
pgDelete.trimDeletesTillPageLimit(5);
ids = pgDelete.getAllIds();
Assert.assertEquals(5, ids.size());
pgDelete.removeAfterCutoff(105);
ids = pgDelete.getAllIds();
Assert.assertEquals(4, ids.size());
Assert.assertTrue(ids.contains(4));
Assert.assertTrue(ids.contains(9));
Assert.assertTrue(ids.contains(24));
Assert.assertTrue(ids.contains(22));
Assert.assertTrue(pgDelete.isDeleteOverFlow());
Assert.assertEquals(pgDelete.getCutOffModsequnce(), 106);
Assert.assertEquals(pgDelete.getLastItemId(), 28);
Multimap<Type, Integer> ids2Type = pgDelete.getTypedItemIds();
Assert.assertEquals(4, ids2Type.size());
Assert.assertTrue(ids2Type.containsEntry(Type.MESSAGE, 4));
Assert.assertTrue(ids2Type.containsEntry(Type.APPOINTMENT, 9));
Assert.assertTrue(ids2Type.containsEntry(Type.MESSAGE, 24));
Assert.assertTrue(ids2Type.containsEntry(Type.MESSAGE, 22));
}
use of com.zimbra.cs.mailbox.MailItem.Type in project zm-mailbox by Zimbra.
the class MailItemResource method patchProperties.
/* Modifies the set of dead properties saved for this resource.
* Properties in the parameter 'set' are added to the existing properties.
* Properties in 'remove' are removed.
*/
@Override
public void patchProperties(DavContext ctxt, java.util.Collection<Element> set, java.util.Collection<QName> remove) throws DavException, IOException {
List<QName> reqProps = new ArrayList<QName>();
for (QName n : remove) {
mDeadProps.remove(n);
reqProps.add(n);
}
for (Element e : set) {
QName name = e.getQName();
if (name.equals(DavElements.E_DISPLAYNAME) && (type == MailItem.Type.FOLDER || type == MailItem.Type.MOUNTPOINT)) {
// rename folder
try {
String val = e.getText();
String uri = getUri();
Mailbox mbox = getMailbox(ctxt);
mbox.rename(ctxt.getOperationContext(), mId, type, val, mFolderId);
setProperty(DavElements.P_DISPLAYNAME, val);
UrlNamespace.addToRenamedResource(getOwner(), uri, this);
UrlNamespace.addToRenamedResource(getOwner(), uri.substring(0, uri.length() - 1), this);
} catch (ServiceException se) {
ctxt.getResponseProp().addPropError(DavElements.E_DISPLAYNAME, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY));
}
mDeadProps.remove(name);
continue;
} else if (name.equals(DavElements.E_CALENDAR_COLOR) && (type == MailItem.Type.FOLDER || type == MailItem.Type.MOUNTPOINT)) {
// change color
String colorStr = e.getText();
Color color = new Color(colorStr.substring(0, 7));
byte col = (byte) COLOR_LIST.indexOf(colorStr);
if (col >= 0)
color.setColor(col);
try {
Mailbox mbox = getMailbox(ctxt);
mbox.setColor(ctxt.getOperationContext(), new int[] { mId }, type, color);
} catch (ServiceException se) {
ctxt.getResponseProp().addPropError(DavElements.E_CALENDAR_COLOR, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY));
}
mDeadProps.remove(name);
continue;
} else if (name.equals(DavElements.E_SUPPORTED_CALENDAR_COMPONENT_SET)) {
// change default view
@SuppressWarnings("unchecked") List<Element> elements = e.elements(DavElements.E_COMP);
boolean isTodo = false;
boolean isEvent = false;
for (Element element : elements) {
Attribute attr = element.attribute(DavElements.P_NAME);
if (attr != null && CalComponent.VTODO.name().equals(attr.getValue())) {
isTodo = true;
} else if (attr != null && CalComponent.VEVENT.name().equals(attr.getValue())) {
isEvent = true;
}
}
if (isEvent ^ isTodo) {
// we support a calendar collection of type event or todo, not both or none.
Type type = (isEvent) ? Type.APPOINTMENT : Type.TASK;
try {
Mailbox mbox = getMailbox(ctxt);
mbox.setFolderDefaultView(ctxt.getOperationContext(), mId, type);
// See UrlNamespace.addToRenamedResource()
if (this instanceof Collection) {
((Collection) this).view = type;
}
} catch (ServiceException se) {
ctxt.getResponseProp().addPropError(name, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY));
}
} else {
ctxt.getResponseProp().addPropError(name, new DavException.CannotModifyProtectedProperty(name));
}
continue;
}
mDeadProps.put(name, e);
reqProps.add(name);
}
String configVal = "";
if (mDeadProps.size() > 0) {
org.dom4j.Document doc = org.dom4j.DocumentHelper.createDocument();
Element top = doc.addElement(CONFIG_KEY);
for (Map.Entry<QName, Element> entry : mDeadProps.entrySet()) top.add(entry.getValue().detach());
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputFormat format = OutputFormat.createCompactFormat();
XMLWriter writer = new XMLWriter(out, format);
writer.write(doc);
configVal = new String(out.toByteArray(), "UTF-8");
if (configVal.length() > PROP_LENGTH_LIMIT)
for (Map.Entry<QName, Element> entry : mDeadProps.entrySet()) ctxt.getResponseProp().addPropError(entry.getKey(), new DavException("prop length exceeded", DavProtocol.STATUS_INSUFFICIENT_STORAGE));
}
Mailbox mbox = null;
try {
mbox = getMailbox(ctxt);
mbox.lock.lock();
Metadata data = mbox.getConfig(ctxt.getOperationContext(), CONFIG_KEY);
if (data == null) {
data = new Metadata();
}
data.put(Integer.toString(mId), configVal);
mbox.setConfig(ctxt.getOperationContext(), CONFIG_KEY, data);
} catch (ServiceException se) {
for (QName qname : reqProps) ctxt.getResponseProp().addPropError(qname, new DavException(se.getMessage(), HttpServletResponse.SC_FORBIDDEN));
} finally {
if (mbox != null)
mbox.lock.release();
}
}
use of com.zimbra.cs.mailbox.MailItem.Type in project zm-mailbox by Zimbra.
the class PendingModifications method deserialize.
@SuppressWarnings("unchecked")
public static PendingModifications deserialize(Mailbox mbox, byte[] data) throws IOException, ClassNotFoundException, ServiceException {
ByteArrayInputStream bis = new ByteArrayInputStream(data);
ObjectInputStream ois = new ObjectInputStream(bis);
PendingModifications pms = new PendingModifications();
pms.changedTypes = (Set<Type>) ois.readObject();
LinkedHashMap<ModificationKeyMeta, String> metaCreated = (LinkedHashMap<ModificationKeyMeta, String>) ois.readObject();
if (metaCreated != null) {
pms.created = new LinkedHashMap<ModificationKey, MailItem>();
Iterator<Entry<ModificationKeyMeta, String>> iter = metaCreated.entrySet().iterator();
while (iter.hasNext()) {
Entry<ModificationKeyMeta, String> entry = iter.next();
Metadata meta = new Metadata(entry.getValue());
MailItem.UnderlyingData ud = new MailItem.UnderlyingData();
ud.deserialize(meta);
MailItem item = MailItem.constructItem(mbox, ud, true);
if (item instanceof Folder) {
Folder folder = ((Folder) item);
folder.setParent(mbox.getFolderById(null, folder.getFolderId()));
}
ModificationKey key = new ModificationKey(entry.getKey().accountId, entry.getKey().itemId);
pms.created.put(key, item);
}
}
Map<ModificationKeyMeta, ChangeMeta> metaModified = (Map<ModificationKeyMeta, ChangeMeta>) ois.readObject();
pms.modified = getOriginal(mbox, metaModified);
Map<ModificationKeyMeta, ChangeMeta> metaDeleted = (Map<ModificationKeyMeta, ChangeMeta>) ois.readObject();
pms.deleted = getOriginal(mbox, metaDeleted);
return pms;
}
use of com.zimbra.cs.mailbox.MailItem.Type in project zm-mailbox by Zimbra.
the class PagedDeleteTest method testRemoveBeforeCutoff.
@Test
public void testRemoveBeforeCutoff() {
TypedIdList tombstone = new TypedIdList();
tombstone.add(Type.MESSAGE, 3, "", 100);
tombstone.add(Type.MESSAGE, 4, "", 101);
tombstone.add(Type.APPOINTMENT, 1, "", 101);
tombstone.add(Type.APPOINTMENT, 5, "", 100);
tombstone.add(Type.APPOINTMENT, 9, "", 103);
tombstone.add(Type.MESSAGE, 2, "", 99);
tombstone.add(Type.MESSAGE, 22, "", 105);
tombstone.add(Type.MESSAGE, 24, "", 103);
PagedDelete pgDelete = new PagedDelete(tombstone, true);
pgDelete.removeBeforeCutoff(4, 101);
Collection<Integer> ids = pgDelete.getAllIds();
Assert.assertEquals(4, ids.size());
pgDelete.trimDeletesTillPageLimit(3);
ids = pgDelete.getAllIds();
Assert.assertEquals(3, ids.size());
Assert.assertTrue(ids.contains(4));
Assert.assertTrue(ids.contains(9));
Assert.assertTrue(ids.contains(24));
Assert.assertTrue(pgDelete.isDeleteOverFlow());
Assert.assertEquals(pgDelete.getCutOffModsequnce(), 105);
Assert.assertEquals(pgDelete.getLastItemId(), 22);
Multimap<Type, Integer> ids2Type = pgDelete.getTypedItemIds();
Assert.assertEquals(3, ids2Type.size());
Assert.assertTrue(ids2Type.containsEntry(Type.MESSAGE, 4));
Assert.assertTrue(ids2Type.containsEntry(Type.APPOINTMENT, 9));
Assert.assertTrue(ids2Type.containsEntry(Type.MESSAGE, 24));
}
use of com.zimbra.cs.mailbox.MailItem.Type in project zm-mailbox by Zimbra.
the class PagedDeleteTest method testTypedDeletesTillPageLimit.
@Test
public void testTypedDeletesTillPageLimit() {
TypedIdList tombstone = new TypedIdList();
tombstone.add(Type.MESSAGE, 3, "", 100);
tombstone.add(Type.MESSAGE, 4, "", 101);
tombstone.add(Type.APPOINTMENT, 1, "", 101);
tombstone.add(Type.APPOINTMENT, 5, "", 100);
tombstone.add(Type.MESSAGE, 9, "", 103);
PagedDelete pgDelete = new PagedDelete(tombstone, true);
pgDelete.trimDeletesTillPageLimit(3);
Collection<Integer> ids = pgDelete.getAllIds();
Assert.assertEquals(3, ids.size());
Assert.assertTrue(ids.contains(3));
Assert.assertTrue(ids.contains(5));
Assert.assertTrue(ids.contains(1));
Assert.assertTrue(pgDelete.isDeleteOverFlow());
Assert.assertTrue(pgDelete.getCutOffModsequnce() == 101);
Assert.assertTrue(pgDelete.getLastItemId() == 4);
Multimap<Type, Integer> ids2Type = pgDelete.getTypedItemIds();
Assert.assertEquals(3, ids2Type.size());
Assert.assertTrue(ids2Type.containsEntry(Type.MESSAGE, 3));
Assert.assertTrue(ids2Type.containsEntry(Type.APPOINTMENT, 5));
Assert.assertTrue(ids2Type.containsEntry(Type.APPOINTMENT, 1));
}
Aggregations