/** * Get list of properties that differs. * * @param oldBean * @param newBean * @return */ public static List<String> getBeanDiffProperties(Object oldBean, Object newBean) { List<String> result = new ArrayList<String>(); Map<String, String> oldMap = getBeanAsMap(oldBean); Map<String, String> newMap = getBeanAsMap(newBean); return getDiffProperties(oldMap, newMap); }
/** * Create update entry from maps. * * @param system * @param user * @param targetType * @param target * @param oldMap * @param newMap * @return */ public static Tapahtuma createUPDATEMaps(String system, String user, String targetType, String target, Map<String, String> oldMap, Map<String, String> newMap) { Tapahtuma t = createUPDATE(system, user, targetType, target); try { Collection<String> changedProperties = SimpleBeanSerializer.getDiffProperties(oldMap, newMap); for (String propertyName : changedProperties) { t.addValueChange(propertyName, oldMap != null ? oldMap.get(propertyName) : null, newMap != null ? newMap.get(propertyName) : null); } } catch (Throwable ex) { t.addValue("DIFF FAILED", ex.toString()); ex.printStackTrace(); } return t; }
/** * Create UPDATE message, tries to generate field change information - best approximaption. * * @param system * @param user * @param targetType * @param target * @param oldObject * @param newObject * @return created event */ public static Tapahtuma createUPDATEBeans(String system, String user, String targetType, String target, Object oldObject, Object newObject) { Tapahtuma t = createUPDATE(system, user, targetType, target); try { Map<String, String> oldMap = SimpleBeanSerializer.getBeanAsMap(oldObject); Map<String, String> newMap = SimpleBeanSerializer.getBeanAsMap(newObject); Collection<String> changedProperties = SimpleBeanSerializer.getDiffProperties(oldMap, newMap); for (String propertyName : changedProperties) { t.addValueChange(propertyName, oldMap.get(propertyName), newMap.get(propertyName)); } } catch (Throwable ex) { t.addValue("SERIALIZATION/DIFF FAILED", ex.toString()); } return t; }