folio-migration-tools 1.9.0rc9__tar.gz → 1.9.0rc11__tar.gz
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-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/PKG-INFO +2 -2
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/pyproject.toml +2 -2
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/__main__.py +23 -5
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/circulation_helper.py +3 -3
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/library_configuration.py +54 -6
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/mapper_base.py +2 -2
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/marc_rules_transformation/hrid_handler.py +1 -1
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/marc_rules_transformation/marc_file_processor.py +21 -23
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/marc_rules_transformation/rules_mapper_base.py +3 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/marc_rules_transformation/rules_mapper_bibs.py +52 -37
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/marc_rules_transformation/rules_mapper_holdings.py +131 -21
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/batch_poster.py +7 -7
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/bibs_transformer.py +6 -59
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/holdings_marc_transformer.py +61 -23
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/loans_migrator.py +5 -5
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/migration_task_base.py +64 -1
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/reserves_migrator.py +1 -1
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/task_configuration.py +18 -1
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/test_infrastructure/mocked_classes.py +94 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/transaction_migration/legacy_loan.py +14 -12
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/transaction_migration/legacy_reserve.py +1 -1
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/LICENSE +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/README.md +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/__init__.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/colors.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/config_file_load.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/custom_dict.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/custom_exceptions.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/extradata_writer.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/folder_structure.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/helper.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/holdings_helper.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/i18n_config.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/mapping_file_transformation/__init__.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/mapping_file_transformation/courses_mapper.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/mapping_file_transformation/holdings_mapper.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/mapping_file_transformation/item_mapper.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/mapping_file_transformation/manual_fee_fines_mapper.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/mapping_file_transformation/mapping_file_mapper_base.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/mapping_file_transformation/notes_mapper.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/mapping_file_transformation/order_mapper.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/mapping_file_transformation/organization_mapper.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/mapping_file_transformation/ref_data_mapping.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/mapping_file_transformation/user_mapper.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/marc_rules_transformation/__init__.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/marc_rules_transformation/conditions.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/marc_rules_transformation/holdings_statementsparser.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/marc_rules_transformation/loc_language_codes.xml +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/marc_rules_transformation/marc_reader_wrapper.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/marc_rules_transformation/rules_mapper_authorities.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_report.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/__init__.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/authority_transformer.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/courses_migrator.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/holdings_csv_transformer.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/items_transformer.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/manual_fee_fines_transformer.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/orders_transformer.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/organization_transformer.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/requests_migrator.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/migration_tasks/user_transformer.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/test_infrastructure/__init__.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/transaction_migration/__init__.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/transaction_migration/legacy_request.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/transaction_migration/transaction_result.py +0 -0
- {folio_migration_tools-1.9.0rc9 → folio_migration_tools-1.9.0rc11}/src/folio_migration_tools/translations/en.json +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: folio_migration_tools
|
|
3
|
-
Version: 1.9.
|
|
3
|
+
Version: 1.9.0rc11
|
|
4
4
|
Summary: A tool allowing you to migrate data from legacy ILS:s (Library systems) into FOLIO LSP
|
|
5
5
|
License: MIT
|
|
6
6
|
Keywords: FOLIO,ILS,LSP,Library Systems,MARC21,Library data
|
|
@@ -20,7 +20,7 @@ Requires-Dist: art (>=6.5,<7.0)
|
|
|
20
20
|
Requires-Dist: deepdiff (>=6.2.3,<7.0.0)
|
|
21
21
|
Requires-Dist: defusedxml (>=0.7.1,<0.8.0)
|
|
22
22
|
Requires-Dist: folio-uuid (>=0.2.8,<0.3.0)
|
|
23
|
-
Requires-Dist: folioclient (
|
|
23
|
+
Requires-Dist: folioclient (==0.70.1)
|
|
24
24
|
Requires-Dist: pyaml (>=21.10.1,<22.0.0)
|
|
25
25
|
Requires-Dist: pydantic (>=1.10.2,<2.0.0)
|
|
26
26
|
Requires-Dist: pyhumps (>=3.7.3,<4.0.0)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "folio_migration_tools"
|
|
3
|
-
version = "1.9.
|
|
3
|
+
version = "1.9.0rc11"
|
|
4
4
|
description = "A tool allowing you to migrate data from legacy ILS:s (Library systems) into FOLIO LSP"
|
|
5
5
|
authors = [
|
|
6
6
|
{name = "Theodor Tolstoy", email = "github.teddes@tolstoy.se"},
|
|
@@ -44,7 +44,7 @@ profile = "black"
|
|
|
44
44
|
|
|
45
45
|
[tool.poetry.dependencies]
|
|
46
46
|
python = "^3.9"
|
|
47
|
-
folioclient = "
|
|
47
|
+
folioclient = "0.70.1"
|
|
48
48
|
pyhumps = "^3.7.3"
|
|
49
49
|
defusedxml = "^0.7.1"
|
|
50
50
|
python-dateutil = "^2.8.2"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from importlib import metadata
|
|
1
2
|
import json
|
|
2
3
|
import logging
|
|
3
4
|
import sys
|
|
@@ -38,7 +39,7 @@ def parse_args(args):
|
|
|
38
39
|
default=environ.get("FOLIO_MIGRATION_TOOLS_TASK_NAME"),
|
|
39
40
|
)
|
|
40
41
|
parser.add_argument(
|
|
41
|
-
"--okapi_password",
|
|
42
|
+
"--folio_password", "--okapi_password",
|
|
42
43
|
help="password for the tenant in the configuration file",
|
|
43
44
|
prompt="FOLIO_MIGRATION_TOOLS_OKAPI_PASSWORD" not in environ,
|
|
44
45
|
default=environ.get("FOLIO_MIGRATION_TOOLS_OKAPI_PASSWORD"),
|
|
@@ -60,11 +61,17 @@ def parse_args(args):
|
|
|
60
61
|
default=environ.get("FOLIO_MIGRATION_TOOLS_REPORT_LANGUAGE", "en"),
|
|
61
62
|
prompt=False,
|
|
62
63
|
)
|
|
64
|
+
parser.add_argument(
|
|
65
|
+
"--version", "-V",
|
|
66
|
+
help="Show the version of the FOLIO Migration Tools",
|
|
67
|
+
action="store_true",
|
|
68
|
+
prompt=False,
|
|
69
|
+
)
|
|
63
70
|
return parser.parse_args(args)
|
|
64
71
|
|
|
65
72
|
def prep_library_config(args):
|
|
66
73
|
config_file_humped = merge_load(args.configuration_path)
|
|
67
|
-
config_file_humped["libraryInformation"]["okapiPassword"] = args.
|
|
74
|
+
config_file_humped["libraryInformation"]["okapiPassword"] = args.folio_password
|
|
68
75
|
config_file_humped["libraryInformation"]["baseFolder"] = args.base_folder_path
|
|
69
76
|
config_file = humps.decamelize(config_file_humped)
|
|
70
77
|
library_config = LibraryConfiguration(**config_file["library_information"])
|
|
@@ -78,11 +85,22 @@ def prep_library_config(args):
|
|
|
78
85
|
sys.exit("ECS Central Iteration Identifier Not Found")
|
|
79
86
|
return config_file, library_config
|
|
80
87
|
|
|
88
|
+
def print_version(args):
|
|
89
|
+
if "-V" in args or "--version" in args:
|
|
90
|
+
print(
|
|
91
|
+
f"FOLIO Migration Tools: {metadata.version('folio_migration_tools')}"
|
|
92
|
+
)
|
|
93
|
+
sys.exit(0)
|
|
94
|
+
return None
|
|
95
|
+
|
|
81
96
|
|
|
82
97
|
def main():
|
|
83
98
|
try:
|
|
84
99
|
task_classes = list(inheritors(migration_task_base.MigrationTaskBase))
|
|
100
|
+
# Check if the script is run with the --version or -V flag
|
|
101
|
+
print_version(sys.argv)
|
|
85
102
|
|
|
103
|
+
# Parse command line arguments
|
|
86
104
|
args = parse_args(sys.argv[1:])
|
|
87
105
|
try:
|
|
88
106
|
i18n.load_config(
|
|
@@ -124,10 +142,10 @@ def main():
|
|
|
124
142
|
try:
|
|
125
143
|
logging.getLogger("httpx").setLevel(logging.WARNING) # Exclude info messages from httpx
|
|
126
144
|
with FolioClient(
|
|
127
|
-
library_config.
|
|
145
|
+
library_config.gateway_url,
|
|
128
146
|
library_config.tenant_id,
|
|
129
|
-
library_config.
|
|
130
|
-
library_config.
|
|
147
|
+
library_config.folio_username,
|
|
148
|
+
library_config.folio_password,
|
|
131
149
|
) as folio_client:
|
|
132
150
|
task_config = task_class.TaskConfiguration(**migration_task_config)
|
|
133
151
|
task_obj = task_class(task_config, library_config, folio_client)
|
|
@@ -138,7 +138,7 @@ class CirculationHelper:
|
|
|
138
138
|
if legacy_loan.proxy_patron_barcode:
|
|
139
139
|
data.update({"proxyUserBarcode": legacy_loan.proxy_patron_barcode})
|
|
140
140
|
path = "/circulation/check-out-by-barcode"
|
|
141
|
-
url = f"{self.folio_client.
|
|
141
|
+
url = f"{self.folio_client.gateway_url}{path}"
|
|
142
142
|
try:
|
|
143
143
|
if legacy_loan.patron_barcode in self.missing_patron_barcodes:
|
|
144
144
|
error_message = i18n.t("Patron barcode already detected as missing")
|
|
@@ -249,7 +249,7 @@ class CirculationHelper:
|
|
|
249
249
|
):
|
|
250
250
|
try:
|
|
251
251
|
path = "/circulation/requests"
|
|
252
|
-
url = f"{folio_client.
|
|
252
|
+
url = f"{folio_client.gateway_url}{path}"
|
|
253
253
|
data = legacy_request.serialize()
|
|
254
254
|
data["requestProcessingParameters"] = {
|
|
255
255
|
"overrideBlocks": {
|
|
@@ -313,7 +313,7 @@ class CirculationHelper:
|
|
|
313
313
|
del loan_to_put["metadata"]
|
|
314
314
|
loan_to_put["dueDate"] = extension_due_date.isoformat()
|
|
315
315
|
loan_to_put["loanDate"] = extend_out_date.isoformat()
|
|
316
|
-
url = f"{folio_client.
|
|
316
|
+
url = f"{folio_client.gateway_url}/circulation/loans/{loan_to_put['id']}"
|
|
317
317
|
|
|
318
318
|
req = httpx.put(
|
|
319
319
|
url, headers=folio_client.okapi_headers, json=loan_to_put, timeout=None
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from enum import Enum
|
|
2
|
-
from typing import Annotated
|
|
2
|
+
from typing import Annotated
|
|
3
3
|
|
|
4
4
|
from pydantic import BaseModel, Field
|
|
5
5
|
from pydantic.types import DirectoryPath
|
|
@@ -68,8 +68,28 @@ class FolioRelease(str, Enum):
|
|
|
68
68
|
|
|
69
69
|
|
|
70
70
|
class LibraryConfiguration(BaseModel):
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
gateway_url: Annotated[
|
|
72
|
+
str,
|
|
73
|
+
Field(
|
|
74
|
+
title="FOLIO API Gateway URL",
|
|
75
|
+
description=(
|
|
76
|
+
"The URL of the FOLIO API gateway instance. "
|
|
77
|
+
"You can find this in Settings > Software versions > API gateway services."
|
|
78
|
+
),
|
|
79
|
+
alias="okapi_url"
|
|
80
|
+
),
|
|
81
|
+
]
|
|
82
|
+
tenant_id: Annotated[
|
|
83
|
+
str,
|
|
84
|
+
Field(
|
|
85
|
+
title="FOLIO tenant ID",
|
|
86
|
+
description=(
|
|
87
|
+
"The ID of the FOLIO tenant instance. "
|
|
88
|
+
"You can find this in Settings > Software versions > API gateway services. "
|
|
89
|
+
"In an ECS environment, this is the ID of the central tenant, for all configurations."
|
|
90
|
+
),
|
|
91
|
+
),
|
|
92
|
+
]
|
|
73
93
|
ecs_tenant_id: Annotated[
|
|
74
94
|
str,
|
|
75
95
|
Field(
|
|
@@ -80,15 +100,43 @@ class LibraryConfiguration(BaseModel):
|
|
|
80
100
|
),
|
|
81
101
|
),
|
|
82
102
|
] = ""
|
|
83
|
-
|
|
84
|
-
|
|
103
|
+
folio_username: Annotated[
|
|
104
|
+
str,
|
|
105
|
+
Field(
|
|
106
|
+
title="FOLIO API Gateway username",
|
|
107
|
+
description=(
|
|
108
|
+
"The username for the FOLIO user account performing the migration. "
|
|
109
|
+
"User should have a full admin permissions/roles in FOLIO. "
|
|
110
|
+
),
|
|
111
|
+
alias="okapi_username"
|
|
112
|
+
),
|
|
113
|
+
]
|
|
114
|
+
folio_password: Annotated[
|
|
115
|
+
str,
|
|
116
|
+
Field(
|
|
117
|
+
title="FOLIO API Gateway password",
|
|
118
|
+
description=(
|
|
119
|
+
"The password for the FOLIO user account performing the migration. "
|
|
120
|
+
),
|
|
121
|
+
alias="okapi_password"
|
|
122
|
+
)
|
|
123
|
+
]
|
|
85
124
|
base_folder: DirectoryPath = Field(
|
|
86
125
|
description=(
|
|
87
126
|
"The base folder for migration. "
|
|
88
127
|
"Should ideally be a github clone of the migration_repo_template"
|
|
89
128
|
)
|
|
90
129
|
)
|
|
91
|
-
multi_field_delimiter:
|
|
130
|
+
multi_field_delimiter: Annotated[
|
|
131
|
+
str,
|
|
132
|
+
Field(
|
|
133
|
+
title="Multi field delimiter",
|
|
134
|
+
description=(
|
|
135
|
+
"The delimiter used to separate multiple values in a single field. "
|
|
136
|
+
"This is used for delimited text (CSV/TSV) fields with multiple sub-delimited values."
|
|
137
|
+
),
|
|
138
|
+
),
|
|
139
|
+
] = "<delimiter>"
|
|
92
140
|
failed_records_threshold: Annotated[
|
|
93
141
|
int,
|
|
94
142
|
Field(description=("Number of failed records until the process shuts down")),
|
|
@@ -272,7 +272,7 @@ class MapperBase:
|
|
|
272
272
|
[
|
|
273
273
|
object_type == FOLIONamespaces.instances,
|
|
274
274
|
(not getattr(self.task_configuration, "data_import_marc", False)),
|
|
275
|
-
getattr(self
|
|
275
|
+
getattr(self, "create_source_records", True),
|
|
276
276
|
]
|
|
277
277
|
):
|
|
278
278
|
return (legacy_id, folio_record["id"], folio_record["hrid"])
|
|
@@ -443,7 +443,7 @@ class MapperBase:
|
|
|
443
443
|
@property
|
|
444
444
|
def base_string_for_folio_uuid(self):
|
|
445
445
|
if self.library_configuration.use_gateway_url_for_uuids and not self.library_configuration.is_ecs:
|
|
446
|
-
return str(self.folio_client.
|
|
446
|
+
return str(self.folio_client.gateway_url)
|
|
447
447
|
elif self.library_configuration.ecs_tenant_id:
|
|
448
448
|
return str(self.library_configuration.ecs_tenant_id)
|
|
449
449
|
else:
|
|
@@ -160,7 +160,7 @@ class HRIDHandler:
|
|
|
160
160
|
self.hrid_settings["instances"]["startNumber"] = self.instance_hrid_counter
|
|
161
161
|
self.hrid_settings["holdings"]["startNumber"] = self.holdings_hrid_counter
|
|
162
162
|
self.hrid_settings["items"]["startNumber"] = self.items_hrid_counter
|
|
163
|
-
url = self.folio_client.
|
|
163
|
+
url = self.folio_client.gateway_url + self.hrid_path
|
|
164
164
|
resp = httpx.put(
|
|
165
165
|
url,
|
|
166
166
|
json=self.hrid_settings,
|
|
@@ -3,7 +3,7 @@ import os
|
|
|
3
3
|
import sys
|
|
4
4
|
import time
|
|
5
5
|
import traceback
|
|
6
|
-
from typing import List
|
|
6
|
+
from typing import BinaryIO, Dict, List, Set, TextIO
|
|
7
7
|
|
|
8
8
|
import i18n
|
|
9
9
|
from folio_uuid.folio_namespaces import FOLIONamespaces
|
|
@@ -24,24 +24,26 @@ from folio_migration_tools.migration_report import MigrationReport
|
|
|
24
24
|
|
|
25
25
|
class MarcFileProcessor:
|
|
26
26
|
def __init__(
|
|
27
|
-
self, mapper: RulesMapperBase, folder_structure: FolderStructure, created_objects_file
|
|
27
|
+
self, mapper: RulesMapperBase, folder_structure: FolderStructure, created_objects_file: TextIO
|
|
28
28
|
):
|
|
29
29
|
self.object_type: FOLIONamespaces = folder_structure.object_type
|
|
30
30
|
self.folder_structure: FolderStructure = folder_structure
|
|
31
31
|
self.mapper: RulesMapperBase = mapper
|
|
32
|
-
self.created_objects_file = created_objects_file
|
|
33
|
-
if mapper.
|
|
34
|
-
|
|
32
|
+
self.created_objects_file: TextIO = created_objects_file
|
|
33
|
+
if mapper.create_source_records and any(
|
|
34
|
+
x.create_source_records for x in mapper.task_configuration.files
|
|
35
|
+
):
|
|
36
|
+
self.srs_records_file: TextIO = open(self.folder_structure.srs_records_path, "w+")
|
|
35
37
|
if getattr(mapper.task_configuration, "data_import_marc", False):
|
|
36
|
-
self.data_import_marc_file = open(self.folder_structure.data_import_marc_path, "wb+")
|
|
37
|
-
self.unique_001s:
|
|
38
|
+
self.data_import_marc_file: BinaryIO = open(self.folder_structure.data_import_marc_path, "wb+")
|
|
39
|
+
self.unique_001s: Set[str] = set()
|
|
38
40
|
self.failed_records_count: int = 0
|
|
39
41
|
self.records_count: int = 0
|
|
40
42
|
self.start: float = time.time()
|
|
41
|
-
self.legacy_ids:
|
|
43
|
+
self.legacy_ids: Set[str] = set()
|
|
42
44
|
if (
|
|
43
45
|
self.object_type == FOLIONamespaces.holdings
|
|
44
|
-
and self.mapper.
|
|
46
|
+
and self.mapper.create_source_records
|
|
45
47
|
):
|
|
46
48
|
logging.info("Loading Parent HRID map for SRS creation")
|
|
47
49
|
self.parent_hrids = {entity[1]: entity[2] for entity in mapper.parent_id_map.values()}
|
|
@@ -78,7 +80,7 @@ class MarcFileProcessor:
|
|
|
78
80
|
|
|
79
81
|
if (
|
|
80
82
|
file_def.create_source_records
|
|
81
|
-
and self.mapper.
|
|
83
|
+
and self.mapper.create_source_records
|
|
82
84
|
):
|
|
83
85
|
self.save_srs_record(
|
|
84
86
|
marc_record,
|
|
@@ -132,7 +134,7 @@ class MarcFileProcessor:
|
|
|
132
134
|
def save_marc_record(
|
|
133
135
|
self,
|
|
134
136
|
marc_record: Record,
|
|
135
|
-
folio_rec:
|
|
137
|
+
folio_rec: Dict,
|
|
136
138
|
object_type: FOLIONamespaces
|
|
137
139
|
):
|
|
138
140
|
self.mapper.save_data_import_marc_record(
|
|
@@ -146,14 +148,10 @@ class MarcFileProcessor:
|
|
|
146
148
|
self,
|
|
147
149
|
marc_record: Record,
|
|
148
150
|
file_def: FileDefinition,
|
|
149
|
-
folio_rec,
|
|
151
|
+
folio_rec: Dict,
|
|
150
152
|
legacy_ids: List[str],
|
|
151
153
|
object_type: FOLIONamespaces,
|
|
152
154
|
):
|
|
153
|
-
if not all(
|
|
154
|
-
[file_def.create_source_records, self.mapper.task_configuration.create_source_records]
|
|
155
|
-
):
|
|
156
|
-
return
|
|
157
155
|
if object_type in [FOLIONamespaces.holdings]:
|
|
158
156
|
if "008" in marc_record and len(marc_record["008"].data) > 32:
|
|
159
157
|
remain, rest = (
|
|
@@ -188,7 +186,7 @@ class MarcFileProcessor:
|
|
|
188
186
|
)
|
|
189
187
|
self.mapper.migration_report.add_general_statistics(i18n.t("SRS records written to disk"))
|
|
190
188
|
|
|
191
|
-
def add_mapped_location_code_to_record(self, marc_record, folio_rec):
|
|
189
|
+
def add_mapped_location_code_to_record(self, marc_record: Record, folio_rec: Dict):
|
|
192
190
|
location_code = next(
|
|
193
191
|
(
|
|
194
192
|
location["code"]
|
|
@@ -225,9 +223,9 @@ class MarcFileProcessor:
|
|
|
225
223
|
|
|
226
224
|
@staticmethod
|
|
227
225
|
def get_valid_folio_record_ids(
|
|
228
|
-
legacy_ids, folio_record_identifiers, migration_report: MigrationReport
|
|
229
|
-
):
|
|
230
|
-
new_ids = set()
|
|
226
|
+
legacy_ids: List[str], folio_record_identifiers: Set[str], migration_report: MigrationReport
|
|
227
|
+
) -> List[str]:
|
|
228
|
+
new_ids: Set[str] = set()
|
|
231
229
|
for legacy_id in legacy_ids:
|
|
232
230
|
if legacy_id not in folio_record_identifiers:
|
|
233
231
|
new_ids.add(legacy_id)
|
|
@@ -266,12 +264,12 @@ class MarcFileProcessor:
|
|
|
266
264
|
self.mapper.mapped_folio_fields,
|
|
267
265
|
self.mapper.mapped_legacy_fields,
|
|
268
266
|
)
|
|
269
|
-
if self
|
|
267
|
+
if hasattr(self, "srs_records_file"):
|
|
270
268
|
self.srs_records_file.seek(0)
|
|
271
269
|
if not self.srs_records_file.seek(0):
|
|
272
270
|
os.remove(self.srs_records_file.name)
|
|
273
271
|
self.srs_records_file.close()
|
|
274
|
-
if
|
|
272
|
+
if hasattr(self, "data_import_marc_file"):
|
|
275
273
|
self.data_import_marc_file.seek(0)
|
|
276
274
|
if not self.data_import_marc_file.read(1):
|
|
277
275
|
os.remove(self.data_import_marc_file.name)
|
|
@@ -281,7 +279,7 @@ class MarcFileProcessor:
|
|
|
281
279
|
logging.info("Transformation report written to %s", report_file.name)
|
|
282
280
|
logging.info("Processor is done.")
|
|
283
281
|
|
|
284
|
-
def add_legacy_ids_to_map(self, folio_rec, filtered_legacy_ids):
|
|
282
|
+
def add_legacy_ids_to_map(self, folio_rec: Dict, filtered_legacy_ids: List[str]):
|
|
285
283
|
for legacy_id in filtered_legacy_ids:
|
|
286
284
|
self.legacy_ids.add(legacy_id)
|
|
287
285
|
if legacy_id not in self.mapper.id_map:
|
|
@@ -51,6 +51,9 @@ class RulesMapperBase(MapperBase):
|
|
|
51
51
|
self.item_json_schema = ""
|
|
52
52
|
self.mappings: dict = {}
|
|
53
53
|
self.schema_properties = None
|
|
54
|
+
self.create_source_records = all(
|
|
55
|
+
[self.task_configuration.create_source_records, (not getattr(self.task_configuration, "data_import_marc", False))]
|
|
56
|
+
)
|
|
54
57
|
if hasattr(self.task_configuration, "hrid_handling"):
|
|
55
58
|
self.hrid_handler = HRIDHandler(
|
|
56
59
|
folio_client,
|