dor-workflow-service 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +26 -135
- data/Gemfile +4 -2
- data/Rakefile +7 -4
- data/bin/console +1 -0
- data/dor-workflow-service.gemspec +11 -8
- data/lib/dor-workflow-service.rb +2 -0
- data/lib/dor/models/response/workflow.rb +26 -0
- data/lib/dor/services/workflow_service.rb +59 -40
- data/lib/dor/workflow_exception.rb +2 -0
- data/lib/dor/workflow_version.rb +3 -1
- data/spec/models/response/workflow_spec.rb +36 -0
- data/spec/plumbing_spec.rb +3 -1
- data/spec/spec_helper.rb +3 -1
- data/spec/workflow_service_spec.rb +94 -72
- metadata +72 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4abc8faa2adf7c8c9f51ed741e5c7347468d1a86c15e7f6d9302500a8985e820
|
4
|
+
data.tar.gz: 9be7245887a6b93ac5461b69f6bea3d72a29e0d906ae14a1ea73b73396145008
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6e52377d0c17001f5e98f301b7d4d21c2572f23fd5c6871e9d03f3d1f9678aa4aa53df1893e7301bde5617d94c41b08552716c51565daf427bca2bfad441956
|
7
|
+
data.tar.gz: 7a4f03c9a5bdc93a289256094690d81f40cea5327343eaab1f9def9b556c239bc2c4d2a6a40556ce097ed2f9df71a3b564f24f1305223d4fb987b5dadda578d9
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,157 +1,48 @@
|
|
1
|
-
# This configuration was generated by
|
2
|
-
#
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2019-02-01 13:34:49 -0600 using RuboCop version 0.63.1.
|
3
4
|
# The point is for the user to remove these configuration records
|
4
5
|
# one by one as the offenses are removed from the code base.
|
5
6
|
# Note that changes in the inspected code, or installation of new
|
6
7
|
# versions of RuboCop, may require this file to be generated again.
|
7
8
|
|
8
9
|
# Offense count: 1
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
Lint/AmbiguousRegexpLiteral:
|
11
|
+
Exclude:
|
12
|
+
- 'spec/workflow_service_spec.rb'
|
12
13
|
|
13
14
|
# Offense count: 1
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
Lint/UselessAssignment:
|
16
|
+
Exclude:
|
17
|
+
- 'lib/dor/services/workflow_service.rb'
|
17
18
|
|
18
19
|
# Offense count: 2
|
19
20
|
Metrics/AbcSize:
|
20
|
-
Max:
|
21
|
-
|
22
|
-
# Offense count: 2
|
23
|
-
# Configuration parameters: CountComments.
|
24
|
-
Metrics/MethodLength:
|
25
|
-
Max: 16
|
21
|
+
Max: 22
|
26
22
|
|
27
23
|
# Offense count: 1
|
28
24
|
# Configuration parameters: CountComments.
|
29
|
-
Metrics/
|
30
|
-
Max:
|
25
|
+
Metrics/ClassLength:
|
26
|
+
Max: 250
|
27
|
+
|
28
|
+
# Offense count: 2
|
29
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
30
|
+
Metrics/MethodLength:
|
31
|
+
Max: 20
|
31
32
|
|
32
33
|
# Offense count: 2
|
33
34
|
# Configuration parameters: CountKeywordArgs.
|
34
35
|
Metrics/ParameterLists:
|
35
36
|
Max: 6
|
36
37
|
|
37
|
-
# Offense count: 2
|
38
|
-
# Cop supports --auto-correct.
|
39
|
-
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
|
40
|
-
Style/AlignHash:
|
41
|
-
Enabled: false
|
42
|
-
|
43
|
-
# Offense count: 2
|
44
|
-
# Cop supports --auto-correct.
|
45
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
|
46
|
-
Style/BlockDelimiters:
|
47
|
-
Enabled: false
|
48
|
-
|
49
|
-
# Offense count: 5
|
50
|
-
# Cop supports --auto-correct.
|
51
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
52
|
-
Style/BracesAroundHashParameters:
|
53
|
-
Enabled: false
|
54
|
-
|
55
|
-
# Offense count: 4
|
56
|
-
Style/ClassVars:
|
57
|
-
Enabled: false
|
58
|
-
|
59
|
-
# Offense count: 1
|
60
|
-
Style/Documentation:
|
61
|
-
Enabled: false
|
62
|
-
|
63
|
-
# Offense count: 2
|
64
|
-
# Cop supports --auto-correct.
|
65
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
66
|
-
Style/EmptyLinesAroundClassBody:
|
67
|
-
Enabled: false
|
68
|
-
|
69
|
-
# Offense count: 1
|
70
|
-
# Cop supports --auto-correct.
|
71
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
72
|
-
Style/EmptyLinesAroundModuleBody:
|
73
|
-
Enabled: false
|
74
|
-
|
75
|
-
# Offense count: 1
|
76
|
-
# Configuration parameters: Exclude.
|
77
|
-
Style/FileName:
|
78
|
-
Enabled: false
|
79
|
-
|
80
|
-
# Offense count: 52
|
81
|
-
# Cop supports --auto-correct.
|
82
|
-
# Configuration parameters: SupportedStyles, UseHashRocketsWithSymbolValues.
|
83
|
-
Style/HashSyntax:
|
84
|
-
EnforcedStyle: hash_rockets
|
85
|
-
|
86
|
-
# Offense count: 2
|
87
|
-
# Cop supports --auto-correct.
|
88
|
-
Style/LeadingCommentSpace:
|
89
|
-
Enabled: false
|
90
|
-
|
91
|
-
# Offense count: 2
|
92
|
-
# Cop supports --auto-correct.
|
93
|
-
Style/MultilineBlockLayout:
|
94
|
-
Enabled: false
|
95
|
-
|
96
|
-
# Offense count: 6
|
97
|
-
# Cop supports --auto-correct.
|
98
|
-
# Configuration parameters: AllowSafeAssignment.
|
99
|
-
Style/ParenthesesAroundCondition:
|
100
|
-
Enabled: false
|
101
|
-
|
102
|
-
# Offense count: 10
|
103
|
-
# Cop supports --auto-correct.
|
104
|
-
# Configuration parameters: PreferredDelimiters.
|
105
|
-
Style/PercentLiteralDelimiters:
|
106
|
-
Enabled: false
|
107
|
-
|
108
38
|
# Offense count: 1
|
109
|
-
# Configuration parameters:
|
110
|
-
|
111
|
-
|
39
|
+
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
40
|
+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
41
|
+
Naming/FileName:
|
42
|
+
Exclude:
|
43
|
+
- 'lib/dor-workflow-service.rb'
|
112
44
|
|
113
|
-
# Offense count:
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
Enabled: false
|
118
|
-
|
119
|
-
# Offense count: 11
|
120
|
-
# Cop supports --auto-correct.
|
121
|
-
# Configuration parameters: MultiSpaceAllowedForOperators.
|
122
|
-
Style/SpaceAroundOperators:
|
123
|
-
Enabled: false
|
124
|
-
|
125
|
-
# Offense count: 6
|
126
|
-
# Cop supports --auto-correct.
|
127
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
128
|
-
Style/SpaceBeforeBlockBraces:
|
129
|
-
Enabled: false
|
130
|
-
|
131
|
-
# Offense count: 8
|
132
|
-
# Cop supports --auto-correct.
|
133
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
134
|
-
Style/SpaceInsideBlockBraces:
|
135
|
-
Enabled: false
|
136
|
-
|
137
|
-
# Offense count: 6
|
138
|
-
# Cop supports --auto-correct.
|
139
|
-
Style/SpaceInsideBrackets:
|
140
|
-
Enabled: false
|
141
|
-
|
142
|
-
# Offense count: 15
|
143
|
-
# Cop supports --auto-correct.
|
144
|
-
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
|
145
|
-
Style/SpaceInsideHashLiteralBraces:
|
146
|
-
Enabled: false
|
147
|
-
|
148
|
-
# Offense count: 4
|
149
|
-
# Cop supports --auto-correct.
|
150
|
-
Style/SpaceInsideParens:
|
151
|
-
Enabled: false
|
152
|
-
|
153
|
-
# Offense count: 1
|
154
|
-
# Cop supports --auto-correct.
|
155
|
-
# Configuration parameters: IgnoredMethods.
|
156
|
-
Style/SymbolProc:
|
157
|
-
Enabled: false
|
45
|
+
# Offense count: 9
|
46
|
+
Style/ClassVars:
|
47
|
+
Exclude:
|
48
|
+
- 'lib/dor/services/workflow_service.rb'
|
data/Gemfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in dor-workflow-service.gemspec
|
@@ -7,7 +9,7 @@ gem 'activesupport', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']
|
|
7
9
|
|
8
10
|
group :development, :test do
|
9
11
|
gem 'byebug'
|
10
|
-
gem
|
11
|
-
gem
|
12
|
+
gem 'simplecov'
|
13
|
+
gem 'vcr'
|
12
14
|
gem 'webmock'
|
13
15
|
end
|
data/Rakefile
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/setup'
|
2
4
|
require 'bundler/gem_tasks'
|
3
5
|
|
4
6
|
require 'rspec/core/rake_task'
|
7
|
+
require 'rubocop/rake_task'
|
5
8
|
|
6
|
-
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
12
|
+
desc 'Run linter and tests'
|
13
|
+
task default: %i[rubocop spec]
|
11
14
|
|
12
15
|
require 'yard'
|
13
16
|
YARD::Rake::YardocTask.new
|
data/bin/console
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'dor/workflow_version'
|
5
6
|
|
@@ -13,21 +14,23 @@ Gem::Specification.new do |gem|
|
|
13
14
|
gem.homepage = 'https://consul.stanford.edu/display/DOR/DOR+services#DORservices-initializeworkflow'
|
14
15
|
|
15
16
|
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
16
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
17
18
|
gem.test_files = gem.files.grep(%r{^(spec)/})
|
18
19
|
gem.require_paths = ['lib']
|
19
20
|
|
20
21
|
gem.add_dependency 'activesupport', '>= 3.2.1', '< 6'
|
21
|
-
gem.add_dependency 'nokogiri', '~> 1.6'
|
22
|
-
gem.add_dependency 'retries'
|
23
22
|
gem.add_dependency 'confstruct', '>= 0.2.7', '< 2'
|
23
|
+
gem.add_dependency 'deprecation'
|
24
24
|
gem.add_dependency 'faraday', '~> 0.9', '>= 0.9.2'
|
25
25
|
gem.add_dependency 'net-http-persistent', '>= 2.9.4', '< 4.a'
|
26
|
+
gem.add_dependency 'nokogiri', '~> 1.6'
|
27
|
+
gem.add_dependency 'retries'
|
26
28
|
|
29
|
+
gem.add_development_dependency 'equivalent-xml', '~> 0.5', '>= 0.5.1'
|
27
30
|
gem.add_development_dependency 'rake'
|
28
|
-
gem.add_development_dependency 'rspec', '~> 3.3'
|
29
|
-
gem.add_development_dependency 'yard'
|
30
31
|
gem.add_development_dependency 'redcarpet'
|
31
|
-
gem.add_development_dependency '
|
32
|
+
gem.add_development_dependency 'rspec', '~> 3.3'
|
33
|
+
gem.add_development_dependency 'rubocop', '~> 0.63.1'
|
32
34
|
gem.add_development_dependency 'simplecov'
|
35
|
+
gem.add_development_dependency 'yard'
|
33
36
|
end
|
data/lib/dor-workflow-service.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dor
|
4
|
+
module Workflow
|
5
|
+
module Response
|
6
|
+
# The response form asking the server about a workflow for an item
|
7
|
+
class Workflow
|
8
|
+
def initialize(xml:)
|
9
|
+
@xml = xml
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param [Integer] version the version we are checking for.
|
13
|
+
def active_for?(version:)
|
14
|
+
result = ng_xml.at_xpath("/workflow/process[@version=#{version}]")
|
15
|
+
result ? true : false
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def ng_xml
|
21
|
+
@ng_xml ||= Nokogiri::XML(@xml)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,12 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support'
|
2
4
|
require 'active_support/core_ext'
|
3
5
|
require 'nokogiri'
|
4
6
|
require 'retries'
|
5
7
|
require 'faraday'
|
6
8
|
require 'dor/workflow_exception'
|
9
|
+
require 'dor/models/response/workflow'
|
10
|
+
require 'deprecation'
|
7
11
|
|
8
12
|
module Dor
|
9
|
-
|
10
13
|
# TODO: major version revision: change pattern of usage to be normal non-singleton class
|
11
14
|
# TODO: convert @@class_vars to regular attributes
|
12
15
|
# TODO: create normal initalize method, deprecate configure
|
@@ -17,6 +20,7 @@ module Dor
|
|
17
20
|
|
18
21
|
# Create and update workflows
|
19
22
|
class WorkflowService
|
23
|
+
extend Deprecation
|
20
24
|
class << self
|
21
25
|
@@handler = nil
|
22
26
|
@@logger = nil
|
@@ -25,7 +29,7 @@ module Dor
|
|
25
29
|
@@http_conn = nil
|
26
30
|
|
27
31
|
# From Workflow Service's admin/Process.java
|
28
|
-
VALID_STATUS = %w
|
32
|
+
VALID_STATUS = %w[waiting completed error queued skipped hold].freeze
|
29
33
|
|
30
34
|
# Creates a workflow for a given object in the repository. If this particular workflow for this objects exists,
|
31
35
|
# it will replace the old workflow with wf_xml passed to this method. You have the option of creating a datastream or not.
|
@@ -41,14 +45,12 @@ module Dor
|
|
41
45
|
# @option opts [String] :lane_id adds laneId attribute to all process elements in the wf_xml workflow xml. Defaults to a value of 'default'
|
42
46
|
# @return [Boolean] always true
|
43
47
|
#
|
44
|
-
def create_workflow(repo, druid, workflow_name, wf_xml, opts = {:
|
48
|
+
def create_workflow(repo, druid, workflow_name, wf_xml, opts = { create_ds: true })
|
45
49
|
lane_id = opts.fetch(:lane_id, 'default')
|
46
50
|
xml = add_lane_id_to_workflow_xml(lane_id, wf_xml)
|
47
51
|
status = workflow_resource_method "#{repo}/objects/#{druid}/workflows/#{workflow_name}", 'put', xml,
|
48
|
-
|
49
|
-
|
50
|
-
:params => { 'create-ds' => opts[:create_ds] }
|
51
|
-
}
|
52
|
+
content_type: 'application/xml',
|
53
|
+
params: { 'create-ds' => opts[:create_ds] }
|
52
54
|
true
|
53
55
|
end
|
54
56
|
|
@@ -75,13 +77,14 @@ module Dor
|
|
75
77
|
# <process name=\"convert\" status=\"completed\" />"
|
76
78
|
def update_workflow_status(repo, druid, workflow, process, status, opts = {})
|
77
79
|
raise ArgumentError, "Unknown status value #{status}" unless VALID_STATUS.include?(status.downcase)
|
78
|
-
|
80
|
+
|
81
|
+
opts = { elapsed: 0, lifecycle: nil, note: nil }.merge!(opts)
|
79
82
|
opts[:elapsed] = opts[:elapsed].to_s
|
80
83
|
current_status = opts.delete(:current_status)
|
81
|
-
xml = create_process_xml({ :
|
84
|
+
xml = create_process_xml({ name: process, status: status.downcase }.merge!(opts))
|
82
85
|
uri = "#{repo}/objects/#{druid}/workflows/#{workflow}/#{process}"
|
83
|
-
uri
|
84
|
-
workflow_resource_method(uri, 'put', xml,
|
86
|
+
uri += "?current-status=#{current_status.downcase}" if current_status
|
87
|
+
workflow_resource_method(uri, 'put', xml, content_type: 'application/xml')
|
85
88
|
true
|
86
89
|
end
|
87
90
|
|
@@ -95,7 +98,8 @@ module Dor
|
|
95
98
|
def get_workflow_status(repo, druid, workflow, process)
|
96
99
|
workflow_md = get_workflow_xml(repo, druid, workflow)
|
97
100
|
doc = Nokogiri::XML(workflow_md)
|
98
|
-
raise Dor::WorkflowException
|
101
|
+
raise Dor::WorkflowException, "Unable to parse response:\n#{workflow_md}" if doc.root.nil?
|
102
|
+
|
99
103
|
processes = doc.root.xpath("//process[@name='#{process}']")
|
100
104
|
process = processes.max { |a, b| a.attr('version').to_i <=> b.attr('version').to_i }
|
101
105
|
process&.attr('status')
|
@@ -122,7 +126,7 @@ module Dor
|
|
122
126
|
# => ["accessionWF", "assemblyWF", "disseminationWF"]
|
123
127
|
def get_workflows(pid, repo = 'dor')
|
124
128
|
xml_doc = Nokogiri::XML(get_workflow_xml(repo, pid, ''))
|
125
|
-
xml_doc.xpath('//workflow').collect {|workflow| workflow['id']}
|
129
|
+
xml_doc.xpath('//workflow').collect { |workflow| workflow['id'] }
|
126
130
|
end
|
127
131
|
|
128
132
|
# Get active workflow names into an array for given PID
|
@@ -135,8 +139,18 @@ module Dor
|
|
135
139
|
# Dor::WorkflowService.get_active_workflows('dor', 'druid:sr100hp0609')
|
136
140
|
# => ["accessionWF", "assemblyWF", "disseminationWF"]
|
137
141
|
def get_active_workflows(repo, pid)
|
142
|
+
Deprecation.warn(self, 'get_active_workflows will be removed without replacement because the workflow server no longer archives processes')
|
138
143
|
doc = Nokogiri::XML(get_workflow_xml(repo, pid, ''))
|
139
|
-
doc.xpath(
|
144
|
+
doc.xpath(%(//workflow[not(process/@archived)]/@id )).map(&:value)
|
145
|
+
end
|
146
|
+
|
147
|
+
# @param [String] repo repository of the object
|
148
|
+
# @param [String] pid id of object
|
149
|
+
# @param [String] workflow_name The name of the workflow
|
150
|
+
# @return [Workflow::Response::Workflow]
|
151
|
+
def workflow(repo: 'dor', pid:, workflow_name:)
|
152
|
+
xml = get_workflow_xml(repo, pid, workflow_name)
|
153
|
+
Workflow::Response::Workflow.new(xml: xml)
|
140
154
|
end
|
141
155
|
|
142
156
|
# Updates the status of one step in a workflow to error.
|
@@ -157,9 +171,9 @@ module Dor
|
|
157
171
|
# PUT "/dor/objects/pid:123/workflows/GoogleScannedWF/convert"
|
158
172
|
# <process name=\"convert\" status=\"error\" />"
|
159
173
|
def update_workflow_error_status(repo, druid, workflow, process, error_msg, opts = {})
|
160
|
-
opts = {:
|
161
|
-
xml = create_process_xml({:
|
162
|
-
workflow_resource_method "#{repo}/objects/#{druid}/workflows/#{workflow}/#{process}", 'put', xml,
|
174
|
+
opts = { error_text: nil }.merge!(opts)
|
175
|
+
xml = create_process_xml({ name: process, status: 'error', errorMessage: error_msg }.merge!(opts))
|
176
|
+
workflow_resource_method "#{repo}/objects/#{druid}/workflows/#{workflow}/#{process}", 'put', xml, content_type: 'application/xml'
|
163
177
|
true
|
164
178
|
end
|
165
179
|
|
@@ -188,6 +202,7 @@ module Dor
|
|
188
202
|
doc = query_lifecycle(repo, druid)
|
189
203
|
milestone = doc.at_xpath("//lifecycle/milestone[text() = '#{milestone}']")
|
190
204
|
return Time.parse(milestone['date']) if milestone
|
205
|
+
|
191
206
|
nil
|
192
207
|
end
|
193
208
|
|
@@ -206,6 +221,7 @@ module Dor
|
|
206
221
|
doc = query_lifecycle(repo, druid, true)
|
207
222
|
milestone = doc.at_xpath("//lifecycle/milestone[text() = '#{milestone}']")
|
208
223
|
return Time.parse(milestone['date']) if milestone
|
224
|
+
|
209
225
|
nil
|
210
226
|
end
|
211
227
|
|
@@ -213,7 +229,7 @@ module Dor
|
|
213
229
|
def get_milestones(repo, druid)
|
214
230
|
doc = query_lifecycle(repo, druid)
|
215
231
|
doc.xpath('//lifecycle/milestone').collect do |node|
|
216
|
-
{ :
|
232
|
+
{ milestone: node.text, at: Time.parse(node['date']), version: node['version'] }
|
217
233
|
end
|
218
234
|
end
|
219
235
|
|
@@ -271,12 +287,12 @@ module Dor
|
|
271
287
|
if completed
|
272
288
|
Array(completed).each do |step|
|
273
289
|
completed_param = qualify_step(options[:default_repository], options[:default_workflow], step)
|
274
|
-
uri_string
|
290
|
+
uri_string += "&completed=#{completed_param}"
|
275
291
|
end
|
276
292
|
end
|
277
293
|
|
278
|
-
uri_string
|
279
|
-
uri_string
|
294
|
+
uri_string += "&limit=#{options[:limit].to_i}" if options[:limit]&.to_i&.positive?
|
295
|
+
uri_string += "&lane-id=#{lane_id}"
|
280
296
|
|
281
297
|
resp = workflow_resource_method uri_string
|
282
298
|
#
|
@@ -367,7 +383,7 @@ module Dor
|
|
367
383
|
# @return [Integer] number of stale, queued steps if the :count_only option was set to true
|
368
384
|
def count_stale_queued_workflows(repository, opts = {})
|
369
385
|
uri_string = build_queued_uri(repository, opts) + '&count-only=true'
|
370
|
-
doc = Nokogiri::XML(workflow_resource_method
|
386
|
+
doc = Nokogiri::XML(workflow_resource_method(uri_string))
|
371
387
|
doc.at_xpath('/objects/@count').value.to_i
|
372
388
|
end
|
373
389
|
|
@@ -375,8 +391,8 @@ module Dor
|
|
375
391
|
# @return [String]
|
376
392
|
def create_process_xml(params)
|
377
393
|
builder = Nokogiri::XML::Builder.new do |xml|
|
378
|
-
attrs = params.reject { |
|
379
|
-
attrs = Hash[
|
394
|
+
attrs = params.reject { |_k, v| v.nil? }
|
395
|
+
attrs = Hash[attrs.map { |k, v| [k.to_s.camelize(:lower), v] }] # camelize all the keys in the attrs hash
|
380
396
|
xml.process(attrs)
|
381
397
|
end
|
382
398
|
builder.to_xml
|
@@ -385,8 +401,8 @@ module Dor
|
|
385
401
|
# @return [Nokogiri::XML::Document]
|
386
402
|
def query_lifecycle(repo, druid, active_only = false)
|
387
403
|
req = "#{repo}/objects/#{druid}/lifecycle"
|
388
|
-
req
|
389
|
-
Nokogiri::XML(workflow_resource_method
|
404
|
+
req += '?active-only=true' if active_only
|
405
|
+
Nokogiri::XML(workflow_resource_method(req))
|
390
406
|
end
|
391
407
|
|
392
408
|
# @param [String] repo The repository the object resides in. The service recoginzes "dor" and "sdr" at the moment
|
@@ -400,10 +416,11 @@ module Dor
|
|
400
416
|
|
401
417
|
# @param [String] repo The repository the object resides in. The service recoginzes "dor" and "sdr" at the moment
|
402
418
|
# @param [String] druid The id of the object to delete the workflow from
|
403
|
-
def archive_workflow(
|
419
|
+
def archive_workflow(_repo, druid, wf_name, version_num = nil)
|
404
420
|
raise 'Please call Dor::WorkflowService.configure(workflow_service_url, :dor_services_url => DOR_SERVIES_URL) once before archiving workflow' if @@dor_services_url.nil?
|
421
|
+
|
405
422
|
url = "/v1/objects/#{druid}/workflows/#{wf_name}/archive"
|
406
|
-
url
|
423
|
+
url += "/#{version_num}" if version_num
|
407
424
|
workflow_resource_method(url, 'post', '')
|
408
425
|
end
|
409
426
|
|
@@ -417,7 +434,7 @@ module Dor
|
|
417
434
|
# @param [Boolean] create_accession_wf Option to create accessionWF when closing a version. Defaults to true
|
418
435
|
def close_version(repo, druid, create_accession_wf = true)
|
419
436
|
uri = "#{repo}/objects/#{druid}/versionClose"
|
420
|
-
uri
|
437
|
+
uri += '?create-accession=false' unless create_accession_wf
|
421
438
|
workflow_resource_method(uri, 'post', '')
|
422
439
|
true
|
423
440
|
end
|
@@ -430,7 +447,7 @@ module Dor
|
|
430
447
|
# @return [Array<String>] all of the distinct laneIds. Array will be empty if no lane ids were found
|
431
448
|
def get_lane_ids(repo, workflow, process)
|
432
449
|
uri = "workflow_queue/lane_ids?step=#{repo}:#{workflow}:#{process}"
|
433
|
-
doc = Nokogiri::XML(workflow_resource_method
|
450
|
+
doc = Nokogiri::XML(workflow_resource_method(uri))
|
434
451
|
nodes = doc.xpath('/lanes/lane')
|
435
452
|
nodes.map { |n| n['id'] }
|
436
453
|
end
|
@@ -439,6 +456,7 @@ module Dor
|
|
439
456
|
# @return [Faraday::Connection] the REST client resource created during configure()
|
440
457
|
def workflow_resource
|
441
458
|
raise 'Please call Dor::WorkflowService.configure(url) once before calling any WorkflowService methods' if @@http_conn.nil?
|
459
|
+
|
442
460
|
@@http_conn
|
443
461
|
end
|
444
462
|
|
@@ -476,7 +494,7 @@ module Dor
|
|
476
494
|
@@dor_services_url = opts[:dor_services_url] if opts[:dor_services_url]
|
477
495
|
# params[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(opts[:client_cert_file])) if opts[:client_cert_file]
|
478
496
|
# params[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(opts[:client_key_file]), opts[:client_key_pass]) if opts[:client_key_file]
|
479
|
-
@@handler =
|
497
|
+
@@handler = proc do |exception, attempt_number, total_delay|
|
480
498
|
@@logger.warn "[Attempt #{attempt_number}] #{exception.class}: #{exception.message}; #{total_delay} seconds elapsed."
|
481
499
|
end
|
482
500
|
@@http_conn = case url_or_connection
|
@@ -484,7 +502,7 @@ module Dor
|
|
484
502
|
Faraday.new(url: url_or_connection) do |faraday|
|
485
503
|
faraday.response :logger if opts[:debug] # logs to STDOUT
|
486
504
|
faraday.use Faraday::Response::RaiseError
|
487
|
-
faraday.adapter
|
505
|
+
faraday.adapter :net_http_persistent # use Keep-Alive connections
|
488
506
|
faraday.options.params_encoder = Faraday::FlatParamsEncoder
|
489
507
|
if opts.key? :timeout
|
490
508
|
faraday.options.timeout = opts[:timeout]
|
@@ -505,8 +523,8 @@ module Dor
|
|
505
523
|
|
506
524
|
def build_queued_uri(repository, opts = {})
|
507
525
|
uri_string = "workflow_queue/all_queued?repository=#{repository}"
|
508
|
-
uri_string
|
509
|
-
uri_string
|
526
|
+
uri_string += "&hours-ago=#{opts[:hours_ago]}" if opts[:hours_ago]
|
527
|
+
uri_string += "&limit=#{opts[:limit]}" if opts[:limit]
|
510
528
|
uri_string
|
511
529
|
end
|
512
530
|
|
@@ -514,10 +532,10 @@ module Dor
|
|
514
532
|
doc = Nokogiri::XML(xml)
|
515
533
|
doc.xpath('/workflows/workflow').collect do |wf_node|
|
516
534
|
{
|
517
|
-
:
|
518
|
-
:
|
519
|
-
:
|
520
|
-
:
|
535
|
+
workflow: wf_node['name'],
|
536
|
+
step: wf_node['process'],
|
537
|
+
druid: wf_node['druid'],
|
538
|
+
lane_id: wf_node['laneId']
|
521
539
|
}
|
522
540
|
end
|
523
541
|
end
|
@@ -535,7 +553,8 @@ module Dor
|
|
535
553
|
|
536
554
|
def extract_object_count(resp)
|
537
555
|
node = Nokogiri::XML(resp).at_xpath('/objects')
|
538
|
-
raise Dor::WorkflowException
|
556
|
+
raise Dor::WorkflowException, 'Unable to determine count from response' if node.nil?
|
557
|
+
|
539
558
|
node['count'].to_i
|
540
559
|
end
|
541
560
|
|
@@ -547,7 +566,7 @@ module Dor
|
|
547
566
|
# @param [Hash] opts addtional headers options
|
548
567
|
# @return [Object] response from method
|
549
568
|
def workflow_resource_method(uri_string, meth = 'get', payload = '', opts = {})
|
550
|
-
with_retries(:
|
569
|
+
with_retries(max_tries: 2, handler: @@handler, rescue: workflow_service_exceptions_to_catch) do |attempt|
|
551
570
|
@@logger.info "[Attempt #{attempt}] #{meth} #{base_url}/#{uri_string}"
|
552
571
|
|
553
572
|
response = send_workflow_resource_request(uri_string, meth, payload, opts)
|