Skip to content

Commit

Permalink
osf:hasOsfAddon supplementary metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Oct 3, 2024
1 parent 7a37b7e commit 43a8475
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
19 changes: 19 additions & 0 deletions osf/metadata/osf_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import rdflib

from osf import models as osfdb
from osf.external.gravy_valet import request_helpers as gv_requests
from osf.metadata import gather
from osf.metadata.rdfutils import (
DATACITE,
Expand Down Expand Up @@ -222,15 +223,19 @@ def osfmap_supplement_for_type(rdftype_iri: str):
OSFMAP_SUPPLEMENT = {
OSF.Project: {
OSF.usage: None,
OSF.hasOsfAddon: None,
},
OSF.ProjectComponent: {
OSF.usage: None,
OSF.hasOsfAddon: None,
},
OSF.Registration: {
OSF.usage: None,
OSF.hasOsfAddon: None,
},
OSF.RegistrationComponent: {
OSF.usage: None,
OSF.hasOsfAddon: None,
},
OSF.Preprint: {
OSF.usage: None,
Expand Down Expand Up @@ -1078,3 +1083,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, SKOS.prefLabel, _addon_settings.config.full_name)
yield (_addon_ref, SKOS.altLabel, _addon_settings.short_name)
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
@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 ;
<http://localhost:5000/w2ibb> osf:hasOsfAddon <urn:osf.io/addons/gitlab> ;
osf:usage [ dcterms:temporal "2123-05"^^xsd:gYearMonth ;
dcat:accessService <http://localhost:5000> ;
foaf:primaryTopic <http://localhost:5000/w2ibb> ;
osf:downloadCount 3 ;
osf:downloadSessionCount 2 ;
osf:viewCount 7 ;
osf:viewSessionCount 5 ] .

<urn:osf.io/addons/gitlab> a osf:AddonImplementation ;
skos:altLabel "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, SKOS.prefLabel, Literal('Box')),
(_box_ref, SKOS.altLabel, Literal('box')),
(self.projectfocus.iri, OSF.hasOsfAddon, _gitlab_ref),
(_gitlab_ref, RDF.type, OSF.AddonImplementation),
(_gitlab_ref, SKOS.prefLabel, Literal('GitLab')),
(_gitlab_ref, SKOS.altLabel, 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 @@ -156,6 +156,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 43a8475

Please sign in to comment.