use of com.zimbra.cs.mailbox.RetentionPolicyManager 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 = zsc.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 zsc.jaxbToElement(res);
}
Aggregations