Class: IiifPrint::SplitPdfs::ChildWorkCreationFromPdfService

Inherits:
Object
  • Object
show all
Defined in:
lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb

Class Method Summary collapse

Class Method Details

.count_existing_pdfs(_work) ⇒ Object

TODO: implement a method to count existing PDFs on a work to support

adding more PDFs to an existing work.


63
64
65
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 63

def self.count_existing_pdfs(_work)
  0
end

.filter_file_ids(input) ⇒ Object



51
52
53
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 51

def self.filter_file_ids(input)
  Array.wrap(input).select(&:present?)
end

.iiif_print_split?(work:) ⇒ Boolean

Is child work splitting defined for model?

Parameters:

  • A (GenericWork, etc)

    valid type of hyrax work

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 21

def self.iiif_print_split?(work:)
  # defined only if work has include IiifPrint.model_configuration with pdf_split_child_model
  return true if work.try(:iiif_print_config)&.pdf_split_child_model
  false
end

.pdf_paths(files:) ⇒ Array

Load an array of paths to pdf files

Parameters:

  • Hyrax::Upload (Array)

    file ids]

Returns:

  • (Array)

    String] file paths to temp directory



10
11
12
13
14
15
16
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 10

def self.pdf_paths(files:)
  upload_ids = filter_file_ids(files)
  return [] if upload_ids.empty?
  uploads = Hyrax::UploadedFile.find(upload_ids)
  paths = uploads.map(&method(:upload_path))
  pdfs_only_for(paths)
end

.pdfs?(paths:) ⇒ Boolean

Are there any PDF files?

Parameters:

  • String] (Array)

    paths to PDFs

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 30

def self.pdfs?(paths:)
  pdf_paths = pdfs_only_for(paths)
  return false unless pdf_paths.count.positive?
  true
end

.pdfs_only_for(paths) ⇒ Object

TODO: Consider other methods to identify a PDF file.

This sub-selection may need to be moved to use mimetype if there
is a need to support paths not ending in .pdf (i.e. remote_urls)


70
71
72
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 70

def self.pdfs_only_for(paths)
  paths.select { |path| path.end_with?('.pdf', '.PDF') }
end

.queue_job(work:, file_locations:, user:, admin_set_id:) ⇒ Object

Submit the job to split PDF into child works

Parameters:

  • A (GenericWork, etc)

    valid type of hyrax work

  • paths (Array<String>)

    to PDF attachments

  • user (User)
  • number (Integer)

    of pdfs already on existing work’s filesets (not yet implemented)



41
42
43
44
45
46
47
48
49
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 41

def self.queue_job(work:, file_locations:, user:, admin_set_id:)
  work.iiif_print_config.pdf_splitter_job.perform_later(
    work,
    file_locations,
    user,
    admin_set_id,
    count_existing_pdfs(work)
  )
end

.upload_path(upload) ⇒ Object

Given Hyrax::Upload object, return path to file on local filesystem



56
57
58
59
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 56

def self.upload_path(upload)
  # so many layers to this onion:
  upload.file.file.file
end