I have Spring Boot app with javers-spring-boot-starter-sql
and use it in a simple way:
@Override
@JaversAuditable
public Company save(Company company) {
return companyRepository.save(company);
}
@Repository
@JaversSpringDataAuditable
public interface CompanyRepository
extends JpaRepository<Company, Long>, JpaSpecificationExecutor<Company> {
}
And return reduced action log by Change.commitMetadata.id
like
QueryBuilder jqlQuery = QueryBuilder.byClass(Account.class);
List<Change> changes = javers.findChanges(jqlQuery.build());
Set<ChangeBunch> bunches = changes.stream().collect(Collectors.groupingBy(this::getId))
.values().stream()
.map(item ->
ChangeBunch.builder().changes(item).comment("My comment").build()
).collect(Collectors.toSet());
return javers.getJsonConverter().toJson(bunches);
private long getId(Change change) {
return change.getCommitMetadata().orElseThrow().getId().getMajorId();
}
And get the output:
[
{
"comment": "My comment",
"changes": [
{
"changeType": "ValueChange",
"globalId": {
"entity": "com.pravvich.demo.model.Account",
"cdoId": 1
},
"commitMetadata": {
"author": "unauthenticated",
"properties": [],
"commitDate": "2021-01-27T02:59:54.361",
"commitDateInstant": "2021-01-26T23:59:54.361277500Z",
"id": 7.00
},
"property": "number",
"propertyChangeType": "PROPERTY_VALUE_CHANGED",
"left": 6,
"right": 100
},
{
"changeType": "ValueChange",
"globalId": {
"entity": "com.pravvich.demo.model.Account",
"cdoId": 1
},
"commitMetadata": {
"author": "unauthenticated",
"properties": [],
"commitDate": "2021-01-27T02:59:54.361",
"commitDateInstant": "2021-01-26T23:59:54.361277500Z",
"id": 7.00
},
"property": "balance",
"propertyChangeType": "PROPERTY_VALUE_CHANGED",
"left": 10.8,
"right": 200
}
]
}
]
But the comment is hardcoded I need to save the comment somehow in the database prefer just in javers
table as metadata but how I can extend it? Perhaps I have another way to leave a comment for the change bunch?
question from:
https://stackoverflow.com/questions/65918812/add-comment-for-audit-bunch-with-javers 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…