Skip to content
Open
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
12 changes: 10 additions & 2 deletions app/models/normalize_primo_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ def links
end
end

# Add Full-text options if pnx['links'] is nil and record has Alma-E (electronic availability)
full_record_link = record_link
if @record.dig('pnx', 'links').nil? &&
@record.dig('delivery', 'deliveryCategory')&.include?('Alma-E') &&
full_record_link.present?
links << { 'url' => "#{full_record_link}#nui.getit.service_viewit", 'kind' => 'Full-text options' }
end
Comment thread
Copilot marked this conversation as resolved.

# Return links if we found any
links.any? ? links : []
Comment thread
qltysh[bot] marked this conversation as resolved.
Comment thread
qltysh[bot] marked this conversation as resolved.
Comment thread
qltysh[bot] marked this conversation as resolved.
Comment thread
qltysh[bot] marked this conversation as resolved.
Comment thread
qltysh[bot] marked this conversation as resolved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 4 issues:

1. Assignment Branch Condition size for links is too high. [<4, 44, 15> 46.66/17] [rubocop:Metrics/AbcSize]


2. Cyclomatic complexity for links is too high. [16/7] [rubocop:Metrics/CyclomaticComplexity]


3. Method has too many lines. [27/10] [rubocop:Metrics/MethodLength]


4. Perceived complexity for links is too high. [17/8] [rubocop:Metrics/PerceivedComplexity]

end
Expand Down Expand Up @@ -327,8 +335,8 @@ def score
# FRBR Group check based on:
# https://knowledge.exlibrisgroup.com/Primo/Knowledge_Articles/Primo_Search_API_-_how_to_get_FRBR_Group_members_after_a_search
def frbrized?
return unless @record['pnx']['facets']
return unless @record['pnx']['facets']['frbrtype']
return false unless @record['pnx']['facets']

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are a result of running rubocop. They are unrelated to this feature.

return false unless @record['pnx']['facets']['frbrtype']

@record['pnx']['facets']['frbrtype'].join == '5'
end
Expand Down
54 changes: 54 additions & 0 deletions test/models/normalize_primo_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,60 @@ def cdi_record
assert_not normalized[:dedup_record]
end

test 'includes Full-text options link when pnx[links] is nil and both Alma-P and Alma-E present' do
record = alma_record.deep_dup

# Ensure no direct links
record['pnx']['links'] = nil

# Add delivery category with both physical and electronic
record['delivery']['deliveryCategory'] = %w[Alma-P Alma-E]
normalized = NormalizePrimoRecord.new(record, 'test').normalize
full_text_link = normalized[:links].find { |link| link['kind'] == 'Full-text options' }
assert_not_nil full_text_link
assert_match %r{/discovery/fulldisplay\?}, full_text_link['url']
assert_match(/#nui\.getit\.service_viewit$/, full_text_link['url'])
end

test 'excludes Full-text options link when pnx[links] is present' do
record = full_record.deep_dup

# Add delivery category with electronic
record['delivery']['deliveryCategory'] = %w[Alma-E]
normalized = NormalizePrimoRecord.new(record, 'test').normalize
full_text_link = normalized[:links].find { |link| link['kind'] == 'Full-text options' }
assert_nil full_text_link
end

test 'excludes Full-text options link when only Alma-P present' do
record = alma_record.deep_dup
record['pnx']['links'] = nil
record['delivery']['deliveryCategory'] = ['Alma-P']
normalized = NormalizePrimoRecord.new(record, 'test').normalize
full_text_link = normalized[:links].find { |link| link['kind'] == 'Full-text options' }
assert_nil full_text_link
end

test 'includes Full-text options link when only Alma-E present' do
record = alma_record.deep_dup
record['pnx']['links'] = nil
record['delivery']['deliveryCategory'] = ['Alma-E']
normalized = NormalizePrimoRecord.new(record, 'test').normalize
full_text_link = normalized[:links].find { |link| link['kind'] == 'Full-text options' }
assert_not_nil full_text_link
assert_match %r{/discovery/fulldisplay\?}, full_text_link['url']
assert_match(/#nui\.getit\.service_viewit$/, full_text_link['url'])
end

test 'excludes Full-text options link when no delivery category present' do
record = alma_record.deep_dup
record['pnx']['links'] = nil
record['delivery']['deliveryCategory'] = nil
normalized = NormalizePrimoRecord.new(record, 'test').normalize
full_text_link = normalized[:links].find { |link| link['kind'] == 'Full-text options' }
assert_nil full_text_link
end

test 'dedup_url requires both frbrized and alma_record conditions' do
# CDI record that is frbrized - should return nil
normalizer = NormalizePrimoRecord.new(cdi_record, 'test')
Expand Down