Skip to content

Commit

Permalink
feat: migrate local/archivesWrapper to custom archives_series field
Browse files Browse the repository at this point in the history
closes #5
  • Loading branch information
phette23 committed Aug 30, 2024
1 parent 140398d commit c6fd0c6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/crosswalk.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ <h1>EQUELLA -> InvenioRDM Crosswalk</h1>
title: Local (/xml/local) Mappings
---
flowchart LR
ASERIESV["archivesWrapper/series, archivesWrapper/subseries"] --> ASERIESI["cca:archive_series custom field"]
viewlevel[viewLevel] --> |TODO Many, many translations| ACCESS["Access restricted/public"]
courseworktype[courseWorkWrapper/courseWorkType] --> |TODO if we have no mods/typeOfResource, map 1st| TYPE["Resource Type (1)"]
</pre>
Expand Down
21 changes: 20 additions & 1 deletion migrate/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ def addl_titles(self) -> list[dict[str, str]]:
atitles.append({"title": title, "type": {"id": "other"}})
return atitles

@property
def archives_series(self) -> dict[str, str] | None:
archives_wrapper = self.xml.get("local", {}).get("archivesWrapper")
series = archives_wrapper.get("series") if archives_wrapper else None
subseries = archives_wrapper.get("subseries", "") if archives_wrapper else None
if series and not subseries:
raise Exception(f"Archives Series without Subseries: {self.vault_url}")
if series and subseries:
return {"series": series, "subseries": subseries}
return {}

@property
def creators(self) -> list[dict[str, Any]]:
# mods/name
Expand Down Expand Up @@ -190,6 +201,14 @@ def creators(self) -> list[dict[str, Any]]:
creators.append({"person_or_org": name})
return creators

@property
def custom_fields(self) -> dict[str, Any]:
cf: dict[str, Any] = {}
# 1) ArchivesSeries custom field, { series, subseries } dict
if self.archives_series:
cf["cca:archives_series"] = self.archives_series
return cf

@property
def dates(self) -> list[dict[str, Any]]:
dates = []
Expand Down Expand Up @@ -501,7 +520,7 @@ def get(self) -> dict[str, Any]:
"record": "public",
},
# ! blocked until we know what custom fields we'll have
"custom_fields": {},
"custom_fields": self.custom_fields,
"files": {
"enabled": bool(len(self.attachments)),
# ! API drops these, whether we define before adding files or after
Expand Down
38 changes: 38 additions & 0 deletions migrate/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,44 @@ def m(r):
return r.get()["metadata"]


# Archives Series
@pytest.mark.parametrize(
"input, expect",
[
# no series
(x("<mods></mods>"), {}),
# wrapper but no series
(x("<local><archivesWrapper></archivesWrapper>></local>"), {}),
(
x(
"<local><archivesWrapper><series>I. Administrative Materials</series><subseries>5. Faculty and Staff Files</subseries></archivesWrapper>></local>"
),
{
"cca:archives_series": {
"series": "I. Administrative Materials",
"subseries": "5. Faculty and Staff Files",
}
},
),
(
x(
"<local><archivesWrapper><series>VIII. Periodicals and Other Publications</series><subseries>4. Yearbooks</subseries></archivesWrapper></local>"
),
{
"cca:archives_series": {
"series": "VIII. Periodicals and Other Publications",
"subseries": "4. Yearbooks",
}
},
),
],
)
def test_archives_series(input, expect):
r = Record(input)
# can't use m(r) helper because custom_fields live outside metadata
assert r.get()["custom_fields"] == expect


# Name
@pytest.mark.parametrize(
"input, expect",
Expand Down

0 comments on commit c6fd0c6

Please sign in to comment.