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 FileMetadata for a File object, attach the File to the FileMetadata, and
attach that FileMetadata 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

#==, collection?, #collection?, #embargo, #embargo=, file?, #file?, #file_set?, human_readable_type, #lease, #lease=, pcdm_collection?, #pcdm_collection?, #pcdm_object?, #permission_manager, #to_rdf_representation, to_rdf_representation, #visibility, #visibility=, #work?, work?

Methods included from WithEvents

#event_class, #events, #log_event, #stream

Class Method Details

.file_set?Boolean

Returns true.

Returns:

  • (Boolean)

    true



117
118
119
# File 'app/models/hyrax/file_set.rb', line 117

def self.file_set?
  true
end

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



55
56
57
# File 'app/models/hyrax/file_set.rb', line 55

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



123
124
125
# File 'app/models/hyrax/file_set.rb', line 123

def self.pcdm_object?
  true
end

Instance Method Details

#extracted_textHyrax::FileMetadata?

Returns:



98
99
100
101
102
# File 'app/models/hyrax/file_set.rb', line 98

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)


105
106
107
# File 'app/models/hyrax/file_set.rb', line 105

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



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

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:



65
66
67
68
69
# File 'app/models/hyrax/file_set.rb', line 65

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)


72
73
74
# File 'app/models/hyrax/file_set.rb', line 72

def original_file_id
  original_file&.id
end

#representative_idValkyrie::ID

Returns:

  • (Valkyrie::ID)


111
112
113
# File 'app/models/hyrax/file_set.rb', line 111

def representative_id
  id
end

#thumbnailHyrax::FileMetadata?

Returns:



86
87
88
89
90
# File 'app/models/hyrax/file_set.rb', line 86

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

#thumbnail_idValkyrie::ID?

Returns:

  • (Valkyrie::ID, nil)


93
94
95
# File 'app/models/hyrax/file_set.rb', line 93

def thumbnail_id
  thumbnail&.id
end