问题
I'm using Javers to tracking record history change (on ModerationEntity) and have the necessary to retrieve it with some criteria in my specific case is filter some of them that have the ListEntity (id = 51).
ModerationEntity
{
"requestedPublicationStatus": "PUBLISHED_NATIONAL",
"currentPublicationStatus": "UNPUBLISHED",
"id": 1000004,
"list": {
"entity": "ListEntity",
"cdoId": 51
},
"status": "IN_MODERATION"
}
After looking around on the Javers JQL Example I didn't find any solution to deal with that except commit-property-filter. However as I'm using Javers with SpringBoot and the Javers commit is performed through JaversSpringDataJpaAuditableRepositoryAspect. In order to have the commit properties stored into DB we need to define the CommitPropertiesProvider (the default is EmptyPropertiesProvider) and unfortunately that it seem currently we just can define the static commit properties map (according to the API).
public interface CommitPropertiesProvider {
Map<String, String> provide();
}
My idea that if possible to have the concern object pass into the CommitPropertiesProvider#provide() API then we can construct the commit properties depend on the context.
public interface CommitPropertiesProvider {
Map<String, String> provide(Object domainObject);
}
By that I can easily declare my own CommitPropertiesProvider in order to define the mapping value return for each commit.
public class CustomCommitPropertiesProvider implements CommitPropertiesProvider {
public Map<String, String> provide(Object domainObject) {
if (domainObject instanceof ModerationEntity) {
// return map with key = "listId" & value = ModerationEntity#listId
}
// return emptyMap
}
}
Currently I cannot found any solution except turn off the springDataAuditableRepositoryAspect
javers.springDataAuditableRepositoryAspectEnabled=false
And then override with my own aspect (extends from AbstractSpringAuditableRepositoryAspect) in order to inject the logic I want.
来源:https://stackoverflow.com/questions/57518008/is-there-possibility-to-provide-object-dependent-map-for-commitpropertiesprovide