Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cds_migrator_kit/rdm/records/transform/models/hr.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class HrModel(CdsOverdo):
980__:CHISBULLETIN OR
980__:CCP OR
980__:CERN-ADMIN-E-GUIDE OR
980__:HR-SMC
980__:HR-SMC OR
(980__:REPORT AND 710__.5:HR) OR
(980__:BROCHURE AND 710__.5:HR)
"""

__ignore_keys__ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from dateutil.parser import ParserError, parse
from dojson.errors import IgnoreKey
from idutils.normalizers import normalize_isbn
from isbnlib import NotValidISBNError

from cds_migrator_kit.errors import UnexpectedValue
from cds_migrator_kit.transform.xml_processing.quality.decorators import (
Expand All @@ -24,6 +26,29 @@
from .research import journal, related_identifiers


@model.over("isbns", "^020__")
def isbn(self, key, value):
"""Map ISBN (020 $a) into related_identifiers — e.g. CERN-HR-Note-2025-019."""
_isbn = StringValue(value.get("a", "")).parse()
if not _isbn:
raise IgnoreKey("isbns")
try:
_isbn = normalize_isbn(_isbn)
except NotValidISBNError:
raise UnexpectedValue("Not a valid ISBN.", field=key, value=value)
new_id = {
"identifier": _isbn,
"scheme": "isbn",
"relation_type": {"id": "isvariantformof"},
"resource_type": {"id": "publication-book"},
}
ids = self.get("related_identifiers", [])
if new_id not in ids:
ids.append(new_id)
self["related_identifiers"] = ids
raise IgnoreKey("isbns")


@model.over("access_grants", "^506[1_]_")
@for_each_value
def access_grants(self, key, value):
Expand Down Expand Up @@ -131,6 +156,9 @@ def collection(self, key, value):
"intnote",
"operational circular",
"publhr",
"pulhr", # typo seen on CERN-HR-Note leftovers
"report",
"cernofficialpressbrochure",
]:
raise UnexpectedValue(subfield="a", value=value, field=key)
raise IgnoreKey("collection")
Expand Down Expand Up @@ -178,6 +206,9 @@ def resource_type(self, key, value):
"hr-smc": {"id": "administrative-regulation"},
"ccp": {"id": "other"},
"conferencepaper": {"id": "publication-conferencepaper"},
# CERN-HR-* leftovers (#623): generic 980 tags scoped via 710 $5 HR
"report": {"id": "publication-report"},
"brochure": {"id": "publication-brochure"},
}
try:

Expand Down Expand Up @@ -261,7 +292,11 @@ def custom_fields(self, key, value):
except IgnoreKey:
author = None
if author:
contributors.append(author[0])
contributor = author[0]
# RDM requires a role on contributors (creators may omit it)
if "role" not in contributor:
contributor["role"] = {"id": "other"}
contributors.append(contributor)
self["contributors"] = contributors

raise IgnoreKey("administrative_unit")
Expand Down
4 changes: 4 additions & 0 deletions tests/cds-rdm/test_hr_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ def test_resource_type_mapping():
assert resource_type({}, "980__", {"a": "conferencepaper"}) == {
"id": "publication-conferencepaper"
}
assert resource_type({}, "980__", {"a": "report"}) == {"id": "publication-report"}
assert resource_type({}, "980__", {"a": "brochure"}) == {
"id": "publication-brochure"
}


def test_resource_type_ignored_values():
Expand Down
Loading