Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public class AuditService {
private final Javers javers;
public AuditService(Javers javers) {
this.javers = javers;
public <T> void commit(String author, T currentVersion) {
javers.commit(author, currentVersion);
public <T> List<VersionDTO<T>> getVersions(T currentVersion, Object id) {
List<Shadow<T>> ds = getShadows(currentVersion.getClass(), id);
AtomicInteger index = new AtomicInteger();
return -> {
VersionDTO<T> version = new VersionDTO<>();
if ( !, d.get()).hasChanges()) {
return version;
public <T> List<VersionsDiffDTO> compare(Class<?> entity, Object id, int left, int right) {
List<Shadow<T>> shadows = getShadows(entity, id);
T v1 = shadows.get(left).get();
T v2 = shadows.get(right).get();
List<Change> changes =, v2).getChanges();
return changes.parallelStream().map(change -> {
VersionsDiffDTO diff = new VersionsDiffDTO();
diff.setPropertyName(((ValueChange) change).getPropertyName());
diff.setPropertyNameWithPath(((ValueChange) change).getPropertyNameWithPath());
diff.setLeft(((ValueChange) change).getLeft());
diff.setRight(((ValueChange) change).getRight());
return diff;
public <T> T getVersion(Class<T> entity, Object id, int version) {
List<Shadow<T>> shadows = getShadows(entity, id);
return shadows.get(version).get();
private <T> List<Shadow<T>> getShadows(Class<?> entity, Object id) {
QueryBuilder jqlQuery = QueryBuilder.byInstanceId(id, entity);
List<Shadow<T>> shadows = javers.findShadows(;
return shadows;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment