Search in sources :

Example 1 with ExportContactsResponse

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

the class ExportContacts 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);
    ExportContactsRequest req = JaxbUtil.elementToJaxb(request);
    String folder = req.getFolderId();
    ItemId iidFolder = folder == null ? null : new ItemId(folder, zsc);
    String ct = req.getContentType();
    if (ct == null)
        throw ServiceException.INVALID_REQUEST("content type missing", null);
    if (!ct.equals("csv"))
        throw ServiceException.INVALID_REQUEST("unsupported content type: " + ct, null);
    String format = req.getCsvFormat();
    String locale = req.getCsvLocale();
    String separator = req.getCsvDelimiter();
    Character sepChar = null;
    if ((separator != null) && (separator.length() > 0))
        sepChar = separator.charAt(0);
    List<Contact> contacts = mbox.getContactList(octxt, iidFolder != null ? iidFolder.getId() : -1);
    StringBuilder sb = new StringBuilder();
    if (contacts == null)
        contacts = new ArrayList<Contact>();
    try {
        ContactCSV contactCSV = new ContactCSV(mbox, octxt);
        contactCSV.toCSV(format, locale, sepChar, contacts.iterator(), sb);
    } catch (ContactCSV.ParseException e) {
        throw MailServiceException.UNABLE_TO_EXPORT_CONTACTS(e.getMessage(), e);
    }
    ExportContactsResponse resp = new ExportContactsResponse(sb.toString());
    return zsc.jaxbToElement(resp);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) ContactCSV(com.zimbra.cs.service.formatter.ContactCSV) ExportContactsResponse(com.zimbra.soap.mail.message.ExportContactsResponse) ArrayList(java.util.ArrayList) ExportContactsRequest(com.zimbra.soap.mail.message.ExportContactsRequest) ItemId(com.zimbra.cs.service.util.ItemId) Contact(com.zimbra.cs.mailbox.Contact) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext)

Aggregations

Contact (com.zimbra.cs.mailbox.Contact)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 ContactCSV (com.zimbra.cs.service.formatter.ContactCSV)1 ItemId (com.zimbra.cs.service.util.ItemId)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 ExportContactsRequest (com.zimbra.soap.mail.message.ExportContactsRequest)1 ExportContactsResponse (com.zimbra.soap.mail.message.ExportContactsResponse)1 ArrayList (java.util.ArrayList)1