Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix-1.6.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Lown committed Apr 16, 2020
2 parents be8726e + 473431c commit 2bceadb
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 5 deletions.
97 changes: 97 additions & 0 deletions app/assets/javascripts/trln_argon/fulltext_links.js
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);
}
});
}
});

});
38 changes: 38 additions & 0 deletions app/controllers/hathitrust_controller.rb
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
4 changes: 4 additions & 0 deletions app/models/hathitrust_overlap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class HathitrustOverlap < ApplicationRecord
end
7 changes: 7 additions & 0 deletions app/views/catalog/_etas_link.html.erb
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 %>
1 change: 1 addition & 0 deletions app/views/catalog/_fulltext_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@
<%= render partial: 'open_access_links', locals: { document: document } %>
<% else %>
<%= render partial: 'hathitrust_link', locals: { document: document } %>
<%= render partial: 'etas_link', locals: { document: document } %>
<%= render partial: 'internet_archive_link', locals: { document: document } %>
<% end %>
14 changes: 11 additions & 3 deletions app/views/catalog/_hathitrust_link.html.erb
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 %>
8 changes: 8 additions & 0 deletions app/views/hathitrust/etas.html.erb
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 %>
12 changes: 12 additions & 0 deletions app/views/trln/_fulltext_links.html.erb
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 %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

resource :styleguide, only: [:show], as: 'styleguide', path: '/styleguide', controller: 'styleguide'

get 'etas/:oclc_numbers', to: 'hathitrust#show_etas', as: 'etas'

# IMPORTANT: This catch-all route should always be last.
match '/*path', to: 'application#not_found', via: :all
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20200415151650_create_hathitrust_overlaps.rb
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 db/migrate/20200415194532_add_access_to_hathitrust_overlap.rb
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
12 changes: 11 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180521201455) do
ActiveRecord::Schema.define(version: 20200415194532) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -27,6 +27,16 @@
t.index ["user_id"], name: "index_bookmarks_on_user_id", using: :btree
end

create_table "hathitrust_overlaps", force: :cascade do |t|
t.string "oclc_number"
t.string "bib_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "access"
t.index ["access"], name: "index_hathitrust_overlaps_on_access", using: :btree
t.index ["bib_id"], name: "index_hathitrust_overlaps_on_bib_id", using: :btree
end

create_table "searches", force: :cascade do |t|
t.binary "query_params"
t.integer "user_id"
Expand Down
2 changes: 1 addition & 1 deletion lib/dul_argon_skin/version.rb
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
21 changes: 21 additions & 0 deletions lib/tasks/dul_argon.rake
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

0 comments on commit 2bceadb

Please sign in to comment.