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;
}
Aggregations