Skip to content

Commit 5d5ce9c

Browse files
authored
Merge pull request #251 from MITLibraries/use-96-frbr-links
Render FRBR links for Alma records only
2 parents 81c6bd8 + 07e2079 commit 5d5ce9c

File tree

5 files changed

+186
-2
lines changed

5 files changed

+186
-2
lines changed

app/models/normalize_primo_record.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,15 @@ def frbrized?
301301
@record['pnx']['facets']['frbrtype'].join == '5'
302302
end
303303

304+
def alma_record?
305+
return false unless record_id
306+
307+
record_id.start_with?('alma')
308+
end
309+
304310
def dedup_url
305311
return unless frbrized?
312+
return unless alma_record? # FRBR links do not work for CDI records
306313
return unless @record['pnx']['facets']['frbrgroupid'] &&
307314
@record['pnx']['facets']['frbrgroupid'].length == 1
308315

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"pnx": {
3+
"display": {
4+
"title": ["Alma Record Testing"],
5+
"creator": ["Smith, John A."],
6+
"creationdate": ["2023"],
7+
"type": ["book"],
8+
"description": ["A test Alma record for FRBR functionality"],
9+
"subject": ["Testing"]
10+
},
11+
"addata": {
12+
"btitle": ["Alma Test Book"],
13+
"date": ["2023"],
14+
"volume": ["1"],
15+
"issue": ["1"],
16+
"pages": ["1-10"],
17+
"jtitle": ["Alma Test Journal"],
18+
"isbn": ["9781234567890"],
19+
"pub": ["Test Press"]
20+
},
21+
"facets": {
22+
"frbrtype": ["5"],
23+
"frbrgroupid": ["alma12345"]
24+
},
25+
"search": {
26+
"creationdate": ["2023"]
27+
},
28+
"control": {
29+
"recordid": ["alma991234567890123456"]
30+
}
31+
},
32+
"context": "contextual",
33+
"delivery": {
34+
"bestlocation": {
35+
"mainLocation": "Test Library",
36+
"subLocation": "Stacks",
37+
"callNumber": "TEST.123 2023",
38+
"availabilityStatus": "available"
39+
},
40+
"holding": [
41+
{"location": "Main Library"}
42+
],
43+
"link": [],
44+
"almaOpenurl": "https://na06.alma.exlibrisgroup.com/view/uresolver/01MIT_INST/openurl?param=value"
45+
}
46+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"pnx": {
3+
"display": {
4+
"title": ["CDI Record Testing"],
5+
"creator": ["Doe, Jane B."],
6+
"creationdate": ["2023"],
7+
"type": ["article"],
8+
"description": ["A test CDI record that should not get FRBR links"],
9+
"subject": ["CDI Testing"]
10+
},
11+
"addata": {
12+
"jtitle": ["CDI Test Journal"],
13+
"date": ["2023"],
14+
"volume": ["2"],
15+
"issue": ["3"],
16+
"pages": ["15-25"],
17+
"issn": ["1234-5678"],
18+
"pub": ["CDI Publisher"]
19+
},
20+
"facets": {
21+
"frbrtype": ["5"],
22+
"frbrgroupid": ["cdi54321"]
23+
},
24+
"search": {
25+
"creationdate": ["2023"]
26+
},
27+
"control": {
28+
"recordid": ["cdi_crossref_primary_10_1234_test_article"]
29+
}
30+
},
31+
"context": "contextual",
32+
"delivery": {
33+
"link": [],
34+
"almaOpenurl": "https://na06.alma.exlibrisgroup.com/view/uresolver/01MIT_INST/openurl?param=value"
35+
}
36+
}

test/fixtures/primo/full_record.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"creationdate": ["2023"]
2828
},
2929
"control": {
30-
"recordid": ["MIT01000000001"]
30+
"recordid": ["alma991000000001234567"]
3131
}
3232
},
3333
"context": "contextual",

test/models/normalize_primo_record_test.rb

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ def minimal_record
1212
JSON.parse(File.read(Rails.root.join('test/fixtures/primo/minimal_record.json')))
1313
end
1414

15+
def alma_record
16+
JSON.parse(File.read(Rails.root.join('test/fixtures/primo/alma_record.json')))
17+
end
18+
19+
def cdi_record
20+
JSON.parse(File.read(Rails.root.join('test/fixtures/primo/cdi_record.json')))
21+
end
22+
1523
test 'normalizes title' do
1624
normalized = NormalizePrimoRecord.new(full_record, 'test').normalize
1725
assert_equal 'Testing the Limits of Knowledge', normalized['title']
@@ -95,7 +103,7 @@ def minimal_record
95103

96104
test 'normalizes identifier' do
97105
normalized = NormalizePrimoRecord.new(full_record, 'test').normalize
98-
assert_equal 'MIT01000000001', normalized['identifier']
106+
assert_equal 'alma991000000001234567', normalized['identifier']
99107
end
100108

101109
test 'normalizes summary' do
@@ -328,4 +336,91 @@ def minimal_record
328336
openurl_link = normalized['links'].find { |link| link['kind'] == 'openurl' }
329337
assert_not_nil openurl_link
330338
end
339+
340+
test 'identifies Alma records correctly' do
341+
normalizer = NormalizePrimoRecord.new(alma_record, 'test')
342+
assert normalizer.send(:alma_record?)
343+
end
344+
345+
test 'identifies CDI records correctly' do
346+
normalizer = NormalizePrimoRecord.new(cdi_record, 'test')
347+
assert_not normalizer.send(:alma_record?)
348+
end
349+
350+
test 'handles missing record ID for alma_record? check' do
351+
record = minimal_record.deep_dup
352+
normalizer = NormalizePrimoRecord.new(record, 'test')
353+
assert_not normalizer.send(:alma_record?)
354+
end
355+
356+
test 'generates FRBR dedup URL for Alma records when frbrized' do
357+
normalized = NormalizePrimoRecord.new(alma_record, 'test query').normalize
358+
full_record_link = normalized['links'].find { |link| link['kind'] == 'full record' }
359+
assert_not_nil full_record_link
360+
361+
# Should use dedup URL for Alma records
362+
assert_match 'frbrgroupid', full_record_link['url']
363+
assert_match 'alma12345', full_record_link['url']
364+
end
365+
366+
test 'does not generate FRBR dedup URL for CDI records even when frbrized' do
367+
normalized = NormalizePrimoRecord.new(cdi_record, 'test query').normalize
368+
full_record_link = normalized['links'].find { |link| link['kind'] == 'full record' }
369+
assert_not_nil full_record_link
370+
371+
# Should use regular record link for CDI records, not dedup URL
372+
assert_match %r{/discovery/fulldisplay\?}, full_record_link['url']
373+
assert_no_match 'frbrgroupid', full_record_link['url']
374+
end
375+
376+
test 'falls back to regular record link for Alma records without FRBR data' do
377+
record = alma_record.deep_dup
378+
record['pnx']['facets']['frbrtype'] = ['3'] # Not frbrized
379+
380+
normalized = NormalizePrimoRecord.new(record, 'test').normalize
381+
full_record_link = normalized['links'].find { |link| link['kind'] == 'full record' }
382+
assert_not_nil full_record_link
383+
384+
# Should use regular record link when not frbrized
385+
assert_match %r{/discovery/fulldisplay\?}, full_record_link['url']
386+
assert_no_match 'frbrgroupid', full_record_link['url']
387+
end
388+
389+
test 'frbrized? method works correctly' do
390+
# Frbrized Alma record
391+
normalizer = NormalizePrimoRecord.new(alma_record, 'test')
392+
assert normalizer.send(:frbrized?)
393+
394+
# Frbrized CDI record
395+
normalizer = NormalizePrimoRecord.new(cdi_record, 'test')
396+
assert normalizer.send(:frbrized?)
397+
398+
# Non-frbrized record
399+
record = alma_record.deep_dup
400+
record['pnx']['facets']['frbrtype'] = ['3']
401+
normalizer = NormalizePrimoRecord.new(record, 'test')
402+
assert_not normalizer.send(:frbrized?)
403+
404+
# Missing FRBR data
405+
normalizer = NormalizePrimoRecord.new(minimal_record, 'test')
406+
assert_not normalizer.send(:frbrized?)
407+
end
408+
409+
test 'dedup_url requires both frbrized and alma_record conditions' do
410+
# CDI record that is frbrized - should return nil
411+
normalizer = NormalizePrimoRecord.new(cdi_record, 'test')
412+
assert_nil normalizer.send(:dedup_url)
413+
414+
# Alma record that is not frbrized - should return nil
415+
record = alma_record.deep_dup
416+
record['pnx']['facets']['frbrtype'] = ['3']
417+
normalizer = NormalizePrimoRecord.new(record, 'test')
418+
assert_nil normalizer.send(:dedup_url)
419+
420+
# Test Alma record that is frbrized - should return URL
421+
normalizer = NormalizePrimoRecord.new(alma_record, 'test')
422+
dedup_url = normalizer.send(:dedup_url)
423+
assert_not_nil dedup_url
424+
assert_match %r{/discovery/search\?}, dedup_url
425+
end
331426
end

0 commit comments

Comments
 (0)