Class: IiifPrint::Jobs::ChildWorksFromPdfJob Deprecated

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/iiif_print/jobs/child_works_from_pdf_job.rb

Overview

Deprecated.

Instance Method Summary collapse

Instance Method Details

#perform(id, pdf_paths, user, admin_set_id) ⇒ Object

Break a pdf into individual pages

rubocop:disable Metrics/MethodLength

Parameters:

  • candidate_for_parency (FileSet, Hydra::PCDM::Work)
  • pdf_paths: (<Array => String>)

    paths to pdfs

  • user: (User)
  • admin_set_id: (<String>)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/jobs/iiif_print/jobs/child_works_from_pdf_job.rb', line 15

def perform(id, pdf_paths, user, admin_set_id, *)
  candidate_for_parency = IiifPrint.find_by(id: id)

  ##
  # We know that we have cases where parent_work is nil, this will definitely raise an
  # exception; which is fine because we were going to do it later anyway.
  @parent_work = if candidate_for_parency.work?
                   pdf_file_set = nil
                   candidate_for_parency
                 else
                   # We likely have a file set
                   pdf_file_set = candidate_for_parency
                   IiifPrint.parent_for(candidate_for_parency)
                 end
  @child_admin_set_id = admin_set_id
  child_model = @parent_work.iiif_print_config.pdf_split_child_model

  # When working with remote files, we have put the PDF file into the correct path before submitting this job.
  # However, there seem to be cases where we still don't have the file when we get here, so to be sure, we
  # re-do the same command that was previously used to prepare the file path. If the file is already here, it
  # simply returns the path, but if not it will copy the file there, giving us one more chance to have what we need.
  redownload = pdf_file_set&.is_a?(ActiveFedora::Base)
  pdf_paths = [Hyrax::WorkingDirectory.find_or_retrieve(pdf_file_set.original_file.id, pdf_file_set.id, pdf_paths.first)] if redownload
  # handle each input pdf (when input is a file set, we will only have one).
  pdf_paths.each do |original_pdf_path|
    split_pdf(original_pdf_path, user, child_model, pdf_file_set)
  end

  # Link newly created child works to the parent
  # @param user: [User] user
  # @param parent_id: [<String>] parent work id
  # @param parent_model: [<String>] parent model
  # @param child_model: [<String>] child model
  IiifPrint::Jobs::CreateRelationshipsJob.set(wait: 10.minutes).perform_later(
    user: user,
    parent_id: @parent_work.id.to_s,
    parent_model: @parent_work.class.to_s,
    child_model: child_model.to_s
  )

  # TODO: clean up image_files and pdf_paths
end