Search in sources :

Example 1 with SummaryItem

use of com.zimbra.cs.rmgmt.RemoteMailQueue.SummaryItem in project zm-mailbox by Zimbra.

the class GetMailQueue method handle.

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);
    boolean scan = queueElem.getAttributeBool(AdminConstants.A_SCAN, false);
    long waitMillis = (queueElem.getAttributeLong(AdminConstants.A_WAIT, MAIL_QUEUE_SCAN_DEFUALT_WAIT_SECONDS)) * 1000;
    Element queryElem = queueElem.getElement(AdminConstants.E_QUERY);
    int offset = (int) queryElem.getAttributeLong(AdminConstants.A_OFFSET, 0);
    int limit = (int) queryElem.getAttributeLong(AdminConstants.A_LIMIT, MAIL_QUEUE_QUERY_DEFAULT_LIMIT);
    Query query = buildLuceneQuery(queryElem);
    RemoteMailQueue rmq = RemoteMailQueue.getRemoteMailQueue(server, queueName, scan);
    boolean stillScanning = rmq.waitForScan(waitMillis);
    RemoteMailQueue.SearchResult sr = rmq.search(query, offset, limit);
    Element response = zsc.createElement(AdminConstants.GET_MAIL_QUEUE_RESPONSE);
    serverElem = response.addElement(AdminConstants.E_SERVER);
    serverElem.addAttribute(AdminConstants.A_NAME, serverName);
    queueElem = serverElem.addElement(AdminConstants.E_QUEUE);
    queueElem.addAttribute(AdminConstants.A_NAME, queueName);
    queueElem.addAttribute(AdminConstants.A_TIME, rmq.getScanTime());
    queueElem.addAttribute(AdminConstants.A_SCAN, stillScanning);
    queueElem.addAttribute(AdminConstants.A_TOTAL, rmq.getNumMessages());
    queueElem.addAttribute(AdminConstants.A_MORE, ((offset + limit) < sr.hits));
    for (QueueAttr attr : sr.sitems.keySet()) {
        List<SummaryItem> slist = sr.sitems.get(attr);
        Collections.sort(slist);
        Element qsElem = queueElem.addElement(AdminConstants.A_QUEUE_SUMMARY);
        qsElem.addAttribute(AdminConstants.A_TYPE, attr.toString());
        int i = 0;
        for (SummaryItem sitem : slist) {
            i++;
            if (i > MAIL_QUEUE_SUMMARY_CUTOFF) {
                break;
            }
            Element qsiElem = qsElem.addElement(AdminConstants.A_QUEUE_SUMMARY_ITEM);
            qsiElem.addAttribute(AdminConstants.A_N, sitem.count());
            qsiElem.addAttribute(AdminConstants.A_T, sitem.term());
        }
    }
    for (Map<QueueAttr, String> qitem : sr.qitems) {
        Element qiElem = queueElem.addElement(AdminConstants.A_QUEUE_ITEM);
        for (QueueAttr attr : qitem.keySet()) {
            qiElem.addAttribute(attr.toString(), qitem.get(attr));
        }
    }
    return response;
}
Also used : Server(com.zimbra.cs.account.Server) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) SummaryItem(com.zimbra.cs.rmgmt.RemoteMailQueue.SummaryItem) RemoteMailQueue(com.zimbra.cs.rmgmt.RemoteMailQueue) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) QueueAttr(com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAttr)

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 QueueAttr (com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAttr)1 SummaryItem (com.zimbra.cs.rmgmt.RemoteMailQueue.SummaryItem)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 Query (org.apache.lucene.search.Query)1 TermQuery (org.apache.lucene.search.TermQuery)1