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
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ class ResearchCommitteeModel(CdsOverdo):

_default_fields = {
"custom_fields": {},
"resource_type": {"id": "publication-other"},
}


research_comm_model = ResearchCommitteeModel(
bases=(rdm_base_publication_model,),
entry_point_group="cds_migrator_kit.migrator.rdm.rules.publication",
entry_point_group="cds_migrator_kit.migrator.rules.research_committee",
)
7 changes: 7 additions & 0 deletions cds_migrator_kit/rdm/records/transform/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ def creators(json, key="creators"):
return _creators

def _resource_type(entry):
# `_resource_type_rank` is bookkeeping for the 980__/697C_
# resource_type rule and research_committee.py's report-number
# detection (see research.py:resource_type) - drop it before it
# reaches the final record.
entry.pop("_resource_type_rank", None)
try:
return entry["resource_type"]
except KeyError:
Expand Down Expand Up @@ -617,6 +622,8 @@ def field_departments(record_json, custom_fields_dict):
if result and result not in custom_fields_dict["cern:departments"]:
custom_fields_dict["cern:departments"].append(result)
elif not result:
if department.lower() == "cern?":
continue
subj = json_output["metadata"].get("subjects", [])
subj.append({"subject": department})
json_output["metadata"]["subjects"] = subj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,7 @@ def corporate_author(self, key, value):
departments = self.get("custom_fields", {}).get("cern:departments", [])
if department and department not in departments:
departments.append(department)
self["custom_fields"]["cern:departments"] = departments
raise IgnoreKey("contributors")
self["custom_fields"]["cern:departments"] = departments
if "b" in value:
unit = value.get("b")
if unit:
Expand Down Expand Up @@ -877,6 +876,14 @@ def related_identifiers_787(self, key, value):
"relation_type": {"id": "references"},
"resource_type": {"id": "publication-report"},
},
"addendum to": {
"relation_type": {"id": "issupplementto"},
"resource_type": {"id": "publication-report"},
},
"complemented by": {
"relation_type": {"id": "issuplementedby"},
"resource_type": {"id": "publication-report"},
},
"preprint": {
"relation_type": {"id": "references"},
"resource_type": {"id": "publication-preprint"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,20 +798,36 @@ def resource_type(self, key, value):
subjects = self.get("subjects")
subjects.append({"subject": value_a if value_a else value_b})
self["subjects"] = subjects
raise IgnoreKey("resource_type")
raise UnexpectedValue(
"Unknown resource type (Publications)", value=best_value, field=key
)

if current:
current_key = next((k for k, v in mapping.items() if v == current), None)
current_rank = priority.get(current_key, float("inf"))
# This function is invoked once per repeated 980__/697C_ occurrence
# (see CdsOverdo.do), with `self["resource_type"]` accumulating the
# best match across calls. An unmapped value here doesn't mean the
# record has no resource type - another occurrence, processed later,
# may still resolve to a known one, so don't abort the whole record.
# If no occurrence ever resolves, the missing resource_type is
# caught downstream (see `_resource_type` in transform.py).
raise IgnoreKey("resource_type")

# `current` may be `resource_type`'s value from an earlier 980__/697C_
# occurrence on this same record, but it may also be a default seeded by
# the model's `_default_fields` (e.g. ResearchCommitteeModel sets
# resource_type to publication-other upfront) before this rule ever ran.
# Reverse-looking up `current` in `mapping` can't tell those apart - a
# seeded default happens to equal "alephdraft"'s mapped value, so it
# would get treated as an already-decided, low-priority match and block
# any later occurrence whose value isn't in `priority` (rank stays
# `inf`, and `inf < inf` is False). Track the rank of our own previous
# decision explicitly instead, so a seeded default never poisons this
# comparison.
current_rank = self.get("_resource_type_rank")

if current and current_rank is not None:
if rank < current_rank:
self["_resource_type_rank"] = rank
return mapping[best_value]
else:
raise IgnoreKey("resource_type")
else:
self["_resource_type_rank"] = rank
return mapping[best_value]


Expand Down
Loading
Loading