Class: ValkyrieIngestJob

Inherits:
Hyrax::ApplicationJob show all
Defined in:
app/jobs/valkyrie_ingest_job.rb

Overview

Ingests a Hyrax::UploadedFile as file member of a Hyrax::FileSet.

The Hyrax::UploadedFile is passed into #perform, and should have a Hyrax::UploadedFile#file_set_uri identifying an existing Hyrax::FileSet.

Instance Method Summary collapse

Instance Method Details

#ingest(file:, pcdm_use:) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/jobs/valkyrie_ingest_job.rb', line 25

def ingest(file:, pcdm_use:)
  file_set_uri = Valkyrie::ID.new(file.file_set_uri)
  file_set = Hyrax.query_service.find_by(id: file_set_uri)

   = upload_file(
    file: file,
    file_set: file_set,
    pcdm_use: pcdm_use,
    user: file.user
  )

  ValkyrieCreateDerivativesJob.perform_later(file_set.id.to_s, .id.to_s)
end

#perform(file, pcdm_use: Hyrax::FileMetadata::Use::ORIGINAL_FILE) ⇒ Object

Parameters:

  • file (Hyrax::UploadedFile)
  • pcdm_use (RDF::URI) (defaults to: Hyrax::FileMetadata::Use::ORIGINAL_FILE)

    is the use/type to apply to the created FileMetadata

See Also:


15
16
17
# File 'app/jobs/valkyrie_ingest_job.rb', line 15

def perform(file, pcdm_use: Hyrax::FileMetadata::Use::ORIGINAL_FILE)
  ingest(file: file, pcdm_use: pcdm_use)
end

#upload_file(file:, file_set:, pcdm_use:, user: nil) ⇒ Hyrax::FileMetadata

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the metadata representing the uploaded file.

Parameters:

Returns:


48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/jobs/valkyrie_ingest_job.rb', line 48

def upload_file(file:, file_set:, pcdm_use:, user: nil)
  carrier_wave_sanitized_file = file.uploader.file
  # Pull file, since carrierwave files don't respond to a proper IO #read. See
  # https://github.com/carrierwaveuploader/carrierwave/issues/1959
  file_io = carrier_wave_sanitized_file.to_file

  ::Hyrax::ValkyrieUpload.file(
    io: file_io,
    filename: carrier_wave_sanitized_file.original_filename,
    file_set: file_set,
    use: pcdm_use,
    user: user
  )
end