Search in sources :

Example 6 with RetentionPolicy

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

the class PurgeTest method tagPurgePolicy.

@Test
public void tagPurgePolicy() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    // Create folder and test messages.
    Tag tag = mbox.createTag(null, "tag", (byte) 0);
    Folder inbox = mbox.getFolderById(null, Mailbox.ID_FOLDER_INBOX);
    Message older = TestUtil.addMessage(mbox, inbox.getId(), "test1", System.currentTimeMillis() - (60 * Constants.MILLIS_PER_MINUTE));
    Message newer = TestUtil.addMessage(mbox, inbox.getId(), "test2", System.currentTimeMillis() - (30 * Constants.MILLIS_PER_MINUTE));
    Message notTagged = TestUtil.addMessage(mbox, inbox.getId(), "test3", System.currentTimeMillis() - (90 * Constants.MILLIS_PER_MINUTE));
    mbox.setTags(null, older.getId(), older.getType(), 0, new String[] { tag.getName() });
    mbox.setTags(null, newer.getId(), newer.getType(), 0, new String[] { tag.getName() });
    // Run purge with default settings and make sure nothing was deleted.
    mbox.purgeMessages(null);
    assertEquals(3, inbox.getSize());
    // Add retention policy.
    Policy p = Policy.newUserPolicy("45m");
    RetentionPolicy purgePolicy = new RetentionPolicy(null, Arrays.asList(p));
    mbox.setRetentionPolicy(null, tag.getId(), MailItem.Type.TAG, purgePolicy);
    // Purge the tag cache and make sure that purge policy is reloaded from metadata.
    mbox.purge(MailItem.Type.TAG);
    tag = mbox.getTagById(null, tag.getId());
    List<Policy> purgeList = tag.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);
    inbox = mbox.getFolderById(null, inbox.getId());
    assertEquals(2, inbox.getSize());
    mbox.getMessageById(null, newer.getId());
    mbox.getMessageById(null, notTagged.getId());
    try {
        mbox.getMessageById(null, older.getId());
        fail("Older message was not purged.");
    } catch (NoSuchItemException e) {
    }
    // Remove purge policy and verify that the folder state was properly updated.
    mbox.setRetentionPolicy(null, tag.getId(), MailItem.Type.TAG, null);
    mbox.purge(MailItem.Type.TAG);
    tag = mbox.getTagById(null, tag.getId());
    assertEquals(0, tag.getRetentionPolicy().getKeepPolicy().size());
    assertEquals(0, tag.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 7 with RetentionPolicy

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

the class PurgeTest method completeRetentionPolicy.

/**
     * Tests {@link RetentionPolicyManager#getCompleteRetentionPolicy(Account, RetentionPolicy).  Confirms
     * that system policy elements are updated with the latest values in LDAP.
     */
@Test
public void completeRetentionPolicy() throws Exception {
    RetentionPolicyManager mgr = RetentionPolicyManager.getInstance();
    Config config = Provisioning.getInstance().getConfig();
    Policy keep1 = mgr.createSystemKeepPolicy(config, "keep1", "300d");
    // Create mailbox policy that references the system policy, and confirm that
    // lookup returns the latest values.
    RetentionPolicy mboxRP = new RetentionPolicy(Arrays.asList(Policy.newSystemPolicy(keep1.getId())), null);
    RetentionPolicy completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP);
    Policy latest = completeRP.getKeepPolicy().get(0);
    assertEquals(keep1, latest);
    // Modify system policy and confirm that the accessor returns the latest values.
    mgr.modifySystemPolicy(config, keep1.getId(), "new keep1", "301d");
    completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP);
    latest = completeRP.getKeepPolicy().get(0);
    assertFalse(keep1.equals(latest));
    assertEquals(keep1.getId(), latest.getId());
    assertEquals("new keep1", latest.getName());
    assertEquals("301d", latest.getLifetime());
}
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)

Example 8 with RetentionPolicy

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

the class SetRetentionPolicyTest method redoTag.

/**
     * Verifies serializing, deserializing, and replaying for tag.
     */
@Test
public void redoTag() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    // Create folder.
    Tag tag = mbox.createTag(null, "tag", (byte) 0);
    assertEquals(0, tag.getRetentionPolicy().getKeepPolicy().size());
    assertEquals(0, tag.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.TAG, tag.getId(), rp);
    // Serialize, deserialize, and redo.
    byte[] data = redoPlayer.testSerialize();
    redoPlayer = new SetRetentionPolicy();
    redoPlayer.setMailboxId(mbox.getId());
    redoPlayer.testDeserialize(data);
    redoPlayer.redo();
    tag = mbox.getTagById(null, tag.getId());
    assertEquals(1, tag.getRetentionPolicy().getKeepPolicy().size());
    assertEquals(1, tag.getRetentionPolicy().getPurgePolicy().size());
    assertEquals("45m", tag.getRetentionPolicy().getPurgePolicy().get(0).getLifetime());
    assertEquals("123", tag.getRetentionPolicy().getKeepPolicy().get(0).getId());
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Tag(com.zimbra.cs.mailbox.Tag) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Test(org.junit.Test)

Example 9 with RetentionPolicy

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

the class GetSystemRetentionPolicy method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    GetSystemRetentionPolicyRequest req = JaxbUtil.elementToJaxb(request);
    Provisioning prov = Provisioning.getInstance();
    // assume default retention policy to be set in globalConfig (for backward compatibility)
    Entry entry = prov.getConfig();
    // check if cos is specified
    CosSelector cosSelector = req.getCos();
    if (cosSelector != null) {
        entry = prov.get(Key.CosBy.fromString(cosSelector.getBy().name()), cosSelector.getKey());
        if (entry == null)
            throw AccountServiceException.NO_SUCH_COS(cosSelector.getKey());
    }
    // check right
    checkGetRight(entry, zsc, context);
    RetentionPolicy rp = RetentionPolicyManager.getInstance().getSystemRetentionPolicy(entry);
    GetSystemRetentionPolicyResponse res = new GetSystemRetentionPolicyResponse(rp);
    return JaxbUtil.jaxbToElement(res, zsc.getResponseProtocol().getFactory());
}
Also used : Entry(com.zimbra.cs.account.Entry) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) CosSelector(com.zimbra.soap.admin.type.CosSelector) GetSystemRetentionPolicyResponse(com.zimbra.soap.admin.message.GetSystemRetentionPolicyResponse) GetSystemRetentionPolicyRequest(com.zimbra.soap.admin.message.GetSystemRetentionPolicyRequest) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Provisioning(com.zimbra.cs.account.Provisioning)

Example 10 with RetentionPolicy

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

the class TagAction method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    Element action = request.getElement(MailConstants.E_ACTION);
    String opAttr = action.getAttribute(MailConstants.A_OPERATION).toLowerCase();
    String operation = getOperation(opAttr);
    if (operation.equals(OP_TAG) || operation.equals(OP_FLAG)) {
        throw ServiceException.INVALID_REQUEST("cannot tag/flag a tag", null);
    }
    if (!TAG_ACTIONS.contains(operation)) {
        throw ServiceException.INVALID_REQUEST("invalid operation on tag: " + opAttr, null);
    }
    String tn = action.getAttribute(MailConstants.A_TAG_NAMES, null);
    if (tn != null) {
        // switch tag names to tag IDs, because that's what ItemAction expects
        StringBuilder tagids = new StringBuilder();
        for (String name : TagUtil.decodeTags(tn)) {
            tagids.append(tagids.length() == 0 ? "" : ",").append(mbox.getTagByName(octxt, name).getId());
        }
        action.addAttribute(MailConstants.A_ID, tagids.toString());
    }
    String successes;
    if (operation.equals(OP_RETENTION_POLICY)) {
        ItemId iid = new ItemId(action.getAttribute(MailConstants.A_ID), zsc);
        RetentionPolicy rp = new RetentionPolicy(action.getElement(MailConstants.E_RETENTION_POLICY));
        mbox.setRetentionPolicy(octxt, iid.getId(), MailItem.Type.TAG, rp);
        successes = new ItemIdFormatter(zsc).formatItemId(iid);
    } else {
        successes = handleCommon(context, request, opAttr, MailItem.Type.TAG);
    }
    Element response = zsc.createElement(MailConstants.TAG_ACTION_RESPONSE);
    Element result = response.addUniqueElement(MailConstants.E_ACTION);
    result.addAttribute(MailConstants.A_ID, successes);
    result.addAttribute(MailConstants.A_TAG_NAMES, tn);
    result.addAttribute(MailConstants.A_OPERATION, opAttr);
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Mailbox(com.zimbra.cs.mailbox.Mailbox) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) ItemId(com.zimbra.cs.service.util.ItemId) 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