From 019a71f90279f0aa9848409f8b864befb3b01cf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olov=20Ylinenp=C3=A4=C3=A4?= <51744858+olovy@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:10:07 +0100 Subject: [PATCH] fix(rest): sameAs redirect for merged docs (#1537) sameAs should redirect to the main id for the entity. This fixes the issue that a deleted (merged) doc with the same id would give 410 DELETED instead TODO this could/should be implemented as a replacedBy inside the tombstone? --- rest/src/main/groovy/whelk/rest/api/Crud.groovy | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rest/src/main/groovy/whelk/rest/api/Crud.groovy b/rest/src/main/groovy/whelk/rest/api/Crud.groovy index a7f2117f9c..13799d27d3 100644 --- a/rest/src/main/groovy/whelk/rest/api/Crud.groovy +++ b/rest/src/main/groovy/whelk/rest/api/Crud.groovy @@ -338,6 +338,16 @@ class Crud extends HttpServlet { Document doc = whelk.storage.load(id, version) if (doc) { + // it has been merged with another doc - main id is in sameAs of remaining doc + // TODO this could/should be implemented as a replacedBy inside the tombstone? + if (doc.deleted && !JsonLd.looksLikeIri(id)) { + String iri = Document.BASE_URI.toString() + id + Document.HASH_IT + String location = whelk.storage.getMainId(iri) + if (location) { + return new Tuple2(null, location) + } + } + return new Tuple2(doc, null) }