use of com.zimbra.soap.admin.message.CreateSystemRetentionPolicyRequest 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.admin.message.CreateSystemRetentionPolicyRequest in project zm-mailbox by Zimbra.
the class CreateSystemRetentionPolicy method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
CreateSystemRetentionPolicyRequest req = zsc.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
checkSetRight(entry, zsc, context, this);
Policy keep = req.getKeepPolicy();
Policy purge = req.getPurgePolicy();
if (keep == null && purge == null) {
throw ServiceException.INVALID_REQUEST("No keep or purge policy specified.", null);
}
if (keep != null && purge != null) {
throw ServiceException.INVALID_REQUEST("Cannot specify both keep and purge policy.", null);
}
Policy newPolicy;
if (keep != null) {
newPolicy = RetentionPolicyManager.getInstance().createSystemKeepPolicy(entry, keep.getName(), keep.getLifetime());
} else {
newPolicy = RetentionPolicyManager.getInstance().createSystemPurgePolicy(entry, purge.getName(), purge.getLifetime());
}
CreateSystemRetentionPolicyResponse res = new CreateSystemRetentionPolicyResponse(newPolicy);
return zsc.jaxbToElement(res);
}
Aggregations