-
Notifications
You must be signed in to change notification settings - Fork 12
isolde: 340, 852, 035 handling #612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
cds_migrator_kit/rdm/records/transform/xml_processing/rules/isolde.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (C) 2026 CERN. | ||
| # | ||
| # CDS-RDM is free software; you can redistribute it and/or modify it under | ||
| # the terms of the MIT License; see LICENSE file for more details. | ||
|
|
||
| """CDS-RDM ISOLDE migration rules.""" | ||
|
|
||
| from dojson.errors import IgnoreKey | ||
|
|
||
| from cds_migrator_kit.errors import UnexpectedValue | ||
| from cds_migrator_kit.transform.xml_processing.quality.decorators import for_each_value | ||
| from cds_migrator_kit.transform.xml_processing.quality.parsers import StringValue | ||
|
|
||
| from ...models.isolde import isolde_model as model | ||
| from .base import identifiers as _base_identifiers | ||
|
|
||
|
|
||
| @model.over("identifiers", "^035__", override_tag=True) | ||
| @for_each_value | ||
| def identifiers(self, key, value): | ||
| """Translates 035__ identifiers. | ||
|
|
||
| - scheme empty or 'CERN ISOLDE': stored as related_identifier with scheme | ||
| 'other' and identifier pattern 'ISOLDE:<a>', relation 'references'. | ||
| - everything else (incl. CERCER → aleph): delegated to the base rule. | ||
| """ | ||
| scheme = value.get("9", "").strip() | ||
| system_control_number = value.get("a", "").strip() | ||
|
|
||
| if not scheme or scheme.upper() == "CERN ISOLDE": | ||
| related_identifiers = self.get("related_identifiers", []) | ||
| new_id = { | ||
| "identifier": f"ISOLDE:{system_control_number}", | ||
| "scheme": "other", | ||
| "relation_type": {"id": "references"}, | ||
| } | ||
| if new_id not in related_identifiers: | ||
| related_identifiers.append(new_id) | ||
| self["related_identifiers"] = related_identifiers | ||
| raise IgnoreKey("identifiers") | ||
|
|
||
| return _base_identifiers.__wrapped__(self, key, value) | ||
|
|
||
|
|
||
| @model.over("medium", "^340__") | ||
| @for_each_value | ||
| def medium(self, key, value): | ||
| """Ignores 340__a when value is 'paper', raises for anything else.""" | ||
| a_value = value.get("a", "").strip().lower() | ||
| if a_value == "paper": | ||
| raise IgnoreKey("medium") | ||
| raise UnexpectedValue(field=key, subfield="a", value=value, stage="transform") | ||
|
|
||
|
|
||
| @model.over("additional_descriptions", "^852__") | ||
| @for_each_value | ||
| def holdings(self, key, value): | ||
| """852 holdings: selectively ignores known location values. | ||
|
|
||
| - 852__c == 'CERN ARC Library': ignored. | ||
| - 852__h (depot code): ignored; records will be bulk-updated post-migration | ||
| once the ATOM/CLC target mapping is established. | ||
| - anything else: raises UnexpectedValue to surface unknown cases. | ||
| """ | ||
| h_value = StringValue(value.get("h", "")).parse() | ||
| c_value = StringValue(value.get("c", "")).parse() | ||
|
|
||
| # Depot location: check the value exists, then ignore. | ||
| # Records will be bulk-updated post-migration via ATOM/CLC mapping. | ||
| if h_value: | ||
| raise IgnoreKey("additional_descriptions") | ||
|
|
||
| if c_value and c_value.lower() == "cern arc library": | ||
| raise IgnoreKey("additional_descriptions") | ||
|
|
||
| if h_value and "cern depot" in h_value.lower(): | ||
| raise IgnoreKey("additional_descriptions") | ||
|
|
||
| if c_value: | ||
| raise UnexpectedValue(field=key, subfield="c", value=value, stage="transform") | ||
|
|
||
| if h_value: | ||
| raise UnexpectedValue(field=key, subfield="h", value=value, stage="transform") | ||
|
|
||
| raise IgnoreKey("additional_descriptions") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it easier to add these fields to ignored? also, by raising IgnoreKey at the end you might also silently ignore other subfields of this field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm but I want to ignore specific values of the 852 subfields only. Keeping in mind also that this could go to the research/base class. Isn't it better like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the ignore keys you can only add the specific ones, you can't add the whole field
but I am re-reading this and now I understood why you do this, sorry 😅 LGTM