Change AuditingEventListener Constructor Signature. (#1908)

Closes #1884.
This commit is contained in:
Michael Reiche
2024-02-22 19:49:27 -05:00
committed by mikereiche
parent f28271b66e
commit 4e8626ce6c
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>> {
private final ObjectFactory<IsNewAwareAuditingHandler> auditingHandlerFactory;
private final ObjectFactory<Object> auditingHandlerFactory;
public AuditingEventListener() {
this.auditingHandlerFactory = null;
@@ -51,8 +51,8 @@ public class AuditingEventListener implements ApplicationListener<CouchbaseMappi
*
* @param auditingHandlerFactory must not be {@literal null}.
*/
public AuditingEventListener(ObjectFactory<IsNewAwareAuditingHandler> auditingHandlerFactory) {
Assert.notNull(auditingHandlerFactory, "IsNewAwareAuditingHandler must not be null!");
public AuditingEventListener(ObjectFactory<Object> auditingHandlerFactory) {
Assert.notNull(auditingHandlerFactory, "auditingHandlerFactory must not be null!");
this.auditingHandlerFactory = auditingHandlerFactory;
}
@@ -63,8 +63,19 @@ public class AuditingEventListener implements ApplicationListener<CouchbaseMappi
@Override
public void onApplicationEvent(CouchbaseMappingEvent<Object> event) {
if (event instanceof BeforeConvertEvent) {
Optional.ofNullable(event.getSource())//
.ifPresent(it -> auditingHandlerFactory.getObject().markAudited(it));
IsNewAwareAuditingHandler h = auditingHandlerFactory != null
&& 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 AfterSaveEvent) {}

View File

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