I need to implement audit history for all the CRUD operations on my project. The project uses Spring JPA Data Rest. I looked around for good library to achieve the required task and came across this Hibernate Envers, which seems quite good and easy to implement. Having incorporated this in my project, I am able to record the revisions of all the CRUD operations.
Now I need to expose the changes wherein users can see the changes done as part of any revisions. Here is how I would want the delta output(I put it in JSON format for easy readability).
[
{
"date": "9 may 2018, 6:06 pm",
"user": "user.name (FName LName)",
"actions": [
{
"field": "name",
"oldValue": "Old Name very long",
"newValue": "New Name also quite long."
},
{
"field": "score",
"oldValue": 2,
"newValue": 4
},
{
"field": "average_rating",
"oldValue": "AA",
"newValue": "A"
}
]
},{
"date": "10 may 2018, 5:06 pm",
"user": "user.name (FName LName)",
"actions": [
{
"field":"name",
"oldValue": "Old Name",
"newValue": "New Name"
},
{
"field":"score",
"oldValue": 1,
"newValue": 6
},
{
"field":"average_rating",
"oldValue": "D",
"newValue": "A+"
},
{
"field":"rating",
"oldValue": "A-",
"newValue": "A"
}
]
},{
"date": "10 may 2018, 5:06 pm",
"user": "user.name3 (FName3 LName3)",
"actions": [
{
"field":"average_rating",
"oldValue": "D",
"newValue": "B"
},
{
"field":"rating",
"oldValue": "C",
"newValue": "D"
}
]
},{
"date": "11 may 2018, 5:06 pm",
"user": "user2.name2 (FName2 LName2)",
"actions": [
{
"field":"score",
"oldValue": 3,
"newValue": 4
},
{
"field":"average_rating",
"oldValue": "C",
"newValue": "B"
}
]
},{
"date": "9 apr 2018, 3:00 pm",
"user": "user.name (FName LName)",
"actions": [
{
"field":"name",
"oldValue": "Old Name very long",
"newValue": "New Name also quite long."
},
{
"field":"score",
"oldValue": 5,
"newValue": 3
},
{
"field":"average_rating",
"oldValue": "AA",
"newValue": "B"
},
{
"field":"edf_score",
"oldValue": 4,
"newValue": 2
},
{
"field":"edf_average_rating",
"oldValue": "BBB+",
"newValue": "BB"
}
]
}
]
I need to expose these in JSON-HAL format.
Thanks in advance.