Class: Sipity::Jobs::DoiCreationRequestJob

Inherits:
Object
  • Object
show all
Defined in:
app/jobs/sipity/jobs/doi_creation_request_job.rb

Overview

Responsible for processing a remote request for minting a DOI.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sip_id, options = {}) ⇒ DoiCreationRequestJob

Returns a new instance of DoiCreationRequestJob


9
10
11
12
13
14
15
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 9

def initialize(sip_id, options = {})
  @repository = options.fetch(:repository) { default_repository }
  @minter = options.fetch(:minter) { default_minter }
  @minter_handled_exceptions = options.fetch(:minter_handled_exceptions) { default_minter_handled_exceptions }
  @sip = repository.find_sip(sip_id)
  @doi_creation_request = repository.find_doi_creation_request(sip: sip)
end

Instance Attribute Details

#doi_creation_requestObject (readonly)

Returns the value of attribute doi_creation_request


16
17
18
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 16

def doi_creation_request
  @doi_creation_request
end

#metadata_gathererObject (readonly)

Returns the value of attribute metadata_gatherer


16
17
18
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 16

def 
  @metadata_gatherer
end

#minterObject (readonly)

Returns the value of attribute minter


16
17
18
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 16

def minter
  @minter
end

#minter_handled_exceptionsObject (readonly)

Returns the value of attribute minter_handled_exceptions


16
17
18
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 16

def minter_handled_exceptions
  @minter_handled_exceptions
end

#repositoryObject (readonly)

Returns the value of attribute repository


16
17
18
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 16

def repository
  @repository
end

#sipObject (readonly)

Returns the value of attribute sip


16
17
18
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 16

def sip
  @sip
end

Class Method Details

.submit(sip_id) ⇒ Object


5
6
7
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 5

def self.submit(sip_id)
  new(sip_id).work
end

Instance Method Details

#default_minterObject (private)


57
58
59
60
61
62
63
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 57

def default_minter
  # REVIEW: Do I need an insulating layer?
  # I chose a lambda instead of capturing the method as the method signature
  # of the underlying Ezid::Identifer is not under my control and could be
  # something I would want to tease apart.
  ->() { Ezid::Identifier.create(metadata: ) }
end

#default_minter_handled_exceptionsObject (private)


65
66
67
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 65

def default_minter_handled_exceptions
  Ezid::Error
end

#default_repositoryObject (private)


69
70
71
72
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 69

def default_repository
  # REVIEW: Do I want multiple repositories to exist?
  Repository.new
end

#guard_doi_creation_request_state!Object (private)


30
31
32
33
34
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 30

def guard_doi_creation_request_state!
  return true if doi_creation_request.request_failed?
  return true if doi_creation_request.
  fail Exceptions::InvalidDoiCreationRequestStateError, entity: doi_creation_request, actual: doi_creation_request.state
end

#handle_remote_response!(response) ⇒ Object (private)


48
49
50
51
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 48

def handle_remote_response!(response)
  repository.update_sip_with_doi_predicate!(sip: sip, values: response.id)
  repository.update_sip_doi_creation_request_state!(sip: sip, state: :request_completed)
end

#metadataObject (private)


53
54
55
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 53

def 
  repository.(sip: sip)
end

#submit_remote_request!Object (private)


40
41
42
43
44
45
46
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 40

def submit_remote_request!
  
  yield(minter.call())
rescue *Array.wrap(minter_handled_exceptions) => e
  repository.update_sip_doi_creation_request_state!(sip: sip, state: :request_failed, response_message: e.message)
  raise e
end

#transition_doi_creation_request_to_submitted!Object (private)


36
37
38
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 36

def 
  repository.update_sip_doi_creation_request_state!(sip: sip, state: :request_submitted)
end

#workObject


18
19
20
21
22
23
24
25
26
# File 'app/jobs/sipity/jobs/doi_creation_request_job.rb', line 18

def work
  # TODO: Do we need to track history for the given person?
  #   If so, who is the requester? Is it the DoiCreationRequest creating_user
  # TODO: Do we need to enforce via the authorization layer?
  guard_doi_creation_request_state!
  submit_remote_request! do |response|
    handle_remote_response!(response)
  end
end