Search in sources :

Example 16 with Element

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

the class SoapProvisioning method getAllDataSources.

@Override
public List<DataSource> getAllDataSources(Account account) throws ServiceException {
    List<DataSource> result = new ArrayList<DataSource>();
    XMLElement req = new XMLElement(AdminConstants.GET_DATA_SOURCES_REQUEST);
    req.addElement(AdminConstants.E_ID).setText(account.getId());
    Element resp = invoke(req);
    for (Element dataSource : resp.listElements(AccountConstants.E_DATA_SOURCE)) {
        result.add(new SoapDataSource(account, dataSource, this));
    }
    return result;
}
Also used : Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) ArrayList(java.util.ArrayList) XMLElement(com.zimbra.common.soap.Element.XMLElement) DataSource(com.zimbra.cs.account.DataSource)

Example 17 with Element

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

the class SoapProvisioning method deleteDataSource.

@Override
public void deleteDataSource(Account account, String dataSourceId) throws ServiceException {
    XMLElement req = new XMLElement(AdminConstants.DELETE_DATA_SOURCE_REQUEST);
    req.addElement(AdminConstants.E_ID).setText(account.getId());
    Element ds = req.addElement(AccountConstants.E_DATA_SOURCE);
    ds.addAttribute(AccountConstants.A_ID, dataSourceId);
    invoke(req);
}
Also used : Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) XMLElement(com.zimbra.common.soap.Element.XMLElement)

Example 18 with Element

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

the class SoapProvisioning method addAttrElements.

public static void addAttrElements(Element req, Map<String, ? extends Object> attrs) throws ServiceException {
    if (attrs == null)
        return;
    for (Entry<String, ? extends Object> entry : attrs.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (value instanceof String) {
            Element a = req.addElement(AdminConstants.E_A);
            a.addAttribute(AdminConstants.A_N, key);
            a.setText((String) value);
        } else if (value instanceof String[]) {
            String[] values = (String[]) value;
            if (values.length == 0) {
                // an empty array == removing the attr
                Element a = req.addElement(AdminConstants.E_A);
                a.addAttribute(AdminConstants.A_N, key);
            } else {
                for (String v : values) {
                    Element a = req.addElement(AdminConstants.E_A);
                    a.addAttribute(AdminConstants.A_N, key);
                    a.setText(v);
                }
            }
        } else if (value == null) {
            Element a = req.addElement(AdminConstants.E_A);
            a.addAttribute(AdminConstants.A_N, key);
        } else {
            throw ZClientException.CLIENT_ERROR("invalid attr type: " + key + " " + value.getClass().getName(), null);
        }
    }
}
Also used : Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement)

Example 19 with Element

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

the class SoapServer method reload.

public void reload(SoapProvisioning prov) throws ServiceException {
    XMLElement req = new XMLElement(AdminConstants.GET_SERVER_REQUEST);
    Element a = req.addElement(AdminConstants.E_SERVER);
    a.setText(getId());
    a.addAttribute(AdminConstants.A_BY, Key.ServerBy.id.name());
    setAttrs(SoapProvisioning.getAttrs(prov.invoke(req).getElement(AdminConstants.E_SERVER)));
}
Also used : XMLElement(com.zimbra.common.soap.Element.XMLElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement)

Example 20 with Element

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

the class SoapProvisioning method autoCompleteGal.

@Override
public SearchGalResult autoCompleteGal(Domain d, String query, GalSearchType type, int limit, GalContact.Visitor visitor) throws ServiceException {
    String typeStr = type == null ? GalSearchType.all.name() : type.name();
    XMLElement req = new XMLElement(AdminConstants.AUTO_COMPLETE_GAL_REQUEST);
    req.addElement(AdminConstants.E_NAME).setText(query);
    req.addAttribute(AdminConstants.A_DOMAIN, d.getName());
    req.addAttribute(AdminConstants.A_TYPE, typeStr);
    req.addAttribute(AdminConstants.A_LIMIT, limit);
    Element resp = invoke(req);
    SearchGalResult result = SearchGalResult.newSearchGalResult(visitor);
    result.setHadMore(resp.getAttributeBool(AdminConstants.A_MORE, false));
    result.setTokenizeKey(resp.getAttribute(AccountConstants.A_TOKENIZE_KEY, null));
    for (Element e : resp.listElements(AdminConstants.E_CN)) {
        result.addMatch(new GalContact(e.getAttribute(AdminConstants.A_ID), getAttrs(e)));
    }
    return result;
}
Also used : GalContact(com.zimbra.cs.account.GalContact) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) XMLElement(com.zimbra.common.soap.Element.XMLElement)

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