/** Writes audit events to DB asynchronously in a new thread */ @Async public void writeAuditEvent(Object target, EntityAuditAction action) { log.debug("-------------- Post {} audit --------------", action.value()); try { EntityAuditEvent auditedEntity = prepareAuditEntity(target, action); if (auditedEntity != null) { auditingEntityRepository.save(auditedEntity); } } catch (Exception e) { log.error("Exception while persisting audit entity for {} error: {}", target, e); } }
private void calculateVersion(EntityAuditEvent auditedEntity) { log.trace("Version calculation. for update/remove"); Integer lastCommitVersion = auditingEntityRepository.findMaxCommitVersion( auditedEntity.getEntityType(), auditedEntity.getEntityId()); log.trace("Last commit version of entity => {}", lastCommitVersion); if (lastCommitVersion != null && lastCommitVersion != 0) { log.trace("Present. Adding version.."); auditedEntity.setCommitVersion(lastCommitVersion + 1); } else { log.trace("No entities.. Adding new version 1"); auditedEntity.setCommitVersion(1); } }