Class: Dor::Services::Client::ObjectWorkflow

Inherits:
VersionedService show all
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

Instance Method Summary collapse

Methods inherited from VersionedService

#async_result

Constructor Details

#initialize(connection:, version:, object_identifier:, workflow_name:) ⇒ ObjectWorkflow

Returns a new instance of ObjectWorkflow.

Parameters:

  • object_identifier (String)

    the druid for the object

  • workflow_name (String)

    The name of the workflow



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_nameObject (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.

Parameters:

  • version (Integer)
  • lane_id (String) (defaults to: 'default')

    adds laneId attribute to all process elements in the wf_xml workflow xml. Defaults to a value of ‘default’

  • context (Hash) (defaults to: nil)

    optional context to be included in the workflow (same for all processes for a given druid/version pair)



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

#findWorkflow::Response::Workflow

Returns:

  • (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

Returns:

Raises:

  • (ArgumentError)


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.

Parameters:

  • note (String)

    a note to be added to the skipped steps



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