dor-workflow-client 3.11.1 → 3.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9befc325f9a9f7f39fb51bfe1ec663ac1e47f4b873a8d86853849ab71842b14d
4
- data.tar.gz: 57cdb8cc8896292bf406298bcfd779cca36cc68fdcdc5d5c352f2a8b63590b58
3
+ metadata.gz: 5cbb16ceddf569a9b82c822b1b885ebba29b592cd012ae340cb76882c61cc3d8
4
+ data.tar.gz: 4f1a7c2f940898abb328618ba1a8e09628fcf5a232e146b5546811a2bd3c223f
5
5
  SHA512:
6
- metadata.gz: 5130e4c0418579681766938f1c53ddeba5ea84ef8aec72e4f1b87877d4120ecc718bd1b8e64c90f7eb515e0383080d73de4eecd6ffdbc6809ab459f2c1136f3b
7
- data.tar.gz: dc7b9d86a50b2dc1bc2f7e706294c212df2e3e1c03c9693ea91d0ce4fe419354b8c8cb05d45716752e9d0ce98fe204351de64ab3b8ca3112d3e60e67943acfa7
6
+ metadata.gz: 228c451516708789a413be980b76fe25cb1efa7cf12865763291350ff86b2bdb63adfae2390ad02c3ef5fe33a213e68213a5a8dfb35a99531bded86fe396e21b
7
+ data.tar.gz: 42646cbdf62345f5128f7cc7c3391f245a387d6255734ddd498c71f38d82e6f6ec6ddbd2d3ad33c553abc09a9fee6525276343f7e6802cda1ed156aa8d55f643
data/Gemfile CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- # Specify your gem's dependencies in dor-workflow-service.gemspec
5
+ # Specify your gem's dependencies in dor-workflow-client.gemspec
6
6
  gemspec
7
7
 
8
8
  gem 'activesupport', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']
data/README.md CHANGED
@@ -24,7 +24,7 @@ Consumers of recent versions of the [dor-services](https://github.com/sul-dlss/d
24
24
  ### Example usage
25
25
  Create a workflow
26
26
  ```
27
- client.create_workflow_by_name('druid:bc123df4567', 'etdSubmitWF')
27
+ client.create_workflow_by_name('druid:bc123df4567', 'etdSubmitWF', version: '1')
28
28
  ```
29
29
 
30
30
  Update a workflow step's status
@@ -43,7 +43,7 @@ module Dor
43
43
  # rubocop:enable Metrics/MethodLength
44
44
 
45
45
  def user_agent
46
- "dor-workflow-service #{VERSION}"
46
+ "dor-workflow-client #{VERSION}"
47
47
  end
48
48
 
49
49
  private
@@ -3,7 +3,7 @@
3
3
  module Dor
4
4
  module Workflow
5
5
  class Client
6
- VERSION = '3.11.1'
6
+ VERSION = '3.12.0'
7
7
  end
8
8
  end
9
9
  end
@@ -34,14 +34,17 @@ module Dor
34
34
  # @param [String] druid The id of the object
35
35
  # @param [String] workflow_name The name of the workflow you want to create. This must correspond with a workflow
36
36
  # name that is known by the workflow service.
37
- # @param [Hash] opts optional params
38
- # @option opts [String] :lane_id adds laneId attribute to all process elements in the wf_xml workflow xml. Defaults to a value of 'default'
39
- # @option opts [Integer] :version specifies the version so that workflow service doesn't need to query dor-services.
37
+ # @param [String] lane_id adds laneId attribute to all process elements in the wf_xml workflow xml. Defaults to a value of 'default'
38
+ # @param [Integer] version specifies the version so that workflow service doesn't need to query dor-services.
40
39
  # @return [Boolean] always true
41
40
  #
42
- def create_workflow_by_name(druid, workflow_name, opts = {})
43
- params = { 'lane-id' => opts.fetch(:lane_id, 'default') }
44
- params['version'] = opts[:version] if opts[:version]
41
+ def create_workflow_by_name(druid, workflow_name, version: nil, lane_id: 'default')
42
+ params = { 'lane-id' => lane_id }
43
+ if version
44
+ params['version'] = version
45
+ else
46
+ Deprecation.warn(self, 'Calling create_workflow_by_name without passing version is deprecated and will result in an error in dor-workflow-client 4.0')
47
+ end
45
48
  requestor.request "objects/#{druid}/workflows/#{workflow_name}", 'post', '',
46
49
  content_type: 'application/xml',
47
50
  params: params
@@ -136,7 +139,7 @@ module Dor
136
139
  workflow = opts[:workflow]
137
140
  process = opts[:process]
138
141
  end
139
- workflow_md = workflow_xml(druid: druid, workflow: workflow)
142
+ workflow_md = fetch_workflow(druid: druid, workflow: workflow)
140
143
  doc = Nokogiri::XML(workflow_md)
141
144
  raise Dor::WorkflowException, "Unable to parse response:\n#{workflow_md}" if doc.root.nil?
142
145
 
@@ -166,11 +169,14 @@ module Dor
166
169
  druid = opts[:druid]
167
170
  workflow = opts[:workflow]
168
171
  end
172
+
169
173
  raise ArgumentError, 'missing workflow' unless workflow
170
174
  return requestor.request "#{repo}/objects/#{druid}/workflows/#{workflow}" if repo
171
175
 
172
- requestor.request "objects/#{druid}/workflows/#{workflow}"
176
+ fetch_workflow(druid: druid, workflow: workflow)
173
177
  end
178
+ deprecation_deprecate workflow_xml: 'workflow_xml will not be replaced'
179
+
174
180
  # rubocop:enable Metrics/MethodLength
175
181
 
176
182
  # Updates the status of one step in a workflow to error.
@@ -246,7 +252,7 @@ module Dor
246
252
  # => ["accessionWF", "assemblyWF", "disseminationWF"]
247
253
  def workflows(pid, repo = nil)
248
254
  Deprecation.warn(self, 'Passing the second argument (repo) to workflows is deprecated and can be omitted') if repo
249
- xml_doc = Nokogiri::XML(workflow_xml(druid: pid, workflow: ''))
255
+ xml_doc = Nokogiri::XML(fetch_workflow(druid: pid, workflow: ''))
250
256
  xml_doc.xpath('//workflow').collect { |workflow| workflow['id'] }
251
257
  end
252
258
 
@@ -256,7 +262,7 @@ module Dor
256
262
  # @return [Workflow::Response::Workflow]
257
263
  def workflow(repo: nil, pid:, workflow_name:)
258
264
  Deprecation.warn(self, 'passing the repo parameter is deprecated and will be removed in the next major versions') if repo
259
- xml = workflow_xml(druid: pid, workflow: workflow_name)
265
+ xml = fetch_workflow(druid: pid, workflow: workflow_name)
260
266
  Workflow::Response::Workflow.new(xml: xml)
261
267
  end
262
268
 
@@ -282,6 +288,12 @@ module Dor
282
288
 
283
289
  attr_reader :requestor
284
290
 
291
+ def fetch_workflow(druid:, workflow:)
292
+ raise ArgumentError, 'missing workflow' unless workflow
293
+
294
+ requestor.request "objects/#{druid}/workflows/#{workflow}"
295
+ end
296
+
285
297
  # @param [Hash] params
286
298
  # @return [String]
287
299
  def create_process_xml(params)
@@ -7,18 +7,22 @@ RSpec.describe Dor::Workflow::Client::ConnectionFactory do
7
7
  let(:mock_logger) { double('Logger', info: true, debug: true, warn: true) }
8
8
 
9
9
  let(:druid) { 'druid:123' }
10
+ let(:request_url) { "http://example.com/objects/#{druid}/workflows/httpException?lane-id=default&version=1" }
10
11
  before do
11
- stub_request(:post, "http://example.com/objects/#{druid}/workflows/httpException?lane-id=default")
12
+ stub_request(:post, request_url)
12
13
  .to_return(status: 500, body: 'Internal error', headers: {})
13
14
  end
14
15
 
15
16
  let(:client) { Dor::Workflow::Client.new url: 'http://example.com', logger: mock_logger }
16
17
 
17
18
  describe '#create_workflow_by_name' do
19
+ subject(:request) { client.create_workflow_by_name(druid, 'httpException', version: '1') }
18
20
  it 'logs an error and retry upon a targeted Faraday exception' do
19
- expect(mock_logger).to receive(:warn).with('retrying connection (1 remaining) to http://example.com/objects/druid:123/workflows/httpException?lane-id=default: (Faraday::RetriableResponse) 500')
20
- expect(mock_logger).to receive(:warn).with('retrying connection (0 remaining) to http://example.com/objects/druid:123/workflows/httpException?lane-id=default: (Faraday::RetriableResponse) 500')
21
- expect { client.create_workflow_by_name(druid, 'httpException') }.to raise_error Dor::WorkflowException
21
+ expect(mock_logger).to receive(:warn)
22
+ .with("retrying connection (1 remaining) to #{request_url}: (Faraday::RetriableResponse) 500")
23
+ expect(mock_logger).to receive(:warn)
24
+ .with("retrying connection (0 remaining) to #{request_url}: (Faraday::RetriableResponse) 500")
25
+ expect { request }.to raise_error Dor::WorkflowException
22
26
  end
23
27
  end
24
28
  end
@@ -7,6 +7,30 @@ RSpec.describe Dor::Workflow::Client::WorkflowRoutes do
7
7
 
8
8
  let(:routes) { described_class.new(requestor: mock_requestor) }
9
9
 
10
+ describe '#fetch_workflow' do
11
+ subject(:fetch_workflow) { routes.send(:fetch_workflow, druid: 'druid:mw971zk1113', workflow: workflow) }
12
+
13
+ context 'when a workflow name is provided' do
14
+ let(:workflow) { 'etdSubmitWF' }
15
+ let(:mock_requestor) { instance_double(Dor::Workflow::Client::Requestor, request: xml) }
16
+ let(:xml) { '<workflow id="etdSubmitWF"><process name="registrar-approval" status="completed" /></workflow>' }
17
+
18
+ it 'returns the xml for a given repository, druid, and workflow' do
19
+ expect(fetch_workflow).to eq(xml)
20
+ expect(mock_requestor).to have_received(:request)
21
+ .with('objects/druid:mw971zk1113/workflows/etdSubmitWF')
22
+ end
23
+ end
24
+
25
+ context 'when no workflow name is provided' do
26
+ let(:workflow) { nil }
27
+
28
+ it 'raises an error' do
29
+ expect { fetch_workflow }.to raise_error ArgumentError
30
+ end
31
+ end
32
+ end
33
+
10
34
  describe '#workflow' do
11
35
  let(:xml) do
12
36
  <<~XML
@@ -17,7 +41,7 @@ RSpec.describe Dor::Workflow::Client::WorkflowRoutes do
17
41
  end
18
42
 
19
43
  before do
20
- allow(routes).to receive(:workflow_xml) { xml }
44
+ allow(routes).to receive(:fetch_workflow) { xml }
21
45
  end
22
46
 
23
47
  it 'returns a workflow' do
@@ -61,7 +61,7 @@ RSpec.describe Dor::Workflow::Client do
61
61
  end
62
62
 
63
63
  it 'has a user_agent' do
64
- expect(conn.headers).to include('User-Agent' => /dor-workflow-service \d+\.\d+\.\d+/)
64
+ expect(conn.headers).to include('User-Agent' => /dor-workflow-client \d+\.\d+\.\d+/)
65
65
  end
66
66
 
67
67
  it 'defaults to using the flat params encoder' do
@@ -83,46 +83,70 @@ RSpec.describe Dor::Workflow::Client do
83
83
  allow(Deprecation).to receive(:warn)
84
84
  end
85
85
 
86
- it 'should request the workflow by name and return the URL to the workflow' do
86
+ it 'requests the workflow by name and return the URL to the workflow' do
87
87
  client.create_workflow(@repo, @druid, 'etdSubmitWF', wf_xml)
88
- expect(Deprecation).to have_received(:warn)
88
+ expect(Deprecation).to have_received(:warn).twice
89
89
  end
90
90
 
91
- it 'should raise on an unexpected Exception' do
91
+ it 'raises on an unexpected Exception' do
92
92
  expect { client.create_workflow(@repo, @druid, 'raiseException', wf_xml) }.to raise_error(Exception, 'broken')
93
- expect(Deprecation).to have_received(:warn)
93
+ expect(Deprecation).to have_received(:warn).twice
94
94
  end
95
95
 
96
96
  it 'sets the lane_id param if provided in options hash' do
97
97
  client.create_workflow(@repo, @druid, 'laneIdWF', wf_xml, lane_id: 'foo_lane')
98
- expect(Deprecation).to have_received(:warn)
98
+ expect(Deprecation).to have_received(:warn).twice
99
99
  end
100
100
  end
101
101
 
102
102
  describe '#create_workflow_by_name' do
103
- let(:stubs) do
104
- Faraday::Adapter::Test::Stubs.new do |stub|
105
- stub.post("objects/#{@druid}/workflows/etdSubmitWF") { |_env| [201, {}, ''] }
106
- stub.post("objects/#{@druid}/workflows/raiseException") { |_env| raise 'broken' }
107
- stub.post("objects/#{@druid}/workflows/laneIdWF?lane-id=foo_lane") { |_env| [201, {}, ''] }
108
- stub.post("objects/#{@druid}/workflows/versionWF?version=2") { |_env| [201, {}, ''] }
103
+ context 'with no args' do
104
+ let(:stubs) do
105
+ Faraday::Adapter::Test::Stubs.new do |stub|
106
+ stub.post("objects/#{@druid}/workflows/etdSubmitWF") { |_env| [201, {}, ''] }
107
+ end
109
108
  end
110
- end
111
109
 
112
- it 'should request the workflow by name and return the URL to the workflow' do
113
- client.create_workflow_by_name(@druid, 'etdSubmitWF')
110
+ it 'requests the workflow by name and return the URL to the workflow' do
111
+ expect(Deprecation).to receive(:warn)
112
+ client.create_workflow_by_name(@druid, 'etdSubmitWF')
113
+ end
114
114
  end
115
115
 
116
- it 'should raise on an unexpected Exception' do
117
- expect { client.create_workflow_by_name(@druid, 'raiseException') }.to raise_error(Exception, 'broken')
116
+ context 'when an unexpected exception is raised' do
117
+ let(:stubs) do
118
+ Faraday::Adapter::Test::Stubs.new do |stub|
119
+ stub.post("objects/#{@druid}/workflows/raiseException") { |_env| raise 'broken' }
120
+ end
121
+ end
122
+
123
+ it 'raises the error' do
124
+ expect { client.create_workflow_by_name(@druid, 'raiseException', version: '1') }.to raise_error(Exception, 'broken')
125
+ end
118
126
  end
119
127
 
120
- it 'sets the lane_id param if provided in options hash' do
121
- client.create_workflow_by_name(@druid, 'laneIdWF', lane_id: 'foo_lane')
128
+ context 'when lane_id is provided' do
129
+ let(:stubs) do
130
+ Faraday::Adapter::Test::Stubs.new do |stub|
131
+ stub.post("objects/#{@druid}/workflows/laneIdWF?lane-id=foo_lane&version=1") { |_env| [201, {}, ''] }
132
+ end
133
+ end
134
+
135
+ it 'sets the lane_id param' do
136
+ client.create_workflow_by_name(@druid, 'laneIdWF', lane_id: 'foo_lane', version: 1)
137
+ end
122
138
  end
123
139
 
124
- it 'sets the version param if provided in options hash' do
125
- client.create_workflow_by_name(@druid, 'versionWF', version: 2)
140
+ context 'when lane_id is not provided' do
141
+ let(:stubs) do
142
+ Faraday::Adapter::Test::Stubs.new do |stub|
143
+ stub.post("objects/#{@druid}/workflows/versionWF?version=2") { |_env| [201, {}, ''] }
144
+ end
145
+ end
146
+
147
+ it 'sets the version param if provided in options hash' do
148
+ client.create_workflow_by_name(@druid, 'versionWF', version: 2)
149
+ end
126
150
  end
127
151
  end
128
152
 
@@ -336,10 +360,10 @@ RSpec.describe Dor::Workflow::Client do
336
360
  end
337
361
 
338
362
  describe '#workflow_xml' do
363
+ before do
364
+ allow(Deprecation).to receive(:warn)
365
+ end
339
366
  context 'with positional args' do
340
- before do
341
- allow(Deprecation).to receive(:warn)
342
- end
343
367
  subject(:workflow_xml) { client.workflow_xml('dor', 'druid:123', workflow) }
344
368
 
345
369
  context 'when a workflow name is provided' do
@@ -371,9 +395,6 @@ RSpec.describe Dor::Workflow::Client do
371
395
 
372
396
  context 'when a repo is provided' do
373
397
  subject(:workflow_xml) { client.workflow_xml(repo: 'dor', druid: 'druid:123', workflow: workflow) }
374
- before do
375
- allow(Deprecation).to receive(:warn)
376
- end
377
398
 
378
399
  let(:workflow) { 'etdSubmitWF' }
379
400
  let(:xml) { '<workflow id="etdSubmitWF"><process name="registrar-approval" status="completed" /></workflow>' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dor-workflow-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.11.1
4
+ version: 3.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willy Mene
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-11-21 00:00:00.000000000 Z
12
+ date: 2019-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport