From 83ef8d7b0ca9ea37870af3ab07137fc8ab52869e Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Tue, 12 Sep 2017 15:51:49 -0400 Subject: [PATCH] Adjust how entity draft auditing works. --- pom.xml | 2 +- .../helenus/core/AbstractAuditedEntityDraft.java | 16 ++++++++++++---- .../java/net/helenus/core/AuditProvider.java | 10 ---------- .../helenus/core/operation/UpdateOperation.java | 15 +++++++++++++++ .../test/integration/core/draft/Inventory.java | 6 ++++-- 5 files changed, 32 insertions(+), 17 deletions(-) delete mode 100644 src/main/java/net/helenus/core/AuditProvider.java diff --git a/pom.xml b/pom.xml index b3d96c8..0669e3b 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 net.helenus helenus-core - 2.0.27-SNAPSHOT + 2.0.28-SNAPSHOT jar helenus diff --git a/src/main/java/net/helenus/core/AbstractAuditedEntityDraft.java b/src/main/java/net/helenus/core/AbstractAuditedEntityDraft.java index 15df4cf..5ec76d3 100644 --- a/src/main/java/net/helenus/core/AbstractAuditedEntityDraft.java +++ b/src/main/java/net/helenus/core/AbstractAuditedEntityDraft.java @@ -9,23 +9,31 @@ import java.util.Date; public abstract class AbstractAuditedEntityDraft extends AbstractEntityDraft { - public AbstractAuditedEntityDraft(MapExportable entity, AuditProvider auditProvider) { + public AbstractAuditedEntityDraft(MapExportable entity) { super(entity); Date in = new Date(); LocalDateTime ldt = LocalDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault()); Date now = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()); - String who = auditProvider == null ? "unknown" : auditProvider.operatorName(); + String who = getCurrentAuditor(); if (entity == null) { - set("createdBy", who); + if (who != null) { + set("createdBy", who); + } set("createdAt", now); } - set("modifiedBy", who); + if (who != null) { + set("modifiedBy", who); + } set("modifiedAt", now); } + protected String getCurrentAuditor() { + return null; + } + public Date createdAt() { return (Date) get("createdAt", Date.class); } diff --git a/src/main/java/net/helenus/core/AuditProvider.java b/src/main/java/net/helenus/core/AuditProvider.java deleted file mode 100644 index 43c28bc..0000000 --- a/src/main/java/net/helenus/core/AuditProvider.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.helenus.core; - -public interface AuditProvider { - - /** - * What to record in the database row as the name of the agent causing the mutation. - * @return a string name that indicates the identity of the operator mutating the data at this time. - */ - public String operatorName(); -} diff --git a/src/main/java/net/helenus/core/operation/UpdateOperation.java b/src/main/java/net/helenus/core/operation/UpdateOperation.java index 40a019b..f04c90e 100644 --- a/src/main/java/net/helenus/core/operation/UpdateOperation.java +++ b/src/main/java/net/helenus/core/operation/UpdateOperation.java @@ -576,4 +576,19 @@ public final class UpdateOperation extends AbstractFilterOperation set = new HashSet(1); + set.add(result); + uow.getCache().put(key, set); + } + } + return result; + } + } diff --git a/src/test/java/net/helenus/test/integration/core/draft/Inventory.java b/src/test/java/net/helenus/test/integration/core/draft/Inventory.java index 86c63fa..a4f7a12 100644 --- a/src/test/java/net/helenus/test/integration/core/draft/Inventory.java +++ b/src/test/java/net/helenus/test/integration/core/draft/Inventory.java @@ -24,18 +24,20 @@ public interface Inventory { // Entity/Draft pattern-enabling methods: Draft(UUID id) { - super(null, null); + super(null); // Primary Key: set("id", id); } Draft(Inventory inventory) { - super((MapExportable) inventory, null); + super((MapExportable) inventory); } public Class getEntityClass() { return Inventory.class; } + protected String getCurrentAuditor() { return "unknown"; } + // Immutable properties: public UUID id() { return this.get("id", UUID.class);