Skip to content

Add missing hooks for callbacks. #1142

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
merged 2 commits into from
Jun 10, 2021
Merged

Conversation

mikereiche
Copy link
Collaborator

@mikereiche mikereiche commented May 28, 2021

  1. the previous change (Add @EnableReactiveCouchbaseAuditing [DATACOUCH-644] #955) to CouchbaseAuditingRegister intended to register
    AuditingEntityCallback instead of AuditingEventListener but only changed the
    name that AuditingEventListener was registered with. Since
    AuditingEventListener does exactly the same thing as AuditingEntityCallback,
    it behaved as those AuditingEntityCallback was being used.

  2. It seems that the two mechanisms - EntityCallback and EventListener
    both do more-or-less the same thing. I'm not sure why there are two
    mechanisms to do the same thing.

  3. Although the ReactiveAuditingEntityCallback mechanism is triggered
    only for reactive operations and the non-reactive AuditingEntityCallback
    is triggered only for non-reactive operations, the events are triggered
    for both. Since there was a desire to have distinct callbacks for
    reactive/non-reactive operations, I also made distinct events for
    reactive/non-reactive operations. However both the reactive and non-reactive
    event mechanisms are triggered for either reactive and non-reactive operations,
    so it is necessary for the mechanism to determine if it should act on the
    event.

  4. Although there is an AbstractCouchbaseEventListener that is extended by
    LoggingEventListener and ValidatingEventListener, AuditingEventListener does
    not extend it (maybe it should).

Closes #1074.

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our JIRA.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@@ -172,7 +178,7 @@ public void setEntityCallbacks(EntityCallbacks entityCallbacks) {
this.entityCallbacks = entityCallbacks;
}

void maybeEmitEvent(CouchbaseMappingEvent<?> event) {
public void maybeEmitEvent(CouchbaseMappingEvent<?> event) {
if (canPublishEvent()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to call from ReactiveRemoveByIdOperationSupport

@@ -95,16 +96,21 @@ public CouchbaseDocument encodeEntity(final Object entityToEncode) {
}

@Override
public Object applyUpdatedCas(final Object entity, final long cas) {
public Object applyUpdatedCas(final Object entity, CouchbaseDocument converted, final long cas) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added converted CouchbaseDocument to args as AfterSaveEvent takes a CouchbaseDocument.

*/
T onAfterConvert(T entity, Document document, String collection);
T onAfterConvert(T entity, CouchbaseDocument document, String collection);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was copied incorrectly from Mongo with the second arg of Document instead of CouchbaseDocument.

@@ -33,17 +35,19 @@
* @author Mark Paluch
* @author Michael Reiche
*/
public class AuditingEventListener implements ApplicationListener<BeforeConvertEvent<Object>> {
public class AuditingEventListener implements ApplicationListener<CouchbaseMappingEvent<Object>> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support any CouchbaseMappingEvent. Not just BeforeConvertEvent.

*/
@Override
public Publisher<Object> onAfterConvert(Object entity, CouchbaseDocument document, String collection) {
LOG.debug("onAfterConvert " + document.toString());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove this debug.

@mikereiche mikereiche requested a review from daschl June 1, 2021 13:20
@mikereiche mikereiche force-pushed the datacouch_1074_aftersave_event_etc branch 3 times, most recently from 2aba7f2 to 615f873 Compare June 8, 2021 19:46
@mikereiche mikereiche force-pushed the datacouch_1074_aftersave_event_etc branch from 615f873 to ed3d923 Compare June 10, 2021 01:18
1) the previous change (#955) to CouchbaseAuditingRegister intended to register
 AuditingEntityCallback instead of AuditingEventListener but only changed the
name that AuditingEventListener was registered with. Since
AuditingEventListener does exactly the same thing as AuditingEntityCallback,
it behaved as those AuditingEntityCallback was being used.

2) It seems that the two mechanisms - EntityCallback and EventListener
both do more-or-less the same thing. I'm not sure why there are two
mechanisms to do the same thing.

3) Although the ReactiveAuditingEntityCallback mechanism is triggered
only for reactive operations and the non-reactive AuditingEntityCallback
is triggered only for non-reactive operations, the events are triggered
for both. Since there was a desire to have distinct callbacks for
reactive/non-reactive operations, I also made distinct events for
reactive/non-reactive operations.  However both the reactive and non-reactive
event mechanisms are triggered for either reactive and non-reactive operations,
so it is necessary for the mechanism to determine if it should act on the
event.

4) Although there is an AbstractCouchbaseEventListener that is extended by
LoggingEventListener and ValidatingEventListener, AuditingEventListener does
not extend it (maybe it should).

Closes #1074.
@mikereiche mikereiche force-pushed the datacouch_1074_aftersave_event_etc branch from ed3d923 to b311c6f Compare June 10, 2021 01:47
@mikereiche mikereiche merged commit 155663e into main Jun 10, 2021
mikereiche added a commit that referenced this pull request Aug 9, 2021
1) the previous change (#955) to CouchbaseAuditingRegister intended to register
 AuditingEntityCallback instead of AuditingEventListener but only changed the
name that AuditingEventListener was registered with. Since
AuditingEventListener does exactly the same thing as AuditingEntityCallback,
it behaved as those AuditingEntityCallback was being used.

2) It seems that the two mechanisms - EntityCallback and EventListener
both do more-or-less the same thing. I'm not sure why there are two
mechanisms to do the same thing.

3) Although the ReactiveAuditingEntityCallback mechanism is triggered
only for reactive operations and the non-reactive AuditingEntityCallback
is triggered only for non-reactive operations, the events are triggered
for both. Since there was a desire to have distinct callbacks for
reactive/non-reactive operations, I also made distinct events for
reactive/non-reactive operations.  However both the reactive and non-reactive
event mechanisms are triggered for either reactive and non-reactive operations,
so it is necessary for the mechanism to determine if it should act on the
event.

4) Although there is an AbstractCouchbaseEventListener that is extended by
LoggingEventListener and ValidatingEventListener, AuditingEventListener does
not extend it (maybe it should).

Closes #1074.

Co-authored-by: mikereiche <michael.reiche@couchbase.com>
@mikereiche mikereiche deleted the datacouch_1074_aftersave_event_etc branch August 11, 2021 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AfterSaveEvent is never triggered
1 participant