Skip to content

Commit

Permalink
Change AuditingEventListener Constructor Signature. (#1908)
Browse files Browse the repository at this point in the history
Closes #1884.
  • Loading branch information
mikereiche committed Mar 13, 2024
1 parent 95e94f2 commit d309692
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public class AuditingEventListener implements ApplicationListener<CouchbaseMappingEvent<Object>> {

private final ObjectFactory<IsNewAwareAuditingHandler> auditingHandlerFactory;
private final ObjectFactory<Object> auditingHandlerFactory;

public AuditingEventListener() {
this.auditingHandlerFactory = null;
Expand All @@ -51,8 +51,8 @@ public AuditingEventListener() {
*
* @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;
}

Expand All @@ -63,8 +63,19 @@ public AuditingEventListener(ObjectFactory<IsNewAwareAuditingHandler> auditingHa
@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) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ public void beforeEach() {
// 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();

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

@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();
Expand Down

0 comments on commit d309692

Please sign in to comment.