Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 5 additions & 44 deletions marc_to_solr/lib/electronic_portfolio_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,31 @@
class ElectronicPortfolioBuilder
# Build electronic portfolio JSON from marc fields
# @param field [MARC::DataField] data from 951 field
# @param date [MARC::DataField] date range data from 953 field
# @param embargo [MARC::DataField] embargo data from 954 field

# @return [String] JSON string
def self.build(field:, date:, embargo:)
new(field:, date:, embargo:).build
def self.build(field:)
new(field:).build
end

attr_reader :embargo, :field, :date
attr_reader :field

# Constructor
# @param field [MARC::DataField] data from 951 field
# @param date [MARC::DataField] date range data from 953 field
# @param embargo [MARC::DataField] embargo data from 954 field
def initialize(field:, date:, embargo:)
def initialize(field:)
@field = field
@date = date
@embargo = embargo
end

def build
{
desc: field['k'],
title: portfolio_title,
url: field['x'],
start: start_date,
end: end_date,
notes: public_notes
}.to_json
end

private

# Formulas for start and end dates come from Alma
# documentation on the embargo operator:
# <= Most recent X year(s) available
# >= Most recent X year(s) not available
# < Most recent X year(s)-1 available
# > Most recent X year(s)+1 not available
def start_date
if embargo && (embargo['b'] == '<=')
(DateTime.now.year - embargo['c'].to_i).to_s
elsif embargo && embargo['b'] == '<'
(DateTime.now.year - (embargo['c'].to_i - 1)).to_s
elsif date
date['b']
end
end

def end_date
if embargo && (embargo['b'] == '>=')
(DateTime.now.year - embargo['c'].to_i).to_s
elsif embargo && (embargo['b'] == '<=')
'latest'
elsif embargo && embargo['b'] == '<'
'latest'
elsif embargo && embargo['b'] == '>'
(DateTime.now.year - (embargo['c'].to_i + 1)).to_s
elsif date && date['c']
date['c']
else
'latest'
end
end

def portfolio_title
field['n'].nil? ? 'Online Content' : field['n']
end
Expand Down
8 changes: 0 additions & 8 deletions marc_to_solr/lib/princeton_marc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,6 @@ def alma_951_active(record)
alma_951&.select { |f| f['a'] == 'Available' }
end

def alma_953(record)
record.fields('953').select { |f| alma_code_start_53?(f['a']) }
end

def alma_954(record)
record.fields('954').select { |f| alma_code_start_53?(f['a']) }
end

def process_holdings(record)
all_holdings = {}
holdings_helpers = ProcessHoldingsHelpers.new(record:)
Expand Down
6 changes: 1 addition & 5 deletions marc_to_solr/lib/traject_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1541,13 +1541,9 @@
to_field 'electronic_portfolio_s' do |record, accumulator|
# Don't check for scsb
fields = alma_951_active(record)
dates = alma_953(record)
embargoes = alma_954(record)

fields.map do |field|
date = dates.find { |d| d['a'] == field['8'] }
embargo = embargoes.find { |e| e['a'] == field['8'] }
accumulator << ElectronicPortfolioBuilder.build(field:, date:, embargo:)
accumulator << ElectronicPortfolioBuilder.build(field:)
end
end

Expand Down
15 changes: 0 additions & 15 deletions spec/marc_to_solr/lib/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,6 @@ def fixture_record(fixture_name, indexer: @indexer)
expect(nature['desc']).to eq 'Available from 1869 volume: 1 issue: 1.'
expect(nature['notes']).to be_empty

# Date range with explicit start and no end date
expect(nature['start']).to eq '1869'
expect(nature['end']).to eq 'latest'

# Date range with explicit start and end
expect(ebsco['start']).to eq '1997'
expect(ebsco['end']).to eq '2015'

# electronic_portfolio_s should not include non alma 951(s).
expect(resource1).to be_nil
expect(resource2).to be_nil
Expand All @@ -276,13 +268,6 @@ def fixture_record(fixture_name, indexer: @indexer)
portfolios = @electronic_portfolio_embargo['electronic_portfolio_s'].map { |p| JSON.parse(p) }
portfolio1 = portfolios.find { |p| p['title'] == 'EBSCOhost Academic Search Ultimate' }
portfolio2 = portfolios.find { |p| p['title'] == 'Taylor & Francis Medical Library' }

# Date range with greater than or equal to embargo
expect(portfolio1['start']).to eq '2001'
expect(portfolio1['end']).to eq (DateTime.now.year - 1).to_s

expect(portfolio2['start']).to eq '1997'
expect(portfolio2['end']).to eq 'latest'
end

it 'does not index an inactive electronic_portfolio' do
Expand Down