Skip to content

Commit

Permalink
Initial implementation of legacyId normalization for III identifiers …
Browse files Browse the repository at this point in the history
…for bibs and holdings
  • Loading branch information
bltravis committed Mar 8, 2024
1 parent 631eb48 commit a476410
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import ast
import i18n

import i18n
from folio_uuid.folio_uuid import FOLIONamespaces
from folio_uuid.folio_uuid import FolioUUID
from folioclient import FolioClient

from folio_migration_tools.custom_exceptions import TransformationRecordFailedError
Expand Down Expand Up @@ -126,28 +127,22 @@ def get_instance_ids(self, legacy_value: str, index_or_id: str):
i18n.t("Number of bib records referenced in item") + f": {len(legacy_bib_ids)}",
)
for legacy_instance_id in legacy_bib_ids:
new_legacy_value = (
f".{legacy_instance_id}"
if legacy_instance_id.startswith("b")
else legacy_instance_id
)
if (
new_legacy_value not in self.instance_id_map
and legacy_instance_id not in self.instance_id_map
):
self.migration_report.add_general_statistics(
i18n.t("Records not matched to Instances")
)
s = "Bib id not in instance id map."
raise TransformationRecordFailedError(index_or_id, s, new_legacy_value)
else:
new_legacy_value := FolioUUID.clean_iii_identifiers(legacy_instance_id)
) and new_legacy_value in self.instance_id_map:
self.migration_report.add_general_statistics(
i18n.t("Records matched to Instances")
)
entry = self.instance_id_map.get(new_legacy_value, "") or self.instance_id_map.get(
legacy_instance_id
)
return_ids.append(entry[1])
else:
self.migration_report.add_general_statistics(
i18n.t("Records not matched to Instances")
)
s = "Bib id not in instance id map."
raise TransformationRecordFailedError(index_or_id, s, new_legacy_value)
if any(return_ids):
return return_ids
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from datetime import timezone
from typing import Set
from uuid import uuid4
import i18n

import i18n
from folio_uuid.folio_uuid import FOLIONamespaces
from folio_uuid.folio_uuid import FolioUUID
from folioclient import FolioClient

from folio_migration_tools.custom_exceptions import TransformationProcessError
Expand Down Expand Up @@ -232,6 +233,7 @@ def get_prop(self, legacy_item, folio_prop_name, index_or_id, schema_default_val
self.unique_barcodes.add(barcode)
return barcode
elif folio_prop_name == "holdingsRecordId":
mapped_value = FolioUUID.clean_iii_identifiers(mapped_value)
if mapped_value in self.holdings_id_map:
return self.holdings_id_map[mapped_value][1]
elif f"{self.bib_id_template}{mapped_value}" in self.holdings_id_map:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import i18n
from folio_uuid.folio_namespaces import FOLIONamespaces
from folio_uuid.folio_uuid import FolioUUID
from pymarc import Field
from pymarc import Record
from pymarc import Subfield
Expand Down Expand Up @@ -254,6 +255,7 @@ def wrap_up(self):

def add_legacy_ids_to_map(self, folio_rec, filtered_legacy_ids):
for legacy_id in filtered_legacy_ids:
legacy_id = FolioUUID.clean_iii_identifiers(legacy_id)
self.legacy_ids.add(legacy_id)
if legacy_id not in self.mapper.id_map:
self.mapper.id_map[legacy_id] = self.mapper.get_id_map_tuple(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def set_instance_id_by_map(self, legacy_ids: list, folio_holding: dict, marc_rec
("No 004 in record. The tools only support bib-mfhd linking throuh 004"),
legacy_ids,
)
legacy_instance_id = marc_record["004"].data.strip()
legacy_instance_id = FolioUUID.clean_iii_identifiers(marc_record["004"].data.strip())
folio_holding["formerIds"].append(f"{self.bib_id_template}{legacy_instance_id}")
if legacy_instance_id in self.parent_id_map:
folio_holding["instanceId"] = self.parent_id_map[legacy_instance_id][1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import sys
import time
import traceback
import i18n
from typing import Annotated
from typing import List
from typing import Optional

import i18n
from folio_uuid.folio_namespaces import FOLIONamespaces
from folio_uuid.folio_uuid import FolioUUID
from httpx import HTTPError
from pydantic import Field

Expand Down Expand Up @@ -249,9 +250,9 @@ def wrap_up(self):
# Prevent the first item in a boundwith to be overwritten
# TODO: Find out why not
# if legacy_id not in self.holdings_id_map:
self.holdings_id_map[legacy_id] = self.mapper.get_id_map_tuple(
legacy_id, holding, self.object_type
)
self.holdings_id_map[
FolioUUID.clean_iii_identifiers(legacy_id)
] = self.mapper.get_id_map_tuple(legacy_id, holding, self.object_type)
Helper.write_to_file(holdings_file, holding)
self.mapper.migration_report.add_general_statistics(
i18n.t("Holdings Records Written to disk")
Expand Down

0 comments on commit a476410

Please sign in to comment.