Skip to content

Commit

Permalink
osf:storageRegion supplementary metadata [ENG-6186]
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Oct 18, 2024
1 parent 86a23e0 commit 6339a7f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 2 deletions.
17 changes: 17 additions & 0 deletions osf/metadata/osf_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,20 @@ def pls_get_magic_metadata_basket(osf_item) -> gather.Basket:
OSFMAP_SUPPLEMENT = {
OSF.Project: {
OSF.hasOsfAddon: None,
OSF.storageRegion: None,
},
OSF.ProjectComponent: {
OSF.hasOsfAddon: None,
OSF.storageRegion: None,
},
OSF.Registration: {
OSF.storageRegion: None,
},
OSF.RegistrationComponent: {
OSF.storageRegion: None,
},
OSF.Preprint: {
OSF.storageRegion: None,
},
OSF.File: {
},
Expand Down Expand Up @@ -688,6 +693,8 @@ def _gather_fileversion(fileversion, fileversion_iri):
version_sha256 = (fileversion.metadata or {}).get('sha256')
if version_sha256:
yield (fileversion_iri, DCTERMS.requires, checksum_iri('sha-256', version_sha256))
if fileversion.region is not None:
yield (fileversion_iri, OSF.storageRegion, rdflib.URIRef(fileversion.region.absolute_api_v2_url))


@gather.er(OSF.contains)
Expand Down Expand Up @@ -1132,3 +1139,13 @@ def gather_addons(focus):
yield (_addon_ref, RDF.type, OSF.AddonImplementation)
yield (_addon_ref, DCTERMS.identifier, _addon_settings.short_name)
yield (_addon_ref, SKOS.prefLabel, _addon_settings.config.full_name)


@gather.er(OSF.storageRegion)
def gather_storage_region(focus):
_region = getattr(focus.dbmodel, 'osfstorage_region', None)
if _region is not None:
_region_ref = rdflib.URIRef(_region.absolute_api_v2_url)
yield (OSF.storageRegion, _region_ref)
yield (_region_ref, RDF.type, OSF.Region)
yield (_region_ref, SKOS.prefLabel, rdflib.Literal(_region.name, lang='en'))
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
dcterms:format "img/png" ;
dcterms:modified "2123-05-04" ;
dcterms:requires <urn:checksum:sha-256::6ac3c336e4094835293a3fed8a4b5fedde1b5e2626d9838fed50693bba00af0e> ;
osf:storageRegion <http://localhost:8000/v2/regions/us/> ;
osf:versionNumber "1" .

<http://localhost:5000/w1ibb> a dcterms:Agent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
dcterms:format "img/png" ;
dcterms:modified "2123-05-04" ;
dcterms:requires <urn:checksum:sha-256::6ac3c336e4094835293a3fed8a4b5fedde1b5e2626d9838fed50693bba00af0e> ;
osf:storageRegion <http://localhost:8000/v2/regions/us/> ;
osf:versionNumber "1" .

<https://moneypockets.example/millions> a osf:FundingAward ;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# correctly empty (for now)
@prefix osf: <https://osf.io/vocab/2022/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .

<http://localhost:5000/w4ibb> osf:storageRegion <http://localhost:8000/v2/regions/us/> .

<http://localhost:8000/v2/regions/us/> a osf:Region ;
skos:prefLabel "United States"@en .
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .

<http://localhost:5000/w2ibb> osf:hasOsfAddon <urn:osf.io:addons:gitlab> ;
osf:storageRegion <http://localhost:8000/v2/regions/us/> .

<urn:osf.io:addons:gitlab> a osf:AddonImplementation ;
dcterms:identifier "gitlab" ;
skos:prefLabel "GitLab" .

<http://localhost:8000/v2/regions/us/> a osf:Region ;
skos:prefLabel "United States"@en .
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# correctly empty (for now)
@prefix osf: <https://osf.io/vocab/2022/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .

<http://localhost:5000/w5ibb> osf:storageRegion <http://localhost:8000/v2/regions/us/> .

<http://localhost:8000/v2/regions/us/> a osf:Region ;
skos:prefLabel "United States"@en .
15 changes: 15 additions & 0 deletions osf_tests/metadata/test_osf_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,3 +805,18 @@ def test_gather_addons(self):
(_gitlab_ref, DCTERMS.identifier, Literal('gitlab')),
(_gitlab_ref, SKOS.prefLabel, Literal('GitLab')),
})

def test_gather_storage_region(self):
_default_region_ref = rdflib.URIRef(f'{website_settings.API_DOMAIN}regions/us/')
assert_triples(osf_gathering.gather_storage_region(self.projectfocus), {
(self.projectfocus.iri, OSF.storageRegion, _default_region_ref),
(_default_region_ref, SKOS.prefLabel, Literal('United States', lang='en')),
})
assert_triples(osf_gathering.gather_storage_region(self.registrationfocus), {
(self.registrationfocus.iri, OSF.storageRegion, _default_region_ref),
(_default_region_ref, SKOS.prefLabel, Literal('United States', lang='en')),
})
assert_triples(osf_gathering.gather_storage_region(self.preprintfocus), {
(self.preprintfocus.iri, OSF.storageRegion, _default_region_ref),
(_default_region_ref, SKOS.prefLabel, Literal('United States', lang='en')),
})

0 comments on commit 6339a7f

Please sign in to comment.