diff --git a/src/main/java/org/radarcns/management/domain/audit/CustomRevisionEntity.java b/src/main/java/org/radarcns/management/domain/audit/CustomRevisionEntity.java index 14845fe61..ccf21fc1f 100644 --- a/src/main/java/org/radarcns/management/domain/audit/CustomRevisionEntity.java +++ b/src/main/java/org/radarcns/management/domain/audit/CustomRevisionEntity.java @@ -1,22 +1,30 @@ package org.radarcns.management.domain.audit; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; +import org.hibernate.envers.ModifiedEntityNames; import org.hibernate.envers.RevisionEntity; import org.hibernate.envers.RevisionNumber; import org.hibernate.envers.RevisionTimestamp; import org.radarcns.management.config.audit.CustomRevisionListener; +import javax.persistence.Column; +import javax.persistence.ElementCollection; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import java.io.Serializable; -import java.text.DateFormat; import java.util.Date; import java.util.Objects; +import java.util.Set; @Entity @RevisionEntity(CustomRevisionListener.class) @@ -36,6 +44,13 @@ public class CustomRevisionEntity implements Serializable { private String auditor; + @ElementCollection(fetch = FetchType.EAGER) + @JoinTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV")) + @Column(name = "ENTITYNAME") + @Fetch(FetchMode.JOIN) + @ModifiedEntityNames + private Set modifiedEntityNames; + public long getId() { return id; } @@ -63,19 +78,23 @@ public boolean equals(Object o) { } CustomRevisionEntity that = (CustomRevisionEntity) o; return id == that.id && Objects.equals(timestamp, that.timestamp) && Objects - .equals(auditor, that.auditor); + .equals(auditor, that.auditor) && Objects + .equals(modifiedEntityNames, that.modifiedEntityNames); } @Override public int hashCode() { - return Objects.hash(id, timestamp, auditor); + return Objects.hash(id, timestamp, auditor, modifiedEntityNames); } @Override public String toString() { - return "CustomRevisionEntity(id = " + id - + ", revisionDate = " + DateFormat.getDateTimeInstance().format( timestamp ) + ", " - + "auditor = " + auditor + ")"; + return "CustomRevisionEntity{" + + "id=" + id + + ", timestamp=" + timestamp + + ", auditor='" + auditor + '\'' + + ", modifiedEntityNames=" + modifiedEntityNames + + '}'; } public String getAuditor() { @@ -85,4 +104,12 @@ public String getAuditor() { public void setAuditor(String auditor) { this.auditor = auditor; } + + public Set getModifiedEntityNames() { + return modifiedEntityNames; + } + + public void setModifiedEntityNames(Set modifiedEntityNames) { + this.modifiedEntityNames = modifiedEntityNames; + } } \ No newline at end of file diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 436baea6b..8ecb504e1 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -61,11 +61,13 @@ spring: physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy properties: + hibernate.hbm2ddl.auto: update org.hibernate.envers: store_data_at_delete: true audit_strategy: org.hibernate.envers.strategy.ValidityAuditStrategy audit_strategy_validity_store_revend_timestamp: true global_with_modified_flag: true + track_entities_changed_in_revision: true messages: basename: i18n/messages mvc: diff --git a/src/main/resources/config/liquibase/changelog/20180313103735_enable_envers_revisions.xml b/src/main/resources/config/liquibase/changelog/20180313103735_enable_envers_revisions.xml index ee074798b..76a7477bd 100644 --- a/src/main/resources/config/liquibase/changelog/20180313103735_enable_envers_revisions.xml +++ b/src/main/resources/config/liquibase/changelog/20180313103735_enable_envers_revisions.xml @@ -542,4 +542,17 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/config/application.yml b/src/test/resources/config/application.yml index b8b55d681..3c7389c3c 100644 --- a/src/test/resources/config/application.yml +++ b/src/test/resources/config/application.yml @@ -53,6 +53,7 @@ spring: audit_strategy: org.hibernate.envers.strategy.ValidityAuditStrategy audit_strategy_validity_store_revend_timestamp: true global_with_modified_flag: true + track_entities_changed_in_revision: true mail: host: localhost messages: