Search in sources :

Example 21 with Element

use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.

the class ZMailbox method iCalReply.

/**
     * Sends an iCalendar REPLY object
     * @param ical iCalendar data
     * @throws ServiceException on error
     */
public void iCalReply(String ical, String sender) throws ServiceException {
    Element req = newRequestElement(MailConstants.ICAL_REPLY_REQUEST);
    Element icalElem = req.addUniqueElement(MailConstants.E_CAL_ICAL);
    icalElem.setText(ical);
    if (sender != null) {
        icalElem.addAttribute(MailConstants.E_CAL_ATTENDEE, sender);
    }
    invoke(req);
}
Also used : JSONElement(com.zimbra.common.soap.Element.JSONElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement)

Example 22 with Element

use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.

the class ZMailbox method getAllContacts.

/**
     *
     * @param optFolderId return contacts only in specified folder (null for all folders)
     * @param sortBy sort results (null for no sorting)
     * @param sync if true, return modified date on contacts
     * @return list of contacts
     * @throws ServiceException on error
     * @param attrs specified attrs to return, or null for all.
     */
public List<ZContact> getAllContacts(String optFolderId, ContactSortBy sortBy, boolean sync, List<String> attrs) throws ServiceException {
    Element req = newRequestElement(MailConstants.GET_CONTACTS_REQUEST);
    if (optFolderId != null) {
        req.addAttribute(MailConstants.A_FOLDER, optFolderId);
    }
    if (sortBy != null) {
        req.addAttribute(MailConstants.A_SORTBY, sortBy.name());
    }
    if (sync) {
        req.addAttribute(MailConstants.A_SYNC, sync);
    }
    if (attrs != null) {
        for (String name : attrs) {
            req.addElement(MailConstants.E_ATTRIBUTE).addAttribute(MailConstants.A_ATTRIBUTE_NAME, name);
        }
    }
    Element response = invoke(req);
    List<ZContact> result = new ArrayList<ZContact>();
    for (Element cn : response.listElements(MailConstants.E_CONTACT)) {
        result.add(new ZContact(cn, this));
    }
    return result;
}
Also used : JSONElement(com.zimbra.common.soap.Element.JSONElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) ArrayList(java.util.ArrayList)

Example 23 with Element

use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.

the class ZMailbox method modifyAppointment.

public ZAppointmentResult modifyAppointment(String id, String component, ZDateTime exceptionId, ZOutgoingMessage message, ZInvite invite) throws ServiceException {
    Element req = newRequestElement(MailConstants.MODIFY_APPOINTMENT_REQUEST);
    req.addAttribute(MailConstants.A_ID, id);
    req.addAttribute(MailConstants.E_INVITE_COMPONENT, component);
    Element mEl = getMessageElement(req, message, null);
    Element invEl = invite.toElement(mEl);
    if (exceptionId != null) {
        Element compEl = invEl.getElement(MailConstants.E_INVITE_COMPONENT);
        exceptionId.toElement(MailConstants.E_CAL_EXCEPTION_ID, compEl);
    }
    return new ZAppointmentResult(invoke(req));
}
Also used : JSONElement(com.zimbra.common.soap.Element.JSONElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement)

Example 24 with Element

use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.

the class ZMailbox method getContactsForFolder.

/**
     * Fetch contacts for a given folder or contacts ids
     * @param folderid folder id of the contact folder
     * @param ids comma-separated list of contact ids
     * @param attrs limit attrs returns to given list
     * @param sortBy sort results (null for no sorting)
     * @param sync if true, return modified date on contacts
     * @return list of contacts
     * @throws ServiceException on error
     */
public List<ZContact> getContactsForFolder(String folderid, String ids, ContactSortBy sortBy, boolean sync, List<String> attrs) throws ServiceException {
    Element req = newRequestElement(MailConstants.GET_CONTACTS_REQUEST);
    if (!StringUtil.isNullOrEmpty(folderid)) {
        req.addAttribute(MailConstants.A_FOLDER, folderid);
    }
    if (sortBy != null) {
        req.addAttribute(MailConstants.A_SORTBY, sortBy.name());
    }
    if (sync) {
        req.addAttribute(MailConstants.A_SYNC, sync);
    }
    if (!StringUtil.isNullOrEmpty(ids)) {
        req.addAttribute(MailConstants.A_DEREF_CONTACT_GROUP_MEMBER, true);
        req.addElement(MailConstants.E_CONTACT).addAttribute(MailConstants.A_ID, ids);
    }
    if (attrs != null) {
        for (String name : attrs) {
            req.addElement(MailConstants.E_ATTRIBUTE).addAttribute(MailConstants.A_ATTRIBUTE_NAME, name);
        }
    }
    List<ZContact> result = new ArrayList<ZContact>();
    for (Element cn : invoke(req).listElements(MailConstants.E_CONTACT)) {
        result.add(new ZContact(cn, this));
    }
    return result;
}
Also used : JSONElement(com.zimbra.common.soap.Element.JSONElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) ArrayList(java.util.ArrayList)

Example 25 with Element

use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.

the class ZMailbox method getValidFolderIds.

/**
     * Validates the given set of folder ids.  If a folder id corresponds to a mountpoint
     * that is not accessible, that id is omitted from the returned list.
     */
public synchronized String getValidFolderIds(String ids) throws ServiceException {
    if (StringUtil.isNullOrEmpty(ids)) {
        return "";
    }
    // 1. Separate Local FolderIds and Remote FolderIds
    // sbResult is a list of valid folderIds
    // sbRemote is a list of mountpoints
    Set<String> mountpointIds = new HashSet<String>();
    Set<String> validIds = new HashSet<String>();
    for (String id : ids.split(",")) {
        ZFolder f = getFolderById(id);
        if (f instanceof ZMountpoint) {
            mountpointIds.add(id);
        } else {
            validIds.add(id);
        }
    }
    //2. Send a batch request GetFolderRequest with sbRemote as input
    try {
        Element batch = newRequestElement(ZimbraNamespace.E_BATCH_REQUEST);
        //Element resp;
        for (String id : mountpointIds) {
            Element folderrequest = batch.addElement(MailConstants.GET_FOLDER_REQUEST);
            Element e = folderrequest.addElement(MailConstants.E_FOLDER);
            e.addAttribute(MailConstants.A_FOLDER, id);
        }
        Element resp = mTransport.invoke(batch);
        //3. Parse the response and add valid folderIds to sbResult.
        for (Element e : resp.listElements()) {
            if (e.getName().equals(MailConstants.GET_FOLDER_RESPONSE.getName())) {
                boolean isBrokenMountpoint = e.getElement(MailConstants.E_MOUNT).getAttributeBool(MailConstants.A_BROKEN, false);
                if (!isBrokenMountpoint) {
                    String id = e.getElement(MailConstants.E_MOUNT).getAttribute(MailConstants.A_ID);
                    validIds.add(id);
                }
            }
        }
        return StringUtil.join(",", validIds);
    } catch (IOException e) {
        throw ZClientException.IO_ERROR("invoke " + e.getMessage(), e);
    }
}
Also used : JSONElement(com.zimbra.common.soap.Element.JSONElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

Element (com.zimbra.common.soap.Element)980 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)315 XMLElement (com.zimbra.common.soap.Element.XMLElement)269 Account (com.zimbra.cs.account.Account)220 Test (org.junit.Test)175 JSONElement (com.zimbra.common.soap.Element.JSONElement)167 Provisioning (com.zimbra.cs.account.Provisioning)147 Mailbox (com.zimbra.cs.mailbox.Mailbox)138 ServiceException (com.zimbra.common.service.ServiceException)103 ItemId (com.zimbra.cs.service.util.ItemId)81 ArrayList (java.util.ArrayList)81 OperationContext (com.zimbra.cs.mailbox.OperationContext)80 HashMap (java.util.HashMap)77 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)56 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)54 Server (com.zimbra.cs.account.Server)49 FilterTest (com.zimbra.soap.mail.type.FilterTest)46 IOException (java.io.IOException)45 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)44 XmlElement (javax.xml.bind.annotation.XmlElement)44