Skip to content

Commit

Permalink
fix(rest): sameAs redirect for merged docs (#1537)
Browse files Browse the repository at this point in the history
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?
  • Loading branch information
olovy authored Dec 10, 2024
1 parent 7820332 commit 019a71f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rest/src/main/groovy/whelk/rest/api/Crud.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 019a71f

Please sign in to comment.