Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "folio_data_import"
version = "0.5.1"
version = "0.5.2"
description = "A python module to perform bulk import of data into a FOLIO environment. Currently supports MARC and user data import."
authors = [{ name = "Brooks Travis", email = "brooks.travis@gmail.com" }]
license = "MIT"
Expand Down
10 changes: 10 additions & 0 deletions src/folio_data_import/BatchPoster.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ async def __aenter__(self):
self._failed_records_path, "w", encoding="utf-8"
)
logger.info(f"Opened failed records file: {self._failed_records_path}")
if (
not hasattr(self.folio_client, "async_httpx_client")
or self.folio_client.async_httpx_client is None
):
self.folio_client.async_httpx_client = self.folio_client.get_folio_http_client_async()
return self

async def __aexit__(self, exc_type, exc_val, exc_tb):
Expand All @@ -344,6 +349,11 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
f"to {self._failed_records_path}"
)
self._failed_records_file_handle = None
if (
hasattr(self.folio_client, "async_httpx_client")
and not self.folio_client.async_httpx_client.is_closed
):
await self.folio_client.async_httpx_client.aclose()

def _write_failed_record(self, record: dict) -> None:
"""
Expand Down
22 changes: 11 additions & 11 deletions src/folio_data_import/UserImport.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ async def do_import(self) -> None:
This method triggers the process of importing users by calling the `process_file` method.
Supports both single file path and list of file paths.
"""
async with httpx.AsyncClient() as client:
async with self.folio_client.get_folio_http_client_async() as client:
self.http_client = client
if not self.config.user_file_paths:
raise FileNotFoundError("No user objects file provided")
Expand Down Expand Up @@ -274,7 +274,7 @@ async def get_existing_user(self, user_obj) -> dict:
match_key = "id" if ("id" in user_obj) else self.config.user_match_key
try:
existing_user = await self.http_client.get(
self.folio_client.gateway_url + "/users",
"/users",
headers=self.folio_client.okapi_headers,
params={"query": f"{match_key}=={user_obj[match_key]}"},
)
Expand All @@ -298,7 +298,7 @@ async def get_existing_rp(self, user_obj, existing_user) -> dict:
"""
try:
existing_rp = await self.http_client.get(
self.folio_client.gateway_url + "/request-preference-storage/request-preference",
"/request-preference-storage/request-preference",
headers=self.folio_client.okapi_headers,
params={"query": f"userId=={existing_user.get('id', user_obj.get('id', ''))}"},
)
Expand All @@ -322,7 +322,7 @@ async def get_existing_pu(self, user_obj, existing_user) -> dict:
"""
try:
existing_pu = await self.http_client.get(
self.folio_client.gateway_url + "/perms/users",
"/perms/users",
headers=self.folio_client.okapi_headers,
params={"query": f"userId=={existing_user.get('id', user_obj.get('id', ''))}"},
)
Expand Down Expand Up @@ -489,7 +489,7 @@ async def update_existing_user(
else:
existing_user[key] = value
create_update_user = await self.http_client.put(
self.folio_client.gateway_url + f"/users/{existing_user['id']}",
f"/users/{existing_user['id']}",
headers=self.folio_client.okapi_headers,
json=existing_user,
)
Expand All @@ -509,7 +509,7 @@ async def create_new_user(self, user_obj) -> dict:
HTTPError: If the HTTP request to create the user fails.
"""
response = await self.http_client.post(
self.folio_client.gateway_url + "/users",
"/users",
headers=self.folio_client.okapi_headers,
json=user_obj,
)
Expand Down Expand Up @@ -719,7 +719,7 @@ async def create_new_rp(self, new_user_obj):
rp_obj = {"holdShelf": True, "delivery": False}
rp_obj["userId"] = new_user_obj["id"]
response = await self.http_client.post(
self.folio_client.gateway_url + "/request-preference-storage/request-preference",
"/request-preference-storage/request-preference",
headers=self.folio_client.okapi_headers,
json=rp_obj,
)
Expand Down Expand Up @@ -763,7 +763,7 @@ async def create_perms_user(self, new_user_obj) -> None:
"""
perms_user_obj = {"userId": new_user_obj["id"], "permissions": []}
response = await self.http_client.post(
self.folio_client.gateway_url + "/perms/users",
"/perms/users",
headers=self.folio_client.okapi_headers,
json=perms_user_obj,
)
Expand Down Expand Up @@ -910,7 +910,7 @@ async def get_existing_spu(self, existing_user):
"""
try:
existing_spu = await self.http_client.get(
self.folio_client.gateway_url + "/service-points-users",
"/service-points-users",
headers=self.folio_client.okapi_headers,
params={"query": f"userId=={existing_user['id']}"},
)
Expand All @@ -934,7 +934,7 @@ async def create_new_spu(self, spu_obj, existing_user):
"""
spu_obj["userId"] = existing_user["id"]
response = await self.http_client.post(
self.folio_client.gateway_url + "/service-points-users",
"/service-points-users",
headers=self.folio_client.okapi_headers,
json=spu_obj,
)
Expand All @@ -953,7 +953,7 @@ async def update_existing_spu(self, spu_obj, existing_spu):
""" # noqa: E501
existing_spu.update(spu_obj)
response = await self.http_client.put(
self.folio_client.gateway_url + f"/service-points-users/{existing_spu['id']}",
f"/service-points-users/{existing_spu['id']}",
headers=self.folio_client.okapi_headers,
json=existing_spu,
)
Expand Down