Skip to content

Change AuditingEventListener Constructor Signature. #1908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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