Skip to content

Commit

Permalink
Merge pull request #998 from sul-dlss/997-temp-loc
Browse files Browse the repository at this point in the history
Use the item temporary location for the current location
  • Loading branch information
jcoyne authored Jul 24, 2023
2 parents d268d43 + 0faa2d1 commit a185ba7
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/folio_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ def sirsi_holdings
@sirsi_holdings ||= items.map do |item|
holding = holdings.find { |holding| holding['id'] == item['holdingsRecordId'] }
item_location_code = item.dig('location', 'permanentLocation', 'code')
item_location_code ||= holding.dig('location', 'permanentLocation', 'code')
item_location_code ||= holding.dig('location', 'effectiveLocation', 'code')
next if item_location_code&.end_with? 'MIGRATE-ERR'

library_code, home_location_code = LocationsMap.for(item_location_code)
_current_library, current_location = LocationsMap.for(item.dig('location', 'location', 'code'))
_current_library, current_location = LocationsMap.for(item.dig('location', 'temporaryLocation', 'code'))
current_location ||= folio_status_to_location(item['status'])

SirsiHolding.new(
Expand All @@ -107,9 +107,12 @@ def sirsi_holdings
def bound_with_holdings
@bound_with_holdings ||= holdings.select { |holding| holding['boundWith'].present? }.map do |holding|
parent_item = holding.dig('boundWith', 'item')
parent_item_perm_location = parent_item.dig('location', 'permanentLocation', 'code')
library_code, home_location_code = LocationsMap.for(parent_item_perm_location)
_current_library, current_location = LocationsMap.for(parent_item.dig('location', 'effectiveLocation', 'code'))
parent_holding = holding.dig('boundWith', 'holding')
item_location_code = parent_item.dig('location', 'permanentLocation', 'code')
item_location_code ||= parent_holding.dig('location', 'effectiveLocation', 'code')

library_code, home_location_code = LocationsMap.for(item_location_code)
_current_library, current_location = LocationsMap.for(parent_item.dig('location', 'temporaryLocation', 'code'))
current_location ||= folio_status_to_location(parent_item['status'])
SirsiHolding.new(
call_number: holding['callNumber'],
Expand Down
11 changes: 11 additions & 0 deletions lib/traject/readers/folio_postgres_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ def sql_query(conditions, addl_from: nil)
'hrid', parentInstance.jsonb ->> 'hrid',
'title', parentInstance.jsonb ->> 'title'
),
'holding', jsonb_build_object(
'location', jsonb_build_object('effectiveLocation',
parentHoldingEffLoc.locJsonb || jsonb_build_object(
'campus', parentHoldingEffLoc.locCampJsonb,
'library', parentHoldingEffLoc.locLibJsonb,
'institution', parentHoldingEffLoc.locInstJsonb)
)
),
'item', jsonb_build_object(
'id', parentItem.id,
'hrid', parentItem.jsonb ->> 'hrid',
Expand Down Expand Up @@ -354,6 +362,9 @@ def sql_query(conditions, addl_from: nil)
-- BW Parent Item's Temporary location relation
LEFT JOIN viewLocations parentItemTempLoc
ON parentItem.temporarylocationid = parentItemTempLoc.locId
-- BW Parent Item's Effective location relation
LEFT JOIN viewLocations parentHoldingEffLoc
ON parentHolding.effectivelocationid = parentHoldingEffLoc.locId
#{addl_from}
WHERE #{conditions.join(' AND ')}
GROUP BY vi.id
Expand Down
164 changes: 164 additions & 0 deletions spec/lib/folio_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,170 @@
end

describe '#sirsi_holdings' do
context 'with an item with a temporary location' do
let(:record) do
{
'instance' => {
'id' => '0e050e3f-b160-5f5d-9fdb-2d49305fbb0d'
},
'pieces' => [{ 'id' => '3b0c1675-b3ec-4bc4-888d-2519fb72b71f',
'holdingId' => '1146c4fa-5798-40e1-9b8e-92ee4c9f2ee2',
'receivingStatus' => 'Expected',
'displayOnHolding' => false }],
'holdings' => [{
'id' => '1146c4fa-5798-40e1-9b8e-92ee4c9f2ee2',
'location' => {
'effectiveLocation' => {
'code' => 'GRE-STACKS'
}
}
}],
'items' => [{
'holdingsRecordId' => '1146c4fa-5798-40e1-9b8e-92ee4c9f2ee2',
'location' => {
'temporaryLocation' => {
'code' => 'GRE-CRES'
}
}
}],
'source_record' => [{
'fields' => [
{ '001' => 'a14154194' }
]
}]
}
end

it 'uses the temp location as the current location' do
expect(folio_record.sirsi_holdings.first).to have_attributes(
current_location: 'GRE-CRES',
home_location: 'STACKS',
library: 'GREEN'
)
end
end

context 'with an item with a permanent location' do
let(:record) do
{
'instance' => {
'id' => '0e050e3f-b160-5f5d-9fdb-2d49305fbb0d'
},
'pieces' => [{ 'id' => '3b0c1675-b3ec-4bc4-888d-2519fb72b71f',
'holdingId' => '1146c4fa-5798-40e1-9b8e-92ee4c9f2ee2',
'receivingStatus' => 'Expected',
'displayOnHolding' => false }],
'holdings' => [{
'id' => '1146c4fa-5798-40e1-9b8e-92ee4c9f2ee2',
'location' => {
'effectiveLocation' => {
'code' => 'GRE-STACKS'
}
}
}],
'items' => [{
'holdingsRecordId' => '1146c4fa-5798-40e1-9b8e-92ee4c9f2ee2',
'location' => {
'permanentLocation' => {
'code' => 'GRE-HH-MAGAZINE'
}
}
}],
'source_record' => [{
'fields' => [
{ '001' => 'a14154194' }
]
}]
}
end

it 'uses the permanent location of the item as the home location' do
expect(folio_record.sirsi_holdings.first).to have_attributes(
current_location: nil,
home_location: 'MAGAZINE',
library: 'GREEN'
)
end
end

context 'with an item without a permanent location' do
let(:record) do
{
'instance' => {
'id' => '0e050e3f-b160-5f5d-9fdb-2d49305fbb0d'
},
'pieces' => [{ 'id' => '3b0c1675-b3ec-4bc4-888d-2519fb72b71f',
'holdingId' => '1146c4fa-5798-40e1-9b8e-92ee4c9f2ee2',
'receivingStatus' => 'Expected',
'displayOnHolding' => false }],
'holdings' => [{
'id' => '1146c4fa-5798-40e1-9b8e-92ee4c9f2ee2',
'location' => {
'effectiveLocation' => {
'code' => 'GRE-STACKS'
}
}
}],
'items' => [{
'holdingsRecordId' => '1146c4fa-5798-40e1-9b8e-92ee4c9f2ee2',
'location' => {}
}],
'source_record' => [{
'fields' => [
{ '001' => 'a14154194' }
]
}]
}
end

it 'uses the effective location of the holding as the home location' do
expect(folio_record.sirsi_holdings.first).to have_attributes(
current_location: nil,
home_location: 'STACKS',
library: 'GREEN'
)
end
end

context 'with an item without a temporary location' do
let(:record) do
{
'instance' => {
'id' => '0e050e3f-b160-5f5d-9fdb-2d49305fbb0d'
},
'pieces' => [{ 'id' => '3b0c1675-b3ec-4bc4-888d-2519fb72b71f',
'holdingId' => '1146c4fa-5798-40e1-9b8e-92ee4c9f2ee2',
'receivingStatus' => 'Expected',
'displayOnHolding' => false }],
'holdings' => [{
'id' => '1146c4fa-5798-40e1-9b8e-92ee4c9f2ee2',
'location' => {
'effectiveLocation' => {
'code' => 'GRE-STACKS'
}
}
}],
'items' => [{
'holdingsRecordId' => '1146c4fa-5798-40e1-9b8e-92ee4c9f2ee2',
'status' => 'In process',
'location' => {}
}],
'source_record' => [{
'fields' => [
{ '001' => 'a14154194' }
]
}]
}
end

it 'uses the item status of the holding as the current location' do
expect(folio_record.sirsi_holdings.first).to have_attributes(
current_location: 'INPROCESS',
home_location: 'STACKS',
library: 'GREEN'
)
end
end
context 'with Symphony migrated data without on-order item records' do
let(:record) do
{
Expand Down

0 comments on commit a185ba7

Please sign in to comment.