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 21, 2024
1 parent aea21ca commit 0441c8e
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 13 deletions.
37 changes: 27 additions & 10 deletions osf/metadata/osf_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ def pls_get_magic_metadata_basket(osf_item) -> gather.Basket:
OSF.hasFunding: None,
}

OSF_FILEVERSION = {
DCTERMS.created: None,
DCTERMS.creator: OSF_AGENT_REFERENCE,
DCTERMS.extent: None,
DCTERMS.modified: None,
DCTERMS.requires: None,
DCTERMS['format']: None,
OSF.versionNumber: None,
}

OSF_FILE_REFERENCE = {
DCTERMS.identifier: None,
DCTERMS.title: None,
Expand All @@ -85,6 +95,7 @@ def pls_get_magic_metadata_basket(osf_item) -> gather.Basket:
OSF.isContainedBy: OSF_OBJECT_REFERENCE,
OSF.fileName: None,
OSF.filePath: None,
OSF.hasFileVersion: OSF_FILEVERSION,
}

OSF_OBJECT = {
Expand Down Expand Up @@ -130,16 +141,6 @@ def pls_get_magic_metadata_basket(osf_item) -> gather.Basket:
OWL.sameAs: None,
}

OSF_FILEVERSION = {
DCTERMS.created: None,
DCTERMS.creator: OSF_AGENT_REFERENCE,
DCTERMS.extent: None,
DCTERMS.modified: None,
DCTERMS.requires: None,
DCTERMS['format']: None,
OSF.versionNumber: None,
}

OSFMAP = {
OSF.Project: {
**OSF_OBJECT,
Expand Down Expand Up @@ -212,15 +213,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 +694,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 +1140,12 @@ 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, 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,6 @@
# 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/> skos:prefLabel "United States"@en .
11 changes: 11 additions & 0 deletions osf_tests/metadata/expected_metadata_files/project_basic.turtle
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,19 @@
dcterms:modified "2123-05-04" ;
osf:fileName "my-file.blarg" ;
osf:filePath "/my-file.blarg" ;
osf:hasFileVersion <http://localhost:5000/w3ibb?revision=1> ;
osf:isContainedBy <http://localhost:5000/w2ibb> .

<http://localhost:5000/w3ibb?revision=1> a osf:FileVersion ;
dcterms:created "2123-05-04" ;
dcterms:creator <http://localhost:5000/w1ibb> ;
dcterms:extent "0.000007 MB" ;
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://cos.io/> a dcterms:Agent,
foaf:Organization ;
dcterms:identifier "https://cos.io/",
Expand Down
11 changes: 11 additions & 0 deletions osf_tests/metadata/expected_metadata_files/project_full.turtle
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,19 @@
dcterms:modified "2123-05-04" ;
osf:fileName "my-file.blarg" ;
osf:filePath "/my-file.blarg" ;
osf:hasFileVersion <http://localhost:5000/w3ibb?revision=1> ;
osf:isContainedBy <http://localhost:5000/w2ibb> .

<http://localhost:5000/w3ibb?revision=1> a osf:FileVersion ;
dcterms:created "2123-05-04" ;
dcterms:creator <http://localhost:5000/w1ibb> ;
dcterms:extent "0.000007 MB" ;
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 ;
dcterms:contributor <https://doi.org/10.$$$$> ;
dcterms:identifier "https://moneypockets.example/millions" ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
@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/> skos:prefLabel "United States"@en .
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
dcterms:title "this is a project title!" ;
dcterms:type <https://schema.datacite.org/meta/kernel-4/#StudyRegistration> ;
dcat:accessService <http://localhost:5000> ;
osf:contains <http://localhost:5000/w6ibb> ;
osf:hostingInstitution <https://cos.io/> .

<http://localhost:5000/w2ibb> a osf:Project ;
Expand All @@ -36,6 +37,25 @@
dcterms:title "this is a project title!" ;
owl:sameAs <https://doi.org/10.70102/FK2osf.io/w2ibb> .

<http://localhost:5000/w6ibb> a osf:File ;
dcterms:created "2123-05-04" ;
dcterms:identifier "http://localhost:5000/w6ibb" ;
dcterms:modified "2123-05-04" ;
osf:fileName "my-reg-file.blarg" ;
osf:filePath "/my-reg-file.blarg" ;
osf:hasFileVersion <http://localhost:5000/w6ibb?revision=1> ;
osf:isContainedBy <http://localhost:5000/w5ibb> .

<http://localhost:5000/w6ibb?revision=1> a osf:FileVersion ;
dcterms:created "2123-05-04" ;
dcterms:creator <http://localhost:5000/w1ibb> ;
dcterms:extent "0.000016 MB" ;
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://cos.io/> a dcterms:Agent,
foaf:Organization ;
dcterms:identifier "https://cos.io/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
dcterms:title "this is a project title!" ;
dcterms:type <https://schema.datacite.org/meta/kernel-4/#StudyRegistration> ;
dcat:accessService <http://localhost:5000> ;
osf:contains <http://localhost:5000/w6ibb> ;
osf:hostingInstitution <https://cos.io/> .

<http://localhost:5000/w2ibb> a osf:Project ;
Expand All @@ -41,6 +42,25 @@
osf:hasFunding <https://moneypockets.example/millions>,
<https://moneypockets.example/millions-more> .

<http://localhost:5000/w6ibb> a osf:File ;
dcterms:created "2123-05-04" ;
dcterms:identifier "http://localhost:5000/w6ibb" ;
dcterms:modified "2123-05-04" ;
osf:fileName "my-reg-file.blarg" ;
osf:filePath "/my-reg-file.blarg" ;
osf:hasFileVersion <http://localhost:5000/w6ibb?revision=1> ;
osf:isContainedBy <http://localhost:5000/w5ibb> .

<http://localhost:5000/w6ibb?revision=1> a osf:FileVersion ;
dcterms:created "2123-05-04" ;
dcterms:creator <http://localhost:5000/w1ibb> ;
dcterms:extent "0.000016 MB" ;
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 ;
dcterms:contributor <https://doi.org/10.$$$$> ;
dcterms:identifier "https://moneypockets.example/millions" ;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# 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/> skos:prefLabel "United States"@en .
18 changes: 17 additions & 1 deletion osf_tests/metadata/test_osf_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ def test_gather_versions(self):
(fileversion_iri, DCTERMS['format'], Literal(fileversion.content_type)),
(fileversion_iri, DCTERMS.extent, Literal('0.118 MB')),
(fileversion_iri, OSF.versionNumber, Literal(fileversion.identifier)),
(fileversion_iri, DCTERMS.requires, checksum_iri('sha-256', self.file_sha256))
(fileversion_iri, DCTERMS.requires, checksum_iri('sha-256', self.file_sha256)),
(fileversion_iri, OSF.storageRegion, URIRef(f'{website_settings.API_DOMAIN}v2/regions/us/')),
})

def test_gather_files(self):
Expand Down Expand Up @@ -805,3 +806,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}v2/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')),
})
7 changes: 7 additions & 0 deletions osf_tests/metadata/test_serialized_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ def setUp(self):
doi_prefix='11.rp',
),
)
self.reg_file = create_test_file(
self.registration,
self.user,
filename='my-reg-file.blarg',
size=17,
sha256='6ac3c336e4094835293a3fed8a4b5fedde1b5e2626d9838fed50693bba00af0e',
)
osfdb.GuidMetadataRecord.objects.for_guid(self.registration._id).update({
'resource_type_general': 'StudyRegistration',
}, auth=self.user)
Expand Down

0 comments on commit 0441c8e

Please sign in to comment.