Search in sources :

Example 16 with RetentionPolicy

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

the class Tag method decodeMetadata.

@Override
void decodeMetadata(Metadata meta) throws ServiceException {
    super.decodeMetadata(meta);
    isListed = meta.getBool(Metadata.FN_LISTED, false);
    Metadata rp = meta.getMap(Metadata.FN_RETENTION_POLICY, true);
    if (rp != null) {
        retentionPolicy = RetentionPolicyManager.retentionPolicyFromMetadata(rp, true);
    } else {
        retentionPolicy = new RetentionPolicy();
    }
}
Also used : RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 17 with RetentionPolicy

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

the class RetentionPolicyManager method getCachedSystemPolicy.

private SystemPolicy getCachedSystemPolicy(Entry entry) throws ServiceException {
    SystemPolicy sp;
    synchronized (entry) {
        sp = (SystemPolicy) entry.getCachedData(SYSTEM_POLICY_KEY);
        if (sp == null) {
            String xml;
            if (entry instanceof Config)
                xml = ((Config) entry).getMailPurgeSystemPolicy();
            else if (entry instanceof Cos)
                xml = ((Cos) entry).getMailPurgeSystemPolicy();
            else
                throw ServiceException.UNSUPPORTED();
            sp = new SystemPolicy();
            if (!Strings.isNullOrEmpty(xml)) {
                ZimbraLog.purge.debug("Parsing system retention policy:\n%s", xml);
                try {
                    Element el = Element.parseXML(xml);
                    RetentionPolicy rp = JaxbUtil.elementToJaxb(el, RetentionPolicy.class);
                    for (Policy p : rp.getKeepPolicy()) {
                        assert (p.getId() != null);
                        sp.keep.put(p.getId(), p);
                    }
                    for (Policy p : rp.getPurgePolicy()) {
                        assert (p.getId() != null);
                        sp.purge.put(p.getId(), p);
                    }
                } catch (XmlParseException e) {
                    throw ServiceException.FAILURE("Unable to parse system retention policy.", e);
                }
            }
            entry.setCachedData(SYSTEM_POLICY_KEY, sp);
        }
    }
    return sp;
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Config(com.zimbra.cs.account.Config) Cos(com.zimbra.cs.account.Cos) XMLElement(com.zimbra.common.soap.Element.XMLElement) Element(com.zimbra.common.soap.Element) XmlParseException(com.zimbra.common.soap.XmlParseException) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 18 with RetentionPolicy

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

the class RetentionPolicyManager method toMetadata.

/**
     * Persists retention policy to {@code Metadata}. 
     * @param rp retention policy data
     * @param forMailbox {@code true} if this is mailbox retention policy,
     *     {@code false} if this is system retention policy.  For mailbox
     *     policy, only the id is persisted.
     * @return
     */
public static Metadata toMetadata(RetentionPolicy rp, boolean forMailbox) {
    MetadataList keep = new MetadataList();
    MetadataList purge = new MetadataList();
    for (Policy p : rp.getKeepPolicy()) {
        keep.add(toMetadata(p, forMailbox));
    }
    for (Policy p : rp.getPurgePolicy()) {
        purge.add(toMetadata(p, forMailbox));
    }
    Metadata m = new Metadata();
    m.put(FN_KEEP, keep);
    m.put(FN_PURGE, purge);
    return m;
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 19 with RetentionPolicy

use of com.zimbra.soap.mail.type.RetentionPolicy 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 20 with RetentionPolicy

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

Aggregations

RetentionPolicy (com.zimbra.soap.mail.type.RetentionPolicy)37 Policy (com.zimbra.soap.mail.type.Policy)22 Test (org.junit.Test)15 Config (com.zimbra.cs.account.Config)7 Element (com.zimbra.common.soap.Element)6 Mailbox (com.zimbra.cs.mailbox.Mailbox)6 ServiceException (com.zimbra.common.service.ServiceException)4 Cos (com.zimbra.cs.account.Cos)4 ZFolder (com.zimbra.client.ZFolder)3 ZMailbox (com.zimbra.client.ZMailbox)3 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)3 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)3 Color (com.zimbra.common.mailbox.Color)2 XMLElement (com.zimbra.common.soap.Element.XMLElement)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 Provisioning (com.zimbra.cs.account.Provisioning)2 DbTag (com.zimbra.cs.db.DbTag)2 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)2 OperationContext (com.zimbra.cs.mailbox.OperationContext)2 AlterItemTag (com.zimbra.cs.redolog.op.AlterItemTag)2