@Test public void shouldUseOverriddenValueFormatter() { Auditor auditor = new Auditor(); final Date date1 = AuditLogDateHelper.from(LocalDateTime.of(2016, Month.APRIL, 8, 14, 15)); final Date date2 = AuditLogDateHelper.from(LocalDateTime.of(2016, Month.APRIL, 13, 10, 00)); OverridingFormatterEntity entity = new OverridingFormatterEntity("uuid-1", date1, date2); ValueContainer container = auditor.inspectEntity(entity); final SortedMap<String, String> attributes = container.getAttributes(); assertThat(attributes.size(), is(2)); assertThat(attributes.get(OverridingFormatterEntity.THE_DATE), is("14:15")); assertThat(attributes.get(OverridingFormatterEntity.THE_DATE_WITHOUT_TEMPORAL), is("2016-04-13 10:00:00.000")); }
ValueContainer inspectEntity(HasUuid entity) { DefaultValueContainer result = new DefaultValueContainer(); EntityInspector inspector = new EntityInspector(entity); for (Method currentAttribute : inspector.getAuditedAttributes()) { try { AuditedAttribute auditedAttribute = currentAttribute.getAnnotation(AuditedAttribute.class); AuditedCollection auditedCollection = currentAttribute.getAnnotation(AuditedCollection.class); boolean isCollection = Collection.class.isAssignableFrom(currentAttribute.getReturnType()); if (auditedAttribute != null || !isCollection) { logAttributeChange(result, inspector, currentAttribute, auditedAttribute); } else if (auditedCollection != null || isCollection) { logCollectionChange(result, inspector, currentAttribute, auditedCollection); } } catch (InvocationTargetException | IllegalAccessException e) { throw new AuditlogException(String.format("No changes for entity %s can be detected.", entity.toString()), e); } } return result; }
Auditor implements Serializable { ValueContainer inspectEntity(HasUuid entity) { DefaultValueContainer result = new DefaultValueContainer(); EntityInspector inspector = new EntityInspector(entity); for (Method currentAttribute : inspector.getAuditedAttributes()) { try { AuditedAttribute auditedAttribute = currentAttribute.getAnnotation(AuditedAttribute.class); AuditedCollection auditedCollection = currentAttribute.getAnnotation(AuditedCollection.class); boolean isCollection = Collection.class.isAssignableFrom(currentAttribute.getReturnType()); if (auditedAttribute != null || !isCollection) { logAttributeChange(result, inspector, currentAttribute, auditedAttribute); } else if (auditedCollection != null || isCollection) { logCollectionChange(result, inspector, currentAttribute, auditedCollection); } } catch (InvocationTargetException | IllegalAccessException e) { throw new AuditlogException(String.format("No changes for entity %s can be detected.", entity.toString()), e); } } return result; } }
Auditor implements Serializable { ValueContainer inspectEntity(HasUuid entity) { DefaultValueContainer result = new DefaultValueContainer(); EntityInspector inspector = new EntityInspector(entity); for (Method currentAttribute : inspector.getAuditedAttributes()) { try { AuditedAttribute auditedAttribute = currentAttribute.getAnnotation(AuditedAttribute.class); AuditedCollection auditedCollection = currentAttribute.getAnnotation(AuditedCollection.class); boolean isCollection = Collection.class.isAssignableFrom(currentAttribute.getReturnType()); if (auditedAttribute != null || !isCollection) { logAttributeChange(result, inspector, currentAttribute, auditedAttribute); } else if (auditedCollection != null || isCollection) { logCollectionChange(result, inspector, currentAttribute, auditedCollection); } } catch (InvocationTargetException | IllegalAccessException e) { throw new AuditlogException(String.format("No changes for entity %s can be detected.", entity.toString()), e); } } return result; }  }
Auditor implements Serializable { ValueContainer inspectEntity(HasUuid entity) { DefaultValueContainer result = new DefaultValueContainer(); EntityInspector inspector = new EntityInspector(entity); for (Method currentAttribute : inspector.getAuditedAttributes()) { try { AuditedAttribute auditedAttribute = currentAttribute.getAnnotation(AuditedAttribute.class); AuditedCollection auditedCollection = currentAttribute.getAnnotation(AuditedCollection.class); boolean isCollection = Collection.class.isAssignableFrom(currentAttribute.getReturnType()); if (auditedAttribute != null || !isCollection) { logAttributeChange(result, inspector, currentAttribute, auditedAttribute); } else if (auditedCollection != null || isCollection) { logCollectionChange(result, inspector, currentAttribute, auditedCollection); } } catch (InvocationTargetException | IllegalAccessException e) { throw new AuditlogException(String.format("No changes for entity %s can be detected.", entity.toString()), e); } } return result; }  void register(HasUuid entity); ChangeEvent detectChanges(HasUuid entity); }
Auditor implements Serializable { ValueContainer inspectEntity(HasUuid entity) { DefaultValueContainer result = new DefaultValueContainer(); EntityInspector inspector = new EntityInspector(entity); for (Method currentAttribute : inspector.getAuditedAttributes()) { try { AuditedAttribute auditedAttribute = currentAttribute.getAnnotation(AuditedAttribute.class); AuditedCollection auditedCollection = currentAttribute.getAnnotation(AuditedCollection.class); boolean isCollection = Collection.class.isAssignableFrom(currentAttribute.getReturnType()); if (auditedAttribute != null || !isCollection) { logAttributeChange(result, inspector, currentAttribute, auditedAttribute); } else if (auditedCollection != null || isCollection) { logCollectionChange(result, inspector, currentAttribute, auditedCollection); } } catch (InvocationTargetException | IllegalAccessException e) { throw new AuditlogException(String.format("No changes for entity %s can be detected.", entity.toString()), e); } } return result; }  void register(HasUuid entity); ChangeEvent detectChanges(HasUuid entity);  }