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: Use correct get single TE for changelog feature [DHIS2-18541] #20109

Merged
merged 1 commit into from
Feb 28, 2025

Conversation

enricocolasante
Copy link
Contributor

@enricocolasante enricocolasante commented Feb 27, 2025

Moving getTrackedEntity() to use the same code as multiple entities has a big impact in a lot of places in the system and it is going to be done in small steps, changing it feature by feature.

In this PR we are starting to change tracker ownership service and controller to use the new and correct getNewTrackedEntity method.

Changes in this PR

  • Use getNewTrackedEntity method in DefaultTrackedEntityChangeLogService.

  • Map trackedEntityType id in order to be used in other services that need managed metadata to work properly. Should we formalize that tracker data are always detached and metadata are always managed, even if they are coming from a tracker service?

Challenges in tests
TrackedEntityAggregate is loading data in new threads so they have their own transaction and not committed data are not visible in those threads, that is why we cannot use @Transactional annotation when we are importing data and reading in one one transaction.

Common misconfigurations in tests

  • Create tracked entity and enrollment but do not create an ownership.
  • Create a tracker program without a tracked entity type

Next Steps

  • Move new methods for changelog feature
  • Move new methods in tracked entity controller
  • Move new methods for deduplication feature
  • Move new methods in all remaining places
  • Remove old getTrackedEntity() methods and rename new ones

@enricocolasante enricocolasante marked this pull request as ready for review February 27, 2025 13:48
@enricocolasante enricocolasante requested a review from a team as a code owner February 27, 2025 13:48

UserDetails currentUser = CurrentUserUtil.getCurrentUserDetails();
Set<UID> trackedEntityAttributes = Collections.emptySet();
if (programUid != null) {
Program program = validateProgram(programUid.getValue());
validateOwnership(currentUser, trackedEntity, program);
} else {
validateTrackedEntity(currentUser, trackedEntity);
trackedEntityAttributes = validateTrackedEntityAttributes(trackedEntity);
Copy link
Contributor

Choose a reason for hiding this comment

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

is that still needed as ACL on TEA might not otherwise be done?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe @muilpp can help us understand this better.
This validation is just checking if there are teas, and, if not, it is returning a tracked entity not found.

Copy link
Contributor

Choose a reason for hiding this comment

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

this checks if the user has access to the TET, and afaik it's the only place where we do it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@muilpp I was asking about validateTrackedEntityAttributes.
The other validation is not needed anymore as it is now present in TrackerEntityService

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm talking about validateTrackedEntityAttributes too.
We don't validate access to TEAs, if the user has access to the TET, then we grant access to the TETA as well.
If this is already present in TrackerEntityService, then we don't need this line either.

@teleivo
Copy link
Contributor

teleivo commented Feb 27, 2025

  • Map trackedEntityType id in order to be used in other services that need managed metadata to work properly. Should we formalize that tracker data are always detached and metadata are always managed, even if they are coming from a tracker service?

maybe

@enricocolasante enricocolasante merged commit 0b37c3c into master Feb 28, 2025
17 checks passed
@enricocolasante enricocolasante deleted the DHIS2-18541-changelog branch February 28, 2025 07:53
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.

4 participants