This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects

audit event failed tests

Merged Philipp Gritsch requested to merge audit-event-failed-test into development
Files
2
@@ -17,6 +17,8 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import tech.jhipster.config.JHipsterProperties;
@@ -37,10 +39,10 @@ public class AuditEventService {
private final PersistenceAuditEventRepository persistenceAuditEventRepository;
private final TransactionTemplate isolatedTransactionTemplate;
private final AuditEventConverter auditEventConverter;
private PlatformTransactionManager platformTransactionManager;
public AuditEventService(
PersistenceAuditEventRepository persistenceAuditEventRepository,
AuditEventConverter auditEventConverter,
@@ -50,9 +52,7 @@ public class AuditEventService {
this.persistenceAuditEventRepository = persistenceAuditEventRepository;
this.auditEventConverter = auditEventConverter;
this.jHipsterProperties = jhipsterProperties;
isolatedTransactionTemplate = new TransactionTemplate(platformTransactionManager);
isolatedTransactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
this.platformTransactionManager = platformTransactionManager;
}
/**
@@ -62,6 +62,11 @@ public class AuditEventService {
*/
@Scheduled(cron = "0 0 23 * * ?")
public int removeOldAuditEvents() {
final TransactionTemplate isolatedTransactionTemplate = new TransactionTemplate(platformTransactionManager);
isolatedTransactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
isolatedTransactionTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED); // this is mainly
// to enable
// testing
boolean next = true;
AtomicInteger count = new AtomicInteger(0);
@@ -79,7 +84,7 @@ public class AuditEventService {
return count.intValue();
}
@javax.transaction.Transactional(javax.transaction.Transactional.TxType.REQUIRES_NEW)
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_UNCOMMITTED)
public int removeOldAuditEvents2() {
Instant deleteBefore = Instant.now().minus(jHipsterProperties.getAuditEvents().getRetentionPeriod(), ChronoUnit.DAYS);
return this.persistenceAuditEventRepository.deleteByAuditEventDateBefore(deleteBefore);