folio-migration-tools 1.9.9__py3-none-any.whl → 1.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- folio_migration_tools/__init__.py +3 -4
- folio_migration_tools/__main__.py +53 -31
- folio_migration_tools/circulation_helper.py +118 -108
- folio_migration_tools/custom_dict.py +2 -2
- folio_migration_tools/custom_exceptions.py +4 -5
- folio_migration_tools/folder_structure.py +17 -7
- folio_migration_tools/helper.py +8 -7
- folio_migration_tools/holdings_helper.py +4 -3
- folio_migration_tools/i18n_cache.py +79 -0
- folio_migration_tools/library_configuration.py +77 -37
- folio_migration_tools/mapper_base.py +45 -31
- folio_migration_tools/mapping_file_transformation/courses_mapper.py +1 -1
- folio_migration_tools/mapping_file_transformation/holdings_mapper.py +7 -3
- folio_migration_tools/mapping_file_transformation/item_mapper.py +13 -26
- folio_migration_tools/mapping_file_transformation/manual_fee_fines_mapper.py +1 -2
- folio_migration_tools/mapping_file_transformation/mapping_file_mapper_base.py +13 -11
- folio_migration_tools/mapping_file_transformation/order_mapper.py +23 -5
- folio_migration_tools/mapping_file_transformation/organization_mapper.py +3 -3
- folio_migration_tools/mapping_file_transformation/ref_data_mapping.py +3 -0
- folio_migration_tools/mapping_file_transformation/user_mapper.py +47 -28
- folio_migration_tools/marc_rules_transformation/conditions.py +82 -97
- folio_migration_tools/marc_rules_transformation/holdings_statementsparser.py +13 -5
- folio_migration_tools/marc_rules_transformation/hrid_handler.py +3 -2
- folio_migration_tools/marc_rules_transformation/marc_file_processor.py +26 -24
- folio_migration_tools/marc_rules_transformation/rules_mapper_base.py +56 -51
- folio_migration_tools/marc_rules_transformation/rules_mapper_bibs.py +28 -17
- folio_migration_tools/marc_rules_transformation/rules_mapper_holdings.py +68 -37
- folio_migration_tools/migration_report.py +18 -7
- folio_migration_tools/migration_tasks/batch_poster.py +285 -354
- folio_migration_tools/migration_tasks/bibs_transformer.py +14 -9
- folio_migration_tools/migration_tasks/courses_migrator.py +2 -3
- folio_migration_tools/migration_tasks/holdings_csv_transformer.py +23 -24
- folio_migration_tools/migration_tasks/holdings_marc_transformer.py +14 -24
- folio_migration_tools/migration_tasks/items_transformer.py +23 -34
- folio_migration_tools/migration_tasks/loans_migrator.py +67 -144
- folio_migration_tools/migration_tasks/manual_fee_fines_transformer.py +3 -3
- folio_migration_tools/migration_tasks/migration_task_base.py +43 -52
- folio_migration_tools/migration_tasks/orders_transformer.py +25 -41
- folio_migration_tools/migration_tasks/organization_transformer.py +9 -18
- folio_migration_tools/migration_tasks/requests_migrator.py +21 -24
- folio_migration_tools/migration_tasks/reserves_migrator.py +6 -5
- folio_migration_tools/migration_tasks/user_transformer.py +25 -20
- folio_migration_tools/task_configuration.py +6 -7
- folio_migration_tools/transaction_migration/legacy_loan.py +15 -27
- folio_migration_tools/transaction_migration/legacy_request.py +1 -1
- folio_migration_tools/translations/en.json +3 -8
- {folio_migration_tools-1.9.9.dist-info → folio_migration_tools-1.10.0.dist-info}/METADATA +19 -28
- folio_migration_tools-1.10.0.dist-info/RECORD +63 -0
- folio_migration_tools-1.10.0.dist-info/WHEEL +4 -0
- folio_migration_tools-1.10.0.dist-info/entry_points.txt +3 -0
- folio_migration_tools/marc_rules_transformation/rules_mapper_authorities.py +0 -241
- folio_migration_tools/migration_tasks/authority_transformer.py +0 -119
- folio_migration_tools/test_infrastructure/__init__.py +0 -0
- folio_migration_tools/test_infrastructure/mocked_classes.py +0 -406
- folio_migration_tools-1.9.9.dist-info/RECORD +0 -67
- folio_migration_tools-1.9.9.dist-info/WHEEL +0 -4
- folio_migration_tools-1.9.9.dist-info/entry_points.txt +0 -3
- folio_migration_tools-1.9.9.dist-info/licenses/LICENSE +0 -21
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
from typing import Annotated, List
|
|
3
3
|
|
|
4
|
-
import i18n
|
|
5
4
|
from folio_uuid.folio_namespaces import FOLIONamespaces
|
|
6
5
|
from pydantic import Field
|
|
7
6
|
|
|
8
7
|
from folio_migration_tools.helper import Helper
|
|
8
|
+
from folio_migration_tools.i18n_cache import i18n_t
|
|
9
9
|
from folio_migration_tools.library_configuration import (
|
|
10
10
|
IlsFlavour,
|
|
11
11
|
LibraryConfiguration,
|
|
@@ -16,7 +16,10 @@ from folio_migration_tools.marc_rules_transformation.marc_file_processor import
|
|
|
16
16
|
from folio_migration_tools.marc_rules_transformation.rules_mapper_bibs import (
|
|
17
17
|
BibsRulesMapper,
|
|
18
18
|
)
|
|
19
|
-
from folio_migration_tools.migration_tasks.migration_task_base import
|
|
19
|
+
from folio_migration_tools.migration_tasks.migration_task_base import (
|
|
20
|
+
MarcTaskConfigurationBase,
|
|
21
|
+
MigrationTaskBase,
|
|
22
|
+
)
|
|
20
23
|
|
|
21
24
|
|
|
22
25
|
class BibsTransformer(MigrationTaskBase):
|
|
@@ -26,7 +29,7 @@ class BibsTransformer(MigrationTaskBase):
|
|
|
26
29
|
Field(
|
|
27
30
|
title="ILS flavour",
|
|
28
31
|
description="The type of ILS you are migrating records from.",
|
|
29
|
-
alias="ils_flavor"
|
|
32
|
+
alias="ils_flavor",
|
|
30
33
|
),
|
|
31
34
|
]
|
|
32
35
|
custom_bib_id_field: Annotated[
|
|
@@ -68,11 +71,11 @@ class BibsTransformer(MigrationTaskBase):
|
|
|
68
71
|
Field(
|
|
69
72
|
title="Generate a MARC file for data import overlay of instances",
|
|
70
73
|
description=(
|
|
71
|
-
"If set to true, the process will generate a file of binary MARC records that
|
|
72
|
-
"be imported into FOLIO using the Data Import APIs. If set to false, only
|
|
73
|
-
"of FOLIO instance records (and optional SRS records) will be generated."
|
|
74
|
+
"If set to true, the process will generate a file of binary MARC records that "
|
|
75
|
+
"can be imported into FOLIO using the Data Import APIs. If set to false, only "
|
|
76
|
+
"a file of FOLIO instance records (and optional SRS records) will be generated." # noqa: E501
|
|
74
77
|
),
|
|
75
|
-
)
|
|
78
|
+
),
|
|
76
79
|
] = True
|
|
77
80
|
parse_cataloged_date: Annotated[
|
|
78
81
|
bool,
|
|
@@ -130,7 +133,9 @@ class BibsTransformer(MigrationTaskBase):
|
|
|
130
133
|
self.check_source_files(
|
|
131
134
|
self.folder_structure.legacy_records_folder, self.task_configuration.files
|
|
132
135
|
)
|
|
133
|
-
self.mapper = BibsRulesMapper(
|
|
136
|
+
self.mapper = BibsRulesMapper(
|
|
137
|
+
self.folio_client, library_config, self.task_configuration, statcode_mapping
|
|
138
|
+
)
|
|
134
139
|
self.bib_ids: set = set()
|
|
135
140
|
if (
|
|
136
141
|
self.task_configuration.reset_hrid_settings
|
|
@@ -148,7 +153,7 @@ class BibsTransformer(MigrationTaskBase):
|
|
|
148
153
|
self.processor.wrap_up()
|
|
149
154
|
with open(self.folder_structure.migration_reports_file, "w+") as report_file:
|
|
150
155
|
self.mapper.migration_report.write_migration_report(
|
|
151
|
-
|
|
156
|
+
i18n_t("Bibliographic records transformation report"),
|
|
152
157
|
report_file,
|
|
153
158
|
self.start_datetime,
|
|
154
159
|
)
|
|
@@ -77,8 +77,7 @@ class CoursesMigrator(MigrationTaskBase):
|
|
|
77
77
|
Field(
|
|
78
78
|
title="Look up instructor",
|
|
79
79
|
description=(
|
|
80
|
-
"Flag to indicate whether to look up instructors. "
|
|
81
|
-
"By default is False."
|
|
80
|
+
"Flag to indicate whether to look up instructors. By default is False."
|
|
82
81
|
),
|
|
83
82
|
),
|
|
84
83
|
] = False
|
|
@@ -91,7 +90,7 @@ class CoursesMigrator(MigrationTaskBase):
|
|
|
91
90
|
self,
|
|
92
91
|
task_configuration: TaskConfiguration,
|
|
93
92
|
library_config: LibraryConfiguration,
|
|
94
|
-
folio_client
|
|
93
|
+
folio_client,
|
|
95
94
|
):
|
|
96
95
|
csv.register_dialect("tsv", delimiter="\t")
|
|
97
96
|
self.task_configuration = task_configuration
|
|
@@ -7,7 +7,6 @@ import time
|
|
|
7
7
|
import traceback
|
|
8
8
|
from typing import Annotated, List, Optional
|
|
9
9
|
|
|
10
|
-
import i18n
|
|
11
10
|
from folio_uuid.folio_namespaces import FOLIONamespaces
|
|
12
11
|
from httpx import HTTPError
|
|
13
12
|
from pydantic import Field
|
|
@@ -18,6 +17,7 @@ from folio_migration_tools.custom_exceptions import (
|
|
|
18
17
|
)
|
|
19
18
|
from folio_migration_tools.helper import Helper
|
|
20
19
|
from folio_migration_tools.holdings_helper import HoldingsHelper
|
|
20
|
+
from folio_migration_tools.i18n_cache import i18n_t
|
|
21
21
|
from folio_migration_tools.library_configuration import (
|
|
22
22
|
FileDefinition,
|
|
23
23
|
HridHandling,
|
|
@@ -57,10 +57,7 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
57
57
|
HridHandling,
|
|
58
58
|
Field(
|
|
59
59
|
title="HRID handling",
|
|
60
|
-
description=(
|
|
61
|
-
"Determining how the HRID generation "
|
|
62
|
-
"should be handled."
|
|
63
|
-
),
|
|
60
|
+
description=("Determining how the HRID generation should be handled."),
|
|
64
61
|
),
|
|
65
62
|
]
|
|
66
63
|
files: Annotated[
|
|
@@ -96,8 +93,7 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
96
93
|
Field(
|
|
97
94
|
title="Previously generated holdings files",
|
|
98
95
|
description=(
|
|
99
|
-
"List of previously generated holdings files. "
|
|
100
|
-
"By default is empty list."
|
|
96
|
+
"List of previously generated holdings files. By default is empty list."
|
|
101
97
|
),
|
|
102
98
|
),
|
|
103
99
|
] = []
|
|
@@ -145,8 +141,7 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
145
141
|
Field(
|
|
146
142
|
title="Reset HRID settings",
|
|
147
143
|
description=(
|
|
148
|
-
"At the end of the run reset "
|
|
149
|
-
"FOLIO with the HRID settings. Default is FALSE."
|
|
144
|
+
"At the end of the run reset FOLIO with the HRID settings. Default is FALSE."
|
|
150
145
|
),
|
|
151
146
|
),
|
|
152
147
|
] = False
|
|
@@ -155,8 +150,7 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
155
150
|
Field(
|
|
156
151
|
title="Update HRID settings",
|
|
157
152
|
description=(
|
|
158
|
-
"At the end of the run update "
|
|
159
|
-
"FOLIO with the HRID settings. Default is TRUE."
|
|
153
|
+
"At the end of the run update FOLIO with the HRID settings. Default is TRUE."
|
|
160
154
|
),
|
|
161
155
|
),
|
|
162
156
|
] = True
|
|
@@ -166,7 +160,7 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
166
160
|
title="Statistical code map file name",
|
|
167
161
|
description=(
|
|
168
162
|
"Path to the file containing the mapping of statistical codes. "
|
|
169
|
-
"The file should be in TSV format with legacy_stat_code and folio_code columns."
|
|
163
|
+
"The file should be in TSV format with legacy_stat_code and folio_code columns." # noqa: E501
|
|
170
164
|
),
|
|
171
165
|
),
|
|
172
166
|
] = ""
|
|
@@ -290,7 +284,8 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
290
284
|
|
|
291
285
|
def load_location_map(self):
|
|
292
286
|
with open(
|
|
293
|
-
self.folder_structure.mapping_files_folder
|
|
287
|
+
self.folder_structure.mapping_files_folder
|
|
288
|
+
/ self.task_configuration.location_map_file_name
|
|
294
289
|
) as location_map_f:
|
|
295
290
|
return self.load_ref_data_map_from_file(
|
|
296
291
|
location_map_f, "Found %s rows in location map"
|
|
@@ -304,7 +299,8 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
304
299
|
|
|
305
300
|
def load_mapped_fields(self):
|
|
306
301
|
with open(
|
|
307
|
-
self.folder_structure.mapping_files_folder
|
|
302
|
+
self.folder_structure.mapping_files_folder
|
|
303
|
+
/ self.task_configuration.holdings_map_file_name # noqa: E501
|
|
308
304
|
) as holdings_mapper_f:
|
|
309
305
|
holdings_map = json.load(holdings_mapper_f)
|
|
310
306
|
logging.info("%s fields in holdings mapping file map", len(holdings_map["data"]))
|
|
@@ -332,7 +328,8 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
332
328
|
print(f"\n{error_str}\nHalting")
|
|
333
329
|
sys.exit(1)
|
|
334
330
|
logging.info(
|
|
335
|
-
f"processed {self.total_records:,} records in
|
|
331
|
+
f"processed {self.total_records:,} records in "
|
|
332
|
+
f"{len(self.task_configuration.files)} files"
|
|
336
333
|
)
|
|
337
334
|
|
|
338
335
|
def wrap_up(self):
|
|
@@ -354,14 +351,14 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
354
351
|
)
|
|
355
352
|
Helper.write_to_file(holdings_file, holding)
|
|
356
353
|
self.mapper.migration_report.add_general_statistics(
|
|
357
|
-
|
|
354
|
+
i18n_t("Holdings Records Written to disk")
|
|
358
355
|
)
|
|
359
356
|
self.mapper.save_id_map_file(
|
|
360
357
|
self.folder_structure.holdings_id_map_path, self.holdings_id_map
|
|
361
358
|
)
|
|
362
359
|
with open(self.folder_structure.migration_reports_file, "w") as migration_report_file:
|
|
363
360
|
self.mapper.migration_report.write_migration_report(
|
|
364
|
-
|
|
361
|
+
i18n_t("Holdings transformation report"),
|
|
365
362
|
migration_report_file,
|
|
366
363
|
self.mapper.start_datetime,
|
|
367
364
|
)
|
|
@@ -379,7 +376,9 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
379
376
|
properties = holdings_schema["properties"].keys()
|
|
380
377
|
logging.info(properties)
|
|
381
378
|
logging.info(self.task_configuration.holdings_merge_criteria)
|
|
382
|
-
res = [
|
|
379
|
+
res = [
|
|
380
|
+
mc for mc in self.task_configuration.holdings_merge_criteria if mc not in properties
|
|
381
|
+
]
|
|
383
382
|
if any(res):
|
|
384
383
|
logging.critical(
|
|
385
384
|
(
|
|
@@ -394,7 +393,7 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
394
393
|
full_path = self.folder_structure.data_folder / "items" / file_def.file_name
|
|
395
394
|
with open(full_path, encoding="utf-8-sig") as records_file:
|
|
396
395
|
self.mapper.migration_report.add_general_statistics(
|
|
397
|
-
|
|
396
|
+
i18n_t("Number of files processed")
|
|
398
397
|
)
|
|
399
398
|
start = time.time()
|
|
400
399
|
records_processed = 0
|
|
@@ -413,7 +412,7 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
413
412
|
except Exception as excepion:
|
|
414
413
|
self.mapper.handle_generic_exception(idx, excepion)
|
|
415
414
|
self.mapper.migration_report.add_general_statistics(
|
|
416
|
-
|
|
415
|
+
i18n_t("Number of Legacy items in file")
|
|
417
416
|
)
|
|
418
417
|
if idx > 1 and idx % 10000 == 0:
|
|
419
418
|
elapsed = idx / (time.time() - start)
|
|
@@ -482,7 +481,7 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
482
481
|
self.holdings[bw_key] = incoming_holding
|
|
483
482
|
self.mapper.create_and_write_boundwith_part(legacy_item_id, incoming_holding["id"])
|
|
484
483
|
self.mapper.migration_report.add_general_statistics(
|
|
485
|
-
|
|
484
|
+
i18n_t("Unique BW Holdings created from Items")
|
|
486
485
|
)
|
|
487
486
|
else:
|
|
488
487
|
self.merge_holding(bw_key, incoming_holding)
|
|
@@ -493,7 +492,7 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
493
492
|
legacy_item_id, self.holdings[bw_key], self.object_type
|
|
494
493
|
)
|
|
495
494
|
self.mapper.migration_report.add_general_statistics(
|
|
496
|
-
|
|
495
|
+
i18n_t("BW Items found tied to previously created BW Holdings")
|
|
497
496
|
)
|
|
498
497
|
else:
|
|
499
498
|
# Regular holding. Merge according to criteria
|
|
@@ -505,12 +504,12 @@ class HoldingsCsvTransformer(MigrationTaskBase):
|
|
|
505
504
|
)
|
|
506
505
|
if self.holdings.get(new_holding_key, None):
|
|
507
506
|
self.mapper.migration_report.add_general_statistics(
|
|
508
|
-
|
|
507
|
+
i18n_t("Holdings already created from Item")
|
|
509
508
|
)
|
|
510
509
|
self.merge_holding(new_holding_key, incoming_holding)
|
|
511
510
|
else:
|
|
512
511
|
self.mapper.migration_report.add_general_statistics(
|
|
513
|
-
|
|
512
|
+
i18n_t("Unique Holdings created from Items")
|
|
514
513
|
)
|
|
515
514
|
self.holdings[new_holding_key] = incoming_holding
|
|
516
515
|
|
|
@@ -3,12 +3,12 @@ import json
|
|
|
3
3
|
import logging
|
|
4
4
|
from typing import Annotated, List
|
|
5
5
|
|
|
6
|
-
import i18n
|
|
7
6
|
from folio_uuid.folio_namespaces import FOLIONamespaces
|
|
8
7
|
from pydantic import Field
|
|
9
8
|
|
|
10
9
|
from folio_migration_tools.custom_exceptions import TransformationProcessError
|
|
11
10
|
from folio_migration_tools.helper import Helper
|
|
11
|
+
from folio_migration_tools.i18n_cache import i18n_t
|
|
12
12
|
from folio_migration_tools.library_configuration import (
|
|
13
13
|
FileDefinition,
|
|
14
14
|
HridHandling,
|
|
@@ -19,7 +19,7 @@ from folio_migration_tools.marc_rules_transformation.rules_mapper_holdings impor
|
|
|
19
19
|
)
|
|
20
20
|
from folio_migration_tools.migration_tasks.migration_task_base import (
|
|
21
21
|
MarcTaskConfigurationBase,
|
|
22
|
-
MigrationTaskBase
|
|
22
|
+
MigrationTaskBase,
|
|
23
23
|
)
|
|
24
24
|
|
|
25
25
|
|
|
@@ -38,18 +38,14 @@ class HoldingsMarcTransformer(MigrationTaskBase):
|
|
|
38
38
|
str,
|
|
39
39
|
Field(
|
|
40
40
|
title="Migration task type",
|
|
41
|
-
description=(
|
|
42
|
-
"The type of migration task you want to perform"
|
|
43
|
-
),
|
|
41
|
+
description=("The type of migration task you want to perform"),
|
|
44
42
|
),
|
|
45
43
|
]
|
|
46
44
|
files: Annotated[
|
|
47
45
|
List[FileDefinition],
|
|
48
46
|
Field(
|
|
49
47
|
title="Source files",
|
|
50
|
-
description=(
|
|
51
|
-
"List of MARC21 files with holdings records"
|
|
52
|
-
),
|
|
48
|
+
description=("List of MARC21 files with holdings records"),
|
|
53
49
|
),
|
|
54
50
|
]
|
|
55
51
|
hrid_handling: Annotated[
|
|
@@ -167,9 +163,7 @@ class HoldingsMarcTransformer(MigrationTaskBase):
|
|
|
167
163
|
str,
|
|
168
164
|
Field(
|
|
169
165
|
title="MARC Holdings Note type",
|
|
170
|
-
description=(
|
|
171
|
-
"The name of the note type to use for MARC (MRK) statements. "
|
|
172
|
-
),
|
|
166
|
+
description=("The name of the note type to use for MARC (MRK) statements. "),
|
|
173
167
|
),
|
|
174
168
|
] = "Original MARC holdings statements"
|
|
175
169
|
include_mfhd_mrk_as_note: Annotated[
|
|
@@ -187,9 +181,7 @@ class HoldingsMarcTransformer(MigrationTaskBase):
|
|
|
187
181
|
str,
|
|
188
182
|
Field(
|
|
189
183
|
title="MARC Record (as MARC Maker Representation) note type",
|
|
190
|
-
description=(
|
|
191
|
-
"The name of the note type to use for MFHD (MRK) note. "
|
|
192
|
-
),
|
|
184
|
+
description=("The name of the note type to use for MFHD (MRK) note. "),
|
|
193
185
|
),
|
|
194
186
|
] = "Original MFHD Record"
|
|
195
187
|
include_mfhd_mrc_as_note: Annotated[
|
|
@@ -208,9 +200,7 @@ class HoldingsMarcTransformer(MigrationTaskBase):
|
|
|
208
200
|
str,
|
|
209
201
|
Field(
|
|
210
202
|
title="MARC Record (as MARC21 decoded string) note type",
|
|
211
|
-
description=(
|
|
212
|
-
"The name of the note type to use for MFHD (MRC) note. "
|
|
213
|
-
),
|
|
203
|
+
description=("The name of the note type to use for MFHD (MRC) note. "),
|
|
214
204
|
),
|
|
215
205
|
] = "Original MFHD (MARC21)"
|
|
216
206
|
|
|
@@ -276,12 +266,12 @@ class HoldingsMarcTransformer(MigrationTaskBase):
|
|
|
276
266
|
"Rows in Bound with relationship map: %s",
|
|
277
267
|
len(self.boundwith_relationship_map_rows),
|
|
278
268
|
)
|
|
279
|
-
except FileNotFoundError:
|
|
269
|
+
except FileNotFoundError as fnfe:
|
|
280
270
|
raise TransformationProcessError(
|
|
281
271
|
"",
|
|
282
|
-
|
|
272
|
+
i18n_t("Provided boundwith relationship file not found"),
|
|
283
273
|
self.task_configuration.boundwith_relationship_file_path,
|
|
284
|
-
)
|
|
274
|
+
) from fnfe
|
|
285
275
|
|
|
286
276
|
location_map_path = (
|
|
287
277
|
self.folder_structure.mapping_files_folder
|
|
@@ -302,7 +292,7 @@ class HoldingsMarcTransformer(MigrationTaskBase):
|
|
|
302
292
|
self.library_configuration,
|
|
303
293
|
self.instance_id_map,
|
|
304
294
|
self.boundwith_relationship_map_rows,
|
|
305
|
-
statcode_mapping
|
|
295
|
+
statcode_mapping,
|
|
306
296
|
)
|
|
307
297
|
self.add_supplemental_mfhd_mappings()
|
|
308
298
|
if (
|
|
@@ -330,12 +320,12 @@ class HoldingsMarcTransformer(MigrationTaskBase):
|
|
|
330
320
|
"Supplemental MFHD mapping rules file must contain a dictionary",
|
|
331
321
|
json.dumps(new_rules),
|
|
332
322
|
)
|
|
333
|
-
except FileNotFoundError:
|
|
323
|
+
except FileNotFoundError as fnfe:
|
|
334
324
|
raise TransformationProcessError(
|
|
335
325
|
"",
|
|
336
326
|
"Provided supplemental MFHD mapping rules file not found",
|
|
337
327
|
self.task_configuration.supplemental_mfhd_mapping_rules_file,
|
|
338
|
-
)
|
|
328
|
+
) from fnfe
|
|
339
329
|
else:
|
|
340
330
|
new_rules = {}
|
|
341
331
|
self.mapper.integrate_supplemental_mfhd_mappings(new_rules)
|
|
@@ -360,7 +350,7 @@ class HoldingsMarcTransformer(MigrationTaskBase):
|
|
|
360
350
|
|
|
361
351
|
with open(self.folder_structure.migration_reports_file, "w+") as report_file:
|
|
362
352
|
self.mapper.migration_report.write_migration_report(
|
|
363
|
-
|
|
353
|
+
i18n_t("Bibliographic records transformation report"),
|
|
364
354
|
report_file,
|
|
365
355
|
self.start_datetime,
|
|
366
356
|
)
|
|
@@ -12,6 +12,8 @@ import i18n
|
|
|
12
12
|
from folio_uuid.folio_namespaces import FOLIONamespaces
|
|
13
13
|
from pydantic import Field
|
|
14
14
|
|
|
15
|
+
from folio_migration_tools.i18n_cache import i18n_t
|
|
16
|
+
|
|
15
17
|
from folio_migration_tools.custom_exceptions import (
|
|
16
18
|
TransformationProcessError,
|
|
17
19
|
TransformationRecordFailedError,
|
|
@@ -53,10 +55,7 @@ class ItemsTransformer(MigrationTaskBase):
|
|
|
53
55
|
HridHandling,
|
|
54
56
|
Field(
|
|
55
57
|
title="HRID handling",
|
|
56
|
-
description=(
|
|
57
|
-
"Determining how the HRID generation "
|
|
58
|
-
"should be handled."
|
|
59
|
-
),
|
|
58
|
+
description=("Determining how the HRID generation should be handled."),
|
|
60
59
|
),
|
|
61
60
|
]
|
|
62
61
|
files: Annotated[
|
|
@@ -91,10 +90,7 @@ class ItemsTransformer(MigrationTaskBase):
|
|
|
91
90
|
Optional[str],
|
|
92
91
|
Field(
|
|
93
92
|
title="Temporary location map file name",
|
|
94
|
-
description=(
|
|
95
|
-
"Temporary file name for location map. "
|
|
96
|
-
"Empty string by default."
|
|
97
|
-
),
|
|
93
|
+
description=("Temporary file name for location map. Empty string by default."),
|
|
98
94
|
),
|
|
99
95
|
] = ""
|
|
100
96
|
material_types_map_file_name: Annotated[
|
|
@@ -115,10 +111,7 @@ class ItemsTransformer(MigrationTaskBase):
|
|
|
115
111
|
Optional[str],
|
|
116
112
|
Field(
|
|
117
113
|
title="Temporary loan types map file name",
|
|
118
|
-
description=(
|
|
119
|
-
"File name for temporary loan types map. "
|
|
120
|
-
"Empty string by default."
|
|
121
|
-
),
|
|
114
|
+
description=("File name for temporary loan types map. Empty string by default."),
|
|
122
115
|
),
|
|
123
116
|
] = ""
|
|
124
117
|
statistical_codes_map_file_name: Annotated[
|
|
@@ -218,9 +211,8 @@ class ItemsTransformer(MigrationTaskBase):
|
|
|
218
211
|
self.folio_keys = MappingFileMapperBase.get_mapped_folio_properties_from_map(
|
|
219
212
|
self.items_map
|
|
220
213
|
)
|
|
221
|
-
if (
|
|
222
|
-
|
|
223
|
-
or any(getattr(k, "statistical_code", "") for k in self.task_configuration.files)
|
|
214
|
+
if any(k for k in self.folio_keys if k.startswith("statisticalCodeIds")) or any(
|
|
215
|
+
getattr(k, "statistical_code", "") for k in self.task_configuration.files
|
|
224
216
|
):
|
|
225
217
|
statcode_mapping = self.load_ref_data_mapping_file(
|
|
226
218
|
"statisticalCodeIds",
|
|
@@ -307,7 +299,7 @@ class ItemsTransformer(MigrationTaskBase):
|
|
|
307
299
|
temporary_loan_type_mapping,
|
|
308
300
|
temporary_location_mapping,
|
|
309
301
|
self.library_configuration,
|
|
310
|
-
self.task_configuration
|
|
302
|
+
self.task_configuration,
|
|
311
303
|
)
|
|
312
304
|
if (
|
|
313
305
|
self.task_configuration.reset_hrid_settings
|
|
@@ -345,7 +337,7 @@ class ItemsTransformer(MigrationTaskBase):
|
|
|
345
337
|
records_in_file = 0
|
|
346
338
|
with open(full_path, encoding="utf-8-sig") as records_file:
|
|
347
339
|
self.mapper.migration_report.add_general_statistics(
|
|
348
|
-
|
|
340
|
+
i18n_t("Number of files processed")
|
|
349
341
|
)
|
|
350
342
|
start = time.time()
|
|
351
343
|
for idx, record in enumerate(self.mapper.get_objects(records_file, full_path)):
|
|
@@ -363,9 +355,7 @@ class ItemsTransformer(MigrationTaskBase):
|
|
|
363
355
|
self.handle_notes(folio_rec)
|
|
364
356
|
if folio_rec["holdingsRecordId"] in self.boundwith_relationship_map:
|
|
365
357
|
for idx_, instance_id in enumerate(
|
|
366
|
-
self.boundwith_relationship_map.get(
|
|
367
|
-
folio_rec["holdingsRecordId"]
|
|
368
|
-
)
|
|
358
|
+
self.boundwith_relationship_map.get(folio_rec["holdingsRecordId"])
|
|
369
359
|
):
|
|
370
360
|
if idx_ == 0:
|
|
371
361
|
bw_id = folio_rec["holdingsRecordId"]
|
|
@@ -380,7 +370,7 @@ class ItemsTransformer(MigrationTaskBase):
|
|
|
380
370
|
# TODO: turn this into a asynchronous task
|
|
381
371
|
Helper.write_to_file(results_file, folio_rec)
|
|
382
372
|
self.mapper.migration_report.add_general_statistics(
|
|
383
|
-
|
|
373
|
+
i18n_t("Number of records written to disk")
|
|
384
374
|
)
|
|
385
375
|
self.mapper.report_folio_mapping(folio_rec, self.mapper.schema)
|
|
386
376
|
except TransformationProcessError as process_error:
|
|
@@ -399,7 +389,7 @@ class ItemsTransformer(MigrationTaskBase):
|
|
|
399
389
|
i18n.t("Number of Legacy items in %{container}", container=file_def),
|
|
400
390
|
)
|
|
401
391
|
self.mapper.migration_report.add_general_statistics(
|
|
402
|
-
|
|
392
|
+
i18n_t("Number of Legacy items in total")
|
|
403
393
|
)
|
|
404
394
|
self.print_progress(idx, start)
|
|
405
395
|
records_in_file = idx + 1
|
|
@@ -453,36 +443,35 @@ class ItemsTransformer(MigrationTaskBase):
|
|
|
453
443
|
def load_boundwith_relationships(self):
|
|
454
444
|
try:
|
|
455
445
|
with open(
|
|
456
|
-
|
|
446
|
+
self.folder_structure.boundwith_relationships_map_path
|
|
457
447
|
) as boundwith_relationship_file:
|
|
458
448
|
self.boundwith_relationship_map = dict(
|
|
459
|
-
|
|
460
|
-
)
|
|
461
|
-
logging.info(
|
|
462
|
-
"Rows in Bound with relationship map: %s",
|
|
463
|
-
len(self.boundwith_relationship_map)
|
|
449
|
+
json.loads(x) for x in boundwith_relationship_file
|
|
464
450
|
)
|
|
465
|
-
|
|
451
|
+
logging.info(
|
|
452
|
+
"Rows in Bound with relationship map: %s", len(self.boundwith_relationship_map)
|
|
453
|
+
)
|
|
454
|
+
except FileNotFoundError as fnfe:
|
|
466
455
|
raise TransformationProcessError(
|
|
467
456
|
"",
|
|
468
457
|
"Boundwith relationship file specified, but relationships file "
|
|
469
458
|
"from holdings transformation not found.",
|
|
470
|
-
self.folder_structure.boundwith_relationships_map_path
|
|
471
|
-
)
|
|
472
|
-
except ValueError:
|
|
459
|
+
self.folder_structure.boundwith_relationships_map_path,
|
|
460
|
+
) from fnfe
|
|
461
|
+
except ValueError as ve:
|
|
473
462
|
raise TransformationProcessError(
|
|
474
463
|
"",
|
|
475
464
|
"Boundwith relationship file specified, but relationships file "
|
|
476
465
|
"from holdings transformation is not a valid line JSON.",
|
|
477
466
|
self.folder_structure.boundwith_relationships_map_path,
|
|
478
|
-
)
|
|
467
|
+
) from ve
|
|
479
468
|
|
|
480
469
|
def wrap_up(self):
|
|
481
470
|
logging.info("Done. Transformer wrapping up...")
|
|
482
471
|
self.extradata_writer.flush()
|
|
483
472
|
with open(self.folder_structure.migration_reports_file, "w") as migration_report_file:
|
|
484
473
|
self.mapper.migration_report.write_migration_report(
|
|
485
|
-
|
|
474
|
+
i18n_t("Item transformation report"),
|
|
486
475
|
migration_report_file,
|
|
487
476
|
self.mapper.start_datetime,
|
|
488
477
|
)
|