folio-data-import 0.2.7__py3-none-any.whl → 0.2.8rc2__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.

Potentially problematic release.


This version of folio-data-import might be problematic. Click here for more details.

@@ -5,6 +5,7 @@ import getpass
5
5
  import json
6
6
  import os
7
7
  import time
8
+ import uuid
8
9
  from datetime import datetime as dt
9
10
  from pathlib import Path
10
11
  from typing import Tuple
@@ -94,6 +95,23 @@ class UserImporter: # noqa: R0902
94
95
  """
95
96
  return {x[name]: x["id"] for x in folio_client.folio_get_all(endpoint, key)}
96
97
 
98
+ @staticmethod
99
+ def validate_uuid(uuid_string: str) -> bool:
100
+ """
101
+ Validate a UUID string.
102
+
103
+ Args:
104
+ uuid_string (str): The UUID string to validate.
105
+
106
+ Returns:
107
+ bool: True if the UUID is valid, otherwise False.
108
+ """
109
+ try:
110
+ uuid.UUID(uuid_string)
111
+ return True
112
+ except ValueError:
113
+ return False
114
+
97
115
  async def do_import(self) -> None:
98
116
  """
99
117
  Main method to import users.
@@ -203,10 +221,20 @@ class UserImporter: # noqa: R0902
203
221
  mapped_addresses = []
204
222
  for address in addresses:
205
223
  try:
206
- address["addressTypeId"] = self.address_type_map[
207
- address["addressTypeId"]
208
- ]
209
- mapped_addresses.append(address)
224
+ if (
225
+ self.validate_uuid(address["addressTypeId"])
226
+ and address["addressTypeId"] in self.address_type_map.values()
227
+ ):
228
+ await self.logfile.write(
229
+ f"Row {line_number}: Address type {address['addressTypeId']} is a UUID, "
230
+ f"skipping mapping\n"
231
+ )
232
+ mapped_addresses.append(address)
233
+ else:
234
+ address["addressTypeId"] = self.address_type_map[
235
+ address["addressTypeId"]
236
+ ]
237
+ mapped_addresses.append(address)
210
238
  except KeyError:
211
239
  if address["addressTypeId"] not in self.address_type_map.values():
212
240
  print(
@@ -232,7 +260,16 @@ class UserImporter: # noqa: R0902
232
260
  None
233
261
  """
234
262
  try:
235
- user_obj["patronGroup"] = self.patron_group_map[user_obj["patronGroup"]]
263
+ if (
264
+ self.validate_uuid(user_obj["patronGroup"])
265
+ and user_obj["patronGroup"] in self.patron_group_map.values()
266
+ ):
267
+ await self.logfile.write(
268
+ f"Row {line_number}: Patron group {user_obj['patronGroup']} is a UUID, "
269
+ f"skipping mapping\n"
270
+ )
271
+ else:
272
+ user_obj["patronGroup"] = self.patron_group_map[user_obj["patronGroup"]]
236
273
  except KeyError:
237
274
  if user_obj["patronGroup"] not in self.patron_group_map.values():
238
275
  print(
@@ -259,7 +296,16 @@ class UserImporter: # noqa: R0902
259
296
  mapped_departments = []
260
297
  for department in user_obj.pop("departments", []):
261
298
  try:
262
- mapped_departments.append(self.department_map[department])
299
+ if (
300
+ self.validate_uuid(department)
301
+ and department in self.department_map.values()
302
+ ):
303
+ await self.logfile.write(
304
+ f"Row {line_number}: Department {department} is a UUID, skipping mapping\n"
305
+ )
306
+ mapped_departments.append(department)
307
+ else:
308
+ mapped_departments.append(self.department_map[department])
263
309
  except KeyError:
264
310
  print(
265
311
  f'Row {line_number}: Department "{department}" not found, ' # noqa: B907
@@ -493,7 +539,7 @@ class UserImporter: # noqa: R0902
493
539
  and the existing PU object (existing_pu).
494
540
  """
495
541
  rp_obj = user_obj.pop("requestPreference", {})
496
- spu_obj = user_obj.pop("servicePointsUser")
542
+ spu_obj = user_obj.pop("servicePointsUser", {})
497
543
  existing_user = await self.get_existing_user(user_obj)
498
544
  if existing_user:
499
545
  existing_rp = await self.get_existing_rp(user_obj, existing_user)
@@ -677,7 +723,13 @@ class UserImporter: # noqa: R0902
677
723
  mapped_service_points = []
678
724
  for sp in spu_obj.pop("servicePointsIds", []):
679
725
  try:
680
- mapped_service_points.append(self.service_point_map[sp])
726
+ if self.validate_uuid(sp) and sp in self.service_point_map.values():
727
+ await self.logfile.write(
728
+ f"Service point {sp} is a UUID, skipping mapping\n"
729
+ )
730
+ mapped_service_points.append(sp)
731
+ else:
732
+ mapped_service_points.append(self.service_point_map[sp])
681
733
  except KeyError:
682
734
  print(
683
735
  f'Service point "{sp}" not found, excluding service point from user: '
@@ -688,7 +740,13 @@ class UserImporter: # noqa: R0902
688
740
  if "defaultServicePointId" in spu_obj:
689
741
  sp_code = spu_obj.pop('defaultServicePointId', '')
690
742
  try:
691
- mapped_sp_id = self.service_point_map[sp_code]
743
+ if self.validate_uuid(sp_code) and sp_code in self.service_point_map.values():
744
+ await self.logfile.write(
745
+ f"Default service point {sp_code} is a UUID, skipping mapping\n"
746
+ )
747
+ mapped_sp_id = sp_code
748
+ else:
749
+ mapped_sp_id = self.service_point_map[sp_code]
692
750
  if mapped_sp_id not in spu_obj.get('servicePointsIds', []):
693
751
  print(
694
752
  f'Default service point "{sp_code}" not found in assigned service points, '
@@ -711,7 +769,7 @@ class UserImporter: # noqa: R0902
711
769
  existing_spu (dict): The existing service-points-user object, if it exists.
712
770
  existing_user (dict): The existing user object associated with the spu_obj.
713
771
  """
714
- if spu_obj is not None:
772
+ if spu_obj:
715
773
  await self.map_service_points(spu_obj, existing_user)
716
774
  if existing_spu:
717
775
  await self.update_existing_spu(spu_obj, existing_spu)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: folio_data_import
3
- Version: 0.2.7
3
+ Version: 0.2.8rc2
4
4
  Summary: A python module to interact with the data importing capabilities of the open-source FOLIO ILS
5
5
  License: MIT
6
6
  Author: Brooks Travis
@@ -0,0 +1,11 @@
1
+ folio_data_import/MARCDataImport.py,sha256=gFBq6DwghC3hXPkkM-c0XlPjtoZwITVAeEhH8joPIQo,23450
2
+ folio_data_import/UserImport.py,sha256=Y9ZjYoUP_vNJVftx_xUcbBqvC5CwWeuzlmCcSVQfzgo,40976
3
+ folio_data_import/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ folio_data_import/__main__.py,sha256=kav_uUsnrIjGjVxQkk3exLKrc1mah9t2x3G6bGS-5I0,3710
5
+ folio_data_import/marc_preprocessors/__init__.py,sha256=Wt-TKkMhUyZWFS-WhAmbShKQLPjXmHKPb2vL6kvkqVA,72
6
+ folio_data_import/marc_preprocessors/_preprocessors.py,sha256=srx36pgY0cwl6_0z6CVOyM_Uzr_g2RObo1jJJjSEZJs,944
7
+ folio_data_import-0.2.8rc2.dist-info/LICENSE,sha256=qJX7wxMC7ky9Kq4v3zij8MjGEiC5wsB7pYeOhLj5TDk,1083
8
+ folio_data_import-0.2.8rc2.dist-info/METADATA,sha256=KJHfmLLY-_U7EhZwxgtsTCRwpkIBUai7vyxwIQVmWP8,6115
9
+ folio_data_import-0.2.8rc2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
10
+ folio_data_import-0.2.8rc2.dist-info/entry_points.txt,sha256=498SxWVXeEMRNw3PUf-eoReZvKewmYwPBtZhIUPr_Jg,192
11
+ folio_data_import-0.2.8rc2.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- folio_data_import/MARCDataImport.py,sha256=gFBq6DwghC3hXPkkM-c0XlPjtoZwITVAeEhH8joPIQo,23450
2
- folio_data_import/UserImport.py,sha256=DPZz6yG2SGWlDvOthohjybOVs7_r494mtNOwv6q66m0,38588
3
- folio_data_import/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- folio_data_import/__main__.py,sha256=kav_uUsnrIjGjVxQkk3exLKrc1mah9t2x3G6bGS-5I0,3710
5
- folio_data_import/marc_preprocessors/__init__.py,sha256=Wt-TKkMhUyZWFS-WhAmbShKQLPjXmHKPb2vL6kvkqVA,72
6
- folio_data_import/marc_preprocessors/_preprocessors.py,sha256=srx36pgY0cwl6_0z6CVOyM_Uzr_g2RObo1jJJjSEZJs,944
7
- folio_data_import-0.2.7.dist-info/LICENSE,sha256=qJX7wxMC7ky9Kq4v3zij8MjGEiC5wsB7pYeOhLj5TDk,1083
8
- folio_data_import-0.2.7.dist-info/METADATA,sha256=YR-xCFmHuQvwIpMGZu4VC_VVlUd2US2m7ANJ6GGvto8,6112
9
- folio_data_import-0.2.7.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
10
- folio_data_import-0.2.7.dist-info/entry_points.txt,sha256=498SxWVXeEMRNw3PUf-eoReZvKewmYwPBtZhIUPr_Jg,192
11
- folio_data_import-0.2.7.dist-info/RECORD,,