Is there possibility to provide object dependent map for CommitPropertiesProvider?

时光毁灭记忆、已成空白 提交于 2019-12-11 17:07:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!