Skip to content

Commit

Permalink
Move library lookup from oclc class to transformer class for general use
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed May 17, 2024
1 parent 0e0ced7 commit 959c5d5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
13 changes: 0 additions & 13 deletions libsys_airflow/plugins/data_exports/marc/oclc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def get_record_id(record: pymarc.Record) -> list:
class OCLCTransformer(Transformer):
def __init__(self):
super().__init__()
self.library_lookup = self.locations_by_library_lookup()
self.libraries = {}
for code in ["CASUM", "HIN", "RCJ", "S7Z", "STF"]:
self.libraries[code] = {"holdings": [], "marc": []}
Expand Down Expand Up @@ -142,18 +141,6 @@ def multiple_codes(self, record: pymarc.Record, code: str, record_ids: list):
instance_id = record['999']['i']
self.staff_notices.append((instance_id, code, record_ids))

def locations_by_library_lookup(self) -> dict:
lookup = {}
libraries_result = self.folio_client.folio_get(
"/location-units/libraries?limit=1000"
)
libraries_lookup = {}
for library in libraries_result.get("loclibs"):
libraries_lookup[library['id']] = library["code"]
for location in self.folio_client.locations:
lookup[location['id']] = libraries_lookup.get(location['libraryId'])
return lookup

def save(self):
"""
Saves existing holdings and marc records to file system
Expand Down
13 changes: 13 additions & 0 deletions libsys_airflow/plugins/data_exports/marc/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self):
self.holdings_type = self.holdings_type_lookup()
self.locations = self.locations_lookup()
self.materialtypes = self.materialtype_lookup()
self.library_lookup = self.locations_by_library_lookup()

def call_number_lookup(self) -> dict:
lookup = {}
Expand Down Expand Up @@ -47,6 +48,18 @@ def materialtype_lookup(self) -> dict:
lookup[m['id']] = m['name']
return lookup

def locations_by_library_lookup(self) -> dict:
lookup = {}
libraries_result = self.folio_client.folio_get(
"/location-units/libraries?limit=1000"
)
libraries_lookup = {}
for library in libraries_result.get("loclibs"):
libraries_lookup[library['id']] = library["code"]
for location in self.folio_client.locations:
lookup[location['id']] = libraries_lookup.get(location['libraryId'])
return lookup

def add_holdings_items(self, marc_file: str, full_dump: bool):
"""
Adds FOLIO Holdings and Items information to MARC records
Expand Down
5 changes: 4 additions & 1 deletion tests/data_exports/test_gobi_exports_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def record(**kwargs):
folio_result = {
"mtypes": [
{"id": "1a54b431-2e4f-452d-9cae-9cee66c9a892", "name": "book"},
]
],
"loclibs": [
{"id": "f6b5519e-88d9-413e-924d-9ed96255f72e", "code": "GREEN"},
],
}


Expand Down
14 changes: 11 additions & 3 deletions tests/data_exports/test_marc_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,26 @@ def mock_folio_client():
'libraryId': 'c1a86906-ced0-46cb-8f5b-8cef542bdd00',
},
]
mock_material_types = {
mock_lookups = {
"mtypes": [
{"id": "d934e614-215d-4667-b231-aed97887f289", "name": "periodical"},
{"id": "1a54b431-2e4f-452d-9cae-9cee66c9a892", "name": "book"},
]
],
"loclibs": [
{"id": 'f5c58187-3db6-4bda-b1bf-e5f0717e2149', "code": 'BUSINESS'},
{"id": "f6b5519e-88d9-413e-924d-9ed96255f72e", "code": "GREEN"},
{"id": "ffe6ea8e-1e14-482f-b3e9-66e05efb04dd", "code": "HILA"},
{"id": "5b2c8449-eed6-4bd3-bcef-af1e5a225400", "code": "LANE"},
{"id": "7e4c05e3-1ce6-427d-b9ce-03464245cd78", "code": "LAW"},
{"id": 'c1a86906-ced0-46cb-8f5b-8cef542bdd00', "code": 'SUL'},
],
}

mock_client = MagicMock()
mock_client.call_number_types = mock_call_number_types
mock_client.holdings_types = mock_holdings_types
mock_client.locations = mock_locations
mock_client.folio_get = lambda *args: mock_material_types
mock_client.folio_get = lambda *args: mock_lookups
return mock_client


Expand Down

0 comments on commit 959c5d5

Please sign in to comment.