Search in sources :

Example 1 with SearchActionRequest

use of com.zimbra.soap.mail.message.SearchActionRequest in project zm-mailbox by Zimbra.

the class SearchAction method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    SearchActionRequest req = zsc.elementToJaxb(request);
    SearchRequest searchRequest = req.getSearchRequest();
    Account acct = mbox.getAccount();
    Server server = Provisioning.getInstance().getServer(acct);
    String url = URLUtil.getSoapURL(server, false);
    com.zimbra.soap.mail.message.SearchResponse resp = null;
    Element searchResponse;
    SoapHttpTransport transport = new SoapHttpTransport(url);
    transport.setTargetAcctId(acct.getId());
    try {
        transport.setAuthToken(octxt.getAuthToken().getEncoded());
        searchResponse = transport.invokeWithoutSession(JaxbUtil.jaxbToElement(searchRequest));
        resp = (com.zimbra.soap.mail.message.SearchResponse) JaxbUtil.elementToJaxb(searchResponse);
        List<SearchHit> searchHits = resp.getSearchHits();
        BulkAction action = req.getBulkAction();
        performAction(action, searchRequest, searchHits, mbox, octxt);
    } catch (AuthTokenException | IOException | HttpException e) {
        throw ServiceException.FAILURE("Failed to execute search request", e);
    }
    SearchActionResponse searchActionResponse = new SearchActionResponse();
    return zsc.jaxbToElement(searchActionResponse);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) Account(com.zimbra.cs.account.Account) Server(com.zimbra.cs.account.Server) SearchHit(com.zimbra.soap.type.SearchHit) Element(com.zimbra.common.soap.Element) IOException(java.io.IOException) BulkAction(com.zimbra.soap.mail.type.BulkAction) SearchActionRequest(com.zimbra.soap.mail.message.SearchActionRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) AuthTokenException(com.zimbra.cs.account.AuthTokenException) HttpException(org.apache.http.HttpException) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) SearchActionResponse(com.zimbra.soap.mail.message.SearchActionResponse)

Aggregations

Element (com.zimbra.common.soap.Element)1 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)1 Account (com.zimbra.cs.account.Account)1 AuthTokenException (com.zimbra.cs.account.AuthTokenException)1 Server (com.zimbra.cs.account.Server)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 SearchActionRequest (com.zimbra.soap.mail.message.SearchActionRequest)1 SearchActionResponse (com.zimbra.soap.mail.message.SearchActionResponse)1 SearchRequest (com.zimbra.soap.mail.message.SearchRequest)1 BulkAction (com.zimbra.soap.mail.type.BulkAction)1 SearchHit (com.zimbra.soap.type.SearchHit)1 IOException (java.io.IOException)1 HttpException (org.apache.http.HttpException)1