Search in sources :

Example 1 with RetentionPolicyManager

use of com.zimbra.cs.mailbox.RetentionPolicyManager in project zm-mailbox by Zimbra.

the class ModifySystemRetentionPolicy method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    ModifySystemRetentionPolicyRequest 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 p = req.getPolicy();
    if (p == null) {
        throw ServiceException.INVALID_REQUEST("policy not specified", null);
    }
    if (p.getId() == null) {
        throw ServiceException.INVALID_REQUEST("id not specified for policy", null);
    }
    RetentionPolicyManager mgr = RetentionPolicyManager.getInstance();
    String id = p.getId();
    Policy current = mgr.getPolicyById(entry, id);
    if (current == null) {
        throw ServiceException.INVALID_REQUEST("Could not find system retention policy with id " + id, null);
    }
    String name = SystemUtil.coalesce(p.getName(), current.getName());
    String lifetime = SystemUtil.coalesce(p.getLifetime(), current.getLifetime());
    Policy latest = mgr.modifySystemPolicy(entry, id, name, lifetime);
    ModifySystemRetentionPolicyResponse res = new ModifySystemRetentionPolicyResponse(latest);
    return zsc.jaxbToElement(res);
}
Also used : ModifySystemRetentionPolicyRequest(com.zimbra.soap.admin.message.ModifySystemRetentionPolicyRequest) Policy(com.zimbra.soap.mail.type.Policy) Entry(com.zimbra.cs.account.Entry) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) CosSelector(com.zimbra.soap.admin.type.CosSelector) ModifySystemRetentionPolicyResponse(com.zimbra.soap.admin.message.ModifySystemRetentionPolicyResponse) Provisioning(com.zimbra.cs.account.Provisioning) RetentionPolicyManager(com.zimbra.cs.mailbox.RetentionPolicyManager)

Aggregations

Entry (com.zimbra.cs.account.Entry)1 Provisioning (com.zimbra.cs.account.Provisioning)1 RetentionPolicyManager (com.zimbra.cs.mailbox.RetentionPolicyManager)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)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