Skip to content

Commit

Permalink
fix: bug in publisher code for multiple originInfo nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
phette23 committed Feb 9, 2024
1 parent 349b4c0 commit 0f7ed48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions migrate/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,12 @@ def publisher(self) -> str:

# 2) CCA/C archives has publisher info mods/originInfo/publisher
# https://vault.cca.edu/items/c4583fe6-2e85-4613-a1bc-774824b3e826/1/%3CXML%3E
publisher = (
self.xml.get("mods", {}).get("originInfo", {}).get("publisher", "")
).strip()
if publisher:
return publisher
# records have multiple originInfo nodes
originInfos = mklist(self.xml.get("mods", {}).get("originInfo"))
for originInfo in originInfos:
publisher: str = originInfo.get("publisher", "").strip()
if publisher:
return publisher

# 3) Press Clips items are not CCA but have only publication, not publisher, info
# 4) Student work has no publisher
Expand Down Expand Up @@ -344,6 +345,7 @@ def type(self) -> dict[str, str]:

@property
def rights(self) -> List[dict[str, str | dict[str, str]]]:
# TODO add maps to maps.py
# https://inveniordm.docs.cern.ch/reference/metadata/#rights-licenses-0-n
# ! returned id values MUST be IDs from licenses.csv in cca/cca_invenio
# CCA/C Archives uses CC-BY-NC4.0 in mods/accessCondition
Expand Down
6 changes: 6 additions & 0 deletions migrate/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@ def test_type(input, expect):
x("<mods><originInfo><publisher>foo</publisher></originInfo></mods>"),
"foo",
),
( # multiple originInfo nodes
x(
"<mods><originInfo><dateType>dateCreated</dateType></originInfo><originInfo><publisher>foo</publisher></originInfo></mods>"
),
"foo",
),
( # no publisher
x("<mods></mods>"),
"",
Expand Down

0 comments on commit 0f7ed48

Please sign in to comment.