Commit 40fb1c1c authored by michael.simon's avatar michael.simon
Browse files

Work on auditing with parent connection

parent 623a8c45
...@@ -51,10 +51,10 @@ public class AuditEntryEntity extends AbstractBaseEntity { ...@@ -51,10 +51,10 @@ public class AuditEntryEntity extends AbstractBaseEntity {
@Column(name = "audit_executor", length=64) @Column(name = "audit_executor", length=64)
private String executor; private String executor;
@ManyToOne(targetEntity = AuditEntryEntity.class, cascade = { CascadeType.MERGE }) @ManyToOne(targetEntity = AuditEntryEntity.class)
private AuditEntryEntity parentEntry; private AuditEntryEntity parentEntry;
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE }, @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE, CascadeType.PERSIST, CascadeType.MERGE },
targetEntity = AuditEntryEntity.class, mappedBy = "parentEntry") targetEntity = AuditEntryEntity.class, mappedBy = "parentEntry")
private Set<AuditEntryEntity> childEntries; private Set<AuditEntryEntity> childEntries;
...@@ -114,5 +114,13 @@ public class AuditEntryEntity extends AbstractBaseEntity { ...@@ -114,5 +114,13 @@ public class AuditEntryEntity extends AbstractBaseEntity {
this.parentEntry = parentEntry; this.parentEntry = parentEntry;
} }
public Set<AuditEntryEntity> getChildEntries() {
return childEntries;
}
public void setChildEntries(Set<AuditEntryEntity> childEntries) {
this.childEntries = childEntries;
}
} }
...@@ -51,8 +51,12 @@ public abstract class AbstractAuditor<T extends AuditEntryEntity> implements Aud ...@@ -51,8 +51,12 @@ public abstract class AbstractAuditor<T extends AuditEntryEntity> implements Aud
@Override @Override
public void setParent(Auditor auditor) { public void setParent(Auditor auditor) {
if (auditor != null) if (auditor != null) {
getAudit().setParentEntry(auditor.getAudit()); getAudit().setParentEntry(auditor.getAudit());
if (auditor.getAudit().getChildEntries() == null)
auditor.getAudit().setChildEntries(new HashSet<AuditEntryEntity>());
auditor.getAudit().getChildEntries().add(getAudit());
}
} }
@Override @Override
...@@ -99,7 +103,11 @@ public abstract class AbstractAuditor<T extends AuditEntryEntity> implements Aud ...@@ -99,7 +103,11 @@ public abstract class AbstractAuditor<T extends AuditEntryEntity> implements Aud
@Override @Override
public void finishAuditTrail() { public void finishAuditTrail() {
getAudit().setEndTime(new Date()); getAudit().setEndTime(new Date());
}
@SuppressWarnings("unchecked")
@Override
public void commitAuditTrail() {
if ((! writeAlways) && if ((! writeAlways) &&
getAudit().getAuditDetails().size() > 0 || getAudit().getAuditDetails().size() > 0 ||
getWriteEmptyAudits()) { getWriteEmptyAudits()) {
......
...@@ -25,4 +25,6 @@ public interface Auditor extends Serializable { ...@@ -25,4 +25,6 @@ public interface Auditor extends Serializable {
void setParent(Auditor auditor); void setParent(Auditor auditor);
void startAuditTrail(String executor, Boolean writeAlways); void startAuditTrail(String executor, Boolean writeAlways);
void commitAuditTrail();
} }
\ No newline at end of file
...@@ -240,6 +240,7 @@ public class UserUpdater implements Serializable { ...@@ -240,6 +240,7 @@ public class UserUpdater implements Serializable {
auditor.setUser(user); auditor.setUser(user);
auditor.finishAuditTrail(); auditor.finishAuditTrail();
auditor.commitAuditTrail();
return user; return user;
} }
......
...@@ -44,9 +44,6 @@ ...@@ -44,9 +44,6 @@
<h:outputText value="#{messages.class}:" /> <h:outputText value="#{messages.class}:" />
<h:outputText value="#{showAuditEntryBean.entity.class.name}" /> <h:outputText value="#{showAuditEntryBean.entity.class.name}" />
<h:outputText value="#{messages.parent}:" />
<h:outputText value="#{showAuditEntryBean.entity.parentEntry.name}" />
<h:outputText value="#{messages.start_time}:" /> <h:outputText value="#{messages.start_time}:" />
<h:outputText value="#{showAuditEntryBean.entity.startTime}" /> <h:outputText value="#{showAuditEntryBean.entity.startTime}" />
...@@ -55,6 +52,14 @@ ...@@ -55,6 +52,14 @@
</p:panelGrid> </p:panelGrid>
<p:panelGrid id="parentAuditData" columns="2"
rendered="#{showAuditEntryBean.entity.parentEntry != null}">
<h:outputText value="#{messages.parent}:" />
<h:link outcome="show-audit-entry.xhtml" value="#{showAuditEntryBean.entity.parentEntry.name}">
<f:param name="id" value="#{showAuditEntryBean.entity.parentEntry.id}"/>
</h:link>
</p:panelGrid>
<p:panelGrid id="baseDataUser" columns="2" <p:panelGrid id="baseDataUser" columns="2"
rendered="#{(showAuditEntryBean.entity.class.simpleName == 'AuditUserCreateEntity') || rendered="#{(showAuditEntryBean.entity.class.simpleName == 'AuditUserCreateEntity') ||
(showAuditEntryBean.entity.class.simpleName == 'AuditUserUpdateEntity')}"> (showAuditEntryBean.entity.class.simpleName == 'AuditUserUpdateEntity')}">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment