Search in sources :

Example 16 with Policy

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

the class SetRetentionPolicy method serializeData.

@Override
protected void serializeData(RedoLogOutput out) throws IOException {
    List<Policy> keepPolicy = retentionPolicy.getKeepPolicy();
    List<Policy> purgePolicy = retentionPolicy.getPurgePolicy();
    out.writeByte(type.toByte());
    out.writeInt(itemId);
    out.writeInt(keepPolicy.size());
    for (Policy policy : keepPolicy) {
        out.writeUTF(policy.getId());
        out.writeUTF(policy.getLifetime());
    }
    out.writeInt(purgePolicy.size());
    for (Policy policy : purgePolicy) {
        out.writeUTF(policy.getId());
        out.writeUTF(policy.getLifetime());
    }
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 17 with Policy

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

the class SetRetentionPolicy method deserializeData.

@Override
protected void deserializeData(RedoLogInput in) throws IOException {
    type = MailItem.Type.of(in.readByte());
    if (type != MailItem.Type.FOLDER && type != MailItem.Type.TAG) {
        throw new IOException("Unexpected item type: " + type);
    }
    itemId = in.readInt();
    int size = in.readInt();
    List<Policy> keep = readPolicyList(in, size);
    size = in.readInt();
    List<Policy> purge = readPolicyList(in, size);
    retentionPolicy = new RetentionPolicy(keep, purge);
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) IOException(java.io.IOException) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 18 with Policy

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

the class SetRetentionPolicy method readPolicyList.

/**
     * Reads a list of {@code RetentionPolicy} objects from input.
     */
private List<Policy> readPolicyList(RedoLogInput in, int size) throws IOException {
    List<Policy> list = Lists.newArrayList();
    for (int i = 1; i <= size; i++) {
        String id = in.readUTF();
        String lifetime = in.readUTF();
        Policy p;
        if (id != null) {
            p = Policy.newSystemPolicy(id);
        } else {
            p = Policy.newUserPolicy(lifetime);
        }
        list.add(p);
    }
    return list;
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 19 with Policy

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

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

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