Skip to content

Commit

Permalink
Merge pull request #362 from scientist-softserv/move-solr-document-de…
Browse files Browse the repository at this point in the history
…corator-out-of-engine

Move solr document decorator out of engine
  • Loading branch information
kirkkwang authored Jul 3, 2024
2 parents 6d1700a + e130bba commit 4c40244
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 79 deletions.
10 changes: 8 additions & 2 deletions app/jobs/iiif_print/jobs/child_works_from_pdf_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def split_pdf(original_pdf_path, user, child_model, pdf_file_set)
)
BatchCreateJob.perform_later(user,
@child_work_titles,
{},
@resource_types,
@uploaded_files,
attributes.merge!(model: child_model.to_s, split_from_pdf_id: @split_from_pdf_id).with_indifferent_access,
operation)
Expand All @@ -99,6 +99,7 @@ def split_pdf(original_pdf_path, user, child_model, pdf_file_set)
def prepare_import_data(original_pdf_path, image_files, user)
@uploaded_files = []
@child_work_titles = {}
@resource_types = {}
number_of_pages_in_pdf = image_files.size
image_files.each_with_index do |image_path, page_number|
file_id = create_uploaded_file(user, image_path).to_s
Expand All @@ -111,6 +112,7 @@ def prepare_import_data(original_pdf_path, image_files, user)
page_padding: number_of_digits(nbr: number_of_pages_in_pdf)
)

@resource_types[file_id] = resource_types
@uploaded_files << file_id
@child_work_titles[file_id] = child_title
# save child work info to create the member relationships
Expand Down Expand Up @@ -144,10 +146,14 @@ def create_uploaded_file(user, path)
uf.id
end

# TODO: what attributes do we need to fill in from the parent work? What about AllinsonFlex?
def attributes
IiifPrint.config.child_work_attributes_function.call(parent_work: @parent_work, admin_set_id: @child_admin_set_id)
end

# TODO: Does this method need to be configurable?
def resource_types
@parent_work.try(:resource_type)
end
end
end
end
2 changes: 1 addition & 1 deletion app/listeners/iiif_print/listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def on_file_characterized(event, service: IiifPrint::SplitPdfs::ChildWorkCreatio
file_set = event[:file_set]
return false unless file_set
return false unless file_set.file_set?
return false unless file_set.original_file.pdf?
return false unless file_set.original_file&.pdf?

work = IiifPrint.parent_for(file_set)
# A short-circuit to avoid fetching the underlying file.
Expand Down
63 changes: 0 additions & 63 deletions app/models/concerns/iiif_print/solr/document.rb

This file was deleted.

47 changes: 47 additions & 0 deletions app/models/concerns/iiif_print/solr_document_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

module IiifPrint
module SolrDocumentDecorator
def digest_sha1
digest[/urn:sha1:([\w]+)/, 1]
end

def method_missing(method_name, *args, &block)
super unless iiif_print_solr_field_names.include? method_name.to_s
self[IiifPrint.solr_name(method_name.to_s)]
end

def respond_to_missing?(method_name, include_private = false)
iiif_print_solr_field_names.include?(method_name.to_s) || super
end

# @see https://github.com/samvera/hyrax/commit/7108409c619cd2ba4ae8c836b9f3b429a7e9837b
def file_set_ids
# Yes, this looks a little odd. But the truth is the prior key (e.g. `file_set_ids_ssim`) was
# an alias of `member_ids_ssim`.
self['member_ids_ssim']
end

def any_highlighting?
response&.[]('highlighting')&.[](id)&.present?
end

def solr_document
self
end
end
end

SolrDocument.prepend(IiifPrint::SolrDocumentDecorator)
SolrDocument.attribute :is_child, Hyrax::SolrDocument::Metadata::Solr::String, 'is_child_bsi'
SolrDocument.attribute :split_from_pdf_id, Hyrax::SolrDocument::Metadata::Solr::String, 'split_from_pdf_id_ssi'
SolrDocument.attribute :digest, Hyrax::SolrDocument::Metadata::Solr::String, 'digest_ssim'

# @note These properties came from the newspaper_works gem. They are configurable.
SolrDocument.class_attribute :iiif_print_solr_field_names, default: %w[alternative_title genre
issn lccn oclcnum held_by text_direction
page_number section author photographer
volume issue_number geographic_coverage
extent publication_date height width
edition_number edition_name frequency preceded_by
succeeded_by]
2 changes: 1 addition & 1 deletion app/services/iiif_print/derivative_rodeo_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def input_uri
else
# TODO: This is the fedora URL representing the file we uploaded; is that adequate? Will we
# have access to this file?
file_set.original_file.uri.to_s
file_set.original_file&.uri&.to_s
end
end

Expand Down
2 changes: 2 additions & 0 deletions config/metadata/child_works_from_pdf_splitting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ attributes:
index_keys:
- "is_child_bsi"
form:
display: false
required: false
primary: false
multiple: false
Expand All @@ -15,6 +16,7 @@ attributes:
index_keys:
- "split_from_pdf_id_ssi"
form:
display: false
required: false
primary: false
multiple: false
Expand Down
6 changes: 2 additions & 4 deletions iiif_print.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ Gem::Specification.new do |spec|
spec.email = ['[email protected]', '[email protected]',
'[email protected]', '[email protected]', '[email protected]',
'[email protected]', '[email protected]']
spec.homepage = 'https://github.com/samvera-labs/iiif_print'
spec.homepage = 'https://github.com/scientist-softserv/iiif_print/'
spec.description = 'Gem/Engine for IIIF Print works in Hyrax-based Samvera Application.'
spec.summary = <<-SUMMARY
iiif_print is a Rails Engine gem providing model and administrative
functions to Hyrax-based Samvera applications, for management of
(primarily scanned) content.
IiifPrint is a gem (Rails "engine") for Hyrax-based digital repository applications to support displaying parent/child works in the same viewer (Universal Viewer) and the ability to search OCR from the parent work to the child work(s). IiifPring was originally based off of the samvera-labs Newspaper gem.
SUMMARY
spec.license = 'Apache-2.0'
spec.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR).select { |f| File.dirname(f) !~ %r{\A"?spec\/?} && f != 'bin/rails' }
Expand Down
2 changes: 1 addition & 1 deletion lib/iiif_print/base_derivative_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def valid?
# @TODO: verify if this works for ActiveFedora and if so, remove commented code.
# If not, modify to use adapter.
# file_set.class.image_mime_types.include?(file_set.mime_type)
file_set.original_file.image?
file_set.original_file&.image?
end

def derivative_path_factory
Expand Down
2 changes: 1 addition & 1 deletion lib/iiif_print/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def child_work_attributes_function
visibility: 'lease',
visibility_after_lease: lease.visibility_after_lease,
visibility_during_lease: lease.visibility_during_lease,
lease_release_date: lease.lease_release_date
lease_release_date: lease.lease_expiration_date
}
else
visibility_params = { visibility: parent_work.visibility.to_s }
Expand Down
4 changes: 0 additions & 4 deletions lib/iiif_print/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ class Engine < ::Rails::Engine
end
end
end

config.after_initialize do
IiifPrint::Solr::Document.decorate(SolrDocument)
end
# rubocop:enable Metrics/BlockLength
end
end
2 changes: 1 addition & 1 deletion lib/iiif_print/persistence_layer/valkyrie_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def self.destroy_children_split_from(file_set:, work:, model:, user:)
end

def self.pdf?(file_set)
file_set.original_file.pdf?
file_set.original_file&.pdf?
end

##
Expand Down
2 changes: 1 addition & 1 deletion lib/iiif_print/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module IiifPrint
VERSION = '1.0.0'.freeze
VERSION = '2.0.1'.freeze
end
22 changes: 22 additions & 0 deletions spec/models/solr_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,26 @@
expect(solr_doc.file_set_ids).to eq(['bar'])
end
end

describe 'iiif_print decorator' do
it 'has extra attributes' do
expect(solr_doc).to respond_to(:is_child)
expect(solr_doc).to respond_to(:split_from_pdf_id)
expect(solr_doc).to respond_to(:digest)
end

it 'has extra class attributes' do
expect(described_class.iiif_print_solr_field_names).to eq %w[alternative_title genre
issn lccn oclcnum held_by text_direction
page_number section author photographer
volume issue_number geographic_coverage
extent publication_date height width
edition_number edition_name frequency preceded_by
succeeded_by]
end

it 'has a method that returns itself' do
expect(solr_doc.solr_document).to be solr_doc
end
end
end

0 comments on commit 4c40244

Please sign in to comment.