use of com.zimbra.soap.admin.type.CosSelector 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);
}
use of com.zimbra.soap.admin.type.CosSelector in project zm-mailbox by Zimbra.
the class GetSystemRetentionPolicy method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
GetSystemRetentionPolicyRequest 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
checkGetRight(entry, zsc, context);
RetentionPolicy rp = RetentionPolicyManager.getInstance().getSystemRetentionPolicy(entry);
GetSystemRetentionPolicyResponse res = new GetSystemRetentionPolicyResponse(rp);
return zsc.jaxbToElement(res);
}
use of com.zimbra.soap.admin.type.CosSelector 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 = 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
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 zsc.jaxbToElement(res);
}
use of com.zimbra.soap.admin.type.CosSelector 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 = 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 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 zsc.jaxbToElement(res);
}
Aggregations