Search in sources :

Example 26 with Policy

use of com.zimbra.soap.mail.type.Policy in project zm-mailbox by Zimbra.

the class RetentionPolicyManager method deleteSystemPolicy.

/**
     * Deletes the system policy with the given id.
     * @return {@code true} if the policy was successfully deleted, {@code false}
     * if no policy exists with the given id
     */
public boolean deleteSystemPolicy(Entry entry, String id) throws ServiceException {
    synchronized (entry) {
        SystemPolicy sp = getCachedSystemPolicy(entry);
        Policy p = sp.keep.remove(id);
        if (p == null) {
            p = sp.purge.remove(id);
        }
        if (p != null) {
            saveSystemPolicy(entry, new RetentionPolicy(sp.keep.values(), sp.purge.values()));
            return true;
        }
    }
    return false;
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 27 with Policy

use of com.zimbra.soap.mail.type.Policy in project zm-mailbox by Zimbra.

the class ToXML method encodePolicyList.

private static void encodePolicyList(Element parent, List<Policy> list) {
    if (list != null) {
        for (Policy p : list) {
            Element elem = parent.addElement(MailConstants.E_POLICY);
            elem.addAttribute(MailConstants.A_ID, p.getId());
            elem.addAttribute(MailConstants.A_NAME, p.getName());
            elem.addAttribute(MailConstants.A_LIFETIME, p.getLifetime());
            elem.addAttribute(MailConstants.A_RETENTION_POLICY_TYPE, p.getType().toString());
        }
    }
}
Also used : RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Policy(com.zimbra.soap.mail.type.Policy) Element(com.zimbra.common.soap.Element)

Example 28 with Policy

use of com.zimbra.soap.mail.type.Policy 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 = JaxbUtil.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 JaxbUtil.jaxbToElement(res, zsc.getResponseProtocol().getFactory());
}
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

Policy (com.zimbra.soap.mail.type.Policy)28 RetentionPolicy (com.zimbra.soap.mail.type.RetentionPolicy)25 Test (org.junit.Test)12 Config (com.zimbra.cs.account.Config)6 Provisioning (com.zimbra.cs.account.Provisioning)4 ZMailbox (com.zimbra.client.ZMailbox)3 ServiceException (com.zimbra.common.service.ServiceException)3 Cos (com.zimbra.cs.account.Cos)3 Entry (com.zimbra.cs.account.Entry)3 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)3 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)3 CosSelector (com.zimbra.soap.admin.type.CosSelector)3 ZFolder (com.zimbra.client.ZFolder)2 Element (com.zimbra.common.soap.Element)2 CreateSystemRetentionPolicyRequest (com.zimbra.soap.admin.message.CreateSystemRetentionPolicyRequest)2 CreateSystemRetentionPolicyResponse (com.zimbra.soap.admin.message.CreateSystemRetentionPolicyResponse)2 DeleteSystemRetentionPolicyRequest (com.zimbra.soap.admin.message.DeleteSystemRetentionPolicyRequest)2 DeleteSystemRetentionPolicyResponse (com.zimbra.soap.admin.message.DeleteSystemRetentionPolicyResponse)2 ModifySystemRetentionPolicyRequest (com.zimbra.soap.admin.message.ModifySystemRetentionPolicyRequest)2 ModifySystemRetentionPolicyResponse (com.zimbra.soap.admin.message.ModifySystemRetentionPolicyResponse)2