Skip to content

Commit

Permalink
pr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcam-src committed Dec 5, 2024
1 parent e8b80a8 commit b49c03e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true
# https://github.com/projectblacklight/blacklight/blob/v8.7.0/app/presenters/blacklight/thumbnail_presenter.rb
module Blacklight
class ThumbnailPresenter
private
Expand All @@ -16,7 +17,7 @@ def retrieve_values(field_config)
if needs_thumbnail_path_update?(document_hash)
file_set_id = document_hash['file_set_ids_ssim']&.first
document_hash['thumbnail_path_ss'] = "/downloads/#{file_set_id}?file=thumbnail"
Rails.logger.info("Updated thumbnail_path_ss: #{document_hash['thumbnail_path_ss']} for work with id #{document.id}")
Rails.logger.info("Updated thumbnail_path_ss: #{document_hash['thumbnail_path_ss']} for work with id #{document_hash['id']}")
# Create a temporary SolrDocument from the updated hash
updated_document = SolrDocument.new(document_hash)
FieldRetriever.new(updated_document, field_config, view_context).fetch
Expand All @@ -38,9 +39,10 @@ def extract_solr_document(doc)
def needs_thumbnail_path_update?(document)
thumbnail_path = document['thumbnail_path_ss'] || ''
file_set_ids = document['file_set_ids_ssim']
thumbnail_missing_or_default = thumbnail_path.blank? || thumbnail_path !~ %r{^/downloads/\w+\?file=thumbnail$}

# Check if the thumbnail path is the default or missing and file_set_ids are present
thumbnail_path !~ %r{^/downloads/\w+\?file=thumbnail$} && file_set_ids.present?
# Returns true if file_set_ids are present and the thumbnail path is the default or missing entirely
file_set_ids.present? && thumbnail_missing_or_default
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
delegate :title, :date_created, :date_issued, :description, :doi, :creator, :place_of_publication,
:creator_display, :contributor, :subject, :publisher, :language, :embargo_release_date,
:lease_expiration_date, :license, :source, :rights_statement, :thumbnail_id, :representative_id,
:rendering_ids, :member_of_collection_ids, :member_ids, :alternative_title, to: :solr_document
:rendering_ids, :member_of_collection_ids, :bibliographic_citation, :alternative_title, :member_ids, to: :solr_document

# [hyc-override] Add default scholarly? method
# Indicates if the work is considered scholarly according to google scholar
Expand All @@ -23,10 +23,10 @@ def fetch_primary_fileset_id
# [hyc-override] Use a work's first related fileset_id instead of the representative_id if it's nil
# @return FileSetPresenter presenter for the representative FileSets
def representative_presenter
primary_fileset_id = fetch_primary_fileset_id
return nil if primary_fileset_id.blank?
@representative_presenter ||=
begin
primary_fileset_id = fetch_primary_fileset_id
return nil if primary_fileset_id.blank?
result = member_presenters([primary_fileset_id]).first
return nil if result.try(:id) == id
result.try(:representative_presenter) || result
Expand Down
6 changes: 4 additions & 2 deletions spec/presenters/blacklight/thumbnail_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
allow(retriever_instance).to receive(:fetch).and_return('default_thumbnail')
allow(presenter).to receive(:extract_solr_document)

presenter.send(:retrieve_values, field_config)
result = presenter.send(:retrieve_values, field_config)
expect(Blacklight::FieldRetriever).to have_received(:new).with(nil, field_config, view_context)
# Presenter should not process the document if it's nil
expect(presenter).not_to have_received(:extract_solr_document)
expect(result).to eq('default_thumbnail')
end

it 'updates the thumbnail_path_ss if it needs an update' do
Expand All @@ -39,11 +40,12 @@
allow(retriever_instance).to receive(:fetch).and_return('updated_thumbnail')
allow(Rails.logger).to receive(:info)

presenter.send(:retrieve_values, field_config)
result = presenter.send(:retrieve_values, field_config)
expect(Rails.logger).to have_received(:info).with('Updated thumbnail_path_ss: /downloads/file_set_1?file=thumbnail for work with id 1')
expect(SolrDocument).to have_received(:new).with(
hash_including('thumbnail_path_ss' => '/downloads/file_set_1?file=thumbnail')
)
expect(result).to eq('updated_thumbnail')
end
end
end

0 comments on commit b49c03e

Please sign in to comment.