Map<String, Object> getAuditLogItem(Object current) { DynaBean currentDynaBean = new WrapDynaBean(current); return propertiesToTrack .stream() .map( name -> { return CollectionUtils.entry(name, currentDynaBean.get(name)); }) .collect(CollectionUtils.nullSafeEntriesToMap()); }
Map<String, Object> getUpdatedAuditLogItem(Object current, Object updated) { DynaBean currentDynaBean = new WrapDynaBean(current); DynaBean updatedDynaBean = new WrapDynaBean(updated); return propertiesToTrack .stream() .map( name -> { Object currentValue = currentDynaBean.get(name); Object newValue = updatedDynaBean.get(name); if (areValuesEqual(currentValue, newValue)) { return CollectionUtils.entry(name, currentValue); } else { Map<String, Object> diffs = Stream.of( CollectionUtils.entry("old", currentValue), CollectionUtils.entry("new", newValue)) .collect(CollectionUtils.nullSafeEntriesToMap()); return CollectionUtils.entry(name, (Object) diffs); } }) .collect(CollectionUtils.nullSafeEntriesToMap()); }