dor-workflow-client 3.7.0 → 3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dor/workflow/client/lifecycle_routes.rb +15 -6
- data/lib/dor/workflow/client/version.rb +1 -1
- data/lib/dor/workflow/client/workflow_routes.rb +28 -6
- data/lib/dor/workflow/client.rb +2 -1
- data/spec/workflow/client/lifecycle_routes_spec.rb +23 -3
- data/spec/workflow/client/workflow_routes_spec.rb +25 -0
- data/spec/workflow/client_spec.rb +7 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79af115a9f02f6d3de631dcf9dd88d6160b1fddc865cb19bf39e2f76077a7992
|
4
|
+
data.tar.gz: 41a3bb9cd2cfe4a7ae7eb74617c4bb54b0f351a266b3c56e13e1ce7962fdc9a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e0e3579ec7be81ae999485c736d9314a71e4daf63116e19aaa7af92c86af59031795e61eca32114e5459c3c314fbe46f31d6640dde2fada2ec124abc1a1ff1c
|
7
|
+
data.tar.gz: 6ff468132eb597d1dc96e0901b828c4e4b9764832a4159ecbbb4920a3d9b705efc848586425eccd2fff195411a48e02a9a8e4e70c808e5ef350a98a636430c45
|
@@ -13,20 +13,23 @@ module Dor
|
|
13
13
|
# @param [String] repo repository name
|
14
14
|
# @param [String] druid object id
|
15
15
|
# @param [String] milestone_name the name of the milestone being queried for
|
16
|
+
# @param [Number] version the version to query for
|
16
17
|
# @return [Time] when the milestone was achieved. Returns nil if the milestone does not exist
|
17
18
|
#
|
18
|
-
def lifecycle(repo, druid, milestone_name)
|
19
|
-
filter_milestone(query_lifecycle(repo, druid), milestone_name)
|
19
|
+
def lifecycle(repo, druid, milestone_name, version: nil)
|
20
|
+
filter_milestone(query_lifecycle(repo, druid, version: version), milestone_name)
|
20
21
|
end
|
21
22
|
|
22
|
-
# Returns the Date for a requested milestone ONLY
|
23
|
+
# Returns the Date for a requested milestone ONLY for the current version.
|
24
|
+
# This is slow as the workflow server will query dor-services-app for the version.
|
25
|
+
# A better approach is #lifecycle with the version tag.
|
23
26
|
# @param [String] repo repository name
|
24
27
|
# @param [String] druid object id
|
25
28
|
# @param [String] milestone_name the name of the milestone being queried for
|
26
29
|
# @return [Time] when the milestone was achieved. Returns nil if the milestone does not exis
|
27
30
|
#
|
28
31
|
def active_lifecycle(repo, druid, milestone_name)
|
29
|
-
filter_milestone(query_lifecycle(repo, druid, true), milestone_name)
|
32
|
+
filter_milestone(query_lifecycle(repo, druid, active_only: true), milestone_name)
|
30
33
|
end
|
31
34
|
|
32
35
|
# @return [Hash]
|
@@ -54,9 +57,15 @@ module Dor
|
|
54
57
|
# <milestone date="2010-06-15T16:08:58-0700">released</milestone>
|
55
58
|
# </lifecycle>
|
56
59
|
#
|
57
|
-
def query_lifecycle(repo, druid, active_only
|
60
|
+
def query_lifecycle(repo, druid, active_only: false, version: nil)
|
58
61
|
req = "#{repo}/objects/#{druid}/lifecycle"
|
59
|
-
req +=
|
62
|
+
req += if version
|
63
|
+
"?version=#{version}"
|
64
|
+
elsif active_only
|
65
|
+
'?active-only=true'
|
66
|
+
else
|
67
|
+
''
|
68
|
+
end
|
60
69
|
Nokogiri::XML(requestor.request(req))
|
61
70
|
end
|
62
71
|
|
@@ -145,9 +145,10 @@ module Dor
|
|
145
145
|
# Updates the status of one step in a workflow to error.
|
146
146
|
# Returns true on success. Caller must handle any exceptions
|
147
147
|
#
|
148
|
-
# @param [String]
|
148
|
+
# @param [String] _repo The repository the object resides in. The service recoginzes "dor" and "sdr" at the moment
|
149
149
|
# @param [String] druid The id of the object
|
150
150
|
# @param [String] workflow The name of the workflow
|
151
|
+
# @param [String] process The name of the workflow step
|
151
152
|
# @param [String] error_msg The error message. Ideally, this is a brief message describing the error
|
152
153
|
# @param [Hash] opts optional values for the workflow step
|
153
154
|
# @option opts [String] :error_text A slot to hold more information about the error, like a full stacktrace
|
@@ -157,14 +158,35 @@ module Dor
|
|
157
158
|
# ==
|
158
159
|
# The method does an HTTP PUT to the URL defined in `Dor::WF_URI`.
|
159
160
|
#
|
160
|
-
# PUT "/
|
161
|
+
# PUT "/objects/pid:123/workflows/GoogleScannedWF/convert"
|
161
162
|
# <process name=\"convert\" status=\"error\" />"
|
162
|
-
def update_workflow_error_status(
|
163
|
-
|
164
|
-
xml = create_process_xml({ name: process, status: 'error', errorMessage: error_msg }.merge!(opts))
|
165
|
-
requestor.request "#{repo}/objects/#{druid}/workflows/#{workflow}/#{process}", 'put', xml, content_type: 'application/xml'
|
163
|
+
def update_workflow_error_status(_repo, druid, workflow, process, error_msg, opts = {})
|
164
|
+
update_error_status(druid: druid, workflow: workflow, process: process, error_msg: error_msg, error_text: opts[:error_text])
|
166
165
|
true
|
167
166
|
end
|
167
|
+
deprecation_deprecate update_workflow_error_status: 'use update_error_status instead.'
|
168
|
+
|
169
|
+
# Updates the status of one step in a workflow to error.
|
170
|
+
# Returns true on success. Caller must handle any exceptions
|
171
|
+
#
|
172
|
+
# @param [String] druid The id of the object
|
173
|
+
# @param [String] workflow The name of the workflow
|
174
|
+
# @param [String] process The name of the workflow step
|
175
|
+
# @param [String] error_msg The error message. Ideally, this is a brief message describing the error
|
176
|
+
# @param [String] error_text A slot to hold more information about the error, like a full stacktrace
|
177
|
+
# @return [Workflow::Response::Update]
|
178
|
+
#
|
179
|
+
# Http Call
|
180
|
+
# ==
|
181
|
+
# The method does an HTTP PUT to the URL defined in `Dor::WF_URI`.
|
182
|
+
#
|
183
|
+
# PUT "/objects/pid:123/workflows/GoogleScannedWF/convert"
|
184
|
+
# <process name=\"convert\" status=\"error\" />"
|
185
|
+
def update_error_status(druid:, workflow:, process:, error_msg:, error_text: nil)
|
186
|
+
xml = create_process_xml(name: process, status: 'error', errorMessage: error_msg, error_text: error_text)
|
187
|
+
response = requestor.request "objects/#{druid}/workflows/#{workflow}/#{process}", 'put', xml, content_type: 'application/xml'
|
188
|
+
Workflow::Response::Update.new(json: response)
|
189
|
+
end
|
168
190
|
|
169
191
|
#
|
170
192
|
# Retrieves the raw XML for all the workflows for the the given object
|
data/lib/dor/workflow/client.rb
CHANGED
@@ -41,7 +41,8 @@ module Dor
|
|
41
41
|
|
42
42
|
delegate :create_workflow, :create_workflow_by_name, :update_workflow_status, :workflow_status,
|
43
43
|
:workflow_xml, :update_workflow_error_status, :all_workflows_xml, :workflows,
|
44
|
-
:workflow, :delete_workflow, :delete_all_workflows, :update_status,
|
44
|
+
:workflow, :delete_workflow, :delete_all_workflows, :update_status, :update_error_status,
|
45
|
+
to: :workflow_routes
|
45
46
|
|
46
47
|
delegate :lifecycle, :active_lifecycle, :milestones, to: :lifecycle_routes
|
47
48
|
|
@@ -3,9 +3,9 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe Dor::Workflow::Client::LifecycleRoutes do
|
6
|
-
let(:
|
7
|
-
|
8
|
-
let(:routes) { described_class.new(requestor:
|
6
|
+
let(:requestor) { instance_double(Dor::Workflow::Client::Requestor, request: response) }
|
7
|
+
let(:response) { '<xml />' }
|
8
|
+
let(:routes) { described_class.new(requestor: requestor) }
|
9
9
|
|
10
10
|
describe '#milestones' do
|
11
11
|
let(:ng_xml) { Nokogiri::XML(xml) }
|
@@ -24,4 +24,24 @@ RSpec.describe Dor::Workflow::Client::LifecycleRoutes do
|
|
24
24
|
expect(milestones.first[:version]).to eq('2')
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
describe '#lifecycle' do
|
29
|
+
context 'without version' do
|
30
|
+
subject(:lifecycle) { routes.lifecycle('dor', 'druid:gv054hp4128', 'submitted') }
|
31
|
+
|
32
|
+
it 'make the request' do
|
33
|
+
lifecycle
|
34
|
+
expect(requestor).to have_received(:request).with('dor/objects/druid:gv054hp4128/lifecycle')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with version' do
|
39
|
+
subject(:lifecycle) { routes.lifecycle('dor', 'druid:gv054hp4128', 'submitted', version: 3) }
|
40
|
+
|
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')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
27
47
|
end
|
@@ -67,6 +67,31 @@ RSpec.describe Dor::Workflow::Client::WorkflowRoutes do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
describe '#update_error_status' do
|
71
|
+
let(:mock_requestor) { instance_double(Dor::Workflow::Client::Requestor, request: '{"next_steps":["submit-marc"]}') }
|
72
|
+
let(:druid) { 'druid:mw971zk1113' }
|
73
|
+
|
74
|
+
context 'when the request is successful' do
|
75
|
+
it 'updates workflow status and return true if successful' do
|
76
|
+
expect(routes.update_error_status(druid: druid, workflow: 'etdSubmitWF', process: 'registrar-approval', error_msg: 'broken')).to be_kind_of Dor::Workflow::Response::Update
|
77
|
+
expect(mock_requestor).to have_received(:request)
|
78
|
+
.with('objects/druid:mw971zk1113/workflows/etdSubmitWF/registrar-approval',
|
79
|
+
'put',
|
80
|
+
"<?xml version=\"1.0\"?>\n<process name=\"registrar-approval\" status=\"error\" errorMessage=\"broken\"/>\n",
|
81
|
+
content_type: 'application/xml')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when the PUT to the DOR workflow service throws an exception' do
|
86
|
+
before do
|
87
|
+
allow(mock_requestor).to receive(:request).and_raise(Dor::WorkflowException, 'status 400')
|
88
|
+
end
|
89
|
+
it 'raises an exception' do
|
90
|
+
expect { routes.update_error_status(druid: druid, workflow: 'errorWF', process: 'registrar-approval', error_msg: 'broken') }.to raise_error(Dor::WorkflowException, /status 400/)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
70
95
|
describe '#delete_all_workflows' do
|
71
96
|
subject(:delete_all_workflows) do
|
72
97
|
routes.delete_all_workflows(pid: 'druid:mw971zk1113')
|
@@ -169,17 +169,21 @@ RSpec.describe Dor::Workflow::Client do
|
|
169
169
|
describe '#update_workflow_error_status' do
|
170
170
|
let(:stubs) do
|
171
171
|
Faraday::Adapter::Test::Stubs.new do |stub|
|
172
|
-
stub.put("
|
172
|
+
stub.put("objects/#{@druid}/workflows/etdSubmitWF/reader-approval") do |env|
|
173
173
|
expect(env.body).to match(/status="error" errorMessage="Some exception" errorText="The optional stacktrace"/)
|
174
|
-
[201, {}, '']
|
174
|
+
[201, {}, '{"next_steps":["submit-marc"]}']
|
175
175
|
end
|
176
176
|
|
177
|
-
stub.put("
|
177
|
+
stub.put("objects/#{@druid}/workflows/errorWF/reader-approval") do |_env|
|
178
178
|
[400, {}, '']
|
179
179
|
end
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
183
|
+
before do
|
184
|
+
allow(Deprecation).to receive(:warn)
|
185
|
+
end
|
186
|
+
|
183
187
|
it 'should update workflow status to error and return true if successful' do
|
184
188
|
client.update_workflow_error_status(@repo, @druid, 'etdSubmitWF', 'reader-approval', 'Some exception', error_text: 'The optional stacktrace')
|
185
189
|
end
|
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.
|
4
|
+
version: 3.8.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-09-
|
12
|
+
date: 2019-09-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|