Sha256: 51fda9d9e983ff723f37396cad8c45df36ef16b925a3dbef30848588eebc87d3

Contents?: true

Size: 1.77 KB

Versions: 25

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true
class BatchCreateJob < Hyrax::ApplicationJob
  queue_as Hyrax.config.ingest_queue_name

  before_enqueue do |job|
    operation = job.arguments.last
    operation.pending_job(self)
  end

  # This copies metadata from the passed in attribute to all of the works that
  # are members of the given upload set
  # @param [User] user
  # @param [Hash<String => String>] titles
  # @param [Hash<String => String>] resource_types
  # @param [Array<String>] uploaded_files Hyrax::UploadedFile IDs
  # @param [Hash] attributes attributes to apply to all works, including :model
  # @param [Hyrax::BatchCreateOperation] operation
  def perform(user, titles, resource_types, uploaded_files, attributes, operation)
    operation.performing!
    titles ||= {}
    resource_types ||= {}
    create(user, titles, resource_types, uploaded_files, attributes, operation)
  end

  private

  def create(user, titles, resource_types, uploaded_files, attributes, operation)
    model = attributes.delete(:model) || attributes.delete('model')
    raise ArgumentError, 'attributes must include "model" => ClassName.to_s' unless model
    uploaded_files.each do |upload_id|
      title = [titles[upload_id]] if titles[upload_id]
      resource_type = Array.wrap(resource_types[upload_id]) if resource_types[upload_id]
      attributes = attributes.merge(uploaded_files: [upload_id],
                                    title: title,
                                    resource_type: resource_type)
      child_operation = Hyrax::Operation.create!(user: user,
                                                 operation_type: "Create Work",
                                                 parent: operation)
      CreateWorkJob.perform_later(user, model, attributes, child_operation)
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/jobs/batch_create_job.rb
hyrax-5.0.0 app/jobs/batch_create_job.rb
hyrax-5.0.0.rc3 app/jobs/batch_create_job.rb
hyrax-5.0.0.rc2 app/jobs/batch_create_job.rb
hyrax-5.0.0.rc1 app/jobs/batch_create_job.rb
hyrax-3.6.0 app/jobs/batch_create_job.rb
hyrax-4.0.0 app/jobs/batch_create_job.rb
hyrax-4.0.0.rc3 app/jobs/batch_create_job.rb
hyrax-4.0.0.rc2 app/jobs/batch_create_job.rb
hyrax-4.0.0.rc1 app/jobs/batch_create_job.rb
hyrax-3.5.0 app/jobs/batch_create_job.rb
hyrax-4.0.0.beta2 app/jobs/batch_create_job.rb
hyrax-3.4.2 app/jobs/batch_create_job.rb
hyrax-4.0.0.beta1 app/jobs/batch_create_job.rb
hyrax-3.4.1 app/jobs/batch_create_job.rb
hyrax-3.4.0 app/jobs/batch_create_job.rb
hyrax-3.3.0 app/jobs/batch_create_job.rb
hyrax-3.2.0 app/jobs/batch_create_job.rb
hyrax-3.1.0 app/jobs/batch_create_job.rb
hyrax-3.0.2 app/jobs/batch_create_job.rb