Class: Wings::CustomQueries::FindFileMetadata
- Inherits:
-
Object
- Object
- Wings::CustomQueries::FindFileMetadata
- Defined in:
- lib/wings/services/custom_queries/find_file_metadata.rb
Overview
Custom query override specific to Wings for finding Hydra::PCDM::File and converting to 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:, use_valkyrie: true) ⇒ Hyrax::FileMetadata, Hydra::PCDM::File
Find a Hyrax::FileMetadata using a Valkyrie ID,.
-
#find_file_metadata_by_alternate_identifier(alternate_identifier:, use_valkyrie: true) ⇒ Hyrax::FileMetadata, Hydra::PCDM::File
Find a Hyrax::FileMetadata using an alternate ID, and map it to a.
-
#find_many_file_metadata_by_ids(ids:, use_valkyrie: true) ⇒ Array<Hyrax::FileMetadata, Hydra::PCDM::File>
Find an array of file metadata using Valkyrie IDs, and map them to Hyrax::FileMetadata maintaining order based on given ids.
-
#find_many_file_metadata_by_use(resource:, use:, use_valkyrie: true) ⇒ Array<Hyrax::FileMetadata, Hydra::PCDM::File>
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.
17 18 19 |
# File 'lib/wings/services/custom_queries/find_file_metadata.rb', line 17 def initialize(query_service:) @query_service = query_service end |
Instance Attribute Details
#query_service ⇒ Object (readonly)
Returns the value of attribute query_service.
21 22 23 |
# File 'lib/wings/services/custom_queries/find_file_metadata.rb', line 21 def query_service @query_service end |
Class Method Details
.queries ⇒ Object
10 11 12 13 14 15 |
# File 'lib/wings/services/custom_queries/find_file_metadata.rb', line 10 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:, use_valkyrie: true) ⇒ Hyrax::FileMetadata, Hydra::PCDM::File
Find a Hyrax::FileMetadata using a Valkyrie ID,
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wings/services/custom_queries/find_file_metadata.rb', line 35 def (id:, use_valkyrie: true) fcrepo_flag = begin ::Valkyrie::StorageAdapter.adapter_for(id: id).is_a?(::Valkyrie::Storage::Fedora) rescue ::Valkyrie::StorageAdapter::AdapterNotFoundError true # assume fcrepo if we can't find an adapter end if fcrepo_flag (alternate_identifier: id, use_valkyrie: use_valkyrie) else result = ActiveFedora::Base.where(file_identifier_ssim: id.to_s).first || raise(Hyrax::ObjectNotFoundError) result.valkyrie_resource end end |
#find_file_metadata_by_alternate_identifier(alternate_identifier:, use_valkyrie: true) ⇒ Hyrax::FileMetadata, Hydra::PCDM::File
Find a Hyrax::FileMetadata using an alternate ID, and map it to a
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/wings/services/custom_queries/find_file_metadata.rb', line 63 def (alternate_identifier:, use_valkyrie: true) alternate_identifier = ::Valkyrie::ID.new(alternate_identifier).to_s object = Hydra::PCDM::File.find(alternate_identifier) raise Hyrax::ObjectNotFoundError if object.new_record? if use_valkyrie == false warn_about_deprecation return object end object.valkyrie_resource end |
#find_many_file_metadata_by_ids(ids:, use_valkyrie: true) ⇒ Array<Hyrax::FileMetadata, Hydra::PCDM::File>
Ignores non-existent ids and ids for non-file metadata resources.
Find an array of file metadata using Valkyrie IDs, and map them to Hyrax::FileMetadata maintaining order based on given ids.
87 88 89 90 91 92 93 |
# File 'lib/wings/services/custom_queries/find_file_metadata.rb', line 87 def (ids:, use_valkyrie: true) ids.each_with_object([]) do |alt_id, results| results << (alternate_identifier: alt_id, use_valkyrie: use_valkyrie) rescue Hyrax::ObjectNotFoundError next end end |
#find_many_file_metadata_by_use(resource:, use:, use_valkyrie: true) ⇒ Array<Hyrax::FileMetadata, Hydra::PCDM::File>
Find file metadata for files within a resource that have the requested use.
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/wings/services/custom_queries/find_file_metadata.rb', line 109 def (resource:, use:, use_valkyrie: true) pcdm_files = (ids: resource.file_ids, use_valkyrie: false) pcdm_files.select! { |pcdm_file| pcdm_file..type.include?(use) } if use_valkyrie == false warn_about_deprecation return pcdm_files end pcdm_files.map(&:valkyrie_resource) end |