This repository has been archived by the owner on Aug 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
229 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
Blacklight.onLoad(function() { | ||
// Fetch Internet Archive IDs from the DOM | ||
// for Internet Archive linking | ||
var internet_archive_ids = []; | ||
$(".internet-archive-link").each(function() { | ||
internet_archive_ids.push ($(this).data("internet-archive-id")); | ||
}); | ||
|
||
// Fetch OCLC Numbers from the DOM | ||
// for Hathitrust linking | ||
var oclc_numbers = []; | ||
$(".hathi-trust-link").each(function() { | ||
oclc_numbers.push ($(this).data("oclc-number")); | ||
}); | ||
|
||
// Fetch OCLC Numbers from the DOM | ||
// for Hathitrust linking | ||
var etas_oclc_numbers = []; | ||
$(".etas-link").each(function() { | ||
etas_oclc_numbers.push ($(this).data("oclc-number")); | ||
}); | ||
|
||
|
||
// Check the internet_archive route for | ||
// any Internet Archive links to render. | ||
// See InternetArchiveControllerBehavior. | ||
if (internet_archive_ids.length !== 0) { | ||
internet_archive_ids = internet_archive_ids.join('||') | ||
var internet_archive_response = $.ajax({ | ||
url: "/internet_archive/" + internet_archive_ids, | ||
timeout: 10000 | ||
}); | ||
} else { | ||
var internet_archive_response = []; | ||
} | ||
|
||
// Check the hathitrust route for | ||
// any Hathitrust links to render. | ||
// See HathitrustControllerBehavior. | ||
if (oclc_numbers.length !== 0) { | ||
oclc_numbers = oclc_numbers.join('|'); | ||
var hathitrust_response = $.ajax({ | ||
url: "/hathitrust/" + oclc_numbers, | ||
timeout: 10000 | ||
}); | ||
} else { | ||
var hathitrust_response = []; | ||
} | ||
|
||
// Check the etas route for | ||
// any Hathitrust links to render. | ||
// See HathitrustControllerBehavior. | ||
if (etas_oclc_numbers.length !== 0) { | ||
etas_oclc_numbers = etas_oclc_numbers.join('|'); | ||
var etas_response = $.ajax({ | ||
url: "/etas/" + etas_oclc_numbers, | ||
timeout: 10000 | ||
}); | ||
} else { | ||
var etas_response = []; | ||
} | ||
|
||
// When both the internet_archive and hathitrust responses are in hand | ||
// first add all the internet_archive links. Then add all the hathitrust | ||
// links. If there is an internet_archive link then the hathitrust link | ||
// will NOT be added if both are available for the same record. | ||
$.when(internet_archive_response, etas_response, hathitrust_response).then(function(ia_data, etas_data, ht_data) { | ||
if (ia_data.length !== 0) { | ||
$.each(ia_data[0], function(key, value) { | ||
if (value) { | ||
var internet_archive_div = $('.internet-archive-link.' + key); | ||
internet_archive_div.html(value); | ||
internet_archive_div.prev('.hathi-trust-link').remove(); | ||
internet_archive_div.prev('.etas-link').remove(); | ||
} | ||
}); | ||
} | ||
|
||
if (etas_data.length !== 0) { | ||
$.each(etas_data[0], function(key, value) { | ||
if (value) { | ||
$('.etas-link.' + key).html(value); | ||
$('.etas-link.' + key).prev('.hathi-trust-link').remove(); | ||
} | ||
}); | ||
} | ||
|
||
if (ht_data.length !== 0) { | ||
$.each(ht_data[0], function(key, value) { | ||
if (value) { | ||
$('.hathi-trust-link.' + key).html(value); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
class HathitrustController < ApplicationController | ||
include TrlnArgon::HathitrustControllerBehavior | ||
|
||
def show_etas | ||
render json: etas_links_grouped_by_oclc_number | ||
end | ||
|
||
private | ||
|
||
def etas_links_grouped_by_oclc_number | ||
hathitrust_response_hash.map do |key, value| | ||
full_text_url = hathitrust_fulltext_url(value) | ||
next unless etas_fulltext_item?(value) | ||
[key.delete(':'), render_etas_partial_to_string(full_text_url)] | ||
end.compact.to_h.to_json | ||
end | ||
|
||
def render_etas_partial_to_string(full_text_url) | ||
render_to_string('hathitrust/etas', | ||
locals: { etas_argon_url_hash: | ||
etas_argon_url_hash(full_text_url) }, | ||
layout: false) | ||
end | ||
|
||
def etas_argon_url_hash(full_text_url) | ||
{ href: "#{full_text_url}?signon=swle:urn:mace:incommon:duke.edu", | ||
type: 'fulltext', | ||
text: I18n.t('trln_argon.links.hathitrust') } | ||
end | ||
|
||
def etas_fulltext_item?(value) | ||
value.fetch('items', []) | ||
.select { |i| i.fetch('usRightsString') == 'Limited (search-only)' } | ||
.any? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class HathitrustOverlap < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!-- TODO: Also check overlap file? --> | ||
<% overlap_oclc_number = HathitrustOverlap.where(bib_id: document.id, access: 'deny').first&.oclc_number %> | ||
<% if overlap_oclc_number.present? %> | ||
<div class="etas-link oclc<%= overlap_oclc_number %>" | ||
data-oclc-number="<%= overlap_oclc_number %>"> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
<!-- NOTE: Override of partial from TrlnArgon gem to turn off --> | ||
<!-- HathiTrust links for Rubenstein records. --> | ||
|
||
<% if show_hathitrust_link_if_available?(document) %> | ||
<div class="hathi-trust-link oclc<%= document.oclc_number %>" | ||
data-oclc-number="<%= document.oclc_number %>"> | ||
<%# if show_hathitrust_link_if_available?(document) %> | ||
<!-- <div class="hathi-trust-link oclc<%# document.oclc_number %>" | ||
data-oclc-number="<%# document.oclc_number %>"> | ||
</div> --> | ||
<%# end %> | ||
|
||
<!-- NOTE: Temporarily use the overlap file to fetch OA HT links. --> | ||
<% overlap_oclc_number = HathitrustOverlap.where(bib_id: document.id, access: 'allow').first&.oclc_number %> | ||
<% if overlap_oclc_number.present? %> | ||
<div class="hathi-trust-link oclc<%= overlap_oclc_number %>" | ||
data-oclc-number="<%= overlap_oclc_number %>"> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<% unless etas_argon_url_hash.fetch(:href, nil).blank? && document.record_owner == 'duke' %> | ||
<div class="<%= primary_link_class %>"> | ||
<ul> | ||
<li><%= link_to_fulltext_url(etas_argon_url_hash) %></li> | ||
</ul> | ||
</div> | ||
<div class="<%= items_spacer_class %>"></div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<%= render partial: 'finding_aid_links', locals: { document: document } %> | ||
|
||
<% if display_expanded_links?(document, inst) %> | ||
<%= render partial: 'expanded_fulltext_links', locals: { document: document, inst: inst } %> | ||
<%= render partial: 'open_access_links', locals: { document: document, inst: inst } %> | ||
<% else %> | ||
<%= render partial: 'hathitrust_link', locals: { document: document } %> | ||
<% if inst == 'duke' %> | ||
<%= render partial: 'etas_link', locals: { document: document } %> | ||
<% end %> | ||
<%= render partial: 'internet_archive_link', locals: { document: document } %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateHathitrustOverlaps < ActiveRecord::Migration[5.0] | ||
def change | ||
create_table :hathitrust_overlaps do |t| | ||
t.string :oclc_number | ||
t.string :bib_id | ||
|
||
t.timestamps | ||
end | ||
add_index :hathitrust_overlaps, :bib_id | ||
end | ||
end |
6 changes: 6 additions & 0 deletions
6
db/migrate/20200415194532_add_access_to_hathitrust_overlap.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddAccessToHathitrustOverlap < ActiveRecord::Migration[5.0] | ||
def change | ||
add_column :hathitrust_overlaps, :access, :string | ||
add_index :hathitrust_overlaps, :access | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module DulArgonSkin | ||
VERSION = '1.6.8' | ||
VERSION = '1.6.9' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'csv' | ||
|
||
namespace :dul_argon do | ||
namespace :hathitrust do | ||
desc 'Reload overlap file for emergency access ' \ | ||
'to restricted HathiTrust material' | ||
# Expects a file with the following CSV format | ||
# oclc_number,bib_id,access | ||
# 74,DUKE000000008,allow | ||
# 75,DUKE000000009,deny | ||
task :reload_overlaps, [:file_path] => [:environment] do |_, args| | ||
return unless args.fetch(:file_path, nil) | ||
HathitrustOverlap.delete_all | ||
CSV.foreach(args[:file_path], headers: true) do |row| | ||
HathitrustOverlap.create!(row.to_hash) | ||
end | ||
end | ||
end | ||
end |