Skip to content

Commit

Permalink
osf:hasOsfAddon supplementary metadata [ENG-6188]
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Oct 21, 2024
1 parent e96c2e8 commit aea21ca
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
16 changes: 16 additions & 0 deletions osf/metadata/osf_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ def pls_get_magic_metadata_basket(osf_item) -> gather.Basket:
# metadata not included in the core record
OSFMAP_SUPPLEMENT = {
OSF.Project: {
OSF.hasOsfAddon: None,
},
OSF.ProjectComponent: {
OSF.hasOsfAddon: None,
},
OSF.Registration: {
},
Expand Down Expand Up @@ -1116,3 +1118,17 @@ def gather_last_month_usage(focus):
yield (_usage_report_ref, OSF.viewSessionCount, _usage_report.view_session_count)
yield (_usage_report_ref, OSF.downloadCount, _usage_report.download_count)
yield (_usage_report_ref, OSF.downloadSessionCount, _usage_report.download_session_count)


@gather.er(OSF.hasOsfAddon)
def gather_addons(focus):
# note: when gravyvalet exists, use `iterate_addons_for_resource`
# from osf.external.gravy_valet.request_helpers and get urls like
# "https://addons.osf.example/v1/addon-imps/..." instead of a urn
for _addon_settings in focus.dbmodel.get_addons():
if not _addon_settings.config.added_default: # skip always-on addons
_addon_ref = rdflib.URIRef(f'urn:osf.io:addons:{_addon_settings.short_name}')
yield (OSF.hasOsfAddon, _addon_ref)
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)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix osf: <https://osf.io/vocab/2022/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://localhost:5000/w2ibb> osf:usage [ dcterms:temporal "2123-05"^^xsd:gYearMonth ;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# correctly empty (for now)
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix osf: <https://osf.io/vocab/2022/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .

<http://localhost:5000/w2ibb> osf:hasOsfAddon <urn:osf.io:addons:gitlab> ;

<urn:osf.io:addons:gitlab> a osf:AddonImplementation ;
dcterms:identifier "gitlab" ;
skos:prefLabel "GitLab" .
19 changes: 19 additions & 0 deletions osf_tests/metadata/test_osf_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def setUpTestData(cls):
)
# project (with components):
cls.project = factories.ProjectFactory(creator=cls.user__admin, is_public=True)
cls.project.add_addon('box', auth=None)
cls.project.add_addon('gitlab', auth=None)
cls.project.add_contributor(cls.user__readwrite, permissions=permissions.WRITE)
cls.project.add_contributor(cls.user__readonly, permissions=permissions.READ, visible=False)
cls.component = factories.ProjectFactory(parent=cls.project, creator=cls.user__admin, is_public=True)
Expand Down Expand Up @@ -786,3 +788,20 @@ def test_gather_last_month_usage(self):
(_usage_bnode, OSF.downloadCount, Literal(43)),
(_usage_bnode, OSF.downloadSessionCount, Literal(11)),
})

def test_gather_addons(self):
# registration (without non-default addon)
assert_triples(osf_gathering.gather_addons(self.registrationfocus), set())
# project (with non-default addons)
_box_ref = rdflib.URIRef('urn:osf.io:addons:box')
_gitlab_ref = rdflib.URIRef('urn:osf.io:addons:gitlab')
assert_triples(osf_gathering.gather_addons(self.projectfocus), {
(self.projectfocus.iri, OSF.hasOsfAddon, _box_ref),
(_box_ref, RDF.type, OSF.AddonImplementation),
(_box_ref, DCTERMS.identifier, Literal('box')),
(_box_ref, SKOS.prefLabel, Literal('Box')),
(self.projectfocus.iri, OSF.hasOsfAddon, _gitlab_ref),
(_gitlab_ref, RDF.type, OSF.AddonImplementation),
(_gitlab_ref, DCTERMS.identifier, Literal('gitlab')),
(_gitlab_ref, SKOS.prefLabel, Literal('GitLab')),
})
1 change: 1 addition & 0 deletions osf_tests/metadata/test_serialized_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def setUp(self):
category='doi',
value=f'10.70102/FK2osf.io/{self.project._id}',
)
self.project.add_addon('gitlab', auth=None)
self.file = create_test_file(
self.project,
self.user,
Expand Down

0 comments on commit aea21ca

Please sign in to comment.