Search in sources :

Example 1 with AttributeConverter

use of com.zimbra.cs.ephemeral.migrate.AttributeConverter in project zm-mailbox by Zimbra.

the class LdapProvisioning method modifyEphemeralAttrs.

private void modifyEphemeralAttrs(Entry entry, Map<String, Object> attrs, Map<String, AttributeInfo> ephemeralAttrMap) throws ServiceException {
    EphemeralLocation location = new LdapEntryLocation(entry);
    EphemeralStore store = EphemeralStore.getFactory().getStore();
    for (Map.Entry<String, Object> e : attrs.entrySet()) {
        String key = e.getKey();
        Object value = e.getValue();
        boolean doAdd = key.charAt(0) == '+';
        boolean doRemove = key.charAt(0) == '-';
        if (doAdd || doRemove) {
            key = key.substring(1);
            if (attrs.containsKey(key))
                throw ServiceException.INVALID_REQUEST("can't mix +attrName/-attrName with attrName", null);
        }
        AttributeInfo ai = ephemeralAttrMap.get(key.toLowerCase());
        AttributeConverter converter = null;
        if (ai == null) {
            continue;
        }
        if (ai.isDynamic()) {
            converter = AttributeMigration.getConverter(key);
            if (converter == null) {
                ZimbraLog.ephemeral.warn("Dynamic ephemeral attribute %s has no registered AttributeConverter, so cannot be modified with modifyAttrs", key);
                continue;
            }
        }
        if (value instanceof Collection) {
            Collection values = (Collection) value;
            if (values.size() == 0) {
                ZimbraLog.ephemeral.warn("Ephemeral attribute %s doesn't support deletion by key; only deletion by key+value is supported", key);
                continue;
            } else {
                for (Object v : values) {
                    if (v == null) {
                        continue;
                    }
                    String s = v.toString();
                    handleEphemeralAttrChange(store, key, s, location, ai, converter, doAdd, doRemove);
                }
            }
        } else if (value instanceof Map) {
            throw ServiceException.FAILURE("Map is not a supported value type", null);
        } else if (value != null) {
            String s = value.toString();
            handleEphemeralAttrChange(store, key, s, location, ai, converter, doAdd, doRemove);
        } else {
            ZimbraLog.ephemeral.warn("Ephemeral attribute %s doesn't support deletion by key; only deletion by key+value is supported", key);
        }
    }
}
Also used : LdapEntryLocation(com.zimbra.cs.ephemeral.LdapEntryLocation) AttributeInfo(com.zimbra.cs.account.AttributeInfo) AttributeConverter(com.zimbra.cs.ephemeral.migrate.AttributeConverter) EphemeralLocation(com.zimbra.cs.ephemeral.EphemeralLocation) Collection(java.util.Collection) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) LdapEphemeralStore(com.zimbra.cs.ephemeral.LdapEphemeralStore)

Aggregations

AttributeInfo (com.zimbra.cs.account.AttributeInfo)1 EphemeralLocation (com.zimbra.cs.ephemeral.EphemeralLocation)1 EphemeralStore (com.zimbra.cs.ephemeral.EphemeralStore)1 LdapEntryLocation (com.zimbra.cs.ephemeral.LdapEntryLocation)1 LdapEphemeralStore (com.zimbra.cs.ephemeral.LdapEphemeralStore)1 AttributeConverter (com.zimbra.cs.ephemeral.migrate.AttributeConverter)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1