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.apply_depositor_metadata(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!
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
BatchCreateFilesWithOrderedMembersJob.perform_later(work, ingest_work, user)
end
|