Skip to content

Commit

Permalink
fix: multiple funding awards from the same funder
Browse files Browse the repository at this point in the history
would previously generate invalid xml for datacite,
now should not.
  • Loading branch information
aaxelb committed Jan 10, 2024
1 parent 393c965 commit 600bc6d
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 31 deletions.
53 changes: 31 additions & 22 deletions osf/metadata/serializers/datacite/datacite_tree_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,33 +268,42 @@ def _visit_dates(self, parent_el):

def _visit_funding_references(self, parent_el):
fundrefs_el = self.visit(parent_el, 'fundingReferences', is_list=True)
_visited_funders = set()
for _funding_award in sorted(self.basket[OSF.hasFunding]):
# datacite allows at most one funder per funding reference
_funder = next(self.basket[_funding_award:DCTERMS.contributor])
self._funding_reference(fundrefs_el, _funder, _funding_award)
_visited_funders.add(_funder)
for _funder in self.basket[OSF.funder]:
fundref_el = self.visit(fundrefs_el, 'fundingReference')
self.visit(fundref_el, 'funderName', text=next(self.basket[_funder:FOAF.name], ''))
funder_identifier = next(self.basket[_funder:DCTERMS.identifier], '')
if _funder not in _visited_funders:
self._funding_reference(fundrefs_el, _funder)

def _funding_reference(self, fundrefs_el, funder, funding_award=None):
_fundref_el = self.visit(fundrefs_el, 'fundingReference')
self.visit(_fundref_el, 'funderName', text=next(self.basket[funder:FOAF.name], ''))
_funder_identifier = next(self.basket[funder:DCTERMS.identifier], '')
self.visit(
_fundref_el,
'funderIdentifier',
text=_funder_identifier,
attrib={
'funderIdentifierType': self._funder_identifier_type(_funder_identifier),
},
)
if funding_award is not None:
self.visit(
fundref_el,
'funderIdentifier',
text=funder_identifier,
_fundref_el,
'awardNumber',
text=next(self.basket[funding_award:OSF.awardNumber], ''),
attrib={
'funderIdentifierType': self._funder_identifier_type(funder_identifier),
'awardURI': (
str(funding_award)
if isinstance(funding_award, rdflib.URIRef)
else ''
)
},
)
for _funding_award in self.basket[OSF.hasFunding]:
if _funder in self.basket[_funding_award:DCTERMS.contributor]:
self.visit(
fundref_el,
'awardNumber',
text=next(self.basket[_funding_award:OSF.awardNumber], ''),
attrib={
'awardURI': (
str(_funding_award)
if isinstance(_funding_award, rdflib.URIRef)
else ''
)
},
)
self.visit(fundref_el, 'awardTitle', text=next(self.basket[_funding_award:DCTERMS.title], ''))
self.visit(_fundref_el, 'awardTitle', text=next(self.basket[funding_award:DCTERMS.title], ''))

def _visit_publication_year(self, parent_el, focus_iri):
year_copyrighted = next(self.basket[focus_iri:DCTERMS.dateCopyrighted], None)
Expand Down
16 changes: 14 additions & 2 deletions osf_tests/metadata/expected_metadata_files/file_full.turtle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
dcterms:title "this is a project title!"@en ;
dcterms:type <https://schema.datacite.org/meta/kernel-4.4/#Dataset> ;
owl:sameAs <https://doi.org/10.70102/FK2osf.io/w2ibb> ;
osf:funder <https://doi.org/10.$$$$> ;
osf:hasFunding <https://moneypockets.example/millions> .
osf:funder <https://doi.org/10.$>,
<https://doi.org/10.$$$$> ;
osf:hasFunding <https://moneypockets.example/millions>,
<https://moneypockets.example/millions-more> .

<http://localhost:5000/w3ibb?revision=1> a osf:FileVersion ;
dcterms:created "2123-05-04" ;
Expand All @@ -46,13 +48,23 @@
dcterms:title "because reasons" ;
osf:awardNumber "10000000" .

<https://moneypockets.example/millions-more> a osf:FundingAward ;
dcterms:contributor <https://doi.org/10.$$$$> ;
dcterms:identifier "https://moneypockets.example/millions-more" ;
dcterms:title "because reasons!" ;
osf:awardNumber "2000000" .

<https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode> dcterms:identifier "https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode" ;
foaf:name "CC-By Attribution-NonCommercial-NoDerivatives 4.0 International" .

<https://doi.org/10.$$$$> a dcterms:Agent ;
dcterms:identifier "https://doi.org/10.$$$$" ;
foaf:name "Mx. Moneypockets" .

<https://doi.org/10.$> a dcterms:Agent ;
dcterms:identifier "https://doi.org/10.$" ;
foaf:name "Caring Fan" .

<http://localhost:5000/w1ibb> a dcterms:Agent,
foaf:Person ;
dcterms:identifier "http://localhost:5000/w1ibb" ;
Expand Down
16 changes: 14 additions & 2 deletions osf_tests/metadata/expected_metadata_files/preprint_full.turtle
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@
dcterms:title "this is a project title!"@en ;
dcterms:type <https://schema.datacite.org/meta/kernel-4.4/#Dataset> ;
owl:sameAs <https://doi.org/10.70102/FK2osf.io/w2ibb> ;
osf:funder <https://doi.org/10.$$$$> ;
osf:hasFunding <https://moneypockets.example/millions> .
osf:funder <https://doi.org/10.$>,
<https://doi.org/10.$$$$> ;
osf:hasFunding <https://moneypockets.example/millions>,
<https://moneypockets.example/millions-more> .

<http://localhost:8000/v2/subjects/subjwobb/> a skos:Concept ;
skos:broader <http://localhost:8000/v2/subjects/subjwibb/> ;
Expand All @@ -77,6 +79,12 @@
dcterms:title "because reasons" ;
osf:awardNumber "10000000" .

<https://moneypockets.example/millions-more> a osf:FundingAward ;
dcterms:contributor <https://doi.org/10.$$$$> ;
dcterms:identifier "https://moneypockets.example/millions-more" ;
dcterms:title "because reasons!" ;
osf:awardNumber "2000000" .

<https://schema.datacite.org/meta/kernel-4.4/#Dataset> rdfs:label "Dataset"@en .

<https://schema.datacite.org/meta/kernel-4.4/#Preprint> rdfs:label "Preprint"@en .
Expand Down Expand Up @@ -106,6 +114,10 @@
dcterms:identifier "https://doi.org/10.$$$$" ;
foaf:name "Mx. Moneypockets" .

<https://doi.org/10.$> a dcterms:Agent ;
dcterms:identifier "https://doi.org/10.$" ;
foaf:name "Caring Fan" .

<http://localhost:8000/v2/subjects/subjwibbb/> a skos:Concept ;
skos:inScheme <https://bepress.com/reference_guide_dc/disciplines/> ;
skos:prefLabel "wibbble" .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@
"funderIdentifierType": "Crossref Funder ID"
},
"funderName": "Mx. Moneypockets"
},
{
"awardNumber": {
"awardNumber": "2000000",
"awardURI": "https://moneypockets.example/millions-more"
},
"awardTitle": "because reasons!",
"funderIdentifier": {
"funderIdentifier": "https://doi.org/10.$$$$",
"funderIdentifierType": "Crossref Funder ID"
},
"funderName": "Mx. Moneypockets"
},
{
"funderIdentifier": {
"funderIdentifier": "https://doi.org/10.$",
"funderIdentifierType": "Crossref Funder ID"
},
"funderName": "Caring Fan"
}
],
"identifier": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
<awardNumber awardURI="https://moneypockets.example/millions">10000000</awardNumber>
<awardTitle>because reasons</awardTitle>
</fundingReference>
<fundingReference>
<funderName>Mx. Moneypockets</funderName>
<funderIdentifier funderIdentifierType="Crossref Funder ID">https://doi.org/10.$$$$</funderIdentifier>
<awardNumber awardURI="https://moneypockets.example/millions-more">2000000</awardNumber>
<awardTitle>because reasons!</awardTitle>
</fundingReference>
<fundingReference>
<funderName>Caring Fan</funderName>
<funderIdentifier funderIdentifierType="Crossref Funder ID">https://doi.org/10.$</funderIdentifier>
</fundingReference>
</fundingReferences>
<relatedIdentifiers>
<relatedIdentifier relatedIdentifierType="URL" relationType="HasVersion">http://localhost:5000/w5ibb</relatedIdentifier>
Expand Down
16 changes: 14 additions & 2 deletions osf_tests/metadata/expected_metadata_files/project_full.turtle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
owl:sameAs <https://doi.org/10.70102/FK2osf.io/w2ibb> ;
dcat:accessService <http://localhost:5000> ;
osf:contains <http://localhost:5000/w3ibb> ;
osf:funder <https://doi.org/10.$$$$> ;
osf:hasFunding <https://moneypockets.example/millions> ;
osf:funder <https://doi.org/10.$>,
<https://doi.org/10.$$$$> ;
osf:hasFunding <https://moneypockets.example/millions>,
<https://moneypockets.example/millions-more> ;
osf:hostingInstitution <https://cos.io/> ;
osf:supplements <http://localhost:5000/w4ibb> .

Expand Down Expand Up @@ -64,6 +66,12 @@
dcterms:title "because reasons" ;
osf:awardNumber "10000000" .

<https://moneypockets.example/millions-more> a osf:FundingAward ;
dcterms:contributor <https://doi.org/10.$$$$> ;
dcterms:identifier "https://moneypockets.example/millions-more" ;
dcterms:title "because reasons!" ;
osf:awardNumber "2000000" .

<https://cos.io/> a dcterms:Agent,
foaf:Organization ;
dcterms:identifier "https://cos.io/",
Expand All @@ -88,6 +96,10 @@
dcterms:identifier "https://doi.org/10.$$$$" ;
foaf:name "Mx. Moneypockets" .

<https://doi.org/10.$> a dcterms:Agent ;
dcterms:identifier "https://doi.org/10.$" ;
foaf:name "Caring Fan" .

<http://localhost:5000/w1ibb> a dcterms:Agent,
foaf:Person ;
dcterms:identifier "http://localhost:5000/w1ibb" ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,23 @@
dcterms:title "this is a project title!"@en ;
dcterms:type <https://schema.datacite.org/meta/kernel-4.4/#Dataset> ;
owl:sameAs <https://doi.org/10.70102/FK2osf.io/w2ibb> ;
osf:funder <https://doi.org/10.$$$$> ;
osf:hasFunding <https://moneypockets.example/millions> .
osf:funder <https://doi.org/10.$>,
<https://doi.org/10.$$$$> ;
osf:hasFunding <https://moneypockets.example/millions>,
<https://moneypockets.example/millions-more> .

<https://moneypockets.example/millions> a osf:FundingAward ;
dcterms:contributor <https://doi.org/10.$$$$> ;
dcterms:identifier "https://moneypockets.example/millions" ;
dcterms:title "because reasons" ;
osf:awardNumber "10000000" .

<https://moneypockets.example/millions-more> a osf:FundingAward ;
dcterms:contributor <https://doi.org/10.$$$$> ;
dcterms:identifier "https://moneypockets.example/millions-more" ;
dcterms:title "because reasons!" ;
osf:awardNumber "2000000" .

<https://cos.io/> a dcterms:Agent,
foaf:Organization ;
dcterms:identifier "https://cos.io/",
Expand All @@ -63,6 +71,10 @@
dcterms:identifier "https://doi.org/10.$$$$" ;
foaf:name "Mx. Moneypockets" .

<https://doi.org/10.$> a dcterms:Agent ;
dcterms:identifier "https://doi.org/10.$" ;
foaf:name "Caring Fan" .

<http://localhost:5000/w1ibb> a dcterms:Agent,
foaf:Person ;
dcterms:identifier "http://localhost:5000/w1ibb" ;
Expand Down
16 changes: 15 additions & 1 deletion osf_tests/metadata/test_serialized_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,27 @@ def _setUp_full(self):
'language': 'en',
'resource_type_general': 'Dataset',
'funding_info': [
{
{ # full funding reference:
'funder_name': 'Mx. Moneypockets',
'funder_identifier': 'https://doi.org/10.$$$$',
'funder_identifier_type': 'Crossref Funder ID',
'award_number': '10000000',
'award_uri': 'https://moneypockets.example/millions',
'award_title': 'because reasons',
}, { # second funding award from the same funder:
'funder_name': 'Mx. Moneypockets',
'funder_identifier': 'https://doi.org/10.$$$$',
'funder_identifier_type': 'Crossref Funder ID',
'award_number': '2000000',
'award_uri': 'https://moneypockets.example/millions-more',
'award_title': 'because reasons!',
}, { # no award info, just a funder:
'funder_name': 'Caring Fan',
'funder_identifier': 'https://doi.org/10.$',
'funder_identifier_type': 'Crossref Funder ID',
'award_number': '',
'award_uri': '',
'award_title': '',
},
],
}, auth=self.user)
Expand Down

0 comments on commit 600bc6d

Please sign in to comment.