Change AuditingEventListener Constructor Signature. (#1908)

Closes #1884.
This commit is contained in:
Michael Reiche
2024-02-22 19:49:27 -05:00
committed by GitHub
parent 43711d00bf
commit 3298a2cb5d
2 changed files with 20 additions and 8 deletions

View File

@@ -37,7 +37,7 @@ import org.springframework.util.Assert;
*/ */
public class AuditingEventListener implements ApplicationListener<CouchbaseMappingEvent<Object>> { public class AuditingEventListener implements ApplicationListener<CouchbaseMappingEvent<Object>> {
private final ObjectFactory<IsNewAwareAuditingHandler> auditingHandlerFactory; private final ObjectFactory<Object> auditingHandlerFactory;
public AuditingEventListener() { public AuditingEventListener() {
this.auditingHandlerFactory = null; this.auditingHandlerFactory = null;
@@ -51,8 +51,8 @@ public class AuditingEventListener implements ApplicationListener<CouchbaseMappi
* *
* @param auditingHandlerFactory must not be {@literal null}. * @param auditingHandlerFactory must not be {@literal null}.
*/ */
public AuditingEventListener(ObjectFactory<IsNewAwareAuditingHandler> auditingHandlerFactory) { public AuditingEventListener(ObjectFactory<Object> auditingHandlerFactory) {
Assert.notNull(auditingHandlerFactory, "IsNewAwareAuditingHandler must not be null!"); Assert.notNull(auditingHandlerFactory, "auditingHandlerFactory must not be null!");
this.auditingHandlerFactory = auditingHandlerFactory; this.auditingHandlerFactory = auditingHandlerFactory;
} }
@@ -63,8 +63,19 @@ public class AuditingEventListener implements ApplicationListener<CouchbaseMappi
@Override @Override
public void onApplicationEvent(CouchbaseMappingEvent<Object> event) { public void onApplicationEvent(CouchbaseMappingEvent<Object> event) {
if (event instanceof BeforeConvertEvent) { if (event instanceof BeforeConvertEvent) {
Optional.ofNullable(event.getSource())// IsNewAwareAuditingHandler h = auditingHandlerFactory != null
.ifPresent(it -> auditingHandlerFactory.getObject().markAudited(it)); && auditingHandlerFactory.getObject() instanceof IsNewAwareAuditingHandler
? (IsNewAwareAuditingHandler) (auditingHandlerFactory.getObject())
: null;
if (auditingHandlerFactory != null && h == null) {
if (LOG.isWarnEnabled()) {
LOG.warn("event:{} source:{} auditingHandler is not an IsNewAwareAuditingHandler: {}",
event.getClass().getSimpleName(), event.getSource(), auditingHandlerFactory.getObject());
}
}
if (h != null) {
Optional.ofNullable(event.getSource()).ifPresent(it -> h.markAudited(it));
}
} }
if (event instanceof BeforeSaveEvent) {} if (event instanceof BeforeSaveEvent) {}
if (event instanceof AfterSaveEvent) {} if (event instanceof AfterSaveEvent) {}

View File

@@ -115,10 +115,12 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
// then do processing for this class // then do processing for this class
couchbaseTemplate.removeByQuery(User.class).withConsistency(REQUEST_PLUS).inCollection(collectionName).all(); couchbaseTemplate.removeByQuery(User.class).withConsistency(REQUEST_PLUS).inCollection(collectionName).all();
couchbaseTemplate.findByQuery(User.class).withConsistency(REQUEST_PLUS).inCollection(collectionName).all(); couchbaseTemplate.findByQuery(User.class).withConsistency(REQUEST_PLUS).inCollection(collectionName).all();
couchbaseTemplate.removeByQuery(Airport.class).inScope(scopeName).inCollection(collectionName).all(); couchbaseTemplate.removeByQuery(Airport.class).withConsistency(REQUEST_PLUS).inScope(scopeName)
.inCollection(collectionName).all();
couchbaseTemplate.findByQuery(Airport.class).withConsistency(REQUEST_PLUS).inScope(scopeName) couchbaseTemplate.findByQuery(Airport.class).withConsistency(REQUEST_PLUS).inScope(scopeName)
.inCollection(collectionName).all(); .inCollection(collectionName).all();
couchbaseTemplate.removeByQuery(Airport.class).inScope(otherScope).inCollection(otherCollection).all(); couchbaseTemplate.removeByQuery(Airport.class).withConsistency(REQUEST_PLUS).inScope(otherScope)
.inCollection(otherCollection).all();
couchbaseTemplate.findByQuery(Airport.class).withConsistency(REQUEST_PLUS).inScope(otherScope) couchbaseTemplate.findByQuery(Airport.class).withConsistency(REQUEST_PLUS).inScope(otherScope)
.inCollection(otherCollection).all(); .inCollection(otherCollection).all();
@@ -528,7 +530,6 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Test @Test
public void existsByIdOther() { // 1 public void existsByIdOther() { // 1
GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10)); ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie.withIcao("lowg")).block(); .one(vie.withIcao("lowg")).block();