Search in sources :

Example 26 with RetentionPolicy

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) {
    }
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) ServiceException(com.zimbra.common.service.ServiceException) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Test(org.junit.Test)

Example 27 with RetentionPolicy

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());
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) HashMap(java.util.HashMap) Cos(com.zimbra.cs.account.Cos) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Test(org.junit.Test)

Example 28 with RetentionPolicy

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) {
    }
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) ServiceException(com.zimbra.common.service.ServiceException) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Test(org.junit.Test)

Example 29 with RetentionPolicy

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());
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Folder(com.zimbra.cs.mailbox.Folder) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Test(org.junit.Test)

Example 30 with RetentionPolicy

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;
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

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