use of com.zimbra.soap.mail.type.Policy in project zm-mailbox by Zimbra.
the class RetentionPolicyManager method deleteSystemPolicy.
/**
* Deletes the system policy with the given id.
* @return {@code true} if the policy was successfully deleted, {@code false}
* if no policy exists with the given id
*/
public boolean deleteSystemPolicy(Entry entry, String id) throws ServiceException {
synchronized (entry) {
SystemPolicy sp = getCachedSystemPolicy(entry);
Policy p = sp.keep.remove(id);
if (p == null) {
p = sp.purge.remove(id);
}
if (p != null) {
saveSystemPolicy(entry, new RetentionPolicy(sp.keep.values(), sp.purge.values()));
return true;
}
}
return false;
}
use of com.zimbra.soap.mail.type.Policy in project zm-mailbox by Zimbra.
the class ToXML method encodePolicyList.
private static void encodePolicyList(Element parent, List<Policy> list) {
if (list != null) {
for (Policy p : list) {
Element elem = parent.addElement(MailConstants.E_POLICY);
elem.addAttribute(MailConstants.A_ID, p.getId());
elem.addAttribute(MailConstants.A_NAME, p.getName());
elem.addAttribute(MailConstants.A_LIFETIME, p.getLifetime());
elem.addAttribute(MailConstants.A_RETENTION_POLICY_TYPE, p.getType().toString());
}
}
}
use of com.zimbra.soap.mail.type.Policy in project zm-mailbox by Zimbra.
the class DeleteSystemRetentionPolicy method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
DeleteSystemRetentionPolicyRequest 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 policy = req.getPolicy();
if (policy == null) {
throw ServiceException.INVALID_REQUEST("policy not specified", null);
}
String id = policy.getId();
if (id == null) {
throw ServiceException.INVALID_REQUEST("Policy id not specified", null);
}
boolean success = RetentionPolicyManager.getInstance().deleteSystemPolicy(entry, id);
if (!success) {
throw ServiceException.INVALID_REQUEST("Could not find policy with id " + id, null);
}
DeleteSystemRetentionPolicyResponse res = new DeleteSystemRetentionPolicyResponse();
return JaxbUtil.jaxbToElement(res, zsc.getResponseProtocol().getFactory());
}
Aggregations