Search in sources :

Example 21 with MappingException

use of org.gluu.site.ldap.persistence.exception.MappingException in project oxCore by GluuFederation.

the class LdapEntryManager method groupListByPropertiesImpl.

private <T> Map<T, List<T>> groupListByPropertiesImpl(Class<T> entryClass, List<T> entries, boolean caseSensetive, Getter[] groupPropertyGetters, Setter[] groupPropertySetters, Getter[] sumProperyGetters, Setter[] sumPropertySetter) {
    Map<String, T> keys = new HashMap<String, T>();
    Map<T, List<T>> groups = new IdentityHashMap<T, List<T>>();
    for (T entry : entries) {
        String key = getEntryKey(entry, caseSensetive, groupPropertyGetters);
        T entryKey = keys.get(key);
        if (entryKey == null) {
            try {
                entryKey = ReflectHelper.createObjectByDefaultConstructor(entryClass);
            } catch (Exception ex) {
                throw new MappingException(String.format("Entry %s should has default constructor", entryClass), ex);
            }
            try {
                ReflectHelper.copyObjectPropertyValues(entry, entryKey, groupPropertyGetters, groupPropertySetters);
            } catch (Exception ex) {
                throw new MappingException("Failed to set values in group Entry", ex);
            }
            keys.put(key, entryKey);
        }
        List<T> groupValues = groups.get(entryKey);
        if (groupValues == null) {
            groupValues = new ArrayList<T>();
            groups.put(entryKey, groupValues);
        }
        try {
            if (sumProperyGetters != null) {
                ReflectHelper.sumObjectPropertyValues(entryKey, entry, sumProperyGetters, sumPropertySetter);
            }
        } catch (Exception ex) {
            throw new MappingException("Failed to sum values in group Entry", ex);
        }
        groupValues.add(entry);
    }
    return groups;
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) EmptyEntryPersistenceException(org.gluu.site.ldap.persistence.exception.EmptyEntryPersistenceException) MappingException(org.gluu.site.ldap.persistence.exception.MappingException) AuthenticationException(org.gluu.site.ldap.persistence.exception.AuthenticationException) InvalidArgumentException(org.gluu.site.ldap.persistence.exception.InvalidArgumentException) ParseException(java.text.ParseException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) ConnectionException(org.gluu.site.ldap.exception.ConnectionException) MappingException(org.gluu.site.ldap.persistence.exception.MappingException)

Aggregations

MappingException (org.gluu.site.ldap.persistence.exception.MappingException)21 LdapJsonObject (org.gluu.site.ldap.persistence.annotation.LdapJsonObject)10 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)9 EmptyEntryPersistenceException (org.gluu.site.ldap.persistence.exception.EmptyEntryPersistenceException)6 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)5 Annotation (java.lang.annotation.Annotation)5 ParseException (java.text.ParseException)5 ConnectionException (org.gluu.site.ldap.exception.ConnectionException)5 AuthenticationException (org.gluu.site.ldap.persistence.exception.AuthenticationException)5 InvalidArgumentException (org.gluu.site.ldap.persistence.exception.InvalidArgumentException)5 LdapAttributesList (org.gluu.site.ldap.persistence.annotation.LdapAttributesList)4 Getter (org.gluu.site.ldap.persistence.property.Getter)4 LdapAttribute (org.gluu.site.ldap.persistence.annotation.LdapAttribute)3 LdapEnum (org.gluu.site.ldap.persistence.annotation.LdapEnum)2 Setter (org.gluu.site.ldap.persistence.property.Setter)2 SimplePagedResultsControl (com.unboundid.ldap.sdk.controls.SimplePagedResultsControl)1 Method (java.lang.reflect.Method)1 AttributeModificationType (org.gluu.site.ldap.persistence.AttributeDataModification.AttributeModificationType)1 LdapEntry (org.gluu.site.ldap.persistence.annotation.LdapEntry)1