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();
}
}
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;
}
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;
}
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);
}
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;
}
Aggregations