Sha256: d5a7ea0f192f3f0dd6f9b376c53a5de0a01867371a6f7d6f837097c2ef34cea6

Contents?: true

Size: 1.61 KB

Versions: 20

Compression:

Stored size: 1.61 KB

Contents

# Converts UploadedFiles into FileSets and attaches them to works.
class AttachFilesToWorkWithOrderedMembersJob < AttachFilesToWorkJob
  attr_reader :ordered_members, :uploaded_files

  # @param [ActiveFedora::Base] work - the work object
  # @param [Array<Hyrax::UploadedFile>] uploaded_files - an array of files to attach
  def perform(work, uploaded_files, **work_attributes)
    @uploaded_files = uploaded_files
    validate_files!(uploaded_files)
    @ordered_members = work.ordered_members.to_a # Build array of ordered members
    depositor = proxy_or_depositor(work)
    user = User.find_by_user_key(depositor)
    metadata = visibility_attributes(work_attributes)
    add_uploaded_files(user, metadata, work)
    add_ordered_members(user, work)
  end

  private

    def add_uploaded_files(user, metadata, work)
      work_permissions = work.permissions.map(&:to_hash)
      uploaded_files.each do |uploaded_file|
        actor = file_set_actor_class.new(FileSet.create, user)
        actor.create_metadata(metadata)
        actor.create_content(uploaded_file)
        actor.attach_to_work(work)
        actor.file_set.permissions_attributes = work_permissions
        ordered_members << actor.file_set
        uploaded_file.update(file_set_uri: actor.file_set.uri)
      end
    end

    # Add all file_sets as ordered_members in a single action
    def add_ordered_members(user, work)
      actor = Hyrax::Actors::OrderedMembersActor.new(ordered_members, user)
      actor.attach_ordered_members_to_work(work)
    end

    class_attribute :file_set_actor_class
    self.file_set_actor_class = Hyrax::Actors::FileSetOrderedMembersActor
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.9.5 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.9.4 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.9.3 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.9.2 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.9.1 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.9.0 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.8.0 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.7.2 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.7.1 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.7.0 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.6.0 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-3.0.0.pre.rc1 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-3.0.0.pre.beta3 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.5.1 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.5.0 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-3.0.0.pre.beta2 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.4.1 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-3.0.0.pre.beta1 app/jobs/attach_files_to_work_with_ordered_members_job.rb
hyrax-2.4.0 app/jobs/attach_files_to_work_with_ordered_members_job.rb