Search in sources :

Example 1 with KeyValuePair

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

the class ZGetInfoResult method getMap.

static Map<String, List<String>> getMap(Element e, String root, String elName) {
    Map<String, List<String>> result = new HashMap<String, List<String>>();
    Element attrsEl = e.getOptionalElement(root);
    if (attrsEl != null) {
        for (KeyValuePair pair : attrsEl.listKeyValuePairs(elName, AccountConstants.A_NAME)) {
            //StringUtil.addToMultiMap(mAttrs, pair.getKey(), pair.getValue());
            String name = pair.getKey();
            List<String> list = result.get(name);
            if (list == null) {
                list = new ArrayList<String>();
                result.put(name, list);
            }
            list.add(pair.getValue());
        }
    }
    return result;
}
Also used : KeyValuePair(com.zimbra.common.soap.Element.KeyValuePair) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with KeyValuePair

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

the class GetAllConfigTest method unmarshallGetAllConfigResponseTest.

@Test
public void unmarshallGetAllConfigResponseTest() throws Exception {
    InputStream is = getClass().getResourceAsStream("GetAllConfigResponse.xml");
    Element elem = Element.parseXML(is);
    List<KeyValuePair> kvps = elem.listKeyValuePairs();
    is.close();
    is = getClass().getResourceAsStream("GetAllConfigResponse.xml");
    GetAllConfigResponse resp = (GetAllConfigResponse) unmarshaller.unmarshal(is);
    Assert.assertNotNull("Response", resp);
    List<Attr> attrs = resp.getAttrs();
    LOG.info("unmarshallGetAllConfigResponseTest:KVPS from elem=" + kvps.size() + " from jaxb=" + attrs.size());
    Assert.assertTrue("Have some attrs", attrs.size() > 20);
    Assert.assertEquals("Number of attrs from elem and from jaxb agree", kvps.size(), attrs.size());
}
Also used : KeyValuePair(com.zimbra.common.soap.Element.KeyValuePair) GetAllConfigResponse(com.zimbra.soap.admin.message.GetAllConfigResponse) InputStream(java.io.InputStream) Element(com.zimbra.common.soap.Element) Attr(com.zimbra.soap.admin.type.Attr) Test(org.junit.Test)

Example 3 with KeyValuePair

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

the class AccountService method getAttrs.

/**
     * @param request
     * @return
     * @throws ServiceException
     */
public static Map<String, Object> getAttrs(Element request, boolean ignoreEmptyValues, String nameAttr) throws ServiceException {
    Map<String, Object> result = new HashMap<String, Object>();
    for (KeyValuePair pair : request.listKeyValuePairs(AdminConstants.E_A, nameAttr)) {
        String name = pair.getKey();
        String value = pair.getValue();
        if (!ignoreEmptyValues || (value != null && value.length() > 0))
            StringUtil.addToMultiMap(result, name, value);
    }
    return result;
}
Also used : KeyValuePair(com.zimbra.common.soap.Element.KeyValuePair) HashMap(java.util.HashMap)

Example 4 with KeyValuePair

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

the class ModifyPrefs method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(zsc);
    if (!canModifyOptions(zsc, account))
        throw ServiceException.PERM_DENIED("can not modify options");
    HashMap<String, Object> prefs = new HashMap<String, Object>();
    Map<String, Set<String>> name2uniqueAttrValues = new HashMap<String, Set<String>>();
    for (KeyValuePair kvp : request.listKeyValuePairs(AccountConstants.E_PREF, AccountConstants.A_NAME)) {
        String name = kvp.getKey(), value = kvp.getValue();
        char ch = name.length() > 0 ? name.charAt(0) : 0;
        int offset = ch == '+' || ch == '-' ? 1 : 0;
        if (!name.startsWith(PREF_PREFIX, offset))
            throw ServiceException.INVALID_REQUEST("pref name must start with " + PREF_PREFIX, null);
        AttributeInfo attrInfo = AttributeManager.getInstance().getAttributeInfo(name.substring(offset));
        if (attrInfo == null) {
            throw ServiceException.INVALID_REQUEST("no such attribute: " + name, null);
        }
        if (attrInfo.isCaseInsensitive()) {
            String valueLowerCase = Strings.nullToEmpty(value).toLowerCase();
            if (name2uniqueAttrValues.get(name) == null) {
                Set<String> set = new HashSet<String>();
                set.add(valueLowerCase);
                name2uniqueAttrValues.put(name, set);
                StringUtil.addToMultiMap(prefs, name, value);
            } else {
                Set<String> set = name2uniqueAttrValues.get(name);
                if (set.add(valueLowerCase)) {
                    StringUtil.addToMultiMap(prefs, name, value);
                }
            }
        } else {
            StringUtil.addToMultiMap(prefs, name, value);
        }
    }
    if (prefs.containsKey(Provisioning.A_zimbraPrefMailForwardingAddress)) {
        if (!account.getBooleanAttr(Provisioning.A_zimbraFeatureMailForwardingEnabled, false))
            throw ServiceException.PERM_DENIED("forwarding not enabled");
    }
    // call modifyAttrs and pass true to checkImmutable
    Provisioning.getInstance().modifyAttrs(account, prefs, true, zsc.getAuthToken());
    Element response = zsc.createElement(AccountConstants.MODIFY_PREFS_RESPONSE);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) Set(java.util.Set) HashSet(java.util.HashSet) KeyValuePair(com.zimbra.common.soap.Element.KeyValuePair) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) AttributeInfo(com.zimbra.cs.account.AttributeInfo) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) HashSet(java.util.HashSet)

Example 5 with KeyValuePair

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

the class ToXML method encodeAttr.

public static void encodeAttr(Element parent, String key, String value, String eltname, String attrname, IDNType idnType, boolean allowed) {
    KeyValuePair kvPair;
    if (allowed) {
        kvPair = parent.addKeyValuePair(key, IDNUtil.toUnicode(value, idnType), eltname, attrname);
    } else {
        kvPair = parent.addKeyValuePair(key, "", eltname, attrname);
        kvPair.addAttribute(AccountConstants.A_PERM_DENIED, true);
    }
}
Also used : KeyValuePair(com.zimbra.common.soap.Element.KeyValuePair)

Aggregations

KeyValuePair (com.zimbra.common.soap.Element.KeyValuePair)5 Element (com.zimbra.common.soap.Element)3 HashMap (java.util.HashMap)3 Account (com.zimbra.cs.account.Account)1 AttributeInfo (com.zimbra.cs.account.AttributeInfo)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 GetAllConfigResponse (com.zimbra.soap.admin.message.GetAllConfigResponse)1 Attr (com.zimbra.soap.admin.type.Attr)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Test (org.junit.Test)1