Skip to content

Commit

Permalink
Make the mhld_display_struct in a format that Searchworks needs
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Sep 14, 2023
1 parent 401ff66 commit 4311df3
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 25 deletions.
10 changes: 6 additions & 4 deletions lib/folio/mhld_builder.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

module Folio
Mhld = Data.define(:library, :location, :public_note, :library_has, :latest)

class MhldBuilder
def self.build(holdings, holding_summaries, pieces)
new(holdings, holding_summaries, pieces).build
Expand All @@ -17,14 +15,18 @@ def initialize(holdings, holding_summaries, pieces)
attr_reader :holdings, :holding_summaries, :pieces

def build
filtered_holdings.flatten.map do |holding|
filtered_holdings.flatten.each_with_object({}) do |holding, result|
library, location = LocationsMap.for(holding.fetch(:location).fetch('code'))
public_note = holding.fetch(:note)
# The acquisitions department would rather not maintain library_has anymore anymore, as it's expensive for staff to keep it up to date.
# However, it seems like it's require for records like `a2149237` where there is no other way to display the volume 7 is not held.
library_has = holding.fetch(:library_has).presence
latest = latest_received(holding.fetch(:location).fetch('code'))
Mhld.new(library:, location:, public_note:, library_has:, latest:) if public_note || library_has || latest
next unless public_note || library_has || latest

result[library] ||= {}
result[library][location] ||= []
result[library][location] << { 'public_note' => public_note, 'library_has' => library_has, 'latest' => latest }.compact
end
end

Expand Down
10 changes: 8 additions & 2 deletions lib/traject/config/folio_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2330,11 +2330,17 @@ def accumulate_summary_struct_fields(matching_fields, tag, label, marc, accumula
to_field 'on_order_library_ssim', extract_marc('596a', translation_map: 'library_on_order_map')

to_field 'mhld_display' do |record, accumulator, _context|
record.mhld.each { |holding| accumulator << [holding.library, holding.location, holding.public_note, holding.library_has, holding.latest].join(' -|- ') }
record.mhld.each do |library, library_holdings|
library_holdings.each do |location, location_holdings|
location_holdings.each do |holding|
accumulator << [library, location, holding['public_note'], holding['library_has'], holding['latest']].join(' -|- ')
end
end
end
end

to_field 'mhld_display_struct' do |record, accumulator, _context|
record.mhld.each { |holding| accumulator << holding.to_h }
accumulator << record.mhld
end

to_field 'bookplates_display' do |record, accumulator|
Expand Down
63 changes: 54 additions & 9 deletions spec/lib/folio/mhld_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@
]
end

it { is_expected.to eq [Folio::Mhld.new(library: 'EARTH-SCI', location: 'STACKS', public_note: 'Library has latest 10 yrs. only.', library_has: 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-', latest: nil)] }
it {
is_expected.to eq({ 'EARTH-SCI' =>
{ 'STACKS' => [
{ 'public_note' => 'Library has latest 10 yrs. only.', 'library_has' => 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-' }
] } })
}

context 'with pieces having a MON YYYY cronology' do
let(:pieces) do
Expand Down Expand Up @@ -105,7 +110,12 @@
'receivedDate' => '2023-03-22T13:58:34.083+00:00' }]
end

it { is_expected.to eq [Folio::Mhld.new(library: 'EARTH-SCI', location: 'STACKS', public_note: 'Library has latest 10 yrs. only.', library_has: 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-', latest: 'v.243:no.10 (OCT 2023)')] }
it {
is_expected.to eq({ 'EARTH-SCI' =>
{ 'STACKS' => [
{ 'public_note' => 'Library has latest 10 yrs. only.', 'library_has' => 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-', 'latest' => 'v.243:no.10 (OCT 2023)' }
] } })
}
end

context 'with pieces having a (season) WIN YYYY cronology' do
Expand Down Expand Up @@ -143,7 +153,12 @@
'receivedDate' => '2023-03-22T13:58:34.083+00:00' }]
end

it { is_expected.to eq [Folio::Mhld.new(library: 'EARTH-SCI', location: 'STACKS', public_note: 'Library has latest 10 yrs. only.', library_has: 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-', latest: 'v.243:no.10 (OCT 2023)')] }
it {
is_expected.to eq({ 'EARTH-SCI' =>
{ 'STACKS' => [
{ 'public_note' => 'Library has latest 10 yrs. only.', 'library_has' => 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-', 'latest' => 'v.243:no.10 (OCT 2023)' }
] } })
}
end

context 'with pieces having a YYYY cronology' do
Expand Down Expand Up @@ -181,7 +196,12 @@
'receivedDate' => '2023-03-22T13:58:34.083+00:00' }]
end

it { is_expected.to eq [Folio::Mhld.new(library: 'EARTH-SCI', location: 'STACKS', public_note: 'Library has latest 10 yrs. only.', library_has: 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-', latest: 'v.244 (2023)')] }
it {
is_expected.to eq({ 'EARTH-SCI' =>
{ 'STACKS' => [
{ 'public_note' => 'Library has latest 10 yrs. only.', 'library_has' => 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-', 'latest' => 'v.244 (2023)' }
] } })
}
end

context 'when the order is one-time' do
Expand Down Expand Up @@ -213,7 +233,12 @@
'orderCloseReason' => nil }]
end

it { is_expected.to eq [Folio::Mhld.new(library: 'EARTH-SCI', location: 'STACKS', public_note: 'Library has latest 10 yrs. only.', library_has: 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-', latest: nil)] }
it {
is_expected.to eq({ 'EARTH-SCI' =>
{ 'STACKS' => [
{ 'public_note' => 'Library has latest 10 yrs. only.', 'library_has' => 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-' }
] } })
}
end

context 'when the order is closed' do
Expand Down Expand Up @@ -245,7 +270,12 @@
'orderCloseReason' => nil }]
end

it { is_expected.to eq [Folio::Mhld.new(library: 'EARTH-SCI', location: 'STACKS', public_note: 'Library has latest 10 yrs. only.', library_has: 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-', latest: nil)] }
it {
is_expected.to eq({ 'EARTH-SCI' =>
{ 'STACKS' => [
{ 'public_note' => 'Library has latest 10 yrs. only.', 'library_has' => 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-' }
] } })
}
end

context 'with unreceived pieces' do
Expand Down Expand Up @@ -283,7 +313,12 @@
'receivedDate' => '2023-03-22T13:58:34.083+00:00' }]
end

it { is_expected.to eq [Folio::Mhld.new(library: 'EARTH-SCI', location: 'STACKS', public_note: 'Library has latest 10 yrs. only.', library_has: 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-', latest: 'v.243:no.9 (SEP 2023)')] }
it {
is_expected.to eq({ 'EARTH-SCI' =>
{ 'STACKS' => [
{ 'public_note' => 'Library has latest 10 yrs. only.', 'library_has' => 'v.195(1999)-v.196(1999),v.201(2002),v.203(2003)-', 'latest' => 'v.243:no.9 (SEP 2023)' }
] } })
}
end
end

Expand Down Expand Up @@ -477,7 +512,12 @@
'displayOnHolding' => true }]
end

it { is_expected.to eq [Folio::Mhld.new(library: 'GREEN', location: 'CURRENTPER', public_note: 'Latest issues in CURRENT PERIODICALS; earlier issues in STACKS', library_has: '2018', latest: 'JUN 2022')] }
it {
is_expected.to eq({ 'GREEN' =>
{ 'CURRENTPER' => [
{ 'public_note' => 'Latest issues in CURRENT PERIODICALS; earlier issues in STACKS', 'library_has' => '2018', 'latest' => 'JUN 2022' }
] } })
}
end

context 'when pieces is present and has no enumeration or chronology' do
Expand Down Expand Up @@ -560,6 +600,11 @@
'displayOnHolding' => true }]
end

it { is_expected.to eq [Folio::Mhld.new(library: 'LAW', location: 'STACKS-1', public_note: 'Library has latest full year only', library_has: nil, latest: nil)] }
it {
is_expected.to eq({ 'LAW' =>
{ 'STACKS-1' => [
{ 'public_note' => 'Library has latest full year only' }
] } })
}
end
end
25 changes: 15 additions & 10 deletions spec/lib/traject/config/mhlds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,35 @@
let(:fixture_file) { 'a2499.json' }

it {
is_expected.to match_array([
hash_including('library' => 'MUSIC', 'location' => 'STACKS', 'library_has' => 'v.1'),
hash_including('library' => 'MUSIC', 'location' => 'STACKS', 'library_has' => 'v.2')
])
is_expected.to eq([{ 'MUSIC' =>
{ 'STACKS' => [
{ 'library_has' => 'v.1' },
{ 'library_has' => 'v.2' }
] } }])
}
end

context 'for a9012' do
let(:fixture_file) { 'a9012.json' }

it {
is_expected.to match_array([
hash_including('library' => 'SAL3', 'location' => 'STACKS', 'library_has' => '1948,1965-1967,1974-1975')
])
is_expected.to eq([{ 'SAL3' => {
'STACKS' => [
{ 'library_has' => '1948,1965-1967,1974-1975' }
]
} }])
}
end

context 'for a1572' do
let(:fixture_file) { 'a1572.json' }

it {
is_expected.to match_array([
hash_including('library' => 'SAL3', 'location' => 'STACKS', 'library_has' => 'Heft 1-2 <v.568-569 in series>')
])
is_expected.to eq([{ 'SAL3' => {
'STACKS' => [
{ 'library_has' => 'Heft 1-2 <v.568-569 in series>' }
]
} }])
}
end

Expand Down

0 comments on commit 4311df3

Please sign in to comment.