Commit b0990501 authored by Matija Obreza's avatar Matija Obreza
Browse files

Triggers: With pointcut on service

parent 953e9d50
......@@ -26,7 +26,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
......@@ -103,13 +103,14 @@ public class AccessionTriggers implements InitializingBean {
accessionClassPk = classPKService.getClassPk(Accession.class);
}
@After(value = "(execution(* org.genesys.blocks.auditlog.persistence.AuditLogRepository.save(..)) || execution(* org.genesys.blocks.auditlog.persistence.AuditLogRepository.saveAndFlush(..))) && args(auditLog)")
public void afterSaveAuditLogs(final JoinPoint joinPoint, final AuditLog auditLog) throws Throwable {
@AfterReturning(value = "(execution(* org.genesys.blocks.auditlog.persistence.AuditLogRepository.save(..)) || execution(* org.genesys.blocks.auditlog.persistence.AuditLogRepository.saveAndFlush(..))) && args(auditLog)")
public void afterSaveAuditLogs(JoinPoint joinPoint, AuditLog auditLog) throws Throwable {
LOG.trace("Checking 1 saved auditLog, cpk={}", this.accessionClassPk);
afterSaveAuditLogs(null, List.of(auditLog));
}
@After(value = "execution(* org.genesys.blocks.auditlog.persistence.AuditLogRepository.saveAll(Iterable)) && args(auditLogs)")
public void afterSaveAuditLogs(final JoinPoint joinPoint, final Collection<AuditLog> auditLogs) throws Throwable {
@AfterReturning(value = "execution(* org.genesys.blocks.auditlog.service.*.addAuditLogs(..))", returning = "auditLogs")
public void afterSaveAuditLogs(JoinPoint joinPoint, Collection<AuditLog> auditLogs) throws Throwable {
LOG.trace("Checking {} saved auditLogs, cpk={}", auditLogs.size(), this.accessionClassPk);
var changedAccessions = new HashMap<Long, HashMap<String, Pair<Object, Object>>>();
auditLogs.stream().filter(this::isAccessionChangeLog).forEach(auditLog -> {
......
......@@ -155,8 +155,10 @@ public class AccessionActionServiceTest extends AbstractServicesTest {
// change accession number
accession.setAccessionNumberPart3("part3");
LOG.warn("\n\nPANIC");
var updated = accessionService.update(accession);
assertThat(updated.getAccessionNumber(), is("AccessionNumberPart1 part3"));
LOG.warn("\n\nPANIC NOW");
assertThat(accessionActionRepository.count(), is(1L));
var filter = new AccessionActionFilter();
......
......@@ -199,6 +199,7 @@ public class AccessionServiceTest extends AbstractServicesTest {
Accession accession = addAccessionToDB();
assertThat(accessionInvNameRepository.count(), is(1L));
assertThat(accession.getAccessionNumber(), is("AccessionNumberPart1"));
LOG.warn("\n\nPANIC NOW");
// change accession number
accession.setAccessionNumberPart3("part3");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment