use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class PurgeTest method invalidFolderMessageLifetime.
@Test
public void invalidFolderMessageLifetime() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Folder folder = mbox.createFolder(null, "/invalidFolderMessageLifetime", new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
Policy p = Policy.newUserPolicy("45x");
RetentionPolicy purgePolicy = new RetentionPolicy(null, Arrays.asList(p));
try {
mbox.setRetentionPolicy(null, folder.getId(), MailItem.Type.FOLDER, purgePolicy);
fail("Invalid time interval should not have been accepted.");
} catch (ServiceException e) {
}
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class PurgeTest method modifyCosSystemPolicy.
@Test
public void modifyCosSystemPolicy() throws Exception {
Map<String, Object> attrs = new HashMap<String, Object>();
Cos cos = Provisioning.getInstance().createCos("testcos", attrs);
RetentionPolicyManager mgr = RetentionPolicyManager.getInstance();
Policy keep1 = mgr.createSystemKeepPolicy(cos, "keep1", "300d");
Policy keep2 = mgr.createSystemKeepPolicy(cos, "keep2", "400d");
Policy purge1 = mgr.createSystemPurgePolicy(cos, "purge1", "500d");
Policy purge2 = mgr.createSystemPurgePolicy(cos, "purge2", "500d");
assertEquals(keep1, mgr.getPolicyById(cos, keep1.getId()));
assertEquals(keep2, mgr.getPolicyById(cos, keep2.getId()));
assertEquals(purge1, mgr.getPolicyById(cos, purge1.getId()));
assertEquals(purge2, mgr.getPolicyById(cos, purge2.getId()));
// Test modify.
mgr.modifySystemPolicy(cos, keep1.getId(), "new keep1", "301d");
Policy newKeep1 = mgr.getPolicyById(cos, keep1.getId());
assertFalse(keep1.equals(newKeep1));
assertEquals(keep1.getId(), newKeep1.getId());
assertEquals("new keep1", newKeep1.getName());
assertEquals("301d", newKeep1.getLifetime());
// Test delete.
assertTrue(mgr.deleteSystemPolicy(cos, purge2.getId()));
assertNull(mgr.getPolicyById(cos, purge2.getId()));
RetentionPolicy rp = mgr.getSystemRetentionPolicy(cos);
assertEquals(2, rp.getKeepPolicy().size());
assertEquals(1, rp.getPurgePolicy().size());
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class PurgeTest method multipleUserPolicy.
@Test
public void multipleUserPolicy() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Folder folder = mbox.createFolder(null, "/multipleUserPolicy", new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
List<Policy> list = Arrays.asList(Policy.newUserPolicy("45d"), Policy.newUserPolicy("60d"));
RetentionPolicy purgePolicy = new RetentionPolicy(null, list);
try {
mbox.setRetentionPolicy(null, folder.getId(), MailItem.Type.FOLDER, purgePolicy);
fail("Multiple purge policies.");
} catch (ServiceException e) {
}
purgePolicy = new RetentionPolicy(list, null);
try {
mbox.setRetentionPolicy(null, folder.getId(), MailItem.Type.FOLDER, purgePolicy);
fail("Multiple keep policies.");
} catch (ServiceException e) {
}
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class SetRetentionPolicyTest method redoFolder.
/**
* Verifies serializing, deserializing, and replaying for folder.
*/
@Test
public void redoFolder() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
// Create folder.
Folder folder = mbox.createFolder(null, "/redo", new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
assertEquals(0, folder.getRetentionPolicy().getKeepPolicy().size());
assertEquals(0, folder.getRetentionPolicy().getPurgePolicy().size());
// Create RedoableOp.
RetentionPolicy rp = new RetentionPolicy(Arrays.asList(Policy.newSystemPolicy("123")), Arrays.asList(Policy.newUserPolicy("45m")));
SetRetentionPolicy redoPlayer = new SetRetentionPolicy(mbox.getId(), MailItem.Type.FOLDER, folder.getId(), rp);
// Serialize, deserialize, and redo.
byte[] data = redoPlayer.testSerialize();
redoPlayer = new SetRetentionPolicy();
redoPlayer.setMailboxId(mbox.getId());
redoPlayer.testDeserialize(data);
redoPlayer.redo();
folder = mbox.getFolderById(null, folder.getId());
assertEquals(1, folder.getRetentionPolicy().getKeepPolicy().size());
assertEquals(1, folder.getRetentionPolicy().getPurgePolicy().size());
assertEquals("45m", folder.getRetentionPolicy().getPurgePolicy().get(0).getLifetime());
assertEquals("123", folder.getRetentionPolicy().getKeepPolicy().get(0).getId());
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class RetentionPolicyManager method createSystemPurgePolicy.
public Policy createSystemPurgePolicy(Entry entry, String name, String lifetime) throws ServiceException {
validateLifetime(lifetime);
Policy p = Policy.newSystemPolicy(generateId(), name, lifetime);
synchronized (entry) {
SystemPolicy sp = getCachedSystemPolicy(entry);
sp.purge.put(p.getId(), p);
saveSystemPolicy(entry, new RetentionPolicy(sp.keep.values(), sp.purge.values()));
}
return p;
}
Aggregations