/** * Use this method to record value changes for fields in "target" objects. * * @param field * @param oldValue * @param newValue */ public void addValueChange(String field, Serializable oldValue, Serializable newValue) { if (field == null) { throw new IllegalArgumentException("Field cannot be unspesified."); } if (oldValue != null) { addValue(field + "_old", oldValue); } if (newValue != null) { addValue(field + "_new", newValue); } }
/** * 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; }
/** * Create trace message. * * @param system * @param targetType * @param target * @param timeMs * @return created event. */ public static final Tapahtuma createTRACE(String system, String targetType, String target, long timeMs) { Tapahtuma t = createREAD(system, null, targetType, target); t.setType("TRACE"); t.addValue("timeMs", timeMs); return t; }
/** * Receives an event and stores it as "sub event" for the root event. * * @param t */ public static void record(Tapahtuma t) { log.info("record(): {}", t); if (isRecording()) { Tapahtuma root = getAuditRootTapahtuma(); if (t != null) { String key = t.getTargetType() + "[" + t.getTarget() + "]"; root.addValue(key, (Serializable) t.getValues()); } } else { log.warn("NOT RECORDING - AUDIT log MESSAGE DISCARDED. {}", t); } } }