Search in sources :

Example 1 with GetSystemRetentionPolicyResponse

use of com.zimbra.soap.admin.message.GetSystemRetentionPolicyResponse 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));
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) DeleteSystemRetentionPolicyResponse(com.zimbra.soap.admin.message.DeleteSystemRetentionPolicyResponse) DeleteSystemRetentionPolicyRequest(com.zimbra.soap.admin.message.DeleteSystemRetentionPolicyRequest) CreateSystemRetentionPolicyResponse(com.zimbra.soap.admin.message.CreateSystemRetentionPolicyResponse) GetSystemRetentionPolicyResponse(com.zimbra.soap.admin.message.GetSystemRetentionPolicyResponse) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) ModifySystemRetentionPolicyRequest(com.zimbra.soap.admin.message.ModifySystemRetentionPolicyRequest) ZMailbox(com.zimbra.client.ZMailbox) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) CreateSystemRetentionPolicyRequest(com.zimbra.soap.admin.message.CreateSystemRetentionPolicyRequest) GetSystemRetentionPolicyRequest(com.zimbra.soap.admin.message.GetSystemRetentionPolicyRequest) ModifySystemRetentionPolicyResponse(com.zimbra.soap.admin.message.ModifySystemRetentionPolicyResponse) Test(org.junit.Test)

Example 2 with GetSystemRetentionPolicyResponse

use of com.zimbra.soap.admin.message.GetSystemRetentionPolicyResponse 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 = 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
    checkGetRight(entry, zsc, context);
    RetentionPolicy rp = RetentionPolicyManager.getInstance().getSystemRetentionPolicy(entry);
    GetSystemRetentionPolicyResponse res = new GetSystemRetentionPolicyResponse(rp);
    return zsc.jaxbToElement(res);
}
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)

Aggregations

GetSystemRetentionPolicyRequest (com.zimbra.soap.admin.message.GetSystemRetentionPolicyRequest)2 GetSystemRetentionPolicyResponse (com.zimbra.soap.admin.message.GetSystemRetentionPolicyResponse)2 RetentionPolicy (com.zimbra.soap.mail.type.RetentionPolicy)2 ZMailbox (com.zimbra.client.ZMailbox)1 Entry (com.zimbra.cs.account.Entry)1 Provisioning (com.zimbra.cs.account.Provisioning)1 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 CreateSystemRetentionPolicyRequest (com.zimbra.soap.admin.message.CreateSystemRetentionPolicyRequest)1 CreateSystemRetentionPolicyResponse (com.zimbra.soap.admin.message.CreateSystemRetentionPolicyResponse)1 DeleteSystemRetentionPolicyRequest (com.zimbra.soap.admin.message.DeleteSystemRetentionPolicyRequest)1 DeleteSystemRetentionPolicyResponse (com.zimbra.soap.admin.message.DeleteSystemRetentionPolicyResponse)1 ModifySystemRetentionPolicyRequest (com.zimbra.soap.admin.message.ModifySystemRetentionPolicyRequest)1 ModifySystemRetentionPolicyResponse (com.zimbra.soap.admin.message.ModifySystemRetentionPolicyResponse)1 CosSelector (com.zimbra.soap.admin.type.CosSelector)1 Policy (com.zimbra.soap.mail.type.Policy)1 Test (org.junit.Test)1