Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added funderidtype and support for funder and sponsor roles to datacite metadata #167

Merged
merged 8 commits into from
Jun 16, 2023
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