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