8000 chore: Separate changelog logic in preparation to table separation [DHIS2-19848] by enricocolasante · Pull Request #21366 · dhis2/dhis2-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore: Separate changelog logic in preparation to table separation [DHIS2-19848] #21366

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 9 commits into from
Jul 9, 2025

Conversation

enricocolasante
Copy link
Contributor
@enricocolasante enricocolasante commented Jul 7, 2025

The idea of this task is to prepare the code for the separation of event table that will happen later.
We will need to create 2 separate tables for eventchangelog as well, so we are already creating different hibernate mappings, stores and services.

Chnages in this PR

  • Created 2 mappings for the different changelogs, but they still point to the same table. When we will separate the event tables, we will only need to point to the correct table and link to the correct event type (single or tracker event table).
  • Separate changelog hibernate object and DTO changelog. DTO does not need to link to the event, so it can be shared by the 2 different types of changelog, while we need 2 different hibernate objects that will represent the 2 different tables.
  • Create EventService to be used in EventChangeLogService. EventChangeLogService is abstract and the correct event service will be injected, here we only need to check if an event exists (or it is accessible) in order to retrieve or not the changelogs.
  • HibernateEventChangeLogStore is an abstract class, as all the logic is the same for the 2 types, only the name of the table is different.
  • EventChangeLogService is abstract because the changelogs retrieved here are the DTOs, that are the same for the 2 types; the only difference is the hibernate object that we are persisting to the DB and this is injected by the implementation of the service.

What we will need to do when separating the event table

  • Update the mapping files
  • Update the code to link to the correct Event type

@enricocolasante enricocolasante changed the title chore: Separate changelog logic in preparation to table separation chore: Separate changelog logic in preparation to table separation [DHIS2-19848] Jul 8, 2025
@enricocolasante enricocolasante marked this pull request as ready for review July 8, 2025 08:23
@enricocolasante enricocolasante requested a review from a team as a code owner July 8, 2025 08:23
@Getter
@Setter
@RequiredArgsConstructor
public class EventChangeLog {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this now be a record 🤔 or @Value. Maybe before it was not possible because of Hibernate 🤷🏻 @muilpp

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have this EventChangeLog and the 2 new event changelog classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can make it a record, I was just lazy to rename all the getters and I didn't want to pollute the PR.
I will do it after the reviews.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

EventChangeLog is the object that we retrieve from the DB and we then map to the view object.
This object does not need to link to an event because we are always retrieving changelogs in the context of one event and in the view object the link to the event is not needed.
On the other side, we need the hibernate objects to link to the event and they will be different events (singleevent and trackerevent) as soon as we split the event table.

@@ -152,7 +155,6 @@ public Page<EventChangeLog> getEventChangeLogs(
results.stream()
.map(
row -> {
Event e = (Event) row[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this not needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are creating an EventChangeLog that does not need to link to an event.
That event was never needed, as it is not mapped to the view in the web layer.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, can we remove the event from the select clause?

<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.hisp.dhis.changelog.ChangeLogType</param>
<param name="useNamed">true</param>
<param name="type">12</param>
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to specify the type.
Hibernate infers it because we use the name method of the changeLogType enum, which already returns a String.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Nope, I cannot remove it, hibernate is complaining that the type is wrong and the application is not starting at all.

@@ -152,7 +155,6 @@ public Page<EventChangeLog> getEventChangeLogs(
results.stream()
.map(
row -> {
Event e = (Event) row[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, can we remove the event from the select clause?

@enricocolasante enricocolasante requested a review from muilpp July 9, 2025 11:17
Copy link
sonarqubecloud bot commented Jul 9, 2025

@enricocolasante enricocolasante enabled auto-merge (squash) July 9, 2025 13:06
@enricocolasante enricocolasante merged commit bc8e77d into master Jul 9, 2025
16 checks passed
@enricocolasante enricocolasante deleted the DHIS2-19701-changelogs branch July 9, 2025 13: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.

3 participants
0