Class: Dor::Services::Client::ObjectWorkflow
- Inherits:
-
VersionedService
- Object
- VersionedService
- Dor::Services::Client::ObjectWorkflow
- Defined in:
- lib/dor/services/client/object_workflow.rb
Overview
API calls around workflow for an object.
Constant Summary
Constants inherited from VersionedService
VersionedService::EXCEPTION_CLASS, VersionedService::JSON_API_MIME_TYPE
Instance Attribute Summary collapse
-
#workflow_name ⇒ Object
readonly
Returns the value of attribute workflow_name.
Instance Method Summary collapse
-
#create(version:, lane_id: 'default', context: nil) ⇒ Object
Creates a workflow for a given object in the repository.
- #find ⇒ Workflow::Response::Workflow
-
#initialize(connection:, version:, object_identifier:, workflow_name:) ⇒ ObjectWorkflow
constructor
A new instance of ObjectWorkflow.
- #process(process) ⇒ Dor::Services::Client::Process
-
#skip_all(note:) ⇒ Object
Skips all steps in a workflow.
Methods inherited from VersionedService
Constructor Details
#initialize(connection:, version:, object_identifier:, workflow_name:) ⇒ ObjectWorkflow
Returns a new instance of ObjectWorkflow.
12 13 14 15 16 |
# File 'lib/dor/services/client/object_workflow.rb', line 12 def initialize(connection:, version:, object_identifier:, workflow_name:) super(connection: connection, version: version) @object_identifier = object_identifier @workflow_name = workflow_name end |
Instance Attribute Details
#workflow_name ⇒ Object (readonly)
Returns the value of attribute workflow_name.
8 9 10 |
# File 'lib/dor/services/client/object_workflow.rb', line 8 def workflow_name @workflow_name end |
Instance Method Details
#create(version:, lane_id: 'default', context: nil) ⇒ Object
Creates a workflow for a given object in the repository. If this particular workflow for this objects exists, it will replace the old workflow.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dor/services/client/object_workflow.rb', line 48 def create(version:, lane_id: 'default', context: nil) # rubocop:disable Metrics/AbcSize resp = connection.post do |req| req.url "#{api_version}/objects/#{object_identifier}/workflows/#{workflow_name}" req.params['version'] = version req.params['lane-id'] = lane_id req.headers['Content-Type'] = 'application/json' req.body = { context: context }.to_json if context end raise_exception_based_on_response!(resp) unless resp.success? end |
#find ⇒ Workflow::Response::Workflow
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dor/services/client/object_workflow.rb', line 32 def find resp = connection.get do |req| req.url "#{api_version}/objects/#{object_identifier}/workflows/#{workflow_name}" req.headers['Accept'] = 'application/xml' end raise_exception_based_on_response!(resp) unless resp.success? Dor::Services::Response::Workflow.new(xml: resp.body) end |
#process(process) ⇒ Dor::Services::Client::Process
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dor/services/client/object_workflow.rb', line 19 def process(process) raise ArgumentError, '`process` argument cannot be blank in call to `#process(process)`' if process.blank? # Return memoized object instance if process value is the same # # This allows the client to interact with multiple workflows for a given object return @process if @process&.process == process @process = Process.new(connection: connection, version: api_version, object_identifier: object_identifier, workflow_name: workflow_name, process: process, object_workflow_client: self) end |
#skip_all(note:) ⇒ Object
Skips all steps in a workflow.
62 63 64 65 66 67 68 69 |
# File 'lib/dor/services/client/object_workflow.rb', line 62 def skip_all(note:) resp = connection.post do |req| req.url "#{api_version}/objects/#{object_identifier}/workflows/#{workflow_name}/skip_all" req.params['note'] = note end raise_exception_based_on_response!(resp) unless resp.success? end |