Skip to content

Commit

Permalink
Merge pull request #167 from dandi/fix/datacite-funderid
Browse files Browse the repository at this point in the history
added funderidtype and support for funder and sponsor roles to datacite metadata
  • Loading branch information
djarecka authored Jun 16, 2023
2 parents 845cb17 + 0f5c77a commit 07856be
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
14 changes: 12 additions & 2 deletions dandischema/datacite.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,26 @@ def to_datacite(
contributors = []
creators = []
for contr_el in meta.contributor:
if contr_el.roleName and RoleType("dcite:Sponsor") in contr_el.roleName:
if contr_el.roleName and (
RoleType("dcite:Sponsor") in contr_el.roleName
or RoleType("dcite:Funder") in contr_el.roleName
):
# no info about "funderIdentifierType", "awardUri", "awardTitle"
dict_fund = {"funderName": contr_el.name}
if contr_el.identifier:
dict_fund["funderIdentifier"] = contr_el.identifier
funderidtype = "Other"
if "ror.org" in contr_el.identifier:
funderidtype = "ROR"
dict_fund["funderIdentifierType"] = funderidtype
if contr_el.awardNumber:
dict_fund["awardNumber"] = contr_el.awardNumber
attributes.setdefault("fundingReferences", []).append(dict_fund)
# if no more roles, it shouldn't be added to creators or contributors
contr_el.roleName.remove(RoleType("dcite:Sponsor"))
if RoleType("dcite:Sponsor") in contr_el.roleName:
contr_el.roleName.remove(RoleType("dcite:Sponsor"))
if RoleType("dcite:Funder") in contr_el.roleName:
contr_el.roleName.remove(RoleType("dcite:Funder"))
if not contr_el.roleName:
continue

Expand Down
54 changes: 54 additions & 0 deletions dandischema/tests/test_datacite.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,60 @@ def test_datacite(dandi_id: str, schema: Any) -> None:
"fundingReferences": (1, {"funderName": "B_last, B_first"}),
},
),
# Add a sponsor with an identifier
(
{
"contributor": [
{
"name": "A_last, A_first",
"roleName": [RoleType("dcite:ContactPerson")],
},
{
"name": "B_last, B_first",
"identifier": "0000-0001-0000-0000",
"roleName": [RoleType("dcite:Sponsor")],
},
],
},
{
"creators": (1, {"name": "A_last, A_first"}),
"fundingReferences": (
1,
{
"funderName": "B_last, B_first",
"funderIdentifier": "0000-0001-0000-0000",
"funderIdentifierType": "Other",
},
),
},
),
# should also work with Funder role
(
{
"contributor": [
{
"name": "A_last, A_first",
"roleName": [RoleType("dcite:ContactPerson")],
},
{
"name": "B_last, B_first",
"identifier": "0000-0001-0000-0000",
"roleName": [RoleType("dcite:Funder")],
},
],
},
{
"creators": (1, {"name": "A_last, A_first"}),
"fundingReferences": (
1,
{
"funderName": "B_last, B_first",
"funderIdentifier": "0000-0001-0000-0000",
"funderIdentifierType": "Other",
},
),
},
),
# additional contributor with 2 roles: Author and Software (doesn't exist in datacite)
# the person should be in creators and contributors (with contributorType Other)
# Adding Orcid ID to the identifier to one of the contributors
Expand Down

0 comments on commit 07856be

Please sign in to comment.