Class: Hyrax::CustomQueries::FindFileMetadata

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/custom_queries/find_file_metadata.rb

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 'app/services/hyrax/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 'app/services/hyrax/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 'app/services/hyrax/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:) ⇒ Hyrax::FileMetadata

Find a file metadata using a Valkyrie ID, and map it to a Hyrax::FileMetadata

Parameters:

  • id (Valkyrie::ID, String)

Returns:

Raises:


28
29
30
31
32
33
34
35
# File 'app/services/hyrax/custom_queries/find_file_metadata.rb', line 28

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

Parameters:

  • alternate_identifier (Valkyrie::ID, String)

Returns:

Raises:


41
42
43
44
45
46
47
48
# File 'app/services/hyrax/custom_queries/find_file_metadata.rb', line 41

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.

Parameters:

  • ids (Array<Valkyrie::ID, String>)

Returns:

  • (Array<Hyrax::FileMetadata>)

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


54
55
56
57
# File 'app/services/hyrax/custom_queries/find_file_metadata.rb', line 54

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.

Examples:

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

Parameters:

  • use (RDF::URI)

    uri for the desired use Type

Returns:

  • (Array<Hyrax::FileMetadata] or empty array if there are no files with the requested use)

    Array<Hyrax::FileMetadata] or empty array if there are no files with the requested use


64
65
66
67
68
69
# File 'app/services/hyrax/custom_queries/find_file_metadata.rb', line 64

def (resource:, use:)
  return [] unless resource.try(:file_ids)

  results = (ids: resource.file_ids)
  results.select { |fm| fm.type.include?(use) }
end