Search in sources :

Example 1 with RetentionPolicy

use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.

the class PurgeTest method completeCosRetentionPolicy.

@Test
public void completeCosRetentionPolicy() throws Exception {
    RetentionPolicyManager mgr = RetentionPolicyManager.getInstance();
    Config config = Provisioning.getInstance().getConfig();
    Policy keep1 = mgr.createSystemKeepPolicy(config, "keep1", "300d");
    Map<String, Object> attrs = new HashMap<String, Object>();
    Cos cos = Provisioning.getInstance().createCos("testcos2", attrs);
    Policy keep2 = mgr.createSystemKeepPolicy(cos, "keep2", "600d");
    // Assign cos to the account
    getAccount().setCOSId(cos.getId());
    // Create mailbox policy that references the system policy, and confirm that
    // lookup returns the latest values.
    RetentionPolicy mboxRP1 = new RetentionPolicy(Arrays.asList(Policy.newSystemPolicy(keep2.getId())), null);
    RetentionPolicy completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP1);
    Policy latest = completeRP.getKeepPolicy().get(0);
    assertEquals(keep2, latest);
    // Modify cos policy and confirm that the accessor returns the latest values.
    mgr.modifySystemPolicy(cos, keep2.getId(), "new keep2", "301d");
    completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP1);
    latest = completeRP.getKeepPolicy().get(0);
    assertFalse(keep2.equals(latest));
    assertEquals(keep2.getId(), latest.getId());
    assertEquals("new keep2", latest.getName());
    assertEquals("301d", latest.getLifetime());
    // Make sure system policy does not apply to this user.
    RetentionPolicy mboxRP2 = new RetentionPolicy(Arrays.asList(Policy.newSystemPolicy(keep1.getId())), null);
    completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP2);
    assertTrue(completeRP.getKeepPolicy().isEmpty());
    // remove cos retention policy
    mgr.deleteSystemPolicy(cos, keep2.getId());
    // make sure account retention policy is empty
    completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP1);
    assertTrue(completeRP.getKeepPolicy().isEmpty());
    // make sure system policy is applicable now
    completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP2);
    latest = completeRP.getKeepPolicy().get(0);
    assertTrue(keep1.equals(latest));
    assertEquals(keep1.getId(), latest.getId());
    assertEquals("keep1", latest.getName());
    assertEquals("300d", latest.getLifetime());
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) HashMap(java.util.HashMap) Config(com.zimbra.cs.account.Config) Cos(com.zimbra.cs.account.Cos) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Test(org.junit.Test)

Example 2 with RetentionPolicy

use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.

the class PurgeTest method folderPurgePolicy.

@Test
public void folderPurgePolicy() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    // Create folder and test messages.
    Folder folder = mbox.createFolder(null, "/folderPurgePolicy", new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
    Message older = TestUtil.addMessage(mbox, folder.getId(), "test1", System.currentTimeMillis() - (60 * Constants.MILLIS_PER_MINUTE));
    Message newer = TestUtil.addMessage(mbox, folder.getId(), "test2", System.currentTimeMillis() - (30 * Constants.MILLIS_PER_MINUTE));
    folder = mbox.getFolderById(null, folder.getId());
    // Run purge with default settings and make sure nothing was deleted.
    mbox.purgeMessages(null);
    folder = mbox.getFolderById(null, folder.getId());
    assertEquals(2, folder.getSize());
    // Add retention policy.
    Policy p = Policy.newUserPolicy("45m");
    RetentionPolicy purgePolicy = new RetentionPolicy(null, Arrays.asList(p));
    mbox.setRetentionPolicy(null, folder.getId(), MailItem.Type.FOLDER, purgePolicy);
    // Purge the folder cache and make sure that purge policy is reloaded from metadata.
    mbox.purge(MailItem.Type.FOLDER);
    folder = mbox.getFolderById(null, folder.getId());
    List<Policy> purgeList = folder.getRetentionPolicy().getPurgePolicy();
    assertEquals(1, purgeList.size());
    assertEquals("45m", purgeList.get(0).getLifetime());
    // Run purge and make sure one of the messages was deleted.
    mbox.purgeMessages(null);
    assertEquals(1, folder.getSize());
    mbox.getMessageById(null, newer.getId());
    try {
        mbox.getMessageById(null, older.getId());
        fail("Older message was not purged.");
    } catch (NoSuchItemException e) {
    // Older message was purged.
    }
    // Remove purge policy and verify that the folder state was properly updated.
    mbox.setRetentionPolicy(null, folder.getId(), MailItem.Type.FOLDER, null);
    mbox.purge(MailItem.Type.FOLDER);
    folder = mbox.getFolderById(null, folder.getId());
    assertEquals(0, folder.getRetentionPolicy().getKeepPolicy().size());
    assertEquals(0, folder.getRetentionPolicy().getPurgePolicy().size());
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) Test(org.junit.Test)

Example 3 with RetentionPolicy

use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.

the class PurgeTest method setUp.

@Before
public void setUp() throws Exception {
    MailboxTestUtil.clearData();
    Provisioning prov = Provisioning.getInstance();
    prov.deleteAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
    prov.createAccount("test@zimbra.com", "secret", new HashMap<String, Object>());
    Config config = Provisioning.getInstance().getConfig();
    RetentionPolicyManager mgr = RetentionPolicyManager.getInstance();
    RetentionPolicy rp = mgr.getSystemRetentionPolicy(config);
    List<Policy> keep = rp.getKeepPolicy();
    if (keep != null) {
        for (Policy policy : keep) {
            mgr.deleteSystemPolicy(config, policy.getId());
        }
    }
    List<Policy> purge = rp.getPurgePolicy();
    if (purge != null) {
        for (Policy policy : purge) {
            mgr.deleteSystemPolicy(config, policy.getId());
        }
    }
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Config(com.zimbra.cs.account.Config) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) MockProvisioning(com.zimbra.cs.account.MockProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) Before(org.junit.Before)

Example 4 with RetentionPolicy

use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.

the class PurgeTest method purgeWithSystemPolicy.

@Test
public void purgeWithSystemPolicy() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    // Create folder and test messages.
    Folder folder = mbox.createFolder(null, "/purgeWithSystemPolicy", new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
    Message older = TestUtil.addMessage(mbox, folder.getId(), "older", System.currentTimeMillis() - (60 * Constants.MILLIS_PER_MINUTE));
    Message newer = TestUtil.addMessage(mbox, folder.getId(), "newer", System.currentTimeMillis() - (30 * Constants.MILLIS_PER_MINUTE));
    folder = mbox.getFolderById(null, folder.getId());
    // Add user and system retention policy.
    Config config = Provisioning.getInstance().getConfig();
    Policy system = RetentionPolicyManager.getInstance().createSystemPurgePolicy(config, "system", "45m");
    Policy p1 = Policy.newUserPolicy("90m");
    Policy p2 = Policy.newSystemPolicy(system.getId());
    RetentionPolicy purgePolicy = new RetentionPolicy(null, Arrays.asList(p1, p2));
    mbox.setRetentionPolicy(null, folder.getId(), MailItem.Type.FOLDER, purgePolicy);
    // Run purge and make sure one of the messages was deleted.
    mbox.purgeMessages(null);
    folder = mbox.getFolderById(folder.getId());
    assertEquals(1, folder.getSize());
    mbox.getMessageById(null, newer.getId());
    try {
        mbox.getMessageById(null, older.getId());
        fail("Older message was not purged.");
    } catch (NoSuchItemException e) {
    }
    // Update system policy, rerun purge, and make sure the older message was deleted.
    RetentionPolicyManager.getInstance().modifySystemPolicy(config, system.getId(), system.getName(), "20m");
    mbox.purgeMessages(null);
    folder = mbox.getFolderById(folder.getId());
    assertEquals(0, folder.getSize());
    try {
        mbox.getMessageById(null, newer.getId());
        fail("Newer message was not purged.");
    } catch (NoSuchItemException e) {
    }
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Config(com.zimbra.cs.account.Config) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) Test(org.junit.Test)

Example 5 with RetentionPolicy

use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.

the class PurgeTest method modifySystemPolicy.

@Test
public void modifySystemPolicy() throws Exception {
    Config config = Provisioning.getInstance().getConfig();
    RetentionPolicyManager mgr = RetentionPolicyManager.getInstance();
    Policy keep1 = mgr.createSystemKeepPolicy(config, "keep1", "300d");
    Policy keep2 = mgr.createSystemKeepPolicy(config, "keep2", "400d");
    Policy purge1 = mgr.createSystemPurgePolicy(config, "purge1", "500d");
    Policy purge2 = mgr.createSystemPurgePolicy(config, "purge2", "500d");
    assertEquals(keep1, mgr.getPolicyById(config, keep1.getId()));
    assertEquals(keep2, mgr.getPolicyById(config, keep2.getId()));
    assertEquals(purge1, mgr.getPolicyById(config, purge1.getId()));
    assertEquals(purge2, mgr.getPolicyById(config, purge2.getId()));
    // Test modify.
    mgr.modifySystemPolicy(config, keep1.getId(), "new keep1", "301d");
    Policy newKeep1 = mgr.getPolicyById(config, 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(config, purge2.getId()));
    assertNull(mgr.getPolicyById(config, purge2.getId()));
    RetentionPolicy rp = mgr.getSystemRetentionPolicy(config);
    assertEquals(2, rp.getKeepPolicy().size());
    assertEquals(1, rp.getPurgePolicy().size());
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Config(com.zimbra.cs.account.Config) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Test(org.junit.Test)

Aggregations

RetentionPolicy (com.zimbra.soap.mail.type.RetentionPolicy)37 Policy (com.zimbra.soap.mail.type.Policy)22 Test (org.junit.Test)15 Config (com.zimbra.cs.account.Config)7 Element (com.zimbra.common.soap.Element)6 Mailbox (com.zimbra.cs.mailbox.Mailbox)6 ServiceException (com.zimbra.common.service.ServiceException)4 Cos (com.zimbra.cs.account.Cos)4 ZFolder (com.zimbra.client.ZFolder)3 ZMailbox (com.zimbra.client.ZMailbox)3 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)3 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)3 Color (com.zimbra.common.mailbox.Color)2 XMLElement (com.zimbra.common.soap.Element.XMLElement)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 Provisioning (com.zimbra.cs.account.Provisioning)2 DbTag (com.zimbra.cs.db.DbTag)2 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)2 OperationContext (com.zimbra.cs.mailbox.OperationContext)2 AlterItemTag (com.zimbra.cs.redolog.op.AlterItemTag)2