This is an automated email from the ASF dual-hosted git repository. danhaywood pushed a commit to branch CAUSEWAY-3688 in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 5b72c19758bb8cb1c7b08e204b4251cf3a56b3c7 Author: danhaywood <[email protected]> AuthorDate: Wed Feb 21 13:58:48 2024 +0000 CAUSEWAY-3688: makes audit trail robust when fail to read current value for all scenarios (new, update, delete) --- .../objectlifecycle/PropertyChangeRecord.java | 40 ++++++++++++++-------- .../changetracking/EntityChangeTrackerDefault.java | 4 +-- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/objectlifecycle/PropertyChangeRecord.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/objectlifecycle/PropertyChangeRecord.java index a22cd85fb7..6c74c4882c 100644 --- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/objectlifecycle/PropertyChangeRecord.java +++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/objectlifecycle/PropertyChangeRecord.java @@ -83,15 +83,7 @@ public final class PropertyChangeRecord { return target.getLogicalTypeName() + "#" + propertyId; } - public PropertyChangeRecord withPreValueSetToNew() { - return withPreValueSetTo(PropertyValuePlaceholder.NEW); - } - - public PropertyChangeRecord withPreValueSetToCurrent() { - return withPreValueSetTo(getPropertyValue()); - } - - private PropertyChangeRecord withPreValueSetToCurrentElseUnknown() { + public PropertyChangeRecord withPreValueSetToCurrentElseUnknown() { try { return withPreValueSetToCurrent(); } catch (Exception ex) { @@ -99,21 +91,41 @@ public final class PropertyChangeRecord { } } + private PropertyChangeRecord withPreValueSetToCurrent() { + return withPreValueSetTo(getPropertyValue()); + } + private PropertyChangeRecord withPreValueSetToUnknown() { return withPreValueSetTo(PropertyValuePlaceholder.UNKNOWN); } - public PropertyChangeRecord withPostValueSetToCurrent() { - return withPostValueSetTo(getPropertyValue()); + private PropertyChangeRecord withPreValueSetToNew() { + return withPreValueSetTo(PropertyValuePlaceholder.NEW); + } + + private PropertyChangeRecord withPreValueSetTo(Object preValue) { + this.preAndPostValue = PreAndPostValue.pre(preValue); + return this; + } + + public PropertyChangeRecord withPostValueSetToCurrentElseUnknown() { + try { + return withPostValueSetToCurrent(); + } catch (Exception ex) { + return withPostValueSetToUnknown(); + } } public PropertyChangeRecord withPostValueSetToDeleted() { return withPostValueSetTo(PropertyValuePlaceholder.DELETED); } - private PropertyChangeRecord withPreValueSetTo(Object preValue) { - this.preAndPostValue = PreAndPostValue.pre(preValue); - return this; + private PropertyChangeRecord withPostValueSetToCurrent() { + return withPostValueSetTo(getPropertyValue()); + } + + private PropertyChangeRecord withPostValueSetToUnknown() { + return withPostValueSetTo(PropertyValuePlaceholder.UNKNOWN); } private PropertyChangeRecord withPostValueSetTo(Object postValue) { diff --git a/persistence/commons/src/main/java/org/apache/causeway/persistence/commons/integration/changetracking/EntityChangeTrackerDefault.java b/persistence/commons/src/main/java/org/apache/causeway/persistence/commons/integration/changetracking/EntityChangeTrackerDefault.java index 88a5cd49d5..8f8a065a5f 100644 --- a/persistence/commons/src/main/java/org/apache/causeway/persistence/commons/integration/changetracking/EntityChangeTrackerDefault.java +++ b/persistence/commons/src/main/java/org/apache/causeway/persistence/commons/integration/changetracking/EntityChangeTrackerDefault.java @@ -186,7 +186,7 @@ implements if(MmEntityUtils.getEntityState(rec.getEntity()).isTransientOrRemoved()) { rec.withPostValueSetToDeleted(); } else { - rec.withPostValueSetToCurrent(); + rec.withPostValueSetToCurrentElseUnknown(); } }) .filter(managedProperty-> shouldPublish(managedProperty.getPreAndPostValue())) @@ -375,7 +375,7 @@ implements .filter(pcrId -> ! enlistedPropertyChangeRecordsById.containsKey(pcrId)) // only if not previously seen .map(pcrId -> enlistedPropertyChangeRecordsById.put(pcrId, PropertyChangeRecord.ofCurrent(pcrId))) .filter(Objects::nonNull) // shouldn't happen, just keeping compiler happy - .forEach(PropertyChangeRecord::withPreValueSetToCurrent); + .forEach(PropertyChangeRecord::withPreValueSetToCurrentElseUnknown); } }); }
