Search in sources :

Example 31 with RetentionPolicy

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

the class RetentionPolicyManager method getCompleteRetentionPolicy.

public RetentionPolicy getCompleteRetentionPolicy(Account acct, RetentionPolicy rp) throws ServiceException {
    // Check CoS first, if not found get from Config
    RetentionPolicy retentionPolicy = RetentionPolicyManager.getInstance().getSystemRetentionPolicy(acct);
    retentionPolicy = RetentionPolicyManager.getInstance().getCompleteRetentionPolicy(retentionPolicy, rp);
    return retentionPolicy;
}
Also used : RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 32 with RetentionPolicy

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

the class RetentionPolicyManager method getSystemRetentionPolicy.

public RetentionPolicy getSystemRetentionPolicy(Account acct) throws ServiceException {
    // Check CoS first, if not found get from Config
    RetentionPolicy retentionPolicy = null;
    Cos cos = acct.getCOS();
    if (cos != null)
        retentionPolicy = RetentionPolicyManager.getInstance().getSystemRetentionPolicy(cos);
    if (retentionPolicy == null || !retentionPolicy.isSet()) {
        Config config = Provisioning.getInstance().getConfig();
        retentionPolicy = RetentionPolicyManager.getInstance().getSystemRetentionPolicy(config);
    }
    return retentionPolicy;
}
Also used : Cos(com.zimbra.cs.account.Cos) Config(com.zimbra.cs.account.Config) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 33 with RetentionPolicy

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

the class RetentionPolicyManager method deleteSystemPolicy.

/**
     * Deletes the system policy with the given id.
     * @return {@code true} if the policy was successfully deleted, {@code false}
     * if no policy exists with the given id
     */
public boolean deleteSystemPolicy(Entry entry, String id) throws ServiceException {
    synchronized (entry) {
        SystemPolicy sp = getCachedSystemPolicy(entry);
        Policy p = sp.keep.remove(id);
        if (p == null) {
            p = sp.purge.remove(id);
        }
        if (p != null) {
            saveSystemPolicy(entry, new RetentionPolicy(sp.keep.values(), sp.purge.values()));
            return true;
        }
    }
    return false;
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 34 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 35 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)

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