Change processing
See original GitHub issueI am trying to figure out how the library would be used to show a traditional “changelog”. By traditional I am referring to something that is grouped together by “commit” then by field.
List<Change> changes = javers.getChangeHistory(InstanceIdDTO.instanceId(table.getInternalId(), Entity.class), 5);
for (Change change : changes) {
CommitMetadata commit = change.getCommitMetadata().get();
System.out.print(commit.getId() + ":" + commit.getCommitDate() + ":" + commit.getAuthor() + " -- ");
// What type of change is it?
// I could say "if (change instanceof ValueChange)" and check for every type
}
So a couple of questions:
- The documentation is missing in some places, so I may have missed it. Is there a way to get “commits” instead of “changes”? Commits would store the CommitMetaData and have a list of Changes? Otherwise, I would just build it myself, which is not too difficult.
- When I am looping over the changes, how do I know what type of change it is? I.E NewObject, ValueChange, MapChange, etc. In all the examples I saw, you were retrieving changes by type. However I would like to build a complete changelog so I don’t know beforehand which types to ask for. I could do a bunch of casting based on instanceof but that doesn’t see right. Is there a more elegant way, given a Change, to determine its actual type?
Issue Analytics
- State:
- Created 9 years ago
- Comments:24 (13 by maintainers)
Top Results From Across the Web
Change Is a Process - Prosci
The easiest, most basic approach to understanding change as a process is to break change down into distinct, understandable elements. The three states...
Read more >Processing change is hard, but there are ways to make it easier
We've all experienced big changes this past year. Here are 7 tips to help you navigate through it all. By Kristina Benoist.
Read more >Change Management Process: Definitive Guide & Templates
A change management process is a consistent, seamless path from the current state to a new one. Here's how to avoid common challenges...
Read more >Change Management Process in 2022: A Conclusive Guide
Change management streamlines the change process, ensuring quick adaptability and organizational growth. Learn how to successfully implement ...
Read more >Processing Big Changes | Mental Health America
When you're processing big changes, your brain may feel like it's constantly racing. It's easy to feel overwhelmed with all of the things...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I totally agree about casting. Should be avoided at all costs. So let’s say I have an entity and I want to build a complete change history to display to the user. In the method you suggested above, I would need to call getChangeHistory a bunch of times, one for each class derived from Change. I would have to look over each set of results and join everything together based on Commit so that I would show it in the order it all happened. It seems like there should be an easier way that would not force me to understand every class that is derived from Change.
One way would be to have the toString method in the Change class be used. Classes like NewObject, PropertyChange, etc. would override it with a relevant description of what actually happened. That would be an improvement and probably makes sense to do. However it would not allow me to customize the message, so I’m not sure if I would call it a complete solution.
Ideally, I could do everything I need from the Change object without knowing the concrete implementation I was working with. A “change” consists of 1 of 3 things:
I am not sure, but it seems like I should be able to get from the Change object somehow:
That would break your current hierarchy, so I’m not sure it is something that would work. However this use case of building a complete history of an entity seems like it should be one of the basic requirements of the library.
Answering your questions
We can add method like that:
So no casting would be required, what do You think?