-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Several changes to enable Envers plus some other fixes
- Add necessary auditing tables in Liquibase - Add some missing foreign key constraints - Add SQL to Liquibase to initialize the first revision for existing data - Rename AbstractAuditingEntity to AbstractEntity - AbstractEntity fields will be populated by AbstractEntityListener on PostLoad - Add Envers settings to application.yml in main and test - Add an AuditReader bean - CustomRevisionEntity no longer inherits DefaultRevisionEntity, this is done to customize the field types, e.g. the timestamp is a Date instead of a Long, the id is a Long instead of an Integer, and we use a custom sequence for this entity's primary key so as not to interfere with our existing sequences - Add a repository for CustomRevisionEntity - Delete EventPublisherEntityListener, we don't need to audit entity events in this way anymore - Add some commented lines in liquibase.gradle, a different config for using another Postgres DB as reference instead of the hibernate reference. When using the hibernate reference it seems the settings for envers in application.yml are not picked up. So if you need to create a diffChangelog, it's best to have a postgres with the 'old' schema and a postgres with the 'new' schema to use as reference and then run gradlew liquibaseDiffChangelog - Revert all changes to the PK sequences for our own entities, these are no longer necessary since we have a custom sequence in CustomRevisionEntity - Remove the created_at, created_by, last_modified_at and last_modified_by columns from all our entity tables. These are no longer necessary as this information is in the audit log. - Remove the `AndCreatedDateBefore` part of the UserRepository method, since we don't have that column anymore - Update the test for deleting non-activated users
- Loading branch information
1 parent
a527f58
commit e32b381
Showing
27 changed files
with
966 additions
and
655 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/org/radarcns/management/config/audit/AuditReaderConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.radarcns.management.config.audit; | ||
|
||
import org.hibernate.envers.AuditReader; | ||
import org.hibernate.envers.AuditReaderFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import javax.persistence.EntityManager; | ||
|
||
@Configuration | ||
public class AuditReaderConfiguration { | ||
|
||
@Autowired | ||
private EntityManager entityManager; | ||
|
||
@Bean | ||
public AuditReader auditReader() { | ||
return AuditReaderFactory.get(entityManager); | ||
} | ||
} |
81 changes: 0 additions & 81 deletions
81
src/main/java/org/radarcns/management/domain/AbstractAuditingEntity.java
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
src/main/java/org/radarcns/management/domain/AbstractEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.radarcns.management.domain; | ||
|
||
import org.radarcns.management.domain.support.AbstractEntityListener; | ||
|
||
import java.io.Serializable; | ||
import java.time.ZonedDateTime; | ||
|
||
/** | ||
* Base abstract class for entities which will hold definitions for created, last modified by and | ||
* created, last modified by date. These will be populated by {@link AbstractEntityListener} on | ||
* the {@code PostLoad} trigger. Since this class is not an Entity or a MappedSuperClass, we need | ||
* to define the entitylistener on each of the subclasses. | ||
*/ | ||
public abstract class AbstractEntity implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private String createdBy; | ||
|
||
private ZonedDateTime createdDate; | ||
|
||
private String lastModifiedBy; | ||
|
||
private ZonedDateTime lastModifiedDate; | ||
|
||
public String getCreatedBy() { | ||
return createdBy; | ||
} | ||
|
||
public void setCreatedBy(String createdBy) { | ||
this.createdBy = createdBy; | ||
} | ||
|
||
public ZonedDateTime getCreatedDate() { | ||
return createdDate; | ||
} | ||
|
||
public void setCreatedDate(ZonedDateTime createdDate) { | ||
this.createdDate = createdDate; | ||
} | ||
|
||
public String getLastModifiedBy() { | ||
return lastModifiedBy; | ||
} | ||
|
||
public void setLastModifiedBy(String lastModifiedBy) { | ||
this.lastModifiedBy = lastModifiedBy; | ||
} | ||
|
||
public ZonedDateTime getLastModifiedDate() { | ||
return lastModifiedDate; | ||
} | ||
|
||
public void setLastModifiedDate(ZonedDateTime lastModifiedDate) { | ||
this.lastModifiedDate = lastModifiedDate; | ||
} | ||
|
||
public abstract Long getId(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.