org.javers.spring.auditable.aspect.JaversAuditableAspectAsync Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javers-spring Show documentation
Show all versions of javers-spring Show documentation
JaVers object auditing and diff framework
package org.javers.spring.auditable.aspect;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.javers.core.Javers;
import org.javers.core.commit.Commit;
import org.javers.spring.annotation.JaversAuditableAsync;
import org.javers.spring.auditable.AuthorProvider;
import org.javers.spring.auditable.CommitPropertiesProvider;
import org.springframework.core.annotation.Order;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
/**
* INCUBATING - Javers Async API has incubating status.
*
*
* Asynchronously commits all arguments passed to methods annotated with {@link JaversAuditableAsync}
* by calling {@link Javers#commitAsync(String, Object, Executor)} for each method argument.
*
*
* This is the {@link AfterReturning} aspect, it triggers
* only if a method exits normally, i.e. if no Exception has been thrown.
*/
@Aspect
@Order(0)
public class JaversAuditableAspectAsync {
private final JaversCommitAdvice javersCommitAdvice;
private Optional> lastAsyncCommit = Optional.empty();
public JaversAuditableAspectAsync(Javers javers, AuthorProvider authorProvider, CommitPropertiesProvider commitPropertiesProvider,Executor executor) {
this(new JaversCommitAdvice(javers, authorProvider, commitPropertiesProvider, executor));
}
JaversAuditableAspectAsync(JaversCommitAdvice javersCommitAdvice) {
this.javersCommitAdvice = javersCommitAdvice;
}
@AfterReturning("@annotation(org.javers.spring.annotation.JaversAuditableAsync)")
public void commitAdvice(JoinPoint pjp) {
lastAsyncCommit = javersCommitAdvice.commitSaveMethodArgumentsAsync(pjp);
}
Optional> getLastAsyncCommit() {
return lastAsyncCommit;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy