Class: Wings::CustomQueries::FindFileMetadata

Inherits:
Object
  • Object
show all
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.

Examples:

Hyrax.custom_queries.(id: valkyrie_id, use_valkyrie: true)
Hyrax.custom_queries.(alternate_identifier: id, use_valkyrie: true)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_serviceObject (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

.queriesObject


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,

Parameters:

  • id (Valkyrie::ID, String)
  • use_valkyrie (boolean) (defaults to: true)

    defaults to true; optionally return ActiveFedora::File objects if false

Returns:

  • (Hyrax::FileMetadata, Hydra::PCDM::File)
    • when use_valkyrie is

    true, returns FileMetadata resource; otherwise, returns ActiveFedora PCDM::File

Raises:


35
36
37
# File 'lib/wings/services/custom_queries/find_file_metadata.rb', line 35

def (id:, use_valkyrie: true)
  (alternate_identifier: id, use_valkyrie: use_valkyrie)
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

Parameters:

  • alternate_identifier (Valkyrie::ID, String)
  • use_valkyrie (boolean) (defaults to: true)

    defaults to true; optionally return ActiveFedora::File objects if false

Returns:

  • (Hyrax::FileMetadata, Hydra::PCDM::File)
    • when use_valkyrie is

    true, returns FileMetadata resource; otherwise, returns ActiveFedora PCDM::File

Raises:


50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/wings/services/custom_queries/find_file_metadata.rb', line 50

def (alternate_identifier:, use_valkyrie: true)
  alternate_identifier = ::Valkyrie::ID.new(alternate_identifier)
  object = Hydra::PCDM::File.find(alternate_identifier.to_s)
  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>

Note:

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.

Parameters:

  • ids (Array<Valkyrie::ID, String>)
  • use_valkyrie (boolean) (defaults to: true)

    defaults to true; optionally return ActiveFedora::File objects if false

Returns:

  • (Array<Hyrax::FileMetadata, Hydra::PCDM::File>)

    or empty array if there are no ids or none of the ids map to Hyrax::FileMetadata


74
75
76
77
78
79
80
81
82
# File 'lib/wings/services/custom_queries/find_file_metadata.rb', line 74

def (ids:, use_valkyrie: true)
  ids.each_with_object([]) do |alt_id, results|
    begin
      results << (alternate_identifier: alt_id, use_valkyrie: use_valkyrie)
    rescue Hyrax::ObjectNotFoundError
      next
    end
  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.

Examples:

Hyrax.query_service.(use: ::RDF::URI("http://pcdm.org/ExtractedText"))

Parameters:

  • use (RDF::URI)

    uri for the desired use Type

  • use_valkyrie (boolean) (defaults to: true)

    defaults to true; optionally return ActiveFedora::File objects if false

Returns:

  • (Array<Hyrax::FileMetadata, Hydra::PCDM::File>)

    or empty array if there are no files with the requested use


98
99
100
101
102
103
104
105
106
107
108
# File 'lib/wings/services/custom_queries/find_file_metadata.rb', line 98

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