Class: Wings::CustomQueries::FindBySourceIdentifier

Inherits:
Object
  • Object
show all
Defined in:
app/services/wings/custom_queries/find_by_source_identifier.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_service:) ⇒ FindBySourceIdentifier

Returns a new instance of FindBySourceIdentifier.



15
16
17
# File 'app/services/wings/custom_queries/find_by_source_identifier.rb', line 15

def initialize(query_service:)
  @query_service = query_service
end

Instance Attribute Details

#query_serviceObject (readonly)

Returns the value of attribute query_service.



12
13
14
# File 'app/services/wings/custom_queries/find_by_source_identifier.rb', line 12

def query_service
  @query_service
end

Class Method Details

.queriesObject

Custom query override specific to Wings



8
9
10
# File 'app/services/wings/custom_queries/find_by_source_identifier.rb', line 8

def self.queries
  [:find_by_property_value]
end

Instance Method Details

#find_by_property_value(property:, value:, search_field:, use_valkyrie: Hyrax.config.use_valkyrie?) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/wings/custom_queries/find_by_source_identifier.rb', line 20

def find_by_property_value(property:, value:, search_field:, use_valkyrie: Hyrax.config.use_valkyrie?)
  # rubocop:enable Lint/UnusedMethodArgument
  # NOTE: This is using the Bulkrax::ObjectFactory (e.g. the one envisioned for ActiveFedora).
  # In doing this, we avoid the situation where Bulkrax::ValkyrieObjectFactory calls this custom query.

  # This is doing a solr search first, so we have to use the search_field instead of the property for "field"
  # If it cannot find the object in Solr, it falls back to an ActiveFedora search, if the object is an ActiveFedora object
  af_object = Bulkrax::ObjectFactory.search_by_property(
    value: value,
    klass: ActiveFedora::Base,
    field: search_field,
    name_field: property
  )

  return if af_object.blank?
  return af_object unless use_valkyrie

  resource_factory.to_resource(object: af_object)
end