dor-workflow-client 3.0.0 → 3.1.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: a466510ea74b36c454ae742892e3f100db970d93f3e584edcb984ba9bff87b30
4
- data.tar.gz: ed836d1b6e9180f9195b407501f0040584c901100b40416e0405a983665b8fbf
3
+ metadata.gz: f379f2897210e36a67cf06fd7eed5ce8caa8b810b329a9c66dae0a03e03475d4
4
+ data.tar.gz: 309659963dca39f119c924d43be8599a3020d5154fb4dac3b4fc9923132542bf
5
5
  SHA512:
6
- metadata.gz: 33f86334702e1e4bdd32ab861bb871bd015781527f1896508897c09b9fe1432482fc1cee2a361e89c79be84b892e9c9ee708ed1c7b848f064b27780d3d3ca61c
7
- data.tar.gz: c597974072d997829af32e0ec449b7c9c69dab90229d0e662acac637fdee85bf26d5b95f780f9bcfbd99f97ce20035f5bcd4958b92626e4a236378c12cb4ff23
6
+ metadata.gz: 3d0240474ec807050bf566fe9f4fe329cd7c5a471da6486966fcf9baa733169ef6a2dd87d5442634180847a245f8e07355f323886450474b401810eb0270a797
7
+ data.tar.gz: f057983eab36e17474eccaebfca7bb96666eb7f0ad103fdd2d1139291ef659023f4cdad56dc32ec1d11de2903d6716deb90d2c9cb3815353c8fe131e3497e3ab
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_dependency 'activesupport', '>= 3.2.1', '< 6'
21
21
  gem.add_dependency 'confstruct', '>= 0.2.7', '< 2'
22
+ gem.add_dependency 'deprecation', '~> 0'
22
23
  gem.add_dependency 'faraday', '~> 0.9', '>= 0.9.2'
23
24
  gem.add_dependency 'faraday_middleware'
24
25
  gem.add_dependency 'net-http-persistent', '>= 2.9.4', '< 4.a'
@@ -5,7 +5,7 @@ require 'dor/models/response/process'
5
5
  module Dor
6
6
  module Workflow
7
7
  module Response
8
- # The response form asking the server about a workflow for an item
8
+ # The response from asking the server about a workflow for an item
9
9
  class Workflow
10
10
  def initialize(xml:)
11
11
  @xml = xml
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dor/models/response/workflow'
4
+
5
+ module Dor
6
+ module Workflow
7
+ module Response
8
+ # The response from asking the server about all workflows for an item
9
+ class Workflows
10
+ def initialize(xml:)
11
+ @xml = xml
12
+ end
13
+
14
+ def pid
15
+ ng_xml.at_xpath('/workflows/@objectId').text
16
+ end
17
+
18
+ def workflows
19
+ @workflows ||= ng_xml.xpath('/workflows/workflow').map do |node|
20
+ Workflow.new(xml: node.to_xml)
21
+ end
22
+ end
23
+
24
+ attr_reader :xml
25
+
26
+ private
27
+
28
+ def ng_xml
29
+ @ng_xml ||= Nokogiri::XML(@xml)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -3,7 +3,7 @@
3
3
  module Dor
4
4
  module Workflow
5
5
  class Client
6
- VERSION = '3.0.0'
6
+ VERSION = '3.1.0'
7
7
  end
8
8
  end
9
9
  end
@@ -1,34 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'deprecation'
4
+
3
5
  module Dor
4
6
  module Workflow
5
7
  class Client
6
8
  # Makes requests relating to a workflow
7
9
  class WorkflowRoutes
10
+ extend Deprecation
11
+
8
12
  def initialize(requestor:)
9
13
  @requestor = requestor
10
14
  end
11
15
 
12
- # Creates a workflow for a given object in the repository. If this particular workflow for this objects exists,
13
- # it will replace the old workflow with wf_xml passed to this method. You have the option of creating a datastream or not.
14
- # Returns true on success. Caller must handle any exceptions
16
+ # This method is deprecated and calls create_workflow_by_name.
15
17
  #
16
- # @param [String] repo The repository the object resides in. The service recoginzes "dor" and "sdr" at the moment
18
+ # @param [String] repo Ignored
17
19
  # @param [String] druid The id of the object
18
20
  # @param [String] workflow_name The name of the workflow you want to create
19
- # @param [String] wf_xml The xml that represents the workflow
21
+ # @param [String] wf_xml Ignored
20
22
  # @param [Hash] opts optional params
21
23
  # @option opts [Boolean] :create_ds if true, a workflow datastream will be created in Fedora. Set to false if you do not want a datastream to be created
22
24
  # If you do not pass in an <b>opts</b> Hash, then :create_ds is set to true by default
23
25
  # @option opts [String] :lane_id adds laneId attribute to all process elements in the wf_xml workflow xml. Defaults to a value of 'default'
24
26
  # @return [Boolean] always true
25
27
  #
26
- def create_workflow(repo, druid, workflow_name, wf_xml, opts = { create_ds: true })
27
- lane_id = opts.fetch(:lane_id, 'default')
28
- xml = add_lane_id_to_workflow_xml(lane_id, wf_xml)
29
- _status = requestor.request "#{repo}/objects/#{druid}/workflows/#{workflow_name}", 'put', xml,
30
- content_type: 'application/xml',
31
- params: { 'create-ds' => opts[:create_ds] }
28
+ def create_workflow(_repo, druid, workflow_name, _wf_xml, opts = { create_ds: true })
29
+ create_workflow_by_name(druid, workflow_name, opts)
30
+ end
31
+ deprecation_deprecate create_workflow: 'use create_workflow_by_name instead'
32
+
33
+ # Creates a workflow for a given object in the repository. If this particular workflow for this objects exists,
34
+ # it will replace the old workflow. You have the option of creating a datastream or not.
35
+ # Returns true on success. Caller must handle any exceptions.
36
+ #
37
+ # @param [String] repo The repository the object resides in. The service recoginzes "dor" and "sdr" at the moment
38
+ # @param [String] druid The id of the object
39
+ # @param [String] workflow_name The name of the workflow you want to create. This must correspond with a workflow
40
+ # name that is known by the workflow service.
41
+ # @param [Hash] opts optional params
42
+ # @option opts [String] :lane_id adds laneId attribute to all process elements in the wf_xml workflow xml. Defaults to a value of 'default'
43
+ # @return [Boolean] always true
44
+ #
45
+ def create_workflow_by_name(druid, workflow_name, opts = { create_ds: true })
46
+ requestor.request "objects/#{druid}/workflows/#{workflow_name}", 'post', '',
47
+ content_type: 'application/xml',
48
+ params: { 'lane-id' => opts.fetch(:lane_id, 'default') }
32
49
  true
33
50
  end
34
51
 
@@ -128,6 +145,14 @@ module Dor
128
145
  requestor.request "objects/#{druid}/workflows"
129
146
  end
130
147
 
148
+ # Retrieves all workflows for the given object
149
+ # @param [String] pid The id of the object
150
+ # @return [Workflow::Response::Workflows]
151
+ def all_workflows(pid:)
152
+ xml = all_workflows_xml(pid)
153
+ Workflow::Response::Workflows.new(xml: xml)
154
+ end
155
+
131
156
  # Get workflow names into an array for given PID
132
157
  # This method only works when this gem is used in a project that is configured to connect to DOR
133
158
  #
@@ -165,17 +190,6 @@ module Dor
165
190
 
166
191
  attr_reader :requestor
167
192
 
168
- # Adds laneId attributes to each process of workflow xml
169
- #
170
- # @param [String] lane_id to add to each process element
171
- # @param [String] wf_xml the workflow xml
172
- # @return [String] wf_xml with lane_id attributes
173
- def add_lane_id_to_workflow_xml(lane_id, wf_xml)
174
- doc = Nokogiri::XML(wf_xml)
175
- doc.xpath('/workflow/process').each { |proc| proc['laneId'] = lane_id }
176
- doc.to_xml
177
- end
178
-
179
193
  # @param [Hash] params
180
194
  # @return [String]
181
195
  def create_process_xml(params)
@@ -4,6 +4,7 @@ require 'active_support'
4
4
  require 'active_support/core_ext'
5
5
  require 'nokogiri'
6
6
  require 'dor/workflow_exception'
7
+ require 'dor/models/response/workflows'
7
8
  require 'dor/models/response/workflow'
8
9
  require 'dor/models/response/update'
9
10
 
@@ -36,8 +37,8 @@ module Dor
36
37
  @requestor = Requestor.new(connection: connection || ConnectionFactory.build_connection(url, timeout: timeout, logger: logger))
37
38
  end
38
39
 
39
- delegate :create_workflow, :update_workflow_status, :workflow_status, :workflow_xml,
40
- :update_workflow_error_status, :all_workflows_xml, :workflows,
40
+ delegate :create_workflow, :create_workflow_by_name, :update_workflow_status, :workflow_status,
41
+ :workflow_xml, :update_workflow_error_status, :all_workflows_xml, :workflows,
41
42
  :workflow, :delete_workflow, to: :workflow_routes
42
43
 
43
44
  delegate :lifecycle, :active_lifecycle, :milestones, to: :lifecycle_routes
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Dor::Workflow::Response::Workflows do
6
+ subject(:instance) { described_class.new(xml: xml) }
7
+
8
+ describe '#pid' do
9
+ subject { instance.pid }
10
+
11
+ let(:xml) do
12
+ <<~XML
13
+ <workflows objectId="druid:mw971zk1113">
14
+ </workflows>
15
+ XML
16
+ end
17
+ it { is_expected.to eq 'druid:mw971zk1113' }
18
+ end
19
+
20
+ describe '#workflows' do
21
+ subject { instance.workflows }
22
+
23
+ let(:xml) do
24
+ <<~XML
25
+ <workflows objectId="druid:mw971zk1113">
26
+ <workflow repository="dor" objectId="druid:mw971zk1113" id="assemblyWF">
27
+ </workflow>
28
+ <workflow repository="dor" objectId="druid:mw971zk1113" id="sdrPreservationWF">
29
+ </workflow>
30
+ </workflows>
31
+ XML
32
+ end
33
+
34
+ it 'has children' do
35
+ expect(subject).to all(be_kind_of Dor::Workflow::Response::Workflow)
36
+ expect(subject.map(&:workflow_name)).to eq %w[assemblyWF sdrPreservationWF]
37
+ end
38
+ end
39
+ end
@@ -6,20 +6,19 @@ require 'spec_helper'
6
6
  RSpec.describe Dor::Workflow::Client::ConnectionFactory do
7
7
  let(:mock_logger) { double('Logger', info: true, debug: true, warn: true) }
8
8
 
9
- let(:repo) { 'dor' }
10
9
  let(:druid) { 'druid:123' }
11
10
  before do
12
- stub_request(:put, "http://example.com/#{repo}/objects/#{druid}/workflows/httpException?create-ds=true")
11
+ stub_request(:post, "http://example.com/objects/#{druid}/workflows/httpException?lane-id=default")
13
12
  .to_return(status: 500, body: 'Internal error', headers: {})
14
13
  end
15
14
 
16
15
  let(:client) { Dor::Workflow::Client.new url: 'http://example.com', logger: mock_logger }
17
16
 
18
- describe '#create_workflow' do
17
+ describe '#create_workflow_by_name' do
19
18
  it 'logs an error and retry upon a targeted Faraday exception' do
20
- expect(mock_logger).to receive(:warn).with('retrying connection (1 remaining) to http://example.com/dor/objects/druid:123/workflows/httpException?create-ds=true: (Faraday::RetriableResponse) 500')
21
- expect(mock_logger).to receive(:warn).with('retrying connection (0 remaining) to http://example.com/dor/objects/druid:123/workflows/httpException?create-ds=true: (Faraday::RetriableResponse) 500')
22
- expect { client.create_workflow(repo, druid, 'httpException', '<xml>') }.to raise_error Dor::WorkflowException
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
23
22
  end
24
23
  end
25
24
  end
@@ -7,33 +7,6 @@ RSpec.describe Dor::Workflow::Client::WorkflowRoutes do
7
7
 
8
8
  let(:routes) { described_class.new(requestor: mock_requestor) }
9
9
 
10
- let(:wf_xml) do
11
- <<-EOXML
12
- <workflow id="etdSubmitWF">
13
- <process name="register-object" status="completed" attempts="1" />
14
- <process name="submit" status="waiting" />
15
- <process name="reader-approval" status="waiting" />
16
- <process name="registrar-approval" status="waiting" />
17
- <process name="start-accession" status="waiting" />
18
- </workflow>
19
- EOXML
20
- end
21
-
22
- describe '#add_lane_id_to_workflow_xml' do
23
- it 'adds laneId attributes to all process elements' do
24
- expected = <<-XML
25
- <workflow id="etdSubmitWF">
26
- <process name="register-object" status="completed" attempts="1" laneId="lane1"/>
27
- <process name="submit" status="waiting" laneId="lane1"/>
28
- <process name="reader-approval" status="waiting" laneId="lane1"/>
29
- <process name="registrar-approval" status="waiting" laneId="lane1"/>
30
- <process name="start-accession" status="waiting" laneId="lane1"/>
31
- </workflow>
32
- XML
33
- expect(routes.send(:add_lane_id_to_workflow_xml, 'lane1', wf_xml)).to be_equivalent_to(expected)
34
- end
35
- end
36
-
37
10
  describe '#workflow' do
38
11
  let(:xml) do
39
12
  <<~XML
@@ -42,6 +15,7 @@ RSpec.describe Dor::Workflow::Client::WorkflowRoutes do
42
15
  </workflow>
43
16
  XML
44
17
  end
18
+
45
19
  before do
46
20
  allow(routes).to receive(:workflow_xml) { xml }
47
21
  end
@@ -50,4 +24,27 @@ RSpec.describe Dor::Workflow::Client::WorkflowRoutes do
50
24
  expect(routes.workflow(pid: 'druid:mw971zk1113', workflow_name: 'accessionWF')).to be_kind_of Dor::Workflow::Response::Workflow
51
25
  end
52
26
  end
27
+
28
+ describe '#all_workflows' do
29
+ let(:xml) do
30
+ <<~XML
31
+ <workflows objectId="druid:mw971zk1113">
32
+ <workflow repository="dor" objectId="druid:mw971zk1113" id="accessionWF">
33
+ <process laneId="default" lifecycle="submitted" elapsed="0.0" attempts="1" datetime="2013-02-18T15:08:10-0800" status="completed" name="start-accession"/>
34
+ </workflow>
35
+ </workflows>
36
+ XML
37
+ end
38
+
39
+ before do
40
+ allow(routes).to receive(:all_workflows_xml) { xml }
41
+ end
42
+
43
+ it 'it returns the workflows' do
44
+ expect(routes.all_workflows(pid: 'druid:mw971zk1113')).to be_kind_of Dor::Workflow::Response::Workflows
45
+ end
46
+ end
47
+
48
+ describe '#create_workflow_by_name' do
49
+ end
53
50
  end
@@ -72,26 +72,51 @@ RSpec.describe Dor::Workflow::Client do
72
72
  describe '#create_workflow' do
73
73
  let(:stubs) do
74
74
  Faraday::Adapter::Test::Stubs.new do |stub|
75
- stub.put("#{@repo}/objects/#{@druid}/workflows/etdSubmitWF") { |_env| [201, {}, ''] }
76
- stub.put("#{@repo}/objects/#{@druid}/workflows/noCreateDsWF?create-ds=false") { |_env| [201, {}, ''] }
77
- stub.put("#{@repo}/objects/#{@druid}/workflows/raiseException") { |_env| raise 'broken' }
75
+ stub.post("objects/#{@druid}/workflows/etdSubmitWF") { |_env| [201, {}, ''] }
76
+ stub.post("objects/#{@druid}/workflows/raiseException") { |_env| raise 'broken' }
77
+ stub.post("objects/#{@druid}/workflows/laneIdWF?lane-id=foo_lane") { |_env| [201, {}, ''] }
78
78
  end
79
79
  end
80
80
 
81
- it 'should pass workflow xml to the DOR workflow service and return the URL to the workflow' do
81
+ before do
82
+ allow(Deprecation).to receive(:warn)
83
+ end
84
+
85
+ it 'should request the workflow by name and return the URL to the workflow' do
82
86
  client.create_workflow(@repo, @druid, 'etdSubmitWF', wf_xml)
87
+ expect(Deprecation).to have_received(:warn)
83
88
  end
84
89
 
85
90
  it 'should raise on an unexpected Exception' do
86
91
  expect { client.create_workflow(@repo, @druid, 'raiseException', wf_xml) }.to raise_error(Exception, 'broken')
92
+ expect(Deprecation).to have_received(:warn)
87
93
  end
88
94
 
89
- it 'sets the create-ds param to the value of the passed in options hash' do
90
- client.create_workflow(@repo, @druid, 'noCreateDsWF', wf_xml, create_ds: false)
95
+ it 'sets the lane_id param if provided in options hash' do
96
+ client.create_workflow(@repo, @druid, 'laneIdWF', wf_xml, lane_id: 'foo_lane')
97
+ expect(Deprecation).to have_received(:warn)
98
+ end
99
+ end
100
+
101
+ describe '#create_workflow_by_name' do
102
+ let(:stubs) do
103
+ Faraday::Adapter::Test::Stubs.new do |stub|
104
+ stub.post("objects/#{@druid}/workflows/etdSubmitWF") { |_env| [201, {}, ''] }
105
+ stub.post("objects/#{@druid}/workflows/raiseException") { |_env| raise 'broken' }
106
+ stub.post("objects/#{@druid}/workflows/laneIdWF?lane-id=foo_lane") { |_env| [201, {}, ''] }
107
+ end
108
+ end
109
+
110
+ it 'should request the workflow by name and return the URL to the workflow' do
111
+ client.create_workflow_by_name(@druid, 'etdSubmitWF')
112
+ end
113
+
114
+ it 'should raise on an unexpected Exception' do
115
+ expect { client.create_workflow_by_name(@druid, 'raiseException') }.to raise_error(Exception, 'broken')
91
116
  end
92
117
 
93
- it 'adds lane_id attributes to all steps if passed in as an option' do
94
- skip 'test not implemented'
118
+ it 'sets the lane_id param if provided in options hash' do
119
+ client.create_workflow_by_name(@druid, 'laneIdWF', lane_id: 'foo_lane')
95
120
  end
96
121
  end
97
122
 
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.0.0
4
+ version: 3.1.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-04-23 00:00:00.000000000 Z
12
+ date: 2019-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -51,6 +51,20 @@ dependencies:
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '2'
54
+ - !ruby/object:Gem::Dependency
55
+ name: deprecation
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
54
68
  - !ruby/object:Gem::Dependency
55
69
  name: faraday
56
70
  requirement: !ruby/object:Gem::Requirement
@@ -258,6 +272,7 @@ files:
258
272
  - lib/dor/models/response/process.rb
259
273
  - lib/dor/models/response/update.rb
260
274
  - lib/dor/models/response/workflow.rb
275
+ - lib/dor/models/response/workflows.rb
261
276
  - lib/dor/workflow/client.rb
262
277
  - lib/dor/workflow/client/connection_factory.rb
263
278
  - lib/dor/workflow/client/lifecycle_routes.rb
@@ -268,6 +283,7 @@ files:
268
283
  - lib/dor/workflow/client/workflow_routes.rb
269
284
  - lib/dor/workflow_exception.rb
270
285
  - spec/models/response/workflow_spec.rb
286
+ - spec/models/response/workflows_spec.rb
271
287
  - spec/spec_helper.rb
272
288
  - spec/workflow/client/connection_factory_spec.rb
273
289
  - spec/workflow/client/lifecycle_routes_spec.rb
@@ -299,6 +315,7 @@ specification_version: 4
299
315
  summary: Provides convenience methods to work with the DOR Workflow Service
300
316
  test_files:
301
317
  - spec/models/response/workflow_spec.rb
318
+ - spec/models/response/workflows_spec.rb
302
319
  - spec/spec_helper.rb
303
320
  - spec/workflow/client/connection_factory_spec.rb
304
321
  - spec/workflow/client/lifecycle_routes_spec.rb