Class: CdmMigrator::CdmIngestFilesJob

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

Instance Method Summary collapse

Instance Method Details

#log(user) ⇒ Object



29
30
31
32
# File 'app/jobs/cdm_migrator/cdm_ingest_files_job.rb', line 29

def log(user)
  Hyrax::Operation.create!(user: user,
                           operation_type: "Attach Remote File")
end

#perform(fs, url, user, ingest_work = nil, last_file = false) ⇒ Object



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

def perform(fs, url, user, ingest_work = nil, last_file = false)
  if url.include?("http") && File.extname(url).include?("pdf")
    download = open(url)
    dir = Rails.root.join('public', 'uploads', 'csv_pdfs')
    FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
    filename = download.base_uri.to_s.split('/').last
    url = dir.join(filename)
    if fs.title.empty?
      fs.title << filename.split('.').first
      fs.save
    end
    IO.copy_stream(download, url)
    url = "file://"+url.to_s
  end
  uri = URI.parse(url.gsub(' ','%20').gsub(/[\[\]@#\$\*{}]/, ""))
  if uri.scheme == 'file'
    IngestLocalFileJob.perform_now(fs, url.gsub('file://',''), user)
  else
    URI.parse(url.gsub(' ','%20'))
    ImportUrlJob.perform_now(fs, log(user))
  end
  ingest_work.update_attribute('complete', true) if last_file
end