Skip to content

Commit 9ebc8e0

Browse files
Load libkey lookup results in UI
** Why are these changes being introduced: Now that there's an integration with libkey via an internal path, the search results page needs to consult that when relevant results are received from our discovery APIs. ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/use-232 ** How does this address that need: This adds fields for DOIs and PMIDs to the Primo record normalizer, on the assumption that any given record has at most one of each of these. If none is found, the field is left out of the normalized record. If one is found that value is added to the normalized record. If more than one is found, a message is sent to Sentry so we can look further. This will help us understand how widespread the condition is. (Any record might have _both_ a DOI and PMID, this is not problematic). When a record has one of these values, we call the internal lookup route via a stimulus controller. If the lookup results in an integration link (not all DOIs or PMIDs will turn out this way), the link is added as the first link in the UI. If a record has both a DOI and a PMID, only the DOI is used. I've written tests for the normalizer model, to confirm that it handles cases with zero, one, and mulitple of each field. The tests don't deal with the Sentry integration, however. ** Document any side effects to this change: The integration with Sentry is a little iffy. I'm not thrilled about directly calling Sentry from a model like this, but I want to be able to use a consistent message text, while defining tags on each message so that we can get the record IDs and DOIs/PMIDs to help us investigate further.
1 parent 2888060 commit 9ebc8e0

5 files changed

Lines changed: 80 additions & 1 deletion

File tree

app/models/normalize_primo_record.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def normalize
1818
links:,
1919
citation:,
2020
identifier:,
21+
doi:,
22+
pmid:,
2123
summary:,
2224
publisher:,
2325
location:,
@@ -142,6 +144,30 @@ def identifier
142144
@record['pnx']['control']['recordid'].join
143145
end
144146

147+
def doi
148+
return unless @record['pnx']['addata'] && @record['pnx']['addata']['doi']
149+
150+
if @record['pnx']['addata']['doi'].length > 1
151+
Sentry.set_tags('mitlib.recordId': identifier || 'empty record id')
152+
Sentry.set_tags('mitlib.dois': @record['pnx']['addata']['doi'])
153+
Sentry.capture_message('Multiple DOIs found in one record')
154+
end
155+
156+
@record['pnx']['addata']['doi'].first
157+
end
158+
159+
def pmid
160+
return unless @record['pnx']['addata'] && @record['pnx']['addata']['pmid']
161+
162+
if @record['pnx']['addata']['pmid'].length > 1
163+
Sentry.set_tags('mitlib.recordId': identifier || 'empty record id')
164+
Sentry.set_tags('mitlib.pmids': @record['pnx']['addata']['pmid'])
165+
Sentry.capture_message('Multiple PMIDs found in one record')
166+
end
167+
168+
@record['pnx']['addata']['pmid'].first
169+
end
170+
145171
def summary
146172
return unless @record['pnx']['display']['description']
147173

app/views/search/_result_primo.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
</div>
3636

3737
<div class="result-get">
38+
<% if Libkey.enabled? && result[:doi].present? %>
39+
<%= render(partial: 'trigger_libkey', locals: { kind: 'doi', identifier: result[:doi] }) %>
40+
<% elsif Libkey.enabled? && result[:pmid].present? %>
41+
<%= render(partial: 'trigger_libkey', locals: { kind: 'pmid', identifier: result[:pmid] }) %>
42+
<% end %>
3843
<% if result[:links].present? %>
3944
<% result[:links].each do |link| %>
4045
<%= link_to link['kind'].titleize, link['url'], class: 'button' %>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<% return unless Libkey.enabled? %>
2+
3+
<% data_url = "/lookup?type=#{kind}&identifier=#{identifier}" %>
4+
5+
<span class="tacos-container"
6+
data-controller="content-loader"
7+
data-content-loader-url-value=<%= data_url %>>
8+
</span>

test/fixtures/primo/full_record.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"pages": ["123-145"],
1818
"jtitle": ["Journal of Testing"],
1919
"isbn": ["9781234567890", "1234567890"],
20-
"pub": ["MIT Press"]
20+
"pub": ["MIT Press"],
21+
"doi": ["one"],
22+
"pmid": ["one"]
2123
},
2224
"facets": {
2325
"frbrtype": ["5"],

test/models/normalize_primo_record_test.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,44 @@ def cdi_record
106106
assert_equal 'alma991000000001234567', normalized[:identifier]
107107
end
108108

109+
test 'normalizes doi' do
110+
normalized = NormalizePrimoRecord.new(full_record, 'test').normalize
111+
assert_equal normalized[:doi], 'one'
112+
end
113+
114+
test 'handles missing doi' do
115+
normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize
116+
assert_nil normalized[:doi]
117+
end
118+
119+
test 'multiple dois normalize to the first one' do
120+
temp_record = full_record
121+
temp_record['pnx']['addata']['doi'] = %w[three two one]
122+
123+
normalized = NormalizePrimoRecord.new(temp_record, 'test').normalize
124+
125+
assert_equal normalized[:doi], 'three'
126+
end
127+
128+
test 'normalizes pmid' do
129+
normalized = NormalizePrimoRecord.new(full_record, 'test').normalize
130+
assert_equal normalized[:pmid], 'one'
131+
end
132+
133+
test 'handles missing pmid' do
134+
normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize
135+
assert_nil normalized[:pmid]
136+
end
137+
138+
test 'multiple pmids normalize to the first one' do
139+
temp_record = full_record
140+
temp_record['pnx']['addata']['pmid'] = %w[three two one]
141+
142+
normalized = NormalizePrimoRecord.new(temp_record, 'test').normalize
143+
144+
assert_equal normalized[:pmid], 'three'
145+
end
146+
109147
test 'normalizes summary' do
110148
normalized = NormalizePrimoRecord.new(full_record, 'test').normalize
111149
assert_equal 'A comprehensive study of testing methodologies', normalized[:summary]

0 commit comments

Comments
 (0)