Skip to content

Commit

Permalink
Queries for HRID settings for Instances and attempts to save back to …
Browse files Browse the repository at this point in the history
…FOLIO
  • Loading branch information
jermnelson committed Dec 6, 2023
1 parent d426c38 commit 3bca2a5
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion ils_middleware/tasks/folio/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import datetime
import logging

import requests

from folio_uuid import FOLIONamespaces, FolioUUID
from folioclient.FolioClient import FolioClient

Expand Down Expand Up @@ -117,6 +119,28 @@ def _instance_type_id(**kwargs) -> tuple:
raise ValueError(f"instanceTypeId for {name} not found")
return "instanceTypeId", ident

def _folio_hrid(folio_client: FolioClient) -> str:
"""Queries for instance hrid, increments, and saves back to folio"""
endpoint = "/hrid-settings-storage/hrid-settings"
hrid_settings = folio_client.folio_get_single_object(endpoint)
instance_count = hrid_settings['instances']['startNumber']
new_instance_count = instance_count + 1
if hrid_settings['commonRetainLeadingZeroes']:
number = str(new_instance_count).zfill(11)
else:
number = new_instance_count
instance_hrid = f"{hrid_settings['instances']['prefix']}{number}"
hrid_settings['instances']['startNumber'] = new_instance_count

# Puts new instance startNumber back into FOLIO
hrid_put_result = requests.put(f"{folio_client.okapi_url}{endpoint}",
headers=folio_client.okapi_headers)
hrid_put_result.raise_for_status()

return instance_hrid




def _language(**kwargs) -> tuple:
values = kwargs["values"]
Expand Down Expand Up @@ -266,7 +290,7 @@ def _inventory_record(**kwargs) -> dict:

record = {
"id": _folio_id(instance_uri, okapi_url),
"hrid": instance_uri,
"hrid": _folio_hrid(folio_client),
"metadata": _create_update_metadata(**kwargs),
"source": "SINOPIA",
}
Expand Down

0 comments on commit 3bca2a5

Please sign in to comment.