public Map<String, String> getAttrs(Map<String, String> defaultValue) throws ServiceException { Map<String, String> attrs = null; for (KeyValuePair pair : mContactEl.listKeyValuePairs(MailConstants.E_ATTRIBUTE, MailConstants.A_ATTRIBUTE_NAME)) { if (attrs == null) attrs = new HashMap<String, String>(); attrs.put(pair.getKey(), pair.getValue()); } return attrs != null ? attrs : defaultValue; }
/** * @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; }
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; }