Skip to content
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

8531 refactor validators #8534

Merged
merged 10 commits into from
Apr 11, 2022
Merged

Conversation

poikilotherm
Copy link
Contributor

@poikilotherm poikilotherm commented Mar 24, 2022

What this PR does / why we need it:
This pull request pays back some technical debt around validators.

  • Cleanup some strange code constructs that slipped in over time
  • Add way more tests for bean validation and programmatic usage
  • Make the programmatic API more comprehensible, adding API docs etc

Which issue(s) this PR closes:

Closes #8531

Special notes for your reviewer:
None. I really put effort into keeping things working. I did draw a line: I did not refactor the JSF validation parts. They are as messy as before (it would make things cleaner by reusing bean validation 🤷 - less duplicated code, less different error messages.). And I did not cleanup all the code in DatasetFieldValueValidator, which could use some love...

Suggestions on how to test this:
There is a large amount of unit tests added with this PR. I tried very hard not to introduce unexpected behavior changes, but better watch out for those.

Does this PR introduce a user interface change? If mockups are available, please link/include them here:
Nope.

Is there a release notes update needed for this change?:
Nope.

Additional documentation:
None so far.

…dValueValidator IQSS#8503

The context parameter has been removed, need to add the violation
message ourselfs. Also adding a true test for email validation.
- Simplify the code for URLValidator
- Make it nullsafe
- Make allowed schemes configurable from annotation
- Rewrite tests to JUnit5, more examples and test with real subject
  classes
- Move message string to validation bundle
- Reuse existing constraints instead of creating our own validator
- Provide programmatic method to use the same from code like OAuth2 etc
- Add much more tests, also for actual bean validation
@poikilotherm poikilotherm added the Component: Code Infrastructure formerly "Feature: Code Infrastructure" label Mar 24, 2022
@coveralls
Copy link

coveralls commented Mar 24, 2022

Coverage Status

Coverage decreased (-0.005%) to 18.884% when pulling 43126e1 on poikilotherm:8531-refactor-validators into c5d1df2 on IQSS:develop.

@poikilotherm
Copy link
Contributor Author

@donsizemore what does "Ansible run terminated abnormally, failing build." on Jenkins mean?

@donsizemore
Copy link
Contributor

it means Ansible exited 1 - EC2 instance fell over, something timed out or generally went splat.

@qqmyers
Copy link
Member

qqmyers commented Mar 25, 2022

If you can click on details, the artifacts tab has the pipeline.log and in the one for this run:
TASK [the root dataverse must be published] ************************************
fatal: [localhost]: FAILED! => {"access_control_allow_headers": "Accept, Content-Type, X-Dataverse-Key", "access_control_allow_methods": "PUT, GET, POST, DELETE, OPTIONS", "access_control_allow_origin": "*", "changed": false, "connection": "close", "content": "{"status":"ERROR","message":"Command edu.harvard.iq.dataverse.engine.command.impl.PublishDataverseCommand@5b1db381 failed: Exception thrown from bean: javax.ejb.EJBTransactionRolledbackException: Exception thrown from bean: javax.ejb.EJBTransactionRolledbackException: Exception thrown from bean: javax.ejb.EJBTransactionRolledbackException: Exception thrown from bean: java.lang.NoClassDefFoundError: org/hibernate/validator/internal/util/CollectionHelper"}", "content_length": "458", "content_type": "application/json;charset=UTF-8", "elapsed": 0, "json": {"message": "Command edu.harvard.iq.dataverse.engine.command.impl.PublishDataverseCommand@5b1db381 failed: Exception thrown from bean: javax.ejb.EJBTransactionRolledbackException: Exception thrown from bean: javax.ejb.EJBTransactionRolledbackException: Exception thrown from bean: javax.ejb.EJBTransactionRolledbackException: Exception thrown from bean: java.lang.NoClassDefFoundError: org/hibernate/validator/internal/util/CollectionHelper", "status": "ERROR"}, "msg": "Status code was 500 and not [200]: HTTP Error 500: Internal Server Error", "redirected": false, "server": "Payara Server 5.2021.6 #badassfish", "status": 500, "url": "http://localhost:8080/api/dataverses/root/actions/:publish", "x_frame_options": "SAMEORIGIN", "x_powered_by": "Servlet/4.0 JSP/2.3 (Payara Server 5.2021.6 #badassfish Java/Red Hat, Inc./11)"}

@poikilotherm
Copy link
Contributor Author

Thx @qqmyers - fixed with 43126e1

@poikilotherm
Copy link
Contributor Author

poikilotherm commented Mar 25, 2022

@qqmyers I see a failing test

java.lang.AssertionError: 
Expected: https://dataverse.org/schema/citation/Contact
     but none found
	at edu.harvard.iq.dataverse.api.DatasetsIT.testSemanticMetadataAPIs(DatasetsIT.java:2333)

I don't think this is related to my changes, as I see the same failures at #8532

@sekmiller sekmiller self-assigned this Mar 25, 2022
Copy link
Contributor

@sekmiller sekmiller left a comment

Choose a reason for hiding this comment

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

Looks good.
(is there any thought to allowing the min and max username size to be configurable?)

@scolapasta scolapasta assigned scolapasta and unassigned sekmiller Mar 28, 2022
@poikilotherm
Copy link
Contributor Author

poikilotherm commented Mar 28, 2022

Looks good.

Thx ❤️

(is there any thought to allowing the min and max username size to be configurable?)

Well it hasn't been configurable for a looooong time, so maybe this is not necessary?

Btw this would be hard to do with annotations, as these require constants at compile time.

And IIRC the schema is generating limitations for SQL fields from this, so it might be necessary to create a schema migration.

@sekmiller
Copy link
Contributor

I wasn't saying that this was desirable or necessary - just wondering if the change here was for something beyond readability and maintainability at some point in the future.

@poikilotherm
Copy link
Contributor Author

poikilotherm commented Mar 28, 2022

Nope, it maintains status quo.

Guess if you'd want to do this at a later point in time, you'd remove the @Size and create a custom annotation that supports retrieving the configured maximum form a setting and makes the model skip any database length restrictions.

@scolapasta scolapasta removed their assignment Mar 30, 2022
@kcondon
Copy link
Contributor

kcondon commented Apr 8, 2022

@poikilotherm would you mind refreshing from develop branch? thanks

@poikilotherm
Copy link
Contributor Author

@poikilotherm would you mind refreshing from develop branch? thanks

✔️

@kcondon kcondon self-assigned this Apr 11, 2022
@kcondon kcondon merged commit 891ff50 into IQSS:develop Apr 11, 2022
@poikilotherm
Copy link
Contributor Author

As always thx for merging @kcondon 🤩

@pdurbin pdurbin added this to the 5.11 milestone Apr 12, 2022
@poikilotherm poikilotherm deleted the 8531-refactor-validators branch June 21, 2022 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Code Infrastructure formerly "Feature: Code Infrastructure"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tech debt: refactor URL + Email validation
8 participants