use of com.zimbra.soap.admin.message.DeleteSystemRetentionPolicyResponse 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.DeleteSystemRetentionPolicyResponse in project zm-mailbox by Zimbra.
the class DeleteSystemRetentionPolicy method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
DeleteSystemRetentionPolicyRequest 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
CreateSystemRetentionPolicy.checkSetRight(entry, zsc, context, this);
Policy policy = req.getPolicy();
if (policy == null) {
throw ServiceException.INVALID_REQUEST("policy not specified", null);
}
String id = policy.getId();
if (id == null) {
throw ServiceException.INVALID_REQUEST("Policy id not specified", null);
}
boolean success = RetentionPolicyManager.getInstance().deleteSystemPolicy(entry, id);
if (!success) {
throw ServiceException.INVALID_REQUEST("Could not find policy with id " + id, null);
}
DeleteSystemRetentionPolicyResponse res = new DeleteSystemRetentionPolicyResponse();
return zsc.jaxbToElement(res);
}
Aggregations