Skip to content

Commit

Permalink
legacy: fix contributor roles mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
slint committed Nov 29, 2023
1 parent 3c02a9e commit 3c72612
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions site/zenodo_rdm/legacy/serializers/schemas/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
from zenodo_legacy.funders import FUNDER_ACRONYMS, FUNDER_ROR_TO_DOI
from zenodo_legacy.licenses import rdm_to_legacy


def to_camel_case(string, split_char=" "):
"""Returns a camel cased string."""
return "".join(word.title() for word in string.split(split_char))


# Maps RDM relation_type to legacy relation
RELATION_TYPE_MAPPING = {
"iscitedby": "isCitedBy",
Expand Down Expand Up @@ -59,6 +53,31 @@ def to_camel_case(string, split_char=" "):
"isalternateidentifier": "isAlternateIdentifier",
}

# Maps RDM creator/contributor roles to legacy roles
ROLE_TYPE_MAPPING = {
"contactperson": "ContactPerson",
"datacollector": "DataCollector",
"datacurator": "DataCurator",
"datamanager": "DataManager",
"distributor": "Distributor",
"editor": "Editor",
"hostinginstitution": "HostingInstitution",
"producer": "Producer",
"projectleader": "ProjectLeader",
"projectmanager": "ProjectManager",
"projectmember": "ProjectMember",
"registrationagency": "RegistrationAgency",
"registrationauthority": "RegistrationAuthority",
"relatedperson": "RelatedPerson",
"researcher": "Researcher",
"researchgroup": "ResearchGroup",
"rightsholder": "RightsHolder",
"sponsor": "Sponsor",
"supervisor": "Supervisor",
"workpackageleader": "WorkPackageLeader",
"other": "Other",
}


class CreatorSchema(Schema):
"""Creator schema."""
Expand Down Expand Up @@ -96,9 +115,8 @@ def dump_role(self, obj):
"""Loads role field."""
# English title matches DataCite prop, used in legacy Zenodo
role = obj.get("role", {})
if role:
title_en = role.get("title", {}).get("en")
return to_camel_case(title_en, " ")
if role and role.get("id") in ROLE_TYPE_MAPPING:
return ROLE_TYPE_MAPPING[role["id"]]


class DateSchema(Schema):
Expand Down

0 comments on commit 3c72612

Please sign in to comment.