diff --git a/osf/metadata/osf_gathering.py b/osf/metadata/osf_gathering.py index 3b21f079aaed..97723e2e235a 100644 --- a/osf/metadata/osf_gathering.py +++ b/osf/metadata/osf_gathering.py @@ -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, @@ -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 = { @@ -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, @@ -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: { }, @@ -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) @@ -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')) diff --git a/osf_tests/metadata/expected_metadata_files/file_basic.turtle b/osf_tests/metadata/expected_metadata_files/file_basic.turtle index 14a78c46c888..1df106c47f96 100644 --- a/osf_tests/metadata/expected_metadata_files/file_basic.turtle +++ b/osf_tests/metadata/expected_metadata_files/file_basic.turtle @@ -34,6 +34,7 @@ dcterms:format "img/png" ; dcterms:modified "2123-05-04" ; dcterms:requires ; + osf:storageRegion ; osf:versionNumber "1" . a dcterms:Agent, diff --git a/osf_tests/metadata/expected_metadata_files/file_full.turtle b/osf_tests/metadata/expected_metadata_files/file_full.turtle index 37dd3c537f0d..3c31ffcbf4b3 100644 --- a/osf_tests/metadata/expected_metadata_files/file_full.turtle +++ b/osf_tests/metadata/expected_metadata_files/file_full.turtle @@ -40,6 +40,7 @@ dcterms:format "img/png" ; dcterms:modified "2123-05-04" ; dcterms:requires ; + osf:storageRegion ; osf:versionNumber "1" . a osf:FundingAward ; diff --git a/osf_tests/metadata/expected_metadata_files/preprint_supplement.turtle b/osf_tests/metadata/expected_metadata_files/preprint_supplement.turtle index 662c197699de..8ac4aa1b9887 100644 --- a/osf_tests/metadata/expected_metadata_files/preprint_supplement.turtle +++ b/osf_tests/metadata/expected_metadata_files/preprint_supplement.turtle @@ -1 +1,6 @@ -# correctly empty (for now) +@prefix osf: . +@prefix skos: . + + osf:storageRegion . + + skos:prefLabel "United States"@en . diff --git a/osf_tests/metadata/expected_metadata_files/project_basic.turtle b/osf_tests/metadata/expected_metadata_files/project_basic.turtle index c38467822737..252bfeac4abe 100644 --- a/osf_tests/metadata/expected_metadata_files/project_basic.turtle +++ b/osf_tests/metadata/expected_metadata_files/project_basic.turtle @@ -53,8 +53,19 @@ dcterms:modified "2123-05-04" ; osf:fileName "my-file.blarg" ; osf:filePath "/my-file.blarg" ; + osf:hasFileVersion ; osf:isContainedBy . + a osf:FileVersion ; + dcterms:created "2123-05-04" ; + dcterms:creator ; + dcterms:extent "0.000007 MB" ; + dcterms:format "img/png" ; + dcterms:modified "2123-05-04" ; + dcterms:requires ; + osf:storageRegion ; + osf:versionNumber "1" . + a dcterms:Agent, foaf:Organization ; dcterms:identifier "https://cos.io/", diff --git a/osf_tests/metadata/expected_metadata_files/project_full.turtle b/osf_tests/metadata/expected_metadata_files/project_full.turtle index 6a84d1414409..329bb734f1ca 100644 --- a/osf_tests/metadata/expected_metadata_files/project_full.turtle +++ b/osf_tests/metadata/expected_metadata_files/project_full.turtle @@ -59,8 +59,19 @@ dcterms:modified "2123-05-04" ; osf:fileName "my-file.blarg" ; osf:filePath "/my-file.blarg" ; + osf:hasFileVersion ; osf:isContainedBy . + a osf:FileVersion ; + dcterms:created "2123-05-04" ; + dcterms:creator ; + dcterms:extent "0.000007 MB" ; + dcterms:format "img/png" ; + dcterms:modified "2123-05-04" ; + dcterms:requires ; + osf:storageRegion ; + osf:versionNumber "1" . + a osf:FundingAward ; dcterms:contributor ; dcterms:identifier "https://moneypockets.example/millions" ; diff --git a/osf_tests/metadata/expected_metadata_files/project_supplement.turtle b/osf_tests/metadata/expected_metadata_files/project_supplement.turtle index e01335e2f214..70363ed33a3c 100644 --- a/osf_tests/metadata/expected_metadata_files/project_supplement.turtle +++ b/osf_tests/metadata/expected_metadata_files/project_supplement.turtle @@ -3,7 +3,10 @@ @prefix skos: . osf:hasOsfAddon ; + osf:storageRegion . a osf:AddonImplementation ; dcterms:identifier "gitlab" ; skos:prefLabel "GitLab" . + + skos:prefLabel "United States"@en . diff --git a/osf_tests/metadata/expected_metadata_files/registration_basic.turtle b/osf_tests/metadata/expected_metadata_files/registration_basic.turtle index eae4a92336c9..693ed41c0cb1 100644 --- a/osf_tests/metadata/expected_metadata_files/registration_basic.turtle +++ b/osf_tests/metadata/expected_metadata_files/registration_basic.turtle @@ -21,6 +21,7 @@ dcterms:title "this is a project title!" ; dcterms:type ; dcat:accessService ; + osf:contains ; osf:hostingInstitution . a osf:Project ; @@ -36,6 +37,25 @@ dcterms:title "this is a project title!" ; owl:sameAs . + 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 ; + osf:isContainedBy . + + a osf:FileVersion ; + dcterms:created "2123-05-04" ; + dcterms:creator ; + dcterms:extent "0.000016 MB" ; + dcterms:format "img/png" ; + dcterms:modified "2123-05-04" ; + dcterms:requires ; + osf:storageRegion ; + osf:versionNumber "1" . + a dcterms:Agent, foaf:Organization ; dcterms:identifier "https://cos.io/", diff --git a/osf_tests/metadata/expected_metadata_files/registration_full.turtle b/osf_tests/metadata/expected_metadata_files/registration_full.turtle index d30c4594bbe3..6db9fd83ca3a 100644 --- a/osf_tests/metadata/expected_metadata_files/registration_full.turtle +++ b/osf_tests/metadata/expected_metadata_files/registration_full.turtle @@ -21,6 +21,7 @@ dcterms:title "this is a project title!" ; dcterms:type ; dcat:accessService ; + osf:contains ; osf:hostingInstitution . a osf:Project ; @@ -41,6 +42,25 @@ osf:hasFunding , . + 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 ; + osf:isContainedBy . + + a osf:FileVersion ; + dcterms:created "2123-05-04" ; + dcterms:creator ; + dcterms:extent "0.000016 MB" ; + dcterms:format "img/png" ; + dcterms:modified "2123-05-04" ; + dcterms:requires ; + osf:storageRegion ; + osf:versionNumber "1" . + a osf:FundingAward ; dcterms:contributor ; dcterms:identifier "https://moneypockets.example/millions" ; diff --git a/osf_tests/metadata/expected_metadata_files/registration_supplement.turtle b/osf_tests/metadata/expected_metadata_files/registration_supplement.turtle index 662c197699de..9c2599245e7c 100644 --- a/osf_tests/metadata/expected_metadata_files/registration_supplement.turtle +++ b/osf_tests/metadata/expected_metadata_files/registration_supplement.turtle @@ -1 +1,6 @@ -# correctly empty (for now) +@prefix osf: . +@prefix skos: . + + osf:storageRegion . + + skos:prefLabel "United States"@en . diff --git a/osf_tests/metadata/test_osf_gathering.py b/osf_tests/metadata/test_osf_gathering.py index bc3415389f7b..790be8679db7 100644 --- a/osf_tests/metadata/test_osf_gathering.py +++ b/osf_tests/metadata/test_osf_gathering.py @@ -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): @@ -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')), + }) diff --git a/osf_tests/metadata/test_serialized_metadata.py b/osf_tests/metadata/test_serialized_metadata.py index eecca396e21e..93001acf1451 100644 --- a/osf_tests/metadata/test_serialized_metadata.py +++ b/osf_tests/metadata/test_serialized_metadata.py @@ -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)