Search in sources :

Example 1 with CosSelector

use of com.zimbra.soap.admin.type.CosSelector 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)

Example 2 with CosSelector

use of com.zimbra.soap.admin.type.CosSelector 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)

Example 3 with CosSelector

use of com.zimbra.soap.admin.type.CosSelector 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);
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) Entry(com.zimbra.cs.account.Entry) CreateSystemRetentionPolicyRequest(com.zimbra.soap.admin.message.CreateSystemRetentionPolicyRequest) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) CosSelector(com.zimbra.soap.admin.type.CosSelector) CreateSystemRetentionPolicyResponse(com.zimbra.soap.admin.message.CreateSystemRetentionPolicyResponse) Provisioning(com.zimbra.cs.account.Provisioning)

Example 4 with CosSelector

use of com.zimbra.soap.admin.type.CosSelector 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);
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) Entry(com.zimbra.cs.account.Entry) DeleteSystemRetentionPolicyResponse(com.zimbra.soap.admin.message.DeleteSystemRetentionPolicyResponse) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) DeleteSystemRetentionPolicyRequest(com.zimbra.soap.admin.message.DeleteSystemRetentionPolicyRequest) CosSelector(com.zimbra.soap.admin.type.CosSelector) Provisioning(com.zimbra.cs.account.Provisioning)

Aggregations

Entry (com.zimbra.cs.account.Entry)4 Provisioning (com.zimbra.cs.account.Provisioning)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 CosSelector (com.zimbra.soap.admin.type.CosSelector)4 Policy (com.zimbra.soap.mail.type.Policy)3 RetentionPolicyManager (com.zimbra.cs.mailbox.RetentionPolicyManager)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 GetSystemRetentionPolicyRequest (com.zimbra.soap.admin.message.GetSystemRetentionPolicyRequest)1 GetSystemRetentionPolicyResponse (com.zimbra.soap.admin.message.GetSystemRetentionPolicyResponse)1 ModifySystemRetentionPolicyRequest (com.zimbra.soap.admin.message.ModifySystemRetentionPolicyRequest)1 ModifySystemRetentionPolicyResponse (com.zimbra.soap.admin.message.ModifySystemRetentionPolicyResponse)1 RetentionPolicy (com.zimbra.soap.mail.type.RetentionPolicy)1