use of com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAction in project zm-mailbox by Zimbra.
the class MailQueueAction method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
Element serverElem = request.getElement(AdminConstants.E_SERVER);
String serverName = serverElem.getAttribute(AdminConstants.A_NAME);
Server server = prov.get(Key.ServerBy.name, serverName);
if (server == null) {
throw ServiceException.INVALID_REQUEST("server with name " + serverName + " could not be found", null);
}
checkRight(zsc, context, server, Admin.R_manageMailQueue);
Element queueElem = serverElem.getElement(AdminConstants.E_QUEUE);
String queueName = queueElem.getAttribute(AdminConstants.A_NAME);
RemoteMailQueue rmq = RemoteMailQueue.getRemoteMailQueue(server, queueName, false);
Element actionElem = queueElem.getElement(AdminConstants.E_ACTION);
String op = actionElem.getAttribute(AdminConstants.A_OP);
QueueAction action = QueueAction.valueOf(op);
if (action == null) {
throw ServiceException.INVALID_REQUEST("bad " + AdminConstants.A_OP + ":" + op, null);
}
String by = actionElem.getAttribute(AdminConstants.A_BY);
String[] ids;
if (by.equals(AdminConstants.BY_ID)) {
ids = actionElem.getText().split(",");
} else if (by.equals(AdminConstants.BY_QUERY)) {
Element queryElem = actionElem.getElement(AdminConstants.E_QUERY);
Query query = GetMailQueue.buildLuceneQuery(queryElem);
RemoteMailQueue.SearchResult sr = rmq.search(query, 0, Integer.MAX_VALUE);
ids = new String[sr.qitems.size()];
int i = 0;
for (Map<QueueAttr, String> qitem : sr.qitems) {
ids[i++] = qitem.get(QueueAttr.id);
}
} else {
throw ServiceException.INVALID_REQUEST("bad " + AdminConstants.A_BY + ": " + by, null);
}
rmq.action(server, action, ids);
Element response = zsc.createElement(AdminConstants.MAIL_QUEUE_ACTION_RESPONSE);
return response;
}
Aggregations