Skip to content

Commit d309692

Browse files
committed
Change AuditingEventListener Constructor Signature. (#1908)
Closes #1884.
1 parent 95e94f2 commit d309692

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/main/java/org/springframework/data/couchbase/core/mapping/event/AuditingEventListener.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
public class AuditingEventListener implements ApplicationListener<CouchbaseMappingEvent<Object>> {
3939

40-
private final ObjectFactory<IsNewAwareAuditingHandler> auditingHandlerFactory;
40+
private final ObjectFactory<Object> auditingHandlerFactory;
4141

4242
public AuditingEventListener() {
4343
this.auditingHandlerFactory = null;
@@ -51,8 +51,8 @@ public AuditingEventListener() {
5151
*
5252
* @param auditingHandlerFactory must not be {@literal null}.
5353
*/
54-
public AuditingEventListener(ObjectFactory<IsNewAwareAuditingHandler> auditingHandlerFactory) {
55-
Assert.notNull(auditingHandlerFactory, "IsNewAwareAuditingHandler must not be null!");
54+
public AuditingEventListener(ObjectFactory<Object> auditingHandlerFactory) {
55+
Assert.notNull(auditingHandlerFactory, "auditingHandlerFactory must not be null!");
5656
this.auditingHandlerFactory = auditingHandlerFactory;
5757
}
5858

@@ -63,8 +63,19 @@ public AuditingEventListener(ObjectFactory<IsNewAwareAuditingHandler> auditingHa
6363
@Override
6464
public void onApplicationEvent(CouchbaseMappingEvent<Object> event) {
6565
if (event instanceof BeforeConvertEvent) {
66-
Optional.ofNullable(event.getSource())//
67-
.ifPresent(it -> auditingHandlerFactory.getObject().markAudited(it));
66+
IsNewAwareAuditingHandler h = auditingHandlerFactory != null
67+
&& auditingHandlerFactory.getObject() instanceof IsNewAwareAuditingHandler
68+
? (IsNewAwareAuditingHandler) (auditingHandlerFactory.getObject())
69+
: null;
70+
if (auditingHandlerFactory != null && h == null) {
71+
if (LOG.isWarnEnabled()) {
72+
LOG.warn("event:{} source:{} auditingHandler is not an IsNewAwareAuditingHandler: {}",
73+
event.getClass().getSimpleName(), event.getSource(), auditingHandlerFactory.getObject());
74+
}
75+
}
76+
if (h != null) {
77+
Optional.ofNullable(event.getSource()).ifPresent(it -> h.markAudited(it));
78+
}
6879
}
6980
if (event instanceof BeforeSaveEvent) {}
7081
if (event instanceof AfterSaveEvent) {}

src/test/java/org/springframework/data/couchbase/core/query/ReactiveCouchbaseTemplateQueryCollectionIntegrationTests.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,12 @@ public void beforeEach() {
115115
// then do processing for this class
116116
couchbaseTemplate.removeByQuery(User.class).withConsistency(REQUEST_PLUS).inCollection(collectionName).all();
117117
couchbaseTemplate.findByQuery(User.class).withConsistency(REQUEST_PLUS).inCollection(collectionName).all();
118-
couchbaseTemplate.removeByQuery(Airport.class).inScope(scopeName).inCollection(collectionName).all();
118+
couchbaseTemplate.removeByQuery(Airport.class).withConsistency(REQUEST_PLUS).inScope(scopeName)
119+
.inCollection(collectionName).all();
119120
couchbaseTemplate.findByQuery(Airport.class).withConsistency(REQUEST_PLUS).inScope(scopeName)
120121
.inCollection(collectionName).all();
121-
couchbaseTemplate.removeByQuery(Airport.class).inScope(otherScope).inCollection(otherCollection).all();
122+
couchbaseTemplate.removeByQuery(Airport.class).withConsistency(REQUEST_PLUS).inScope(otherScope)
123+
.inCollection(otherCollection).all();
122124
couchbaseTemplate.findByQuery(Airport.class).withConsistency(REQUEST_PLUS).inScope(otherScope)
123125
.inCollection(otherCollection).all();
124126

@@ -528,7 +530,6 @@ public void upsertById() { // 10
528530

529531
@Test
530532
public void existsByIdOther() { // 1
531-
GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
532533
ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10));
533534
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
534535
.one(vie.withIcao("lowg")).block();

0 commit comments

Comments
 (0)