Skip to content

Introduce ValidatingEntityCallback and deprecate ValidatingMongoEventListener #4910

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

Closed
wants to merge 6 commits into from

Conversation

rfelgent
Copy link
Contributor

@rfelgent rfelgent commented Mar 2, 2025

  • You have read the Spring Data contribution guidelines.
  • 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).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 2, 2025
* JSR-303 dependant entities validator.
* <p>
* When it is registered as Spring component its automatically invoked
* after any {@link AbstractMongoEventListener} and before entities are saved in database.
Copy link
Contributor Author

@rfelgent rfelgent Mar 2, 2025

Choose a reason for hiding this comment

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

@mp911de , I copied the documentation from ValidatingMongoEventListener and adjusted it for the ValidatingEntityCallback.
Is the statement regarding automatic invocation still valid?


private static final Log LOG = LogFactory.getLog(ValidatingEntityCallback.class);

// TODO: create a validation handler (similar to "AuditingHandler") an reference it from "ValidatingMongoEventListener" and "ValidatingMongoEventListener"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

personally, I could live with this implementation (and duplicate the validation code logic of ValidatingMongoEventListener)

@Override
public Object onBeforeSave(Object entity, Document document, String collection) {

if (LOG.isDebugEnabled()) {
Copy link
Contributor Author

@rfelgent rfelgent Mar 2, 2025

Choose a reason for hiding this comment

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

pls tell me, is "debug" or "trace" the appropriate choice for bean validation ?

@rfelgent rfelgent changed the title Feature/gh 4901 GH-4901 Mar 2, 2025
@mp911de mp911de changed the title GH-4901 Introduce ValidatingEntityCallback and deprecate ValidatingMongoEventListener Mar 3, 2025
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 3, 2025
Copy link
Member

@mp911de mp911de left a comment

Choose a reason for hiding this comment

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

Thanks a lot. For validation, we should also consider the reactive flow that should not throw exceptions but rather return Mono.error(e). I think it makes sense to extract a tiny superclass returning Set<ConstraintValitation> and let the callback and event listener reuse those bits. We could then get rid of logging in each component.

Admittedly, it's not much code, but a few concerns that we do not require in subclasses.

Also, we should deprecate the event listener and ideally find a place in the reference documentation to mention Bean Validation support.

Let me know how comfortable you are addressing these aspects and what guidance I can provide you with.

@rfelgent
Copy link
Contributor Author

rfelgent commented Mar 3, 2025

... I think it makes sense to extract a tiny superclass returning Set...

agreed. I will add a parent class and make ValidatingEntityCallback and ValidatingMongEventListener a subclass of it.

... we should also consider the reactive flow ...

agreed, should the introduction of a reactive-based entity validor be part of this pull request or another one?

... we should deprecate the event listener ...

agreed, should this be part of this pull request or another one ?

rfelgent added 5 commits March 3, 2025 11:31
Signed-off-by: felgentraeger <rene.felgentraeger@gvl.de>
Signed-off-by: felgentraeger <rene.felgentraeger@gvl.de>
Signed-off-by: felgentraeger <rene.felgentraeger@gvl.de>
Signed-off-by: felgentraeger <rene.felgentraeger@gvl.de>
Signed-off-by: felgentraeger <rene.felgentraeger@gvl.de>
@mp911de
Copy link
Member

mp911de commented Mar 3, 2025

Let's handle everything right here, no need to spread this enhancement over multiple tickets as these changes sum up nicely in a single logical change.

@mp911de mp911de self-assigned this Mar 4, 2025
@mp911de mp911de added this to the 4.5 M2 (2025.0.0) milestone Mar 4, 2025
@mp911de
Copy link
Member

mp911de commented Mar 4, 2025

Thank you for your contribution. That's merged and polished now. I extracted a few bits and tweaked the documentation slightly, adding a reactive callback variant.

@mp911de mp911de closed this Mar 4, 2025
mp911de pushed a commit that referenced this pull request Mar 4, 2025
Closes #4901
Original pull request: #4910

Signed-off-by: felgentraeger <rene.felgentraeger@gvl.de>
mp911de added a commit that referenced this pull request Mar 4, 2025
Introduce ReactiveValidatingEntityCallback, extract BeanValidationDelegate. Document Bean Validation callbacks.

See #4901
Original pull request: #4910
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce ValidatingEntityCallback and deprecate ValidatingMongoEventListener
3 participants