Class: Hyrax::CustomQueries::FindFileMetadata
- Inherits:
-
Object
- Object
- Hyrax::CustomQueries::FindFileMetadata
- Defined in:
- app/services/hyrax/custom_queries/find_file_metadata.rb
Overview
Provide custom queries for finding Hyrax::FileMetadata
Instance Attribute Summary collapse
-
#query_service ⇒ Object
readonly
Returns the value of attribute query_service.
Class Method Summary collapse
Instance Method Summary collapse
-
#find_file_metadata_by(id:) ⇒ Hyrax::FileMetadata
Find a file metadata using a Valkyrie ID, and map it to a Hyrax::FileMetadata.
-
#find_file_metadata_by_alternate_identifier(alternate_identifier:) ⇒ Hyrax::FileMetadata
Find a file metadata using an alternate ID, and map it to a Hyrax::FileMetadata.
-
#find_many_file_metadata_by_ids(ids:) ⇒ Array<Hyrax::FileMetadata>
Find an array of file metadata using Valkyrie IDs, and map them to Hyrax::FileMetadata maintaining order based on given ids NOTE: Ignores non-existent ids and ids for non-file metadata resources.
-
#find_many_file_metadata_by_use(resource:, use:) ⇒ Array<Hyrax::FileMetadata] or empty array if there are no files with the requested use
Find file metadata for files within a resource that have the requested use.
-
#initialize(query_service:) ⇒ FindFileMetadata
constructor
A new instance of FindFileMetadata.
Constructor Details
#initialize(query_service:) ⇒ FindFileMetadata
Returns a new instance of FindFileMetadata.
19 20 21 |
# File 'app/services/hyrax/custom_queries/find_file_metadata.rb', line 19 def initialize(query_service:) @query_service = query_service end |
Instance Attribute Details
#query_service ⇒ Object (readonly)
Returns the value of attribute query_service.
23 24 25 |
# File 'app/services/hyrax/custom_queries/find_file_metadata.rb', line 23 def query_service @query_service end |
Class Method Details
.queries ⇒ Object
12 13 14 15 16 17 |
# File 'app/services/hyrax/custom_queries/find_file_metadata.rb', line 12 def self.queries [:find_file_metadata_by, :find_file_metadata_by_alternate_identifier, :find_many_file_metadata_by_ids, :find_many_file_metadata_by_use] end |
Instance Method Details
#find_file_metadata_by(id:) ⇒ Hyrax::FileMetadata
Find a file metadata using a Valkyrie ID, and map it to a Hyrax::FileMetadata
30 31 32 33 34 35 36 37 |
# File 'app/services/hyrax/custom_queries/find_file_metadata.rb', line 30 def (id:) result = query_service.find_by(id: id) unless result.is_a? Hyrax::FileMetadata raise ::Valkyrie::Persistence::ObjectNotFoundError, "Result type #{result.internal_resource} for id #{id} is not a `Hyrax::FileMetadata`" end result end |
#find_file_metadata_by_alternate_identifier(alternate_identifier:) ⇒ Hyrax::FileMetadata
Find a file metadata using an alternate ID, and map it to a Hyrax::FileMetadata
43 44 45 46 47 48 49 50 |
# File 'app/services/hyrax/custom_queries/find_file_metadata.rb', line 43 def (alternate_identifier:) result = query_service.find_by_alternate_identifier(alternate_identifier: alternate_identifier) unless result.is_a? Hyrax::FileMetadata raise ::Valkyrie::Persistence::ObjectNotFoundError, "Result type #{result.internal_resource} for alternate_identifier #{alternate_identifier} is not a `Hyrax::FileMetadata`" end result end |
#find_many_file_metadata_by_ids(ids:) ⇒ Array<Hyrax::FileMetadata>
Find an array of file metadata using Valkyrie IDs, and map them to Hyrax::FileMetadata maintaining order based on given ids NOTE: Ignores non-existent ids and ids for non-file metadata resources.
56 57 58 59 |
# File 'app/services/hyrax/custom_queries/find_file_metadata.rb', line 56 def (ids:) results = query_service.find_many_by_ids(ids: ids) results.select { |resource| resource.is_a? Hyrax::FileMetadata } end |
#find_many_file_metadata_by_use(resource:, use:) ⇒ Array<Hyrax::FileMetadata] or empty array if there are no files with the requested use
Find file metadata for files within a resource that have the requested use.
66 67 68 69 70 71 |
# File 'app/services/hyrax/custom_queries/find_file_metadata.rb', line 66 def (resource:, use:) return [] if resource.try(:file_ids).blank? results = (ids: resource.file_ids) results.select { |fm| fm.pcdm_use.include?(use) } end |