@Test public void shouldProperlyLogEmbeddables() { NotAuditedEmbeddable notAudited = new NotAuditedEmbeddable(42); FirstEmbeddable fe = new FirstEmbeddable(4711, new SimpleBooleanFlagEntity("uuid-2", false), "notAudited"); EntityWithEmbedables entity = new EntityWithEmbedables("uuid-1", "someValue", fe, notAudited); Auditor cut = new Auditor(); SortedMap<String, String> changes = cut.inspectEntity(entity).getAttributes(); assertThat(changes.size(), is(3)); assertThat(changes.get("firstEmbeddable.integer"), is("4711")); assertThat(changes.get("firstEmbeddable.entity"), is("uuid-2")); assertThat(changes.get("someAttribute"), is("someValue")); }
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);  }