dor-workflow-client 3.6.0 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa5a23b0984a3d7da51db957e5a2d7c6edce81362f78ff539ecacfc6b84d533c
4
- data.tar.gz: 39414c933993e60ba993de7de54f4798b0d0afe5db787b4bf3891debc59f6fb9
3
+ metadata.gz: dc0e250229c8ecc7c2e6301ce8315580d3b00c722b3c433d2449f4f463e2ce8a
4
+ data.tar.gz: 589ae27fd6229f5f4484bedb4e17f519552e7c832ca0c9eaa8c483890c721546
5
5
  SHA512:
6
- metadata.gz: 8dd823c38cf34f668096682bf54ec5727572fd3cf34c095dab6e7d88a4ede15a3003fe25248d36b81c72e77457a00f6a2615b4c0b2fbcd20afb5b03a4108ca7a
7
- data.tar.gz: e6821dc36b1bd5c637b2c6f4aeb010e4f1e8f9e5ba2fce698ccf6a6bd8bd65d7e161e7bf59df57c89903bbaba718821fd51401b818d526ae1d6450a3bd49516a
6
+ metadata.gz: 0e94ca49bca7bc61552a167fec185994184b718a28b8143aca6a66091669b768868d111101103067a08313d86b40e5319009fdc4177f166736c333477c10177f
7
+ data.tar.gz: 7970103464337acdbc9fe721f1521d8192bb5ba14f055743d930e38984106160007fa574e5dd690c445507076566a2af39d58b5877eef0d3eaaa4ae5fb606773
data/.rubocop_todo.yml CHANGED
@@ -1,12 +1,12 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-04-06 08:08:20 -0500 using RuboCop version 0.63.1.
3
+ # on 2019-09-13 10:43:44 -0500 using RuboCop version 0.63.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 3
9
+ # Offense count: 2
10
10
  Metrics/AbcSize:
11
11
  Max: 23
12
12
 
@@ -15,7 +15,7 @@ Metrics/AbcSize:
15
15
  Metrics/MethodLength:
16
16
  Max: 13
17
17
 
18
- # Offense count: 2
18
+ # Offense count: 3
19
19
  # Configuration parameters: CountKeywordArgs.
20
20
  Metrics/ParameterLists:
21
- Max: 6
21
+ Max: 8
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'faraday'
4
3
  require 'faraday_middleware'
5
4
 
6
5
  module Dor
@@ -3,7 +3,7 @@
3
3
  module Dor
4
4
  module Workflow
5
5
  class Client
6
- VERSION = '3.6.0'
6
+ VERSION = '3.7.0'
7
7
  end
8
8
  end
9
9
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'deprecation'
4
-
5
3
  module Dor
6
4
  module Workflow
7
5
  class Client
@@ -49,6 +47,37 @@ module Dor
49
47
  true
50
48
  end
51
49
 
50
+ # Updates the status of one step in a workflow.
51
+ # Returns true on success. Caller must handle any exceptions
52
+ #
53
+ # @param [String] repo The repository the object resides in. The service recoginzes "dor" and "sdr" at the moment
54
+ # @param [String] druid The id of the object
55
+ # @param [String] workflow The name of the workflow
56
+ # @param [String] process The name of the process step
57
+ # @param [String] status The status that you want to set -- using one of the values in VALID_STATUS
58
+ # @param [Float] :elapsed The number of seconds it took to complete this step. Can have a decimal. Is set to 0 if not passed in.
59
+ # @param [String] :lifecycle Bookeeping label for this particular workflow step. Examples are: 'registered', 'shelved'
60
+ # @param [String] :note Any kind of string annotation that you want to attach to the workflow
61
+ # @param [String] :current_status Setting this string tells the workflow service to compare the current status to this value. If the current value does not match this value, the update is not performed
62
+ # @return [Boolean] always true
63
+ # Http Call
64
+ # ==
65
+ # The method does an HTTP PUT to the URL defined in `Dor::WF_URI`. As an example:
66
+ #
67
+ # PUT "/objects/pid:123/workflows/GoogleScannedWF/convert"
68
+ # <process name=\"convert\" status=\"completed\" />"
69
+ def update_status(druid:, workflow:, process:, status:, elapsed: 0, lifecycle: nil, note: nil, current_status: nil)
70
+ raise ArgumentError, "Unknown status value #{status}" unless VALID_STATUS.include?(status)
71
+ raise ArgumentError, "Unknown current_status value #{current_status}" if current_status && !VALID_STATUS.include?(current_status)
72
+
73
+ xml = create_process_xml(name: process, status: status, elapsed: elapsed, lifecycle: lifecycle, note: note)
74
+ uri = "objects/#{druid}/workflows/#{workflow}/#{process}"
75
+ uri += "?current-status=#{current_status}" if current_status
76
+ response = requestor.request(uri, 'put', xml, content_type: 'application/xml')
77
+
78
+ Workflow::Response::Update.new(json: response)
79
+ end
80
+
52
81
  # Updates the status of one step in a workflow.
53
82
  # Returns true on success. Caller must handle any exceptions
54
83
  #
@@ -80,9 +109,9 @@ module Dor
80
109
  uri = "#{repo}/objects/#{druid}/workflows/#{workflow}/#{process}"
81
110
  uri += "?current-status=#{current_status.downcase}" if current_status
82
111
  response = requestor.request(uri, 'put', xml, content_type: 'application/xml')
83
-
84
112
  Workflow::Response::Update.new(json: response)
85
113
  end
114
+ deprecation_deprecate update_workflow_status: 'use update_status instead.'
86
115
 
87
116
  #
88
117
  # Retrieves the process status of the given workflow for the given object identifier
@@ -4,6 +4,8 @@ require 'active_support'
4
4
  require 'active_support/core_ext'
5
5
  require 'nokogiri'
6
6
  require 'zeitwerk'
7
+ require 'faraday'
8
+ require 'deprecation'
7
9
 
8
10
  loader = Zeitwerk::Loader.new
9
11
  # Zeitwerk::GemInflector wants to be instantiated with the main .rb entrypoint
@@ -39,7 +41,7 @@ module Dor
39
41
 
40
42
  delegate :create_workflow, :create_workflow_by_name, :update_workflow_status, :workflow_status,
41
43
  :workflow_xml, :update_workflow_error_status, :all_workflows_xml, :workflows,
42
- :workflow, :delete_workflow, :delete_all_workflows, to: :workflow_routes
44
+ :workflow, :delete_workflow, :delete_all_workflows, :update_status, to: :workflow_routes
43
45
 
44
46
  delegate :lifecycle, :active_lifecycle, :milestones, to: :lifecycle_routes
45
47
 
@@ -25,6 +25,48 @@ RSpec.describe Dor::Workflow::Client::WorkflowRoutes do
25
25
  end
26
26
  end
27
27
 
28
+ describe '#update_status' do
29
+ let(:mock_requestor) { instance_double(Dor::Workflow::Client::Requestor, request: '{"next_steps":["submit-marc"]}') }
30
+ let(:druid) { 'druid:mw971zk1113' }
31
+
32
+ context 'when the request is successful' do
33
+ it 'updates workflow status and return true if successful' do
34
+ expect(routes.update_status(druid: druid, workflow: 'etdSubmitWF', process: 'registrar-approval', status: 'completed', note: 'annotation')).to be_kind_of Dor::Workflow::Response::Update
35
+ expect(mock_requestor).to have_received(:request)
36
+ .with('objects/druid:mw971zk1113/workflows/etdSubmitWF/registrar-approval',
37
+ 'put',
38
+ "<?xml version=\"1.0\"?>\n<process name=\"registrar-approval\" status=\"completed\" elapsed=\"0\" note=\"annotation\"/>\n",
39
+ content_type: 'application/xml')
40
+ end
41
+ end
42
+
43
+ context 'when the PUT to the DOR workflow service throws an exception' do
44
+ before do
45
+ allow(mock_requestor).to receive(:request).and_raise(Dor::WorkflowException, 'status 400')
46
+ end
47
+ it 'raises an exception' do
48
+ expect { routes.update_status(druid: druid, workflow: 'errorWF', process: 'registrar-approval', status: 'completed') }.to raise_error(Dor::WorkflowException, /status 400/)
49
+ end
50
+ end
51
+
52
+ context 'when current-status is passed as a parameter' do
53
+ it 'performs a conditional update' do
54
+ expect(routes.update_status(druid: druid, workflow: 'etdSubmitWF', process: 'registrar-approval', status: 'completed', note: 'annotation', current_status: 'queued')).to be_kind_of Dor::Workflow::Response::Update
55
+ expect(mock_requestor).to have_received(:request)
56
+ .with('objects/druid:mw971zk1113/workflows/etdSubmitWF/registrar-approval?current-status=queued',
57
+ 'put',
58
+ "<?xml version=\"1.0\"?>\n<process name=\"registrar-approval\" status=\"completed\" elapsed=\"0\" note=\"annotation\"/>\n",
59
+ content_type: 'application/xml')
60
+ end
61
+ end
62
+
63
+ context 'when an invalid status is provided' do
64
+ it 'throws an exception' do
65
+ expect { routes.update_status(druid: druid, workflow: 'accessionWF', process: 'publish', status: 'NOT_VALID_STATUS') }.to raise_error(ArgumentError)
66
+ end
67
+ end
68
+ end
69
+
28
70
  describe '#delete_all_workflows' do
29
71
  subject(:delete_all_workflows) do
30
72
  routes.delete_all_workflows(pid: 'druid:mw971zk1113')
@@ -143,6 +143,9 @@ RSpec.describe Dor::Workflow::Client do
143
143
  end
144
144
  end
145
145
  end
146
+ before do
147
+ allow(Deprecation).to receive(:warn)
148
+ end
146
149
 
147
150
  it 'should update workflow status and return true if successful' do
148
151
  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
@@ -181,7 +184,7 @@ RSpec.describe Dor::Workflow::Client do
181
184
  client.update_workflow_error_status(@repo, @druid, 'etdSubmitWF', 'reader-approval', 'Some exception', error_text: 'The optional stacktrace')
182
185
  end
183
186
  it 'should return false if the PUT to the DOR workflow service throws an exception' do
184
- expect { client.update_workflow_status(@repo, @druid, 'errorWF', 'reader-approval', 'completed') }.to raise_error(Dor::WorkflowException, /status 400/)
187
+ expect { client.update_workflow_error_status(@repo, @druid, 'errorWF', 'reader-approval', 'completed') }.to raise_error(Dor::WorkflowException, /status 400/)
185
188
  end
186
189
  end
187
190
 
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.6.0
4
+ version: 3.7.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 00:00:00.000000000 Z
12
+ date: 2019-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport