Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Code change to share in pairing session #266

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions lib/iiif_print/split_pdfs/derivative_rodeo_splitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DerivativeRodeoSplitter
#
# @see IiifPrint::SplitPdfs::BaseSplitter
def self.call(filename, file_set:)
new(filename, file_set: file_set).split_files
new(filename, file_set: file_set).call
end

##
Expand Down Expand Up @@ -145,20 +145,49 @@ def rodeo_conformant_uri_exists?(uri)
private :rodeo_conformant_uri_exists?

##
# @return [Array<Strings>] the paths to each of the images split off from the PDF.
# @return [Array<Strings>] the local paths to each of the images split off from the PDF.
def call
# TODO: Could we off-load the copy to another job? I'm afraid of the "cost" of copying
# a large number of files.
copy(split_files)
end

private

##
# @return [Array<DerivativeRodeo::StorageLocations::BaseLocation>]
def split_files
DerivativeRodeo::Generators::PdfSplitGenerator.new(
input_uris: [input_uri],
output_location_template: output_location_template,
preprocessed_location_template: preprocessed_location_template
).generated_files.map(&:file_path)
).generated_files
rescue => e
message = "#{self.class}##{__method__} encountered `#{e.class}' “#{e}” for " \
"input_uri: #{input_uri.inspect}, " \
"output_location_template: #{output_location_template.inspect}, and " \
"preprocessed_location_template: #{preprocessed_location_template.inspect}."
exception = RuntimeError.new(message)
exception.set_backtrace(e.backtrace)
DerivativeRodeo.logger.error(message)
raise exception
end

##
# @param [Array<DerivativeRodeo::StorageLocations::BaseLocation>]
# @return [Array<String>]
def copy(generated_files)
DerivativeRodeo::Generators::CopyGenerator.new(
input_uris: generated_files.map(&:file_uri),
output_location_template: output_location_template
).generated_files.map(&:file_path)
rescue => e
message = "#{self.class}##{__method__} encountered `#{e.class}' “#{e}” for " \
"input_uri: #{@input_uri.inspect}, " \
"output_location_template: #{output_location_template.inspect}"
exception = RuntimeError.new(message)
exception.set_backtrace(e.backtrace)
DerivativeRodeo.logger.error(message)
raise exception
end
end
Expand Down
Loading