Skip to content

Commit

Permalink
Merge pull request #1027 from sul-dlss/637-fix-items
Browse files Browse the repository at this point in the history
Skip adding 999s for holdings and items that are discoverySuppress-ed
  • Loading branch information
jgreben authored May 28, 2024
2 parents e293299 + bb32cf9 commit 308122e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
40 changes: 25 additions & 15 deletions libsys_airflow/plugins/data_exports/marc/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ def add_holdings_items_fields(self, instance_subfields: list) -> list:

for holding_tuple in holdings_result:
holding = holding_tuple[0]
if len(holding.get("discoverySuppress", "")) > 0:
if bool(holding["discoverySuppress"]):
continue

field_999 = self.add_holdings_subfields(holding)

holding_id = holding["id"]
Expand All @@ -139,22 +143,30 @@ def add_holdings_items_fields(self, instance_subfields: list) -> list:
sql=f"select jsonb from sul_mod_inventory_storage.item where holdingsrecordid = '{holding_id}'",
).execute(get_current_context())

match len(items_result):
active_items = []
for _item in items_result:
try:
if not bool(_item[0]["discoverySuppress"]):
active_items.append(_item)
except KeyError:
active_items.append(_item)

match len(active_items):
case 0:
if len(field_999.subfields) > 0:
fields.append(field_999)

case 1:
self.add_item_subfields(field_999, items_result[0][0])
self.add_item_subfields(field_999, active_items[0][0])
if len(field_999.subfields) > 0:
fields.append(field_999)

case _:
org_999 = copy.deepcopy(field_999)
self.add_item_subfields(field_999, items_result[0][0])
self.add_item_subfields(field_999, active_items[0][0])
if len(field_999.subfields) > 0:
fields.append(field_999)
for item_tuple in items_result[1:]:
for item_tuple in active_items[1:]:
item = item_tuple[0]
new_999 = copy.deepcopy(org_999)
self.add_item_subfields(new_999, item)
Expand All @@ -166,24 +178,22 @@ def add_holdings_items_fields(self, instance_subfields: list) -> list:

return fields

def add_holdings_subfields(self, holdings: dict) -> pymarc.Field:
def add_holdings_subfields(self, holding: dict) -> pymarc.Field:
field_999 = pymarc.Field(tag="999", indicators=[' ', ' '])
if len(holdings.get("holdingsTypeId", "")) > 0:
holdings_type_name = self.holdings_type.get(holdings["holdingsTypeId"])
if len(holding.get("holdingsTypeId", "")) > 0:
holdings_type_name = self.holdings_type.get(holding["holdingsTypeId"])
if holdings_type_name:
field_999.add_subfield('h', holdings_type_name)
if len(holdings.get("permanentLocationId", "")) > 0:
permanent_location_code = self.locations.get(
holdings['permanentLocationId']
)
if len(holding.get("permanentLocationId", "")) > 0:
permanent_location_code = self.locations.get(holding['permanentLocationId'])
if permanent_location_code:
field_999.add_subfield('l', permanent_location_code)
if len(holdings.get("callNumberTypeId", "")) > 0:
call_number_type = self.call_numbers.get(holdings['callNumberTypeId'])
if len(holding.get("callNumberTypeId", "")) > 0:
call_number_type = self.call_numbers.get(holding['callNumberTypeId'])
if call_number_type:
field_999.add_subfield('w', call_number_type)
if len(holdings.get("callNumber", "")) > 0:
field_999.add_subfield('a', holdings['callNumber'], 0)
if len(holding.get("callNumber", "")) > 0:
field_999.add_subfield('a', holding['callNumber'], 0)
return field_999

def add_item_subfields(self, field_999: pymarc.Field, item: dict):
Expand Down
20 changes: 20 additions & 0 deletions tests/data_exports/test_marc_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ def execute(self, context):
'permanentLocationId': 'b0a1a8c3-cc9a-487c-a2ed-308fc3a49a91',
},
),
(
{
'id': '9d69696b-b84e-4caa-bcdc-d517a8e242d9',
'instanceId': 'c77d294c-4d83-4fe0-87b1-f94a845c0d49',
'holdingsTypeId': '996f93e2-5b5e-4cf2-9168-33ced1f95eed',
'callNumberTypeId': '054d460d-d6b9-4469-9e37-7a78a2266655',
'callNumber': "QA 124378 C 2",
'permanentLocationId': 'b0a1a8c3-cc9a-487c-a2ed-308fc3a49a91',
'discoverySuppress': 'true',
},
),
]


Expand All @@ -69,6 +80,15 @@ def execute(self, context):
'effectiveLocationId': 'b0a1a8c3-cc9a-487c-a2ed-308fc3a49a91',
},
),
(
{
'id': '94d81a9d-a9bb-4f2c-b5d7-e574f811f6bd',
'materialTypeId': 'd934e614-215d-4667-b231-aed97887f289',
'enumeration': 'eV.18 1993',
'effectiveLocationId': 'b0a1a8c3-cc9a-487c-a2ed-308fc3a49a91',
'discoverySuppress': 'true',
},
),
]

single_holdings = [
Expand Down

0 comments on commit 308122e

Please sign in to comment.