Class: Hyrax::WorkResourceQueryService

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

Overview

Note:

This was extracted from the ProxyDepositRequest, which was coordinating lots of effort. It was also an ActiveRecord object that required lots of Fedora/Solr interactions.

Responsible for retrieving information based on the given work.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:) ⇒ WorkResourceQueryService

Returns a new instance of WorkResourceQueryService.

Parameters:

  • id (String)
    • The id of the work



11
12
13
# File 'app/services/hyrax/work_resource_query_service.rb', line 11

def initialize(id:)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'app/services/hyrax/work_resource_query_service.rb', line 14

def id
  @id
end

Instance Method Details

#deleted_work?Boolean

Returns if the work has been deleted.

Returns:

  • (Boolean)

    if the work has been deleted



17
18
19
20
21
22
# File 'app/services/hyrax/work_resource_query_service.rb', line 17

def deleted_work?
  Hyrax.query_service.find_by(id: id)
  false
rescue Valkyrie::Persistence::ObjectNotFoundError
  true
end

#to_sObject



31
32
33
34
35
36
37
# File 'app/services/hyrax/work_resource_query_service.rb', line 31

def to_s
  if deleted_work?
    'work not found'
  else
    solr_doc.to_s
  end
end

#workObject

Raises:



24
25
26
27
28
29
# File 'app/services/hyrax/work_resource_query_service.rb', line 24

def work
  # Need to ensure it is a work?
  resource = Hyrax.query_service.find_by(id: id)
  raise ModelMismatchError, "Expected work but got #{resource.class}" unless resource.work?
  resource
end