From d99da3c18558e1ac808217db9ec7911be9de4026 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Sat, 18 Nov 2023 01:54:14 -0500 Subject: [PATCH] Create Child Works based on PDF fileset's file The incoming path has been using a temp file location which no longer exists when the ChildWorksFromPdfJob runs. This change uses the fileset's actual file to trigger the child works creation behavior. --- .../iiif_print/actors/file_set_actor_decorator.rb | 11 ++++++++++- .../child_work_creation_from_pdf_service.rb | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/actors/iiif_print/actors/file_set_actor_decorator.rb b/app/actors/iiif_print/actors/file_set_actor_decorator.rb index fda63b65..7a3248f3 100644 --- a/app/actors/iiif_print/actors/file_set_actor_decorator.rb +++ b/app/actors/iiif_print/actors/file_set_actor_decorator.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true # override to add PDF splitting for file sets and remove splitting upon fileset delete + +# Depending on whether we have an uploaded file or a remote url, the sequence of calling +# attach_to_work and create_content will switch. module IiifPrint module Actors module FileSetActorDecorator @@ -9,7 +12,9 @@ def create_content(file, relation = :original_file, from_url: false) super if from_url - args = { file_set: file_set, file: file, import_url: file_set.import_url, user: @user } + # in this case, the file that came in is a temp file, and we need to use the actual file. + # the file was attached to the file_set in Hyrax::ImportUrlJob so we can just access it. + args = { file_set: file_set, file: file_set.files.first, import_url: file_set.import_url, user: @user } returned_value = service.conditionally_enqueue(**args) Rails.logger.info("Result of #{returned_value} for conditional enqueueing of #{args.inspect}") true @@ -24,6 +29,10 @@ def attach_to_work(work, file_set_params = {}) # Locks to ensure that only one process is operating on the list at a time. super + # when we are importing a remote_url, this method is called before the file is attached. + # We want to short-circuit the process and prevent unnecessarily confusing logging. + return unless @file + args = { file_set: file_set, work: work, file: @file, user: @user } returned_value = service.conditionally_enqueue(**args) Rails.logger.info("Result of #{returned_value} for conditional enqueueing of #{args.inspect}") diff --git a/lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb b/lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb index 6d2309cb..7034c95f 100644 --- a/lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb +++ b/lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb @@ -28,7 +28,7 @@ def self.conditionally_enqueue(file_set:, file:, user:, import_url: nil, work: n return :no_split_for_parent unless iiif_print_split?(work: work) return :no_pdfs_for_import_url if import_url && !pdfs?(paths: [import_url]) file_locations = if import_url - [file.path] + [Hyrax::WorkingDirectory.find_or_retrieve(file.id, file_set.id)] else pdf_paths(files: [file.try(:id)&.to_s].compact) end