use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class TestPurge method testTagRetentionPolicy.
@Test
public void testTagRetentionPolicy() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZTag tag = mbox.createTag(NAME_PREFIX + "-testTagRetentionPolicy", null);
// Set user keep policy for folder.
TagActionSelector action = new TagActionSelector(tag.getId(), "retentionpolicy");
RetentionPolicy rp = new RetentionPolicy(Arrays.asList(Policy.newUserPolicy("30d")), null);
action.setRetentionPolicy(rp);
TagActionRequest req = new TagActionRequest(action);
TagActionResponse res = mbox.invokeJaxb(req);
Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
Assert.assertEquals(tag.getId(), res.getAction().getSuccesses());
// Make sure that the retention policy is now set.
tag = mbox.getTagById(tag.getId());
rp = tag.getRetentionPolicy();
Assert.assertEquals(1, rp.getKeepPolicy().size());
Assert.assertEquals(0, rp.getPurgePolicy().size());
Policy p = rp.getKeepPolicy().get(0);
Assert.assertEquals(Policy.Type.USER, p.getType());
Assert.assertEquals("30d", p.getLifetime());
// Turn off keep policy and set purge policy.
action = new TagActionSelector(tag.getId(), "retentionpolicy");
rp = new RetentionPolicy(null, Arrays.asList(Policy.newUserPolicy("45d")));
action.setRetentionPolicy(rp);
req = new TagActionRequest(action);
res = mbox.invokeJaxb(req);
Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
Assert.assertEquals(tag.getId(), res.getAction().getSuccesses());
// Make sure that the retention policy is now set.
tag = mbox.getTagById(tag.getId());
rp = tag.getRetentionPolicy();
Assert.assertEquals(0, rp.getKeepPolicy().size());
Assert.assertEquals(1, rp.getPurgePolicy().size());
p = rp.getPurgePolicy().get(0);
Assert.assertEquals(Policy.Type.USER, p.getType());
Assert.assertEquals("45d", p.getLifetime());
// Start a new session and make sure that the retention policy is still returned.
mbox = TestUtil.getZMailbox(USER_NAME);
tag = mbox.getTagById(tag.getId());
Assert.assertTrue(tag.getRetentionPolicy().isSet());
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class TestPurge method testFolderRetentionPolicy.
/**
* Tests the SOAP API for setting retention policy on a folder.
*/
@Test
public void testFolderRetentionPolicy() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZFolder folder = TestUtil.createFolder(mbox, "/" + NAME_PREFIX + "-testFolderRetentionPolicy");
// Set user keep policy for folder.
FolderActionSelector action = new FolderActionSelector(folder.getId(), "retentionpolicy");
RetentionPolicy rp = new RetentionPolicy(Arrays.asList(Policy.newUserPolicy("30d")), null);
action.setRetentionPolicy(rp);
FolderActionRequest req = new FolderActionRequest(action);
FolderActionResponse res = mbox.invokeJaxb(req);
Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
Assert.assertEquals(folder.getId(), res.getAction().getId());
// Make sure that the retention policy is now set.
folder = mbox.getFolderById(folder.getId());
rp = folder.getRetentionPolicy();
Assert.assertEquals(1, rp.getKeepPolicy().size());
Assert.assertEquals(0, rp.getPurgePolicy().size());
Policy p = rp.getKeepPolicy().get(0);
Assert.assertEquals(Policy.Type.USER, p.getType());
Assert.assertEquals("30d", p.getLifetime());
// Turn off keep policy and set purge policy.
action = new FolderActionSelector(folder.getId(), "retentionpolicy");
rp = new RetentionPolicy(null, Arrays.asList(Policy.newUserPolicy("45d")));
action.setRetentionPolicy(rp);
req = new FolderActionRequest(action);
res = mbox.invokeJaxb(req);
Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
Assert.assertEquals(folder.getId(), res.getAction().getId());
// Make sure that the retention policy is now set.
folder = mbox.getFolderById(folder.getId());
rp = folder.getRetentionPolicy();
Assert.assertEquals(0, rp.getKeepPolicy().size());
Assert.assertEquals(1, rp.getPurgePolicy().size());
p = rp.getPurgePolicy().get(0);
Assert.assertEquals(Policy.Type.USER, p.getType());
Assert.assertEquals("45d", p.getLifetime());
// Start a new session and make sure that the retention policy is still returned.
mbox = TestUtil.getZMailbox(USER_NAME);
folder = mbox.getFolderById(folder.getId());
Assert.assertTrue(folder.getRetentionPolicy().isSet());
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class TestPurge method testSystemRetentionPolicy.
@Test
public void testSystemRetentionPolicy() throws Exception {
SoapProvisioning prov = TestUtil.newSoapProvisioning();
// Test getting empty system policy.
GetSystemRetentionPolicyRequest getReq = new GetSystemRetentionPolicyRequest();
GetSystemRetentionPolicyResponse getRes = prov.invokeJaxb(getReq);
RetentionPolicy rp = getRes.getRetentionPolicy();
Assert.assertEquals(0, rp.getKeepPolicy().size());
Assert.assertEquals(0, rp.getPurgePolicy().size());
// Create keep policy.
Policy keep = Policy.newSystemPolicy("keep", "60d");
CreateSystemRetentionPolicyRequest createReq = CreateSystemRetentionPolicyRequest.newKeepRequest(keep);
CreateSystemRetentionPolicyResponse createRes = prov.invokeJaxb(createReq);
Policy p = createRes.getPolicy();
Assert.assertNotNull(p.getId());
Assert.assertEquals(keep.getName(), p.getName());
Assert.assertEquals(keep.getLifetime(), p.getLifetime());
keep = p;
// Create purge policy.
Policy purge1 = Policy.newSystemPolicy("purge1", "120d");
createReq = CreateSystemRetentionPolicyRequest.newPurgeRequest(purge1);
createRes = prov.invokeJaxb(createReq);
purge1 = createRes.getPolicy();
Policy purge2 = Policy.newSystemPolicy("purge2", "240d");
createReq = CreateSystemRetentionPolicyRequest.newPurgeRequest(purge2);
createRes = prov.invokeJaxb(createReq);
purge2 = createRes.getPolicy();
// Test getting updated system policy.
getRes = prov.invokeJaxb(getReq);
rp = getRes.getRetentionPolicy();
Assert.assertEquals(1, rp.getKeepPolicy().size());
Assert.assertEquals(keep, rp.getKeepPolicy().get(0));
Assert.assertEquals(2, rp.getPurgePolicy().size());
Assert.assertEquals(purge1, rp.getPolicyById(purge1.getId()));
Assert.assertEquals(purge2, rp.getPolicyById(purge2.getId()));
// Get system policy with the mail API.
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
com.zimbra.soap.mail.message.GetSystemRetentionPolicyResponse mailRes = mbox.invokeJaxb(new com.zimbra.soap.mail.message.GetSystemRetentionPolicyRequest());
Assert.assertEquals(rp, mailRes.getRetentionPolicy());
// Modify lifetime.
Policy modLifetime = Policy.newSystemPolicy(purge1.getId(), null, "121d");
ModifySystemRetentionPolicyRequest modifyReq = new ModifySystemRetentionPolicyRequest(modLifetime);
ModifySystemRetentionPolicyResponse modifyRes = prov.invokeJaxb(modifyReq);
Policy newPurge1 = modifyRes.getPolicy();
Assert.assertEquals(Policy.newSystemPolicy(purge1.getId(), "purge1", "121d"), newPurge1);
getRes = prov.invokeJaxb(getReq);
Assert.assertEquals(newPurge1, getRes.getRetentionPolicy().getPolicyById(newPurge1.getId()));
// Modify name.
Policy modName = Policy.newSystemPolicy(purge1.getId(), "purge1-new", null);
modifyReq = new ModifySystemRetentionPolicyRequest(modName);
modifyRes = prov.invokeJaxb(modifyReq);
newPurge1 = modifyRes.getPolicy();
Assert.assertEquals(Policy.newSystemPolicy(purge1.getId(), "purge1-new", "121d"), newPurge1);
// Delete.
DeleteSystemRetentionPolicyRequest deleteReq = new DeleteSystemRetentionPolicyRequest(purge1);
@SuppressWarnings("unused") DeleteSystemRetentionPolicyResponse deleteRes = prov.invokeJaxb(deleteReq);
getRes = prov.invokeJaxb(getReq);
rp = getRes.getRetentionPolicy();
Assert.assertEquals(1, rp.getKeepPolicy().size());
Assert.assertEquals(keep, rp.getKeepPolicy().get(0));
Assert.assertEquals(1, rp.getPurgePolicy().size());
Assert.assertEquals(purge2, rp.getPurgePolicy().get(0));
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class RetentionPolicyManager method modifySystemPolicy.
/**
* Updates the properties of the system policy with the given id.
* @return {@code null} if a {@code Policy} with the given id could not be found
*/
public Policy modifySystemPolicy(Entry entry, String id, String name, String lifetime) throws ServiceException {
validateLifetime(lifetime);
synchronized (entry) {
SystemPolicy sp = getCachedSystemPolicy(entry);
if (sp.keep.containsKey(id)) {
Policy p = Policy.newSystemPolicy(id, name, lifetime);
sp.keep.put(id, p);
saveSystemPolicy(entry, new RetentionPolicy(sp.keep.values(), sp.purge.values()));
return p;
}
if (sp.purge.containsKey(id)) {
Policy p = Policy.newSystemPolicy(id, name, lifetime);
sp.purge.put(id, p);
saveSystemPolicy(entry, new RetentionPolicy(sp.keep.values(), sp.purge.values()));
return p;
}
}
return null;
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class RetentionPolicyManager method createSystemKeepPolicy.
public Policy createSystemKeepPolicy(Entry entry, String name, String lifetime) throws ServiceException {
validateLifetime(lifetime);
Policy p = Policy.newSystemPolicy(generateId(), name, lifetime);
synchronized (entry) {
SystemPolicy sp = getCachedSystemPolicy(entry);
sp.keep.put(p.getId(), p);
saveSystemPolicy(entry, new RetentionPolicy(sp.keep.values(), sp.purge.values()));
}
return p;
}
Aggregations