Class: Hyrax::FileSet

Inherits:
Resource
  • Object
show all
Defined in:
app/models/hyrax/file_set.rb,
app/models/concerns/hyrax/file_set/indexing.rb,
app/models/concerns/hyrax/file_set/querying.rb,
app/models/concerns/hyrax/file_set/derivatives.rb,
app/models/concerns/hyrax/file_set/belongs_to_works.rb,
app/models/concerns/hyrax/file_set/characterization.rb

Overview

Valkyrie model for ‘FileSet` domain objects in the Hydra Works model.

## Relationships

### FileSet and Work

  • Defined: The relationship is defined by the inverse relationship stored in the work’s ‘:member_ids` attribute.

  • Tested: The test for the Work class tests the relationship.

  • FileSet to Work: (n..1) A FileSet must be in one and only one work. A Work can have zero to many FileSets.

  • See Hyrax::Work for code to get and set file sets for the work.

### FileSet and FileMetadata

  • Defined: The relationship is defined by the FileSet’s ‘:file_ids` attribute.

  • FileSet to FileMetadata: (0..n) A FileSet can have many FileMetadatas. A FileMetadata must be in one and only one FileSet.

### FileMetadata and Files

  • Defined: The relationship is defined by the FileMetadata’s ‘:file_identifier` attribute.

  • FileMetadata to File: (1..1) A FileMetadata can have one and only one File

Examples:

Get Work for a FileSet:

work = Hyrax.custom_queries.find_parent_work(resource: file_set)

Get all FileMetadata for a FileSet:

 = Hyrax.custom_queries.find_files(file_set: file_set)

Attach a File to a FileSet through a FileMetadata. This will create

a  for a File object, attach the File to the , and
attach that  to a given FileSet.
  ::Hyrax::ValkyrieUpload.file(
    io: file_io,
    filename: "myfile.jpg",
    file_set: file_set,
    use: pcdm_use,
    user: user
  )

Get a File for a FileMetadata

file = Hyrax.storage_adapter.find_by(id: .file_identifier)

See Also:

Direct Known Subclasses

FileSet

Defined Under Namespace

Modules: BelongsToWorks, Characterization, Derivatives, Indexing, Querying

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, acts_as_flexible_resource, collection?, #collection?, #file?, file?, #file_set?, #flexible?, flexible?, human_readable_type, inherited, pcdm_collection?, #pcdm_collection?, #pcdm_object?, #permission_manager, to_rdf_representation, #to_rdf_representation, #visibility, #visibility=, #wings?, work?, #work?

Methods included from WithEmbargoesAndLeases

#embargo, #embargo=, #lease, #lease=

Methods included from WithEvents

#event_class, #events, #log_event, #stream

Class Method Details

.file_set?Boolean

Returns true.

Returns:

  • (Boolean)

    true



144
145
146
# File 'app/models/hyrax/file_set.rb', line 144

def self.file_set?
  true
end

.model_name(name_class: Hyrax::Name) ⇒ Object



57
58
59
# File 'app/models/hyrax/file_set.rb', line 57

def self.model_name(name_class: Hyrax::Name)
  @_model_name ||= name_class.new(self, nil, 'FileSet')
end

.pcdm_object?Boolean

Returns true.

Returns:

  • (Boolean)

    true



150
151
152
# File 'app/models/hyrax/file_set.rb', line 150

def self.pcdm_object?
  true
end

Instance Method Details

#extensions_and_mime_typesArray

rubocop:disable Metrics/MethodLength

Examples:

[{:id=>"123", :extension=>"pdf", :mime_type=>"application/pdf", :name=>nil, :use=>"OriginalFile"},
 {:id=>"234", :extension=>"jpeg", :mime_type=>"application/octet-stream", :name=>"thumbnail", :use=>"ThumbnailImage"}]

Returns:

  • (Array)

    All ids, extensions, mime types, names, and uses



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/models/hyrax/file_set.rb', line 117

def extensions_and_mime_types
  return [] if file_ids.empty?
  Hyrax.custom_queries.find_files(file_set: self).each_with_object([]) do |fm, arr|
    next unless fm.original_filename
    extension = File.extname(fm.original_filename)
    next if extension.empty?
    use = fm.filtered_pcdm_use.first.to_s.split("#").last
    name = use == 'OriginalFile' ? nil : File.basename(fm.original_filename, extension).split('-').last
    arr << {
      id: fm.id.to_s,
      extension: extension[1..], # remove leading '.'
      mime_type: fm.mime_type,
      name: name,
      use: use
    }
  end
  # rubocop:enable Metrics/MethodLength
end

#extracted_textHyrax::FileMetadata?

Returns:



100
101
102
103
104
# File 'app/models/hyrax/file_set.rb', line 100

def extracted_text
  Hyrax.custom_queries.find_extracted_text(file_set: self)
rescue Valkyrie::Persistence::ObjectNotFoundError
  nil
end

#extracted_text_idValkyrie::ID?

Returns:

  • (Valkyrie::ID, nil)


107
108
109
# File 'app/models/hyrax/file_set.rb', line 107

def extracted_text_id
  extracted_text&.id
end

#iiif_idString, Nil

Returns versioned identifier suitable for use in a IIIF manifest.

Returns:

  • (String, Nil)

    versioned identifier suitable for use in a IIIF manifest



79
80
81
82
83
84
85
# File 'app/models/hyrax/file_set.rb', line 79

def iiif_id
  orig_file = original_file
  return nil if orig_file.nil? || orig_file.file_identifier.blank?
  latest_file = Hyrax::VersioningService.latest_version_of(orig_file)
  version = latest_file&.version_id ? Digest::MD5.hexdigest(latest_file.version_id) : nil
  "#{id}/files/#{orig_file.id}#{'/' + version if version}"
end

#original_fileHyrax::FileMetadata?

Returns:



67
68
69
70
71
# File 'app/models/hyrax/file_set.rb', line 67

def original_file
  Hyrax.custom_queries.find_original_file(file_set: self)
rescue Valkyrie::Persistence::ObjectNotFoundError
  nil
end

#original_file_idValkyrie::ID?

Returns:

  • (Valkyrie::ID, nil)


74
75
76
# File 'app/models/hyrax/file_set.rb', line 74

def original_file_id
  original_file&.id
end

#representative_idValkyrie::ID

Returns:

  • (Valkyrie::ID)


138
139
140
# File 'app/models/hyrax/file_set.rb', line 138

def representative_id
  id
end

#thumbnailHyrax::FileMetadata?

Returns:



88
89
90
91
92
# File 'app/models/hyrax/file_set.rb', line 88

def thumbnail
  Hyrax.custom_queries.find_thumbnail(file_set: self)
rescue Valkyrie::Persistence::ObjectNotFoundError
  nil
end

#thumbnail_idValkyrie::ID?

Returns:

  • (Valkyrie::ID, nil)


95
96
97
# File 'app/models/hyrax/file_set.rb', line 95

def thumbnail_id
  thumbnail&.id
end