From 75430693b650674655de8342665cc0ae88d65670 Mon Sep 17 00:00:00 2001 From: Ihor Sokhan Date: Wed, 25 Nov 2026 17:33:33 +0200 Subject: [PATCH] send redirect_url of guid to SHARE under dcterms:isReplacedBy term --- osf/metadata/osf_gathering.py | 6 ++++++ osf_tests/metadata/test_osf_gathering.py | 25 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/osf/metadata/osf_gathering.py b/osf/metadata/osf_gathering.py index 7c08d7864f6..6ea6660d2d0 100644 --- a/osf/metadata/osf_gathering.py +++ b/osf/metadata/osf_gathering.py @@ -354,6 +354,12 @@ def gather_identifiers(focus: gather.Focus): yield (OWL.sameAs, rdflib.URIRef(_iri)) yield (DCTERMS.identifier, rdflib.Literal(_iri)) + _guids = getattr(focus.dbmodel, 'guids', None) + if _guids is not None: + for _guid in _guids.all(): + if _guid.redirect_url: + yield (DCTERMS.isReplacedBy, rdflib.Literal(_guid.redirect_url)) + @gather.er(DCTERMS.type) def gather_flexible_types(focus): diff --git a/osf_tests/metadata/test_osf_gathering.py b/osf_tests/metadata/test_osf_gathering.py index d0fc41cde95..7e68ad64cbd 100644 --- a/osf_tests/metadata/test_osf_gathering.py +++ b/osf_tests/metadata/test_osf_gathering.py @@ -163,6 +163,31 @@ def test_gather_identifiers(self): (self.filefocus.iri, DCTERMS.identifier, Literal(self.filefocus.iri)), }) + def test_gather_guid_redirect_urls(self): + project_redirect_url = 'https://example.org/projects/redirected' + project_guid = self.project.guids.first() + project_guid.redirect_url = project_redirect_url + project_guid.save() + + assert_triples(osf_gathering.gather_identifiers(self.projectfocus), { + (self.projectfocus.iri, DCTERMS.identifier, Literal(self.projectfocus.iri)), + (self.projectfocus.iri, DCTERMS.isReplacedBy, Literal(project_redirect_url)), + }) + + preprint_redirect_url = 'https://example.org/preprints/redirected' + preprint_guid = self.preprint.guids.first() + preprint_guid.redirect_url = preprint_redirect_url + preprint_guid.save() + _sameAs_iri = URIRef('https://doi.org/None/FK2osf.io/' + self.preprint._id) + _identifier_iri = Literal('https://doi.org/None/FK2osf.io/' + self.preprint._id) + + assert_triples(osf_gathering.gather_identifiers(self.preprintfocus), { + (self.preprintfocus.iri, OWL.sameAs, _sameAs_iri), + (self.preprintfocus.iri, DCTERMS.identifier, _identifier_iri), + (self.preprintfocus.iri, DCTERMS.identifier, Literal(self.preprintfocus.iri)), + (self.preprintfocus.iri, DCTERMS.isReplacedBy, Literal(preprint_redirect_url)), + }) + def test_gather_flexible_types(self): # focus: project assert_triples(osf_gathering.gather_flexible_types(self.projectfocus), {