-
Notifications
You must be signed in to change notification settings - Fork 10
INFO: Full Text PDF Links
Records returned as a result of issuing a SEARCH (as opposed to a RETRIEVE) will not include the direct link to the PDF document, even if the user is not a guest. Rather, you need to issue a RETRIEVE request for that record.
In addition, the PDF link will eventually expire, so it is highly recommended you send a RETRIEVE call at the moment the user indicates they want a PDF, and forward the user to the PDF URL. In other words, don’t put the PDF URL directly on the page the user is viewing the record on – show a PDF Icon or Link, but when a user clicks on it, in the background, issue the RETRIEVE request to grab the URL, then forward your user there immediately. This will prevent the links from timing out when the user is looking at the screen, and will prevent users from copying links that will expire and trying to send them to others.
Here's one way to handle this in Blacklight:
- Add a route to config/routes.rb for EDS full text links
get '/catalog/:id/:type/fulltext', to: 'catalog#fulltext', as: 'fulltext_link'
- Add something like this to the EDS application_helper.rb
def best_fulltext(options={})
# alter the order of the types list below, putting the most desired links first
types = %w(cataloglink pdf ebook-pdf ebook-epub smartlinks customlink-fulltext customlink-other)
opts = options[:value].first
if opts['links'].empty?
'Not available'
else
label = ''
url = ''
types.each do |type|
opts['links'].each do |link|
if link['type'] == type
# use the new fulltext route and controller to avoid time-bombed pdf links
if type == 'pdf' || type == 'ebook-pdf'
url = '/catalog/' + opts['id'] + '/' + type + '/fulltext'
else
url = link['url']
end
# replace 'URL' label for catalog links
if type == 'cataloglink'
label = 'Catalog Link'
else
label = link['label']
end
# sign in and redirect if guest
if current_or_guest_user.guest
session[:current_url] = url
url = '/users/sign_in'
label = label + ', login to view'
end
break
end
end
end
link_to(label, url, target: '_blank')
end
end
- Add this to the EDS catalog_controller.rb
config.add_index_field 'fulltext_link', label: 'Fulltext', helper_method: :best_fulltext
config.add_show_field 'fulltext_link', label: 'Fulltext', helper_method: :best_fulltext
- Add this to the EDS repository.rb
def fulltext_url(id, type, params = {}, eds_params = {})
eds = EBSCO::EDS::Session.new(eds_options(eds_params.update(caller: 'bl-repo-find')))
dbid = id.split('__').first
accession = id.split('__').last
accession.gsub!(/_/, '.')
record = eds.retrieve(dbid: dbid, an: accession)
url = record.fulltext_link(type)[:url]
return url
end
- Add this to the EDS search_service.rb
def fetch_fulltext(id, type, extra_controller_params)
@repository.fulltext_url id, type,extra_controller_params, @eds_params
end
- Add this to the EDS catalog.rb
def fulltext
eds_params = {'guest' => session['guest'], 'session_token' => session['eds_session_token']}
fulltext_url = search_service.fetch_fulltext(params[:id], params[:type], eds_params)
redirect_to fulltext_url, status: 303 if !fulltext_url.nil?
end