I am using spring-data-envers in my spring boot application. I can successfully register audits at my facilities.
Now I need to show the verified data to the user in the user interface. Similar to the search form, where the user can select the duration and entity for which he wants to see audit logs.
The RevisionRepository provided with string-data-envers has only three methods.
@NoRepositoryBean public interface RevisionRepository<T, ID extends Serializable, N extends Number & Comparable<N>> { Revision<N, T> findLastChangeRevision(ID id); Revisions<N, T> findRevisions(ID id); Page<Revision<N, T>> findRevisions(ID id, Pageable pageable); }
How to write your own query to get all changes for an entity between two dates by a specific user.
Please note that I added additional columns to the user_rev_entity table, where I store the user ID and the modified date. If I join this table using the entity_aud table, I can get the results.
The following are the scenarios of my audit tables.
CREATE TABLE `user_rev_entity` ( `id` int(11) NOT NULL AUTO_INCREMENT, `timestamp` bigint(20) NOT NULL, `created_by` bigint(20) NOT NULL, `created_date` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 CREATE TABLE `revchanges` ( `rev` int(11) NOT NULL, `entityname` varchar(255) DEFAULT NULL, KEY `FK_et6b2lrkqkab5mhvxkv861n8h` (`rev`), CONSTRAINT `FK_et6b2lrkqkab5mhvxkv861n8h` FOREIGN KEY (`rev`) REFERENCES `user_rev_entity` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 CREATE TABLE `roles_aud` ( `role_id` bigint(20) NOT NULL, `rev` int(11) NOT NULL, `revtype` tinyint(4) DEFAULT NULL, `description` varchar(255) DEFAULT NULL, `description_mod` bit(1) DEFAULT NULL, `display_name` varchar(255) DEFAULT NULL, `display_name_mod` bit(1) DEFAULT NULL, `is_enabled` bit(1) DEFAULT NULL, `enabled_mod` bit(1) DEFAULT NULL, `title` varchar(255) DEFAULT NULL, `title_mod` bit(1) DEFAULT NULL, PRIMARY KEY (`role_id`,`rev`), KEY `FK_pkqm51vsc35w2axvnns4bpas9` (`rev`), CONSTRAINT `FK_pkqm51vsc35w2axvnns4bpas9` FOREIGN KEY (`rev`) REFERENCES `user_rev_entity` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1
So basically I'm looking for all the changes made by a particular user at a specific time when the entity says βRoleβ.
There will be more such facilities.