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

fix: AuditType failing enum conversion when get tracked entity audits [DHIS2-15805] #14632

Merged
merged 5 commits into from
Jan 8, 2024

Conversation

lucaCambi77
Copy link
Contributor

@lucaCambi77 lucaCambi77 commented Jul 18, 2023

https://dhis2.atlassian.net/browse/DHIS2-15805

Note: This is the audit that will soon convert to changelog

The addTrackedEntityAudit in the HibernateTrackedEntityAuditStore method for a list of TrackedEntityAudit inserts lowercase AuditType.
Eventually, some audits are lowercase on the database, and others inserted by other methods are uppercase.
Then, when getting back a list of audits, hibernate cannot convert the enum when the audit type is lowercase.
The Audit type is exposed as upper case in the endpoints.
Notice that this error is not showing in DefaultTrackedEntityAuditService because it is @Async

Solution:

We could leverage at a query level to convert to uppercase. However, a straightforward solution is to make the addTrackedEntityAudit work the same as the other audits and rename what is lowercase in the database.

It seems that only the trackedentityaudit is currently affected. However, we apply the same database update for the other audit tables, which could potentially have had the same logic in the past.

Notice also that this issue is internally reported and not by any user. Therefore, it might be that, for example, the changelog is not enabled by instances, and there are no records to update. Or the endpoint is not queried.

When passing the audit type as a parameter in a request, the endpoints should be able to manage the lowercase in case.

This also drops the metadataaudit table that apparently is not in use.

@codecov
Copy link

codecov bot commented Jul 18, 2023

Codecov Report

Merging #14632 (b96649e) into master (ffcfca3) will increase coverage by 0.02%.
Report is 15 commits behind head on master.
The diff coverage is 100.00%.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #14632      +/-   ##
============================================
+ Coverage     66.41%   66.43%   +0.02%     
- Complexity    31548    31560      +12     
============================================
  Files          3506     3506              
  Lines        130523   130525       +2     
  Branches      15224    15228       +4     
============================================
+ Hits          86684    86716      +32     
+ Misses        36767    36739      -28     
+ Partials       7072     7070       -2     
Flag Coverage Δ
integration 50.37% <100.00%> (+0.01%) ⬆️
integration-h2 32.31% <83.33%> (+<0.01%) ⬆️
unit 30.37% <83.33%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
.../src/main/java/org/hisp/dhis/common/AuditType.java 100.00% <100.00%> (+10.00%) ⬆️
...ty/hibernate/HibernateTrackedEntityAuditStore.java 64.28% <100.00%> (+30.35%) ⬆️

... and 18 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ffcfca3...b96649e. Read the comment docs.

@sonarcloud
Copy link

sonarcloud bot commented Jul 18, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@lucaCambi77 lucaCambi77 marked this pull request as ready for review December 14, 2023 16:07
@lucaCambi77 lucaCambi77 changed the title fix: Audit failing enum conversion fix: AuditType failing enum conversion when get tracked entity audits [ DHIS2-15805] Dec 14, 2023
@lucaCambi77 lucaCambi77 changed the title fix: AuditType failing enum conversion when get tracked entity audits [ DHIS2-15805] fix: AuditType failing enum conversion when get tracked entity audits [DHIS2-15805] Dec 14, 2023
@lucaCambi77 lucaCambi77 requested review from netroms and a team December 19, 2023 15:42
Copy link

sonarcloud bot commented Dec 19, 2023

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.

3 participants