From 327d8fcd08f05b38d7ed00cef134b03829167532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olov=20Ylinenp=C3=A4=C3=A4?= Date: Fri, 15 Nov 2024 10:31:49 +0100 Subject: [PATCH] fix(bulk-changes): preview diff for created records --- .../groovy/whelk/housekeeping/BulkChangePreviewAPI.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/housekeeping/src/main/groovy/whelk/housekeeping/BulkChangePreviewAPI.java b/housekeeping/src/main/groovy/whelk/housekeeping/BulkChangePreviewAPI.java index 1bf8fe8519..c9446511d5 100644 --- a/housekeeping/src/main/groovy/whelk/housekeeping/BulkChangePreviewAPI.java +++ b/housekeeping/src/main/groovy/whelk/housekeeping/BulkChangePreviewAPI.java @@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.Date; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -163,7 +164,6 @@ private Map makePreviewChangeSet(RecordedChange recordChange) { var recordAfter = getRecord.apply(recordChange.after()); var recordCopy = new LinkedHashMap<>(recordBefore.isEmpty() ? recordAfter : recordBefore); - // Remove @id from record to prevent it from being shown as a link in the diff view recordBefore.remove(ID_KEY); recordAfter.remove(ID_KEY); @@ -179,6 +179,13 @@ private Map makePreviewChangeSet(RecordedChange recordChange) { // However when the diff is computed we need "@graph form", hence the same record copy at @graph,0 in both versions var beforeDoc = new Document(Map.of(GRAPH_KEY, List.of(recordCopy, thingBefore))); var afterDoc = new Document(Map.of(GRAPH_KEY, List.of(recordCopy, thingAfter))); + if (beforeDoc.getModified() == null) { + beforeDoc.setModified(new Date()); + } + if (afterDoc.getModified() == null) { + afterDoc.setModified(new Date()); + } + var id = (String) recordCopy.get(ID_KEY); var result = getChangeSetsMap(beforeDoc, afterDoc, id);