Search in sources :

Example 1 with QueueAction

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;
}
Also used : Server(com.zimbra.cs.account.Server) RemoteMailQueue(com.zimbra.cs.rmgmt.RemoteMailQueue) Query(org.apache.lucene.search.Query) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) QueueAction(com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAction) Map(java.util.Map) Provisioning(com.zimbra.cs.account.Provisioning)

Aggregations

Element (com.zimbra.common.soap.Element)1 Provisioning (com.zimbra.cs.account.Provisioning)1 Server (com.zimbra.cs.account.Server)1 RemoteMailQueue (com.zimbra.cs.rmgmt.RemoteMailQueue)1 QueueAction (com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAction)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 Map (java.util.Map)1 Query (org.apache.lucene.search.Query)1