Class: CdmMigrator::CreateWorkJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/cdm_migrator/create_work_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(ingest_work, user, admin_set_id, collection_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/jobs/cdm_migrator/create_work_job.rb', line 5

def perform(ingest_work, user, admin_set_id, collection_id)
  admin_set = ::AdminSet.find(admin_set_id) rescue nil
  collection = Hyrax.config.collection_class.find(collection_id) rescue nil
  work = Object.const_get(ingest_work.work_type).new
  work.(user)
  work.attributes = ingest_work.data
  work.member_of_collections = [collection] if collection
  work.admin_set = admin_set if admin_set
  work.date_uploaded = DateTime.now
  add_configured_permissions(work)
  work.try(:to_controlled_vocab)
  begin
    work.save!
  # Weird error where descriptions with whitespace chars \n or \r don't save the 1st time

  # but do on the second

  rescue Ldp::BadRequest
    old_descr = work.description.clone.to_a
    work.description = work.description.map { |w| w.gsub("\n","").gsub("\r","") }
    work.save!
    work.description = old_descr
    work.save!
  end
  # Creating file (sets) with Hyrax::Actors::OrderedMembersActor is now the default.

  # To use the original Hyrax::Actors::FileSetActor, replace the line below with

  # BatchCreateFilesJob.perform_later(work, ingest_work, user)

  BatchCreateFilesWithOrderedMembersJob.perform_later(work, ingest_work, user)
end