folio-migration-tools 1.9.1__py3-none-any.whl → 1.9.2__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.
@@ -1,10 +1,12 @@
1
1
  import ast
2
+ import json
3
+ import logging
2
4
 
3
5
  import i18n
4
6
  from folio_uuid.folio_uuid import FOLIONamespaces
5
7
  from folioclient import FolioClient
6
8
 
7
- from folio_migration_tools.custom_exceptions import TransformationRecordFailedError
9
+ from folio_migration_tools.custom_exceptions import TransformationProcessError, TransformationRecordFailedError
8
10
  from folio_migration_tools.library_configuration import (
9
11
  FileDefinition,
10
12
  LibraryConfiguration,
@@ -59,6 +61,21 @@ class HoldingsMapper(MappingFileMapperBase):
59
61
  "name",
60
62
  "CallNumberTypeMapping",
61
63
  )
64
+ self.holdings_sources = self.get_holdings_sources()
65
+
66
+ def get_holdings_sources(self):
67
+ res = {}
68
+ holdings_sources = list(
69
+ self.folio_client.folio_get_all("/holdings-sources", "holdingsRecordsSources")
70
+ )
71
+ logging.info("Fetched %s holdingsRecordsSources from tenant", len(holdings_sources))
72
+ res = {n["name"].upper(): n["id"] for n in holdings_sources}
73
+ if "FOLIO" not in res:
74
+ raise TransformationProcessError("", "No holdings source with name FOLIO in tenant")
75
+ if "MARC" not in res:
76
+ raise TransformationProcessError("", "No holdings source with name MARC in tenant")
77
+ logging.info(json.dumps(res, indent=4))
78
+ return res
62
79
 
63
80
  def perform_additional_mappings(self, legacy_ids, folio_rec, file_def):
64
81
  self.handle_suppression(folio_rec, file_def)
@@ -171,14 +171,15 @@ class MappingFileMapperBase(MapperBase):
171
171
  object_type: FOLIONamespaces,
172
172
  accept_duplicate_ids: bool = False,
173
173
  ):
174
+ folio_object = {}
174
175
  if self.ignore_legacy_identifier:
175
- return (
176
+ folio_object.update(
176
177
  {
177
178
  "id": str(uuid.uuid4()),
178
179
  "type": "object",
179
- },
180
- index_or_id,
180
+ }
181
181
  )
182
+ return folio_object, index_or_id
182
183
 
183
184
  if not (
184
185
  legacy_id := " ".join(
@@ -205,13 +206,21 @@ class MappingFileMapperBase(MapperBase):
205
206
  )
206
207
  else:
207
208
  self.unique_record_ids.add(generated_id)
208
- return (
209
+ folio_object.update(
209
210
  {
210
211
  "id": generated_id,
211
212
  "type": "object",
212
- },
213
- legacy_id,
213
+ }
214
214
  )
215
+ if object_type == FOLIONamespaces.holdings and hasattr(self, "holdings_sources"):
216
+ folio_object['sourceId'] = self.holdings_sources.get("FOLIO")
217
+ elif object_type == FOLIONamespaces.holdings and not hasattr(self, "holdings_sources"):
218
+ raise TransformationProcessError(
219
+ index_or_id,
220
+ "Holdings source not set in the mapper",
221
+ None
222
+ )
223
+ return folio_object, legacy_id
215
224
 
216
225
  def get_statistical_code(self, legacy_item: dict, folio_prop_name: str, index_or_id):
217
226
  if self.statistical_codes_mapping:
@@ -559,6 +559,16 @@ class RulesMapperBase(MapperBase):
559
559
  if k == "authorityId" and (legacy_subfield_9 := marc_field.get("9")):
560
560
  marc_field.add_subfield("0", legacy_subfield_9)
561
561
  marc_field.delete_subfield("9")
562
+ if k == "authorityId" and (entity_subfields := entity_mapping.get("subfield", [])):
563
+ for subfield in entity_subfields:
564
+ if subfield != "9":
565
+ Helper.log_data_issue(
566
+ index_or_legacy_id,
567
+ f"authorityId mapping from ${subfield} is not supported. Data Import will fail. "
568
+ "Use only $9 for authority id mapping in MARC-to-Instance mapping rules.",
569
+ marc_field,
570
+ )
571
+ entity_mapping["subfield"] = ["9"]
562
572
  if my_values := [
563
573
  v
564
574
  for v in self.apply_rules(marc_field, entity_mapping, index_or_legacy_id)
@@ -165,7 +165,7 @@ class BibsRulesMapper(RulesMapperBase):
165
165
  Helper.log_data_issue(
166
166
  legacy_ids,
167
167
  "Multiple main entry fields in record. Record will fail Data Import. Creating Instance anyway.",
168
- main_entry_fields
168
+ [str(field) for field in main_entry_fields]
169
169
  )
170
170
  if not main_entry_fields:
171
171
  main_entry_fields += marc_record.get_fields("700", "710", "711", "730")
@@ -209,7 +209,6 @@ class HoldingsCsvTransformer(MigrationTaskBase):
209
209
  self.holdings = {}
210
210
  self.total_records = 0
211
211
  self.holdings_id_map = self.load_id_map(self.folder_structure.holdings_id_map_path)
212
- self.holdings_sources = self.get_holdings_sources()
213
212
  self.results_path = self.folder_structure.created_objects_path
214
213
  self.holdings_types = list(
215
214
  self.folio_client.folio_get_all("/holdings-types", "holdingsTypes")
@@ -432,8 +431,6 @@ class HoldingsCsvTransformer(MigrationTaskBase):
432
431
  if not folio_rec.get("holdingsTypeId", ""):
433
432
  folio_rec["holdingsTypeId"] = self.fallback_holdings_type["id"]
434
433
 
435
- folio_rec["sourceId"] = self.holdings_sources.get("FOLIO")
436
-
437
434
  holdings_from_row = []
438
435
  all_instance_ids = folio_rec.get("instanceId", [])
439
436
  if len(all_instance_ids) == 1:
@@ -521,20 +518,6 @@ class HoldingsCsvTransformer(MigrationTaskBase):
521
518
  self.holdings[holdings_key], new_holdings_record
522
519
  )
523
520
 
524
- def get_holdings_sources(self):
525
- res = {}
526
- holdings_sources = list(
527
- self.mapper.folio_client.folio_get_all("/holdings-sources", "holdingsRecordsSources")
528
- )
529
- logging.info("Fetched %s holdingsRecordsSources from tenant", len(holdings_sources))
530
- res = {n["name"].upper(): n["id"] for n in holdings_sources}
531
- if "FOLIO" not in res:
532
- raise TransformationProcessError("", "No holdings source with name FOLIO in tenant")
533
- if "MARC" not in res:
534
- raise TransformationProcessError("", "No holdings source with name MARC in tenant")
535
- logging.info(json.dumps(res, indent=4))
536
- return res
537
-
538
521
 
539
522
  def explode_former_ids(folio_holding: dict):
540
523
  temp_ids = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: folio_migration_tools
3
- Version: 1.9.1
3
+ Version: 1.9.2
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
@@ -14,10 +14,10 @@ folio_migration_tools/library_configuration.py,sha256=LzICsZQdOkXwIqdDfh59x0-Cx7
14
14
  folio_migration_tools/mapper_base.py,sha256=IYER8Dq-4qLq3qiAvUpnzc33usUbfZtNKzyZJD6DNds,23567
15
15
  folio_migration_tools/mapping_file_transformation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  folio_migration_tools/mapping_file_transformation/courses_mapper.py,sha256=yX8yCCw6B54r7JUn5IPhMYKBgImiagUzfwBxNVRf5MQ,8091
17
- folio_migration_tools/mapping_file_transformation/holdings_mapper.py,sha256=DY4cpSWaJWJo-8ESpO4PSf_raTIRAVSt9N0-aV1ShGc,7504
17
+ folio_migration_tools/mapping_file_transformation/holdings_mapper.py,sha256=qT8LMWZytSaOyUC9OzfJeekVIkLkNim4OzfoGlAh75g,8290
18
18
  folio_migration_tools/mapping_file_transformation/item_mapper.py,sha256=ZmPc64X_l3hq8qc0WDhZ020TdjvucZoQciIVIpPzwiA,10472
19
19
  folio_migration_tools/mapping_file_transformation/manual_fee_fines_mapper.py,sha256=2-W2Z8hwAhWT77zfDWuwWqm20j4w1mfzeAXWiyssQ8I,13434
20
- folio_migration_tools/mapping_file_transformation/mapping_file_mapper_base.py,sha256=4A3oG5-ZTq6OalIWMo34I2nX4mympLaoMPnAj2W6S9M,37901
20
+ folio_migration_tools/mapping_file_transformation/mapping_file_mapper_base.py,sha256=LqxpULlickaQhIv92iBA7SwSXy1PN7l-9swLHQdnx6g,38408
21
21
  folio_migration_tools/mapping_file_transformation/notes_mapper.py,sha256=vCmZmjrjyYtXeFCyVqvWfnP8y1jGGu15RXzXIHh12xY,3530
22
22
  folio_migration_tools/mapping_file_transformation/order_mapper.py,sha256=-JEBEeOntNPE9-NYhWAJ1hpQI03ZzMv-_mkyLzSa9x4,17750
23
23
  folio_migration_tools/mapping_file_transformation/organization_mapper.py,sha256=u1Lb6tApn-nVLqbbJV38BuipKL3OK8Y2uQ4ogoyGQaI,14639
@@ -31,8 +31,8 @@ folio_migration_tools/marc_rules_transformation/loc_language_codes.xml,sha256=zt
31
31
  folio_migration_tools/marc_rules_transformation/marc_file_processor.py,sha256=M-PHduzMYmZnrMwOSlwnWQ5bT-566gVRFSMo-JgS2d4,12346
32
32
  folio_migration_tools/marc_rules_transformation/marc_reader_wrapper.py,sha256=9ATjYMRAjy0QcXtmNZaHVhHLJ5hE1WUgOcF6KMJjbgo,5309
33
33
  folio_migration_tools/marc_rules_transformation/rules_mapper_authorities.py,sha256=PGt2w8h2pj8_8sGjQe3L-odFDlquURtKnoNFRWQB3GI,9621
34
- folio_migration_tools/marc_rules_transformation/rules_mapper_base.py,sha256=6vVvrNoViZZ1g2piKtOPMlqYspej-2eei8HIwM-K_Lg,45309
35
- folio_migration_tools/marc_rules_transformation/rules_mapper_bibs.py,sha256=H7RrU1KfFlTj6M0l7HXD3vOtxKHY4FD5xrXmGjCjcRc,30324
34
+ folio_migration_tools/marc_rules_transformation/rules_mapper_base.py,sha256=loNZ9gEYaAwjkP2_wLlXGedjWvSdHoGF_oJN9g6gI3s,45928
35
+ folio_migration_tools/marc_rules_transformation/rules_mapper_bibs.py,sha256=GYZmVrEKcHkOEH4U3027-vQjS6mfMbk84GJTqiVrD4E,30350
36
36
  folio_migration_tools/marc_rules_transformation/rules_mapper_holdings.py,sha256=wT9HDodIRYeGbjutVHDHpSBVWrXsuA2LO8e_MmBMmzE,28498
37
37
  folio_migration_tools/migration_report.py,sha256=BkRspM1hwTBnWeqsHamf7yVEofzLj560Q-9G--O00hw,4258
38
38
  folio_migration_tools/migration_tasks/__init__.py,sha256=ZkbY_yGyB84Ke8OMlYUzyyBj4cxxNrhMTwQlu_GbdDs,211
@@ -40,7 +40,7 @@ folio_migration_tools/migration_tasks/authority_transformer.py,sha256=AoXg9s-GLO
40
40
  folio_migration_tools/migration_tasks/batch_poster.py,sha256=uXxvmxlLSTEhvdBH9FgxhIHHXB4ezLt35LSN6lKprYE,39673
41
41
  folio_migration_tools/migration_tasks/bibs_transformer.py,sha256=46d44pcDAodFXDYbrTCMRASISbDciXmA0CXYfhP2IaE,6298
42
42
  folio_migration_tools/migration_tasks/courses_migrator.py,sha256=CzXnsu-KGP7B4zcINJzLYUqz47D16NuFfzu_DPqRlTQ,7061
43
- folio_migration_tools/migration_tasks/holdings_csv_transformer.py,sha256=g3r4J1Y18vU18BjUmye7oSANR_TLTrP95la41flqj5M,22736
43
+ folio_migration_tools/migration_tasks/holdings_csv_transformer.py,sha256=kMhtHE8DJjA4d6kXBcfflueha3R3nwlBQjdec8CaY8c,21926
44
44
  folio_migration_tools/migration_tasks/holdings_marc_transformer.py,sha256=DVYdSNUPmdTv6GfLJdyT806dZV6UQHH_T8gkqtPgXaU,14143
45
45
  folio_migration_tools/migration_tasks/items_transformer.py,sha256=hkrllccEkKajp24BFSS85uiCpaEJinfkfvdjXGxNgCM,19223
46
46
  folio_migration_tools/migration_tasks/loans_migrator.py,sha256=CPsin9XLzHwNrpKHPMHAvgRvpoH8QvAfYZYr1FSxAN4,34520
@@ -60,8 +60,8 @@ folio_migration_tools/transaction_migration/legacy_request.py,sha256=1ulyFzPQw_I
60
60
  folio_migration_tools/transaction_migration/legacy_reserve.py,sha256=qzw0okg4axAE_ezXopP9gFsQ_e60o0zh7zqRzFBSWHY,1806
61
61
  folio_migration_tools/transaction_migration/transaction_result.py,sha256=cTdCN0BnlI9_ZJB2Z3Fdkl9gpymIi-9mGZsRFlQcmDk,656
62
62
  folio_migration_tools/translations/en.json,sha256=FeoaN3INfim4_-l3DSamHo2hn1SUJr5DsgDgsV4XUek,39693
63
- folio_migration_tools-1.9.1.dist-info/LICENSE,sha256=PhIEkitVi3ejgq56tt6sWoJIG_zmv82cjjd_aYPPGdI,1072
64
- folio_migration_tools-1.9.1.dist-info/METADATA,sha256=b-sCQR0tmU4tv_LJ2zTQUmgRWnsY4PB3c3Ivv-AAZWs,7444
65
- folio_migration_tools-1.9.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
66
- folio_migration_tools-1.9.1.dist-info/entry_points.txt,sha256=Hbe-HjqMcU8FwVshVIkeWyZd9XwgT1CCMNf06EpHQu8,77
67
- folio_migration_tools-1.9.1.dist-info/RECORD,,
63
+ folio_migration_tools-1.9.2.dist-info/LICENSE,sha256=PhIEkitVi3ejgq56tt6sWoJIG_zmv82cjjd_aYPPGdI,1072
64
+ folio_migration_tools-1.9.2.dist-info/METADATA,sha256=Cqu9bvuBBESPXOo3GoNF9GgijMciQSPtMPFnl94q4a4,7444
65
+ folio_migration_tools-1.9.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
66
+ folio_migration_tools-1.9.2.dist-info/entry_points.txt,sha256=Hbe-HjqMcU8FwVshVIkeWyZd9XwgT1CCMNf06EpHQu8,77
67
+ folio_migration_tools-1.9.2.dist-info/RECORD,,