dor-workflow-client 3.19.0 → 3.23.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -42,32 +42,38 @@ module Dor
42
42
  end
43
43
 
44
44
  # @return [Hash{Symbol => Object}] including :status_code and :status_time
45
+ # rubocop:disable Metrics/MethodLength
45
46
  def info
46
- # if we have an accessioned milestone, this is the last possible step and should be the status regardless of time stamp
47
- accessioned_milestones = current_milestones.select { |m| m[:milestone] == 'accessioned' }
48
- return { status_code: STEPS['accessioned'], status_time: accessioned_milestones.last[:at].utc.xmlschema } unless accessioned_milestones.empty?
49
-
50
- status_code = 0
51
- status_time = nil
52
- # for each milestone in the current version, see if it comes at the same time or after the current 'last' step, if so, make it the last and record the date/time
53
- current_milestones.each do |m|
54
- m_name = m[:milestone]
55
- m_time = m[:at].utc.xmlschema
56
- next unless STEPS.key?(m_name) && (!status_time || m_time >= status_time)
57
-
58
- status_code = STEPS[m_name]
59
- status_time = m_time
47
+ @info ||= begin
48
+ # if we have an accessioned milestone, this is the last possible step and should be the status regardless of time stamp
49
+ accessioned_milestones = current_milestones.select { |m| m[:milestone] == 'accessioned' }
50
+ return { status_code: STEPS['accessioned'], status_time: accessioned_milestones.last[:at].utc.xmlschema } unless accessioned_milestones.empty?
51
+
52
+ status_code = 0
53
+ status_time = nil
54
+ # for each milestone in the current version, see if it comes at the same time or after the current 'last' step, if so, make it the last and record the date/time
55
+ current_milestones.each do |m|
56
+ m_name = m[:milestone]
57
+ m_time = m[:at].utc.xmlschema
58
+ next unless STEPS.key?(m_name) && (!status_time || m_time >= status_time)
59
+
60
+ status_code = STEPS[m_name]
61
+ status_time = m_time
62
+ end
63
+
64
+ { status_code: status_code, status_time: status_time }
60
65
  end
66
+ end
67
+ # rubocop:enable Metrics/MethodLength
61
68
 
62
- { status_code: status_code, status_time: status_time }
69
+ def status_code
70
+ info.fetch(:status_code)
63
71
  end
64
72
 
65
73
  # @param [Boolean] include_time
66
74
  # @return [String] single composed status from status_info
67
75
  def display(include_time: false)
68
- status_info_hash = info
69
- status_code = status_info_hash[:status_code]
70
- status_time = status_info_hash[:status_time]
76
+ status_time = info[:status_time]
71
77
 
72
78
  # use the translation table to get the appropriate verbage for the latest step
73
79
  result = "v#{version} #{STATUS_CODE_DISP_TXT[status_code]}"
@@ -75,14 +81,24 @@ module Dor
75
81
  result
76
82
  end
77
83
 
84
+ def display_simplified
85
+ simplified_status_code(STATUS_CODE_DISP_TXT[status_code])
86
+ end
87
+
78
88
  def milestones
79
- @milestones ||= lifecycle_routes.milestones('dor', druid)
89
+ @milestones ||= lifecycle_routes.milestones(druid: druid)
80
90
  end
81
91
 
82
92
  private
83
93
 
84
94
  attr_reader :druid, :version, :lifecycle_routes
85
95
 
96
+ # @return [String] text translation of the status code, minus any trailing parenthetical explanation
97
+ # e.g. 'In accessioning (described)' and 'In accessioning (described, published)' both return 'In accessioning'
98
+ def simplified_status_code(display)
99
+ display.gsub(/\(.*\)$/, '').strip
100
+ end
101
+
86
102
  def current_milestones
87
103
  current = []
88
104
  # only get steps that are part of accessioning and part of the current version. That can mean they were archived with the current version
@@ -3,7 +3,7 @@
3
3
  module Dor
4
4
  module Workflow
5
5
  class Client
6
- VERSION = '3.19.0'
6
+ VERSION = '3.23.0'
7
7
  end
8
8
  end
9
9
  end
@@ -274,13 +274,20 @@ module Dor
274
274
  workflow(pid: pid, workflow_name: workflow_name).process_for_recent_version(name: process)
275
275
  end
276
276
 
277
- # Deletes a workflow from a particular repository and druid
277
+ # Deletes a workflow from a particular repository and druid. This is only used by Hydrus.
278
278
  # @param [String] repo The repository the object resides in. The service recoginzes "dor" and "sdr" at the moment
279
279
  # @param [String] druid The id of the object to delete the workflow from
280
280
  # @param [String] workflow The name of the workflow to be deleted
281
+ # @param [Integer] version The version of the workflow to delete
281
282
  # @return [Boolean] always true
282
- def delete_workflow(repo, druid, workflow)
283
- requestor.request "#{repo}/objects/#{druid}/workflows/#{workflow}", 'delete'
283
+ def delete_workflow(repo, druid, workflow, version: nil)
284
+ qs_args = if version
285
+ "?version=#{version}"
286
+ else
287
+ Deprecation.warn(self, 'Calling delete_workflow without passing version is deprecated and will result in an error in dor-workflow-client 4.0')
288
+ ''
289
+ end
290
+ requestor.request "#{repo}/objects/#{druid}/workflows/#{workflow}#{qs_args}", 'delete'
284
291
  true
285
292
  end
286
293
 
@@ -5,6 +5,9 @@ module Dor
5
5
  module Response
6
6
  # Represents the status of an object doing a workflow process
7
7
  class Process
8
+ extend Deprecation
9
+ self.deprecation_horizon = '4.x'
10
+
8
11
  # @params [Workflow] parent
9
12
  # @params [Hash] attributes
10
13
  def initialize(parent:, **attributes)
@@ -49,6 +52,7 @@ module Dor
49
52
  end
50
53
 
51
54
  delegate :pid, :workflow_name, :repository, to: :parent
55
+ deprecation_deprecate :repository
52
56
 
53
57
  private
54
58
 
@@ -5,6 +5,9 @@ module Dor
5
5
  module Response
6
6
  # The response from asking the server about a workflow for an item
7
7
  class Workflow
8
+ extend Deprecation
9
+ self.deprecation_horizon = '4.x'
10
+
8
11
  def initialize(xml:)
9
12
  @xml = xml
10
13
  end
@@ -20,6 +23,7 @@ module Dor
20
23
  def repository
21
24
  workflow['repository']
22
25
  end
26
+ deprecation_deprecate :repository
23
27
 
24
28
  # @param [Integer] version the version we are checking for.
25
29
  def active_for?(version:)
@@ -33,6 +33,10 @@ RSpec.describe Dor::Workflow::Response::Process do
33
33
  end
34
34
 
35
35
  describe '#repository' do
36
+ before do
37
+ allow(Deprecation).to receive(:warn)
38
+ end
39
+
36
40
  subject { instance.repository }
37
41
 
38
42
  let(:xml) do
@@ -32,6 +32,10 @@ RSpec.describe Dor::Workflow::Response::Workflow do
32
32
  describe '#repository' do
33
33
  subject { instance.repository }
34
34
 
35
+ before do
36
+ allow(Deprecation).to receive(:warn)
37
+ end
38
+
35
39
  let(:xml) do
36
40
  <<~XML
37
41
  <workflow repository="dor" objectId="druid:mw971zk1113" id="assemblyWF">
@@ -6,6 +6,8 @@ RSpec.describe Dor::Workflow::Client::LifecycleRoutes do
6
6
  let(:requestor) { instance_double(Dor::Workflow::Client::Requestor, request: response) }
7
7
  let(:response) { '<xml />' }
8
8
  let(:routes) { described_class.new(requestor: requestor) }
9
+ let(:repo) { 'dor' }
10
+ let(:druid) { 'druid:gv054hp4128' }
9
11
 
10
12
  describe '#milestones' do
11
13
  let(:ng_xml) { Nokogiri::XML(xml) }
@@ -15,52 +17,177 @@ RSpec.describe Dor::Workflow::Client::LifecycleRoutes do
15
17
 
16
18
  before do
17
19
  allow(routes).to receive(:query_lifecycle).and_return(ng_xml)
20
+ allow(Deprecation).to receive(:warn)
18
21
  end
19
22
 
20
- subject(:milestones) { routes.milestones('dor', 'druid:gv054hp4128') }
23
+ context 'with positional arguments' do
24
+ subject(:milestones) { routes.milestones(repo, druid) }
21
25
 
22
- it 'includes the version in with the milestones' do
23
- expect(milestones.first[:milestone]).to eq('published')
24
- expect(milestones.first[:version]).to eq('2')
26
+ it 'includes the version in with the milestones' do
27
+ expect(milestones.first[:milestone]).to eq('published')
28
+ expect(milestones.first[:version]).to eq('2')
29
+ expect(Deprecation).to have_received(:warn).twice
30
+ end
31
+ end
32
+
33
+ context 'with kwargs' do
34
+ subject(:milestones) { routes.milestones(druid: druid) }
35
+
36
+ it 'includes the version in with the milestones' do
37
+ expect(milestones.first[:milestone]).to eq('published')
38
+ expect(milestones.first[:version]).to eq('2')
39
+ end
25
40
  end
26
41
  end
27
42
 
28
43
  describe '#lifecycle' do
29
- context 'without version' do
30
- subject(:lifecycle) { routes.lifecycle('dor', 'druid:gv054hp4128', 'submitted') }
44
+ context 'with positional arguments' do
45
+ before do
46
+ allow(Deprecation).to receive(:warn)
47
+ end
48
+
49
+ context 'without version' do
50
+ subject(:lifecycle) { routes.lifecycle(repo, druid, 'submitted') }
51
+
52
+ it 'make the request' do
53
+ lifecycle
54
+ expect(requestor).to have_received(:request).with('objects/druid:gv054hp4128/lifecycle')
55
+ expect(Deprecation).to have_received(:warn).twice
56
+ end
57
+ end
31
58
 
32
- it 'make the request' do
33
- lifecycle
34
- expect(requestor).to have_received(:request).with('dor/objects/druid:gv054hp4128/lifecycle')
59
+ context 'with version' do
60
+ subject(:lifecycle) { routes.lifecycle(repo, druid, 'submitted', version: 3) }
61
+
62
+ it 'makes the request with the version' do
63
+ lifecycle
64
+ expect(requestor).to have_received(:request).with('objects/druid:gv054hp4128/lifecycle?version=3')
65
+ expect(Deprecation).to have_received(:warn).twice
66
+ end
35
67
  end
36
68
  end
37
69
 
38
- context 'with version' do
39
- subject(:lifecycle) { routes.lifecycle('dor', 'druid:gv054hp4128', 'submitted', version: 3) }
70
+ context 'with kwargs' do
71
+ before do
72
+ allow(Deprecation).to receive(:warn)
73
+ end
74
+
75
+ context 'with deprecated repo arg' do
76
+ context 'without version' do
77
+ subject(:lifecycle) { routes.lifecycle(repo: repo, druid: druid, milestone_name: 'submitted') }
78
+
79
+ it 'make the request' do
80
+ lifecycle
81
+ expect(requestor).to have_received(:request).with('objects/druid:gv054hp4128/lifecycle')
82
+ expect(Deprecation).to have_received(:warn)
83
+ end
84
+ end
85
+
86
+ context 'with version' do
87
+ subject(:lifecycle) { routes.lifecycle(repo: repo, druid: druid, milestone_name: 'submitted', version: 3) }
40
88
 
41
- it 'makes the request with the version' do
42
- lifecycle
43
- expect(requestor).to have_received(:request).with('dor/objects/druid:gv054hp4128/lifecycle?version=3')
89
+ it 'makes the request with the version' do
90
+ lifecycle
91
+ expect(requestor).to have_received(:request).with('objects/druid:gv054hp4128/lifecycle?version=3')
92
+ expect(Deprecation).to have_received(:warn)
93
+ end
94
+ end
95
+ end
96
+
97
+ context 'without version' do
98
+ subject(:lifecycle) { routes.lifecycle(druid: druid, milestone_name: 'submitted') }
99
+
100
+ it 'make the request' do
101
+ lifecycle
102
+ expect(requestor).to have_received(:request).with('objects/druid:gv054hp4128/lifecycle')
103
+ expect(Deprecation).not_to have_received(:warn)
104
+ end
105
+ end
106
+
107
+ context 'with version' do
108
+ subject(:lifecycle) { routes.lifecycle(druid: druid, milestone_name: 'submitted', version: 3) }
109
+
110
+ it 'makes the request with the version' do
111
+ lifecycle
112
+ expect(requestor).to have_received(:request).with('objects/druid:gv054hp4128/lifecycle?version=3')
113
+ expect(Deprecation).not_to have_received(:warn)
114
+ end
44
115
  end
45
116
  end
46
117
  end
47
118
 
48
119
  describe '#active_lifecycle' do
49
- context 'without version' do
50
- subject(:active_lifecycle) { routes.active_lifecycle('dor', 'druid:gv054hp4128', 'submitted') }
120
+ context 'with positional arguments' do
121
+ before do
122
+ allow(Deprecation).to receive(:warn)
123
+ end
51
124
 
52
- it 'make the request' do
53
- active_lifecycle
54
- expect(requestor).to have_received(:request).with('dor/objects/druid:gv054hp4128/lifecycle?active-only=true')
125
+ context 'without version' do
126
+ subject(:active_lifecycle) { routes.active_lifecycle(repo, druid, 'submitted') }
127
+
128
+ it 'make the request' do
129
+ active_lifecycle
130
+ expect(requestor).to have_received(:request).with('objects/druid:gv054hp4128/lifecycle?active-only=true')
131
+ expect(Deprecation).to have_received(:warn).twice
132
+ end
133
+ end
134
+
135
+ context 'with version' do
136
+ subject(:active_lifecycle) { routes.active_lifecycle(repo, druid, 'submitted', version: 3) }
137
+
138
+ it 'makes the request with the version' do
139
+ active_lifecycle
140
+ expect(requestor).to have_received(:request).with('objects/druid:gv054hp4128/lifecycle?version=3&active-only=true')
141
+ expect(Deprecation).to have_received(:warn).twice
142
+ end
55
143
  end
56
144
  end
57
145
 
58
- context 'with version' do
59
- subject(:active_lifecycle) { routes.active_lifecycle('dor', 'druid:gv054hp4128', 'submitted', version: 3) }
146
+ context 'with kwargs' do
147
+ before do
148
+ allow(Deprecation).to receive(:warn)
149
+ end
150
+
151
+ context 'with deprecated repo arg' do
152
+ context 'without version' do
153
+ subject(:active_lifecycle) { routes.active_lifecycle(repo: repo, druid: druid, milestone_name: 'submitted') }
154
+
155
+ it 'make the request' do
156
+ active_lifecycle
157
+ expect(requestor).to have_received(:request).with('objects/druid:gv054hp4128/lifecycle?active-only=true')
158
+ expect(Deprecation).to have_received(:warn)
159
+ end
160
+ end
161
+
162
+ context 'with version' do
163
+ subject(:active_lifecycle) { routes.active_lifecycle(repo: repo, druid: druid, milestone_name: 'submitted', version: 3) }
164
+
165
+ it 'makes the request with the version' do
166
+ active_lifecycle
167
+ expect(requestor).to have_received(:request).with('objects/druid:gv054hp4128/lifecycle?version=3&active-only=true')
168
+ expect(Deprecation).to have_received(:warn)
169
+ end
170
+ end
171
+ end
172
+
173
+ context 'without version' do
174
+ subject(:active_lifecycle) { routes.active_lifecycle(druid: druid, milestone_name: 'submitted') }
175
+
176
+ it 'make the request' do
177
+ active_lifecycle
178
+ expect(requestor).to have_received(:request).with('objects/druid:gv054hp4128/lifecycle?active-only=true')
179
+ expect(Deprecation).not_to have_received(:warn)
180
+ end
181
+ end
182
+
183
+ context 'with version' do
184
+ subject(:active_lifecycle) { routes.active_lifecycle(druid: druid, milestone_name: 'submitted', version: 3) }
60
185
 
61
- it 'makes the request with the version' do
62
- active_lifecycle
63
- expect(requestor).to have_received(:request).with('dor/objects/druid:gv054hp4128/lifecycle?version=3&active-only=true')
186
+ it 'makes the request with the version' do
187
+ active_lifecycle
188
+ expect(requestor).to have_received(:request).with('objects/druid:gv054hp4128/lifecycle?version=3&active-only=true')
189
+ expect(Deprecation).not_to have_received(:warn)
190
+ end
64
191
  end
65
192
  end
66
193
  end
@@ -14,12 +14,6 @@ RSpec.describe Dor::Workflow::Client::Status do
14
14
  describe '#display' do
15
15
  subject(:status) { instance.display }
16
16
 
17
- before do
18
- # TODO: this stub is too knowledgable about the inner workings of the LifecycleRoutest
19
- # instead it should just stub :milestones which returns an array of hashes
20
- # expect(lifecycle_routes).to receive(:query_lifecycle).and_return(xml)
21
- end
22
-
23
17
  context 'for gv054hp4128' do
24
18
  context 'when current version is published, but does not have a version attribute' do
25
19
  let(:xml) do
@@ -178,4 +172,23 @@ RSpec.describe Dor::Workflow::Client::Status do
178
172
  end
179
173
  end
180
174
  end
175
+
176
+ describe '#display_simplified' do
177
+ subject(:status) { instance.display_simplified }
178
+ let(:xml) do
179
+ '<?xml version="1.0" encoding="UTF-8"?>
180
+ <lifecycle objectId="druid:gv054hp4128">
181
+ <milestone date="2012-11-06T16:19:15-0800" version="2">described</milestone>
182
+ <milestone date="2012-11-06T16:21:02-0800">opened</milestone>
183
+ <milestone date="2012-11-06T16:30:03-0800">submitted</milestone>
184
+ <milestone date="2012-11-06T16:35:00-0800">described</milestone>
185
+ <milestone date="2012-11-06T16:59:39-0800" version="3">published</milestone>
186
+ <milestone date="2012-11-06T16:59:39-0800">published</milestone>
187
+ </lifecycle>'
188
+ end
189
+
190
+ it 'generates a status string' do
191
+ expect(status).to eq('In accessioning')
192
+ end
193
+ end
181
194
  end
@@ -44,7 +44,6 @@ RSpec.describe Dor::Workflow::Client do
44
44
  let(:mock_logger) { double('Logger', info: true, debug: true, warn: true) }
45
45
 
46
46
  before do
47
- @repo = 'dor'
48
47
  @druid = 'druid:123'
49
48
  end
50
49
 
@@ -84,17 +83,17 @@ RSpec.describe Dor::Workflow::Client do
84
83
  end
85
84
 
86
85
  it 'requests the workflow by name and return the URL to the workflow' do
87
- client.create_workflow(@repo, @druid, 'etdSubmitWF', wf_xml)
86
+ client.create_workflow(nil, @druid, 'etdSubmitWF', wf_xml)
88
87
  expect(Deprecation).to have_received(:warn).twice
89
88
  end
90
89
 
91
90
  it 'raises on an unexpected Exception' do
92
- expect { client.create_workflow(@repo, @druid, 'raiseException', wf_xml) }.to raise_error(Exception, 'broken')
91
+ expect { client.create_workflow(nil, @druid, 'raiseException', wf_xml) }.to raise_error(Exception, 'broken')
93
92
  expect(Deprecation).to have_received(:warn).twice
94
93
  end
95
94
 
96
95
  it 'sets the lane_id param if provided in options hash' do
97
- client.create_workflow(@repo, @druid, 'laneIdWF', wf_xml, lane_id: 'foo_lane')
96
+ client.create_workflow(nil, @druid, 'laneIdWF', wf_xml, lane_id: 'foo_lane')
98
97
  expect(Deprecation).to have_received(:warn).twice
99
98
  end
100
99
  end
@@ -153,16 +152,16 @@ RSpec.describe Dor::Workflow::Client do
153
152
  describe '#update_workflow_status' do
154
153
  let(:stubs) do
155
154
  Faraday::Adapter::Test::Stubs.new do |stub|
156
- stub.put("#{@repo}/objects/#{@druid}/workflows/etdSubmitWF/registrar-approval?current-status=queued") do |_env|
155
+ stub.put("objects/#{@druid}/workflows/etdSubmitWF/registrar-approval?current-status=queued") do |_env|
157
156
  [201, {}, '{"next_steps":["submit-marc"]}']
158
157
  end
159
158
 
160
- stub.put("#{@repo}/objects/#{@druid}/workflows/etdSubmitWF/registrar-approval") do |env|
159
+ stub.put("objects/#{@druid}/workflows/etdSubmitWF/registrar-approval") do |env|
161
160
  expect(env.body).to eq "<?xml version=\"1.0\"?>\n<process name=\"registrar-approval\" status=\"completed\" elapsed=\"0\" note=\"annotation\" version=\"2\" laneId=\"lane2\"/>\n"
162
161
  [201, {}, '{"next_steps":["submit-marc"]}']
163
162
  end
164
163
 
165
- stub.put("#{@repo}/objects/#{@druid}/workflows/errorWF/registrar-approval") do |_env|
164
+ stub.put("objects/#{@druid}/workflows/errorWF/registrar-approval") do |_env|
166
165
  [400, {}, '']
167
166
  end
168
167
  end
@@ -172,21 +171,21 @@ RSpec.describe Dor::Workflow::Client do
172
171
  end
173
172
 
174
173
  it 'should update workflow status and return true if successful' do
175
- expect(client.update_workflow_status(@repo, @druid, 'etdSubmitWF', 'registrar-approval', 'completed', version: 2, note: 'annotation', lane_id: 'lane2')).to be_kind_of Dor::Workflow::Response::Update
174
+ expect(client.update_workflow_status(nil, @druid, 'etdSubmitWF', 'registrar-approval', 'completed', version: 2, note: 'annotation', lane_id: 'lane2')).to be_kind_of Dor::Workflow::Response::Update
176
175
  end
177
176
 
178
177
  it 'should return false if the PUT to the DOR workflow service throws an exception' do
179
- expect { client.update_workflow_status(@repo, @druid, 'errorWF', 'registrar-approval', 'completed') }.to raise_error(Dor::WorkflowException, /status 400/)
178
+ expect { client.update_workflow_status(nil, @druid, 'errorWF', 'registrar-approval', 'completed') }.to raise_error(Dor::WorkflowException, /status 400/)
180
179
  end
181
180
 
182
181
  it 'performs a conditional update when current-status is passed as a parameter' do
183
- expect(mock_http_connection).to receive(:put).with("#{@repo}/objects/#{@druid}/workflows/etdSubmitWF/registrar-approval?current-status=queued").and_call_original
182
+ expect(mock_http_connection).to receive(:put).with("/objects/#{@druid}/workflows/etdSubmitWF/registrar-approval?current-status=queued").and_call_original
184
183
 
185
- expect(client.update_workflow_status(@repo, @druid, 'etdSubmitWF', 'registrar-approval', 'completed', version: 2, note: 'annotation', lane_id: 'lane1', current_status: 'queued')).to be_kind_of Dor::Workflow::Response::Update
184
+ expect(client.update_workflow_status(nil, @druid, 'etdSubmitWF', 'registrar-approval', 'completed', version: 2, note: 'annotation', lane_id: 'lane1', current_status: 'queued')).to be_kind_of Dor::Workflow::Response::Update
186
185
  end
187
186
 
188
187
  it 'should throw exception if invalid status provided' do
189
- expect { client.update_workflow_status(@repo, @druid, 'accessionWF', 'publish', 'NOT_VALID_STATUS') }.to raise_error(ArgumentError)
188
+ expect { client.update_workflow_status(nil, @druid, 'accessionWF', 'publish', 'NOT_VALID_STATUS') }.to raise_error(ArgumentError)
190
189
  end
191
190
  end
192
191
 
@@ -209,10 +208,10 @@ RSpec.describe Dor::Workflow::Client do
209
208
  end
210
209
 
211
210
  it 'should update workflow status to error and return true if successful' do
212
- client.update_workflow_error_status(@repo, @druid, 'etdSubmitWF', 'reader-approval', 'Some exception', error_text: 'The optional stacktrace')
211
+ client.update_workflow_error_status(nil, @druid, 'etdSubmitWF', 'reader-approval', 'Some exception', error_text: 'The optional stacktrace')
213
212
  end
214
213
  it 'should return false if the PUT to the DOR workflow service throws an exception' do
215
- expect { client.update_workflow_error_status(@repo, @druid, 'errorWF', 'reader-approval', 'completed') }.to raise_error(Dor::WorkflowException, /status 400/)
214
+ expect { client.update_workflow_error_status(nil, @druid, 'errorWF', 'reader-approval', 'completed') }.to raise_error(Dor::WorkflowException, /status 400/)
216
215
  end
217
216
  end
218
217
 
@@ -255,7 +254,7 @@ RSpec.describe Dor::Workflow::Client do
255
254
  end
256
255
 
257
256
  describe '#workflow_status' do
258
- let(:repo) { @repo }
257
+ let(:repo) { nil }
259
258
  let(:druid) { @druid }
260
259
  let(:stubs) do
261
260
  Faraday::Adapter::Test::Stubs.new do |stub|
@@ -401,6 +400,7 @@ RSpec.describe Dor::Workflow::Client do
401
400
  context 'with keyword args' do
402
401
  subject(:workflow_xml) { client.workflow_xml(druid: 'druid:123', workflow: workflow) }
403
402
 
403
+ # TODO: Remove this `context` block altogether when repos are wiped out for good
404
404
  context 'when a repo is provided' do
405
405
  subject(:workflow_xml) { client.workflow_xml(repo: 'dor', druid: 'druid:123', workflow: workflow) }
406
406
 
@@ -488,7 +488,7 @@ RSpec.describe Dor::Workflow::Client do
488
488
  describe '#lifecycle' do
489
489
  let(:stubs) do
490
490
  Faraday::Adapter::Test::Stubs.new do |stub|
491
- stub.get('dor/objects/druid:123/lifecycle') do |_env|
491
+ stub.get('objects/druid:123/lifecycle') do |_env|
492
492
  [200, {}, <<-EOXML]
493
493
  <lifecycle objectId="druid:ct011cv6501">
494
494
  <milestone date="2010-04-27T11:34:17-0700">registered</milestone>
@@ -498,7 +498,7 @@ RSpec.describe Dor::Workflow::Client do
498
498
  EOXML
499
499
  end
500
500
 
501
- stub.get('dor/objects/druid:abc/lifecycle') do |_env|
501
+ stub.get('objects/druid:abc/lifecycle') do |_env|
502
502
  [200, {}, <<-EOXML]
503
503
  <lifecycle />
504
504
  EOXML
@@ -507,18 +507,18 @@ RSpec.describe Dor::Workflow::Client do
507
507
  end
508
508
 
509
509
  it 'returns a Time object reprenting when the milestone was reached' do
510
- expect(client.lifecycle('dor', 'druid:123', 'released').beginning_of_day).to eq(Time.parse('2010-06-15T16:08:58-0700').beginning_of_day)
510
+ expect(client.lifecycle(druid: 'druid:123', milestone_name: 'released').beginning_of_day).to eq(Time.parse('2010-06-15T16:08:58-0700').beginning_of_day)
511
511
  end
512
512
 
513
513
  it "returns nil if the milestone hasn't been reached yet" do
514
- expect(client.lifecycle('dor', 'druid:abc', 'inprocess')).to be_nil
514
+ expect(client.lifecycle(druid: 'druid:abc', milestone_name: 'inprocess')).to be_nil
515
515
  end
516
516
  end
517
517
 
518
518
  describe '#active_lifecycle' do
519
519
  let(:stubs) do
520
520
  Faraday::Adapter::Test::Stubs.new do |stub|
521
- stub.get("dor/objects/#{@druid}/lifecycle") do |_env|
521
+ stub.get("objects/#{@druid}/lifecycle") do |_env|
522
522
  [200, {}, <<-EOXML]
523
523
  <lifecycle objectId="#{@druid}">
524
524
  <milestone date="2010-04-27T11:34:17-0700">registered</milestone>
@@ -528,7 +528,7 @@ RSpec.describe Dor::Workflow::Client do
528
528
  EOXML
529
529
  end
530
530
 
531
- stub.get("dor/objects/#{@druid}/lifecycle") do |_env|
531
+ stub.get("objects/#{@druid}/lifecycle") do |_env|
532
532
  [200, {}, <<-EOXML]
533
533
  <lifecycle />
534
534
  EOXML
@@ -537,17 +537,16 @@ RSpec.describe Dor::Workflow::Client do
537
537
  end
538
538
 
539
539
  it 'parses out the active lifecycle' do
540
- expect(client.active_lifecycle('dor', @druid, 'released').beginning_of_day).to eq(Time.parse('2010-06-15T16:08:58-0700').beginning_of_day)
540
+ expect(client.active_lifecycle(druid: @druid, milestone_name: 'released').beginning_of_day).to eq(Time.parse('2010-06-15T16:08:58-0700').beginning_of_day)
541
541
  end
542
542
 
543
543
  it 'handles missing lifecycle' do
544
- expect(client.active_lifecycle('dor', @druid, 'NOT_FOUND')).to be_nil
544
+ expect(client.active_lifecycle(druid: @druid, milestone_name: 'NOT_FOUND')).to be_nil
545
545
  end
546
546
  end
547
547
 
548
548
  context '#objects_for_workstep' do
549
549
  before(:all) do
550
- @repository = 'dor'
551
550
  @workflow = 'googleScannedBookWF'
552
551
  @completed = 'google-download'
553
552
  @waiting = 'process-content'
@@ -555,7 +554,7 @@ RSpec.describe Dor::Workflow::Client do
555
554
 
556
555
  let(:stubs) do
557
556
  Faraday::Adapter::Test::Stubs.new do |stub|
558
- stub.get("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&lane-id=default") do |_env|
557
+ stub.get("workflow_queue?waiting=#{@workflow}:#{@waiting}&completed=#{@workflow}:#{@completed}&lane-id=default") do |_env|
559
558
  [200, {}, '<objects count="1"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>']
560
559
  end
561
560
  end
@@ -563,7 +562,7 @@ RSpec.describe Dor::Workflow::Client do
563
562
 
564
563
  describe 'a query with one step completed and one waiting' do
565
564
  it 'creates the URI string with only the one completed step' do
566
- expect(client.objects_for_workstep(@completed, @waiting, 'default', default_repository: @repository, default_workflow: @workflow)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
565
+ expect(client.objects_for_workstep(@completed, @waiting, 'default', default_workflow: @workflow)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
567
566
  end
568
567
  end
569
568
 
@@ -571,21 +570,21 @@ RSpec.describe Dor::Workflow::Client do
571
570
  it 'creates the URI string with the two completed steps correctly' do
572
571
  second_completed = 'google-convert'
573
572
  xml = %(<objects count="1"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>)
574
- allow(mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&completed=#{@repository}:#{@workflow}:#{second_completed}&lane-id=default").and_return(double(Faraday::Response, body: xml))
575
- expect(client.objects_for_workstep([@completed, second_completed], @waiting, 'default', default_repository: @repository, default_workflow: @workflow)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
573
+ allow(mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@workflow}:#{@waiting}&completed=#{@workflow}:#{@completed}&completed=#{@workflow}:#{second_completed}&lane-id=default").and_return(double(Faraday::Response, body: xml))
574
+ expect(client.objects_for_workstep([@completed, second_completed], @waiting, 'default', default_workflow: @workflow)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
576
575
  end
577
576
  end
578
577
 
579
578
  context 'a query using qualified workflow names for completed and waiting' do
580
579
  before :each do
581
- @qualified_waiting = "#{@repository}:#{@workflow}:#{@waiting}"
582
- @qualified_completed = "#{@repository}:#{@workflow}:#{@completed}"
580
+ @qualified_waiting = "#{@workflow}:#{@waiting}"
581
+ @qualified_completed = "#{@workflow}:#{@completed}"
583
582
  end
584
583
 
585
584
  RSpec.shared_examples 'lane-aware' do
586
585
  it 'creates the URI string with the two completed steps across repositories correctly' do
587
- qualified_completed2 = 'sdr:sdrIngestWF:complete-deposit'
588
- qualified_completed3 = 'sdr:sdrIngestWF:ingest-transfer'
586
+ qualified_completed2 = 'sdrIngestWF:complete-deposit'
587
+ qualified_completed3 = 'sdrIngestWF:ingest-transfer'
589
588
  xml = %(<objects count="2"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>)
590
589
  allow(mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@qualified_waiting}&completed=#{@qualified_completed}&completed=#{qualified_completed2}&completed=#{qualified_completed3}&lane-id=#{laneid}").and_return(double(Faraday::Response, body: xml))
591
590
  args = [[@qualified_completed, qualified_completed2, qualified_completed3], @qualified_waiting]
@@ -627,7 +626,6 @@ RSpec.describe Dor::Workflow::Client do
627
626
 
628
627
  context 'get empty workflow queue' do
629
628
  before(:all) do
630
- @repository = 'dor'
631
629
  @workflow = 'googleScannedBookWF'
632
630
  @completed = 'google-download'
633
631
  @waiting = 'process-content'
@@ -635,27 +633,26 @@ RSpec.describe Dor::Workflow::Client do
635
633
 
636
634
  let(:stubs) do
637
635
  Faraday::Adapter::Test::Stubs.new do |stub|
638
- stub.get("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&lane-id=default") do |_env|
636
+ stub.get("workflow_queue?waiting=#{@workflow}:#{@waiting}&completed=#{@workflow}:#{@completed}&lane-id=default") do |_env|
639
637
  [200, {}, '<objects count="0"/>']
640
638
  end
641
639
  end
642
640
  end
643
641
 
644
642
  it 'returns an empty list if it encounters an empty workflow queue' do
645
- expect(client.objects_for_workstep(@completed, @waiting, 'default', default_repository: @repository, default_workflow: @workflow)).to eq([])
643
+ expect(client.objects_for_workstep(@completed, @waiting, 'default', default_workflow: @workflow)).to eq([])
646
644
  end
647
645
  end
648
646
 
649
647
  context 'get errored workflow steps' do
650
648
  before(:all) do
651
- @repository = 'dor'
652
649
  @workflow = 'accessionWF'
653
650
  @step = 'publish'
654
651
  end
655
652
 
656
653
  let(:stubs) do
657
654
  Faraday::Adapter::Test::Stubs.new do |stub|
658
- stub.get("/workflow_queue?error=#{@step}&repository=#{@repository}&workflow=#{@workflow}") do |_env|
655
+ stub.get("/workflow_queue?error=#{@step}&workflow=#{@workflow}") do |_env|
659
656
  [200, {}, <<-EOXML]
660
657
  <objects count="1">
661
658
  <object id="druid:ab123cd4567" errorMessage="This is an error message"/>
@@ -667,27 +664,26 @@ RSpec.describe Dor::Workflow::Client do
667
664
 
668
665
  describe 'errored_objects_for_workstep' do
669
666
  it 'returns error messages for errored objects' do
670
- expect(client.errored_objects_for_workstep(@workflow, @step, @repository)).to eq('druid:ab123cd4567' => 'This is an error message')
667
+ expect(client.errored_objects_for_workstep(@workflow, @step)).to eq('druid:ab123cd4567' => 'This is an error message')
671
668
  end
672
669
  end
673
670
 
674
671
  describe 'count_errored_for_workstep' do
675
672
  it 'counts how many steps are errored out' do
676
- expect(client.count_errored_for_workstep(@workflow, @step, @repository)).to eq(1)
673
+ expect(client.count_errored_for_workstep(@workflow, @step)).to eq(1)
677
674
  end
678
675
  end
679
676
  end
680
677
 
681
678
  describe '#count_queued_for_workstep' do
682
679
  before(:all) do
683
- @repository = 'dor'
684
680
  @workflow = 'accessionWF'
685
681
  @step = 'publish'
686
682
  end
687
683
 
688
684
  let(:stubs) do
689
685
  Faraday::Adapter::Test::Stubs.new do |stub|
690
- stub.get("/workflow_queue?queued=#{@step}&repository=#{@repository}&workflow=#{@workflow}") do |_env|
686
+ stub.get("/workflow_queue?queued=#{@step}&workflow=#{@workflow}") do |_env|
691
687
  [200, {}, <<-EOXML]
692
688
  <objects count="1">
693
689
  <object id="druid:ab123cd4567"/>
@@ -698,7 +694,7 @@ RSpec.describe Dor::Workflow::Client do
698
694
  end
699
695
 
700
696
  it 'counts how many steps are errored out' do
701
- expect(client.count_queued_for_workstep(@workflow, @step, @repository)).to eq(1)
697
+ expect(client.count_queued_for_workstep(@workflow, @step)).to eq(1)
702
698
  end
703
699
  end
704
700
 
@@ -707,12 +703,11 @@ RSpec.describe Dor::Workflow::Client do
707
703
  @workflow = 'sdrIngestWF'
708
704
  @step = 'start-ingest'
709
705
  @type = 'waiting'
710
- @repository = 'sdr'
711
706
  end
712
707
 
713
708
  let(:stubs) do
714
709
  Faraday::Adapter::Test::Stubs.new do |stub|
715
- stub.get("/workflow_queue?repository=#{@repository}&workflow=#{@workflow}&#{@type}=#{@step}") do |_env|
710
+ stub.get("/workflow_queue?workflow=#{@workflow}&#{@type}=#{@step}") do |_env|
716
711
  [200, {}, <<-EOXML]
717
712
  <objects count="1">
718
713
  <object id="druid:oo000ra0001" url="null/fedora/objects/druid:oo000ra0001"/>
@@ -723,29 +718,45 @@ RSpec.describe Dor::Workflow::Client do
723
718
  end
724
719
 
725
720
  it 'counts how many objects are at the type of step' do
726
- expect(client.count_objects_in_step(@workflow, @step, @type, @repository)).to eq(1)
721
+ expect(client.count_objects_in_step(@workflow, @step, @type)).to eq(1)
727
722
  end
728
723
  end
729
724
 
730
725
  describe '#delete_workflow' do
731
- let(:url) { "#{@repo}/objects/#{@druid}/workflows/accessionWF" }
732
-
733
726
  let(:stubs) do
734
727
  Faraday::Adapter::Test::Stubs.new do |stub|
735
728
  stub.delete(url) { |_env| [202, {}, ''] }
736
729
  end
737
730
  end
738
731
 
739
- it 'sends a delete request to the workflow service' do
740
- expect(mock_http_connection).to receive(:delete).with(url).and_call_original
741
- client.delete_workflow(@repo, @druid, 'accessionWF')
732
+ context 'without a version' do
733
+ let(:url) { "/objects/#{@druid}/workflows/accessionWF" }
734
+
735
+ it 'sends a delete request to the workflow service' do
736
+ expect(Deprecation).to receive(:warn)
737
+ expect(mock_http_connection).to receive(:delete).with(url).and_call_original
738
+ client.delete_workflow(nil, @druid, 'accessionWF')
739
+ end
740
+ end
741
+
742
+ context 'with a version' do
743
+ let(:url) { "/objects/#{@druid}/workflows/accessionWF?version=5" }
744
+
745
+ it 'sends a delete request to the workflow service' do
746
+ expect(mock_http_connection).to receive(:delete).with(url).and_call_original
747
+ client.delete_workflow(nil, @druid, 'accessionWF', version: 5)
748
+ end
742
749
  end
743
750
  end
744
751
 
745
752
  describe '.stale_queued_workflows' do
753
+ before do
754
+ allow(Deprecation).to receive(:warn)
755
+ end
756
+
746
757
  let(:stubs) do
747
758
  Faraday::Adapter::Test::Stubs.new do |stub|
748
- stub.get('workflow_queue/all_queued?repository=dor&hours-ago=24&limit=100') do |_env|
759
+ stub.get('workflow_queue/all_queued?hours-ago=24&limit=100') do |_env|
749
760
  [200, {}, <<-XML]
750
761
  <workflows>
751
762
  <workflow laneId="lane1" note="annotation" lifecycle="in-process" errorText="stacktrace" errorMessage="NullPointerException" elapsed="1.173" repository="dor" attempts="0" datetime="2008-11-15T13:30:00-0800" status="waiting" process="content-metadata" name="accessionWF" druid="dr:123"/>
@@ -758,6 +769,7 @@ RSpec.describe Dor::Workflow::Client do
758
769
 
759
770
  it 'returns an Array of Hashes containing each workflow step' do
760
771
  ah = client.stale_queued_workflows 'dor', hours_ago: 24, limit: 100
772
+ expect(Deprecation).to have_received(:warn).once
761
773
  expected = [
762
774
  { workflow: 'accessionWF', step: 'content-metadata', druid: 'dr:123', lane_id: 'lane1' },
763
775
  { workflow: 'assemblyWF', step: 'jp2-create', druid: 'dr:456', lane_id: 'lane2' }
@@ -767,9 +779,13 @@ RSpec.describe Dor::Workflow::Client do
767
779
  end
768
780
 
769
781
  describe '.count_stale_queued_workflows' do
782
+ before do
783
+ allow(Deprecation).to receive(:warn)
784
+ end
785
+
770
786
  let(:stubs) do
771
787
  Faraday::Adapter::Test::Stubs.new do |stub|
772
- stub.get('workflow_queue/all_queued?repository=dor&hours-ago=48&count-only=true') do |_env|
788
+ stub.get('workflow_queue/all_queued?hours-ago=48&count-only=true') do |_env|
773
789
  [200, {}, '<objects count="10"/>']
774
790
  end
775
791
  end
@@ -777,10 +793,15 @@ RSpec.describe Dor::Workflow::Client do
777
793
 
778
794
  it 'returns the number of queued workflow steps' do
779
795
  expect(client.count_stale_queued_workflows('dor', hours_ago: 48)).to eq(10)
796
+ expect(Deprecation).to have_received(:warn).once
780
797
  end
781
798
  end
782
799
 
783
800
  describe '.lane_ids' do
801
+ before do
802
+ allow(Deprecation).to receive(:warn)
803
+ end
804
+
784
805
  let(:stubs) do
785
806
  Faraday::Adapter::Test::Stubs.new do |stub|
786
807
  stub.get('workflow_queue/lane_ids?lane_ids?step=dor:accessionWF:shelve') do |_env|
@@ -796,6 +817,7 @@ RSpec.describe Dor::Workflow::Client do
796
817
 
797
818
  it 'returns the lane ids for a given workflow step' do
798
819
  expect(client.lane_ids('dor', 'accessionWF', 'shelve')).to eq(%w[lane1 lane2])
820
+ expect(Deprecation).to have_received(:warn).once
799
821
  end
800
822
  end
801
823
  end