dor-workflow-service 2.5.0 → 2.6.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: 4abc8faa2adf7c8c9f51ed741e5c7347468d1a86c15e7f6d9302500a8985e820
4
- data.tar.gz: 9be7245887a6b93ac5461b69f6bea3d72a29e0d906ae14a1ea73b73396145008
3
+ metadata.gz: 394cba37203c6683aa63f395f51d95167593b54051a83371bb36dd258ec96c2c
4
+ data.tar.gz: 6161481760df3525936c53fff102f502e23667224f645d0afa60ff92b5b0dc1d
5
5
  SHA512:
6
- metadata.gz: d6e52377d0c17001f5e98f301b7d4d21c2572f23fd5c6871e9d03f3d1f9678aa4aa53df1893e7301bde5617d94c41b08552716c51565daf427bca2bfad441956
7
- data.tar.gz: 7a4f03c9a5bdc93a289256094690d81f40cea5327343eaab1f9def9b556c239bc2c4d2a6a40556ce097ed2f9df71a3b564f24f1305223d4fb987b5dadda578d9
6
+ metadata.gz: 2c06e4de8b093c5a40018637562abd74269a27c645210a072b9a3512e6411aa28ea70558f35e30ad2084b3a25baad1405dec47c6abff0d4cf4751498e8a75762
7
+ data.tar.gz: d35f946bf8c3904f08b094e6e5fe784121c4042c17691a7b0dc2825e79491b45a613b4397d9990c7e26591bc5ed7adf8219133f901cebfd99e777417282f5879
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dor
4
+ module Workflow
5
+ module Response
6
+ # Represents the status of an object doing a workflow process
7
+ class Process
8
+ # @params [Workflow] parent
9
+ # @params [Hash] attributes
10
+ def initialize(parent:, **attributes)
11
+ @parent = parent
12
+ @attributes = attributes
13
+ end
14
+
15
+ def name
16
+ @attributes[:name].presence
17
+ end
18
+
19
+ def status
20
+ @attributes[:status].presence
21
+ end
22
+
23
+ def datetime
24
+ @attributes[:datetime].presence
25
+ end
26
+
27
+ def elapsed
28
+ @attributes[:elapsed].presence
29
+ end
30
+
31
+ def attempts
32
+ @attributes[:attempts].presence
33
+ end
34
+
35
+ def lifecycle
36
+ @attributes[:lifecycle].presence
37
+ end
38
+
39
+ def note
40
+ @attributes[:note].presence
41
+ end
42
+
43
+ delegate :pid, :workflow_name, to: :parent
44
+
45
+ private
46
+
47
+ attr_reader :parent
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'dor/models/response/process'
4
+
3
5
  module Dor
4
6
  module Workflow
5
7
  module Response
@@ -15,8 +17,26 @@ module Dor
15
17
  result ? true : false
16
18
  end
17
19
 
20
+ # Returns the process, for the most recent version that matches the given name:
21
+ def process_for_recent_version(name:)
22
+ nodes = process_nodes_for(name: name)
23
+ node = nodes.max { |a, b| a.attr('version').to_i <=> b.attr('version').to_i }
24
+ attributes = node ? Hash[node.attributes.collect { |k, v| [k.to_sym, v.value] }] : {}
25
+ Process.new(parent: self, **attributes)
26
+ end
27
+
28
+ def empty?
29
+ ng_xml.xpath('/workflow/process').empty?
30
+ end
31
+
32
+ attr_reader :xml
33
+
18
34
  private
19
35
 
36
+ def process_nodes_for(name:)
37
+ ng_xml.xpath("/workflow/process[@name = '#{name}']")
38
+ end
39
+
20
40
  def ng_xml
21
41
  @ng_xml ||= Nokogiri::XML(@xml)
22
42
  end
@@ -3,7 +3,7 @@
3
3
  module Dor
4
4
  module Workflow
5
5
  module Service
6
- VERSION = '2.5.0'
6
+ VERSION = '2.6.0'
7
7
  end
8
8
  end
9
9
  end
@@ -33,4 +33,85 @@ RSpec.describe Dor::Workflow::Response::Workflow do
33
33
  it { is_expected.to be true }
34
34
  end
35
35
  end
36
+
37
+ describe '#empty?' do
38
+ subject { instance.empty? }
39
+
40
+ context 'when there is xml' do
41
+ let(:xml) do
42
+ '<?xml version="1.0" encoding="UTF-8"?>
43
+ <workflow repository="dor" objectId="druid:oo201oo0001" id="accessionWF">
44
+ <process version="2" lifecycle="submitted" elapsed="0.0" archived="true" attempts="1"
45
+ datetime="2012-11-06T16:18:24-0800" status="completed" name="start-accession"/>
46
+ <process version="2" elapsed="0.0" archived="true" attempts="1"
47
+ datetime="2012-11-06T16:18:58-0800" status="completed" name="technical-metadata"/>
48
+ <process version="2" elapsed="0.0" archived="true" attempts="1"
49
+ datetime="2012-11-06T16:19:02-0800" status="completed" name="provenance-metadata"/>
50
+ <process version="2" elapsed="0.0" archived="true" attempts="1"
51
+ datetime="2012-11-06T16:19:05-0800" status="completed" name="remediate-object"/>
52
+ <process version="2" elapsed="0.0" archived="true" attempts="1"
53
+ datetime="2012-11-06T16:19:06-0800" status="completed" name="shelve"/>
54
+ <process version="2" lifecycle="published" elapsed="0.0" archived="true" attempts="1"
55
+ datetime="2012-11-06T16:19:07-0800" status="completed" name="publish"/>
56
+ <process version="2" elapsed="0.0" archived="true" attempts="1"
57
+ datetime="2012-11-06T16:19:09-0800" status="completed" name="sdr-ingest-transfer"/>
58
+ <process version="2" lifecycle="accessioned" elapsed="0.0" archived="true" attempts="1"
59
+ datetime="2012-11-06T16:19:10-0800" status="completed" name="cleanup"/>
60
+ <process version="2" elapsed="0.0" archived="true" attempts="1"
61
+ datetime="2012-11-06T16:19:13-0800" status="completed" name="rights-metadata"/>
62
+ <process version="2" lifecycle="described" elapsed="0.0" archived="true" attempts="1"
63
+ datetime="2012-11-06T16:19:15-0800" status="completed" name="descriptive-metadata"/>
64
+ <process version="2" elapsed="0.0" archived="true" attempts="2"
65
+ datetime="2012-11-06T16:19:16-0800" status="completed" name="content-metadata"/>
66
+ </workflow>'
67
+ end
68
+
69
+ it { is_expected.to be false }
70
+ end
71
+
72
+ context 'when the xml is empty' do
73
+ let(:xml) { '' }
74
+
75
+ it { is_expected.to be true }
76
+ end
77
+ end
78
+
79
+ describe '#process_for_recent_version' do
80
+ subject(:process) { instance.process_for_recent_version(name: 'jp2-create') }
81
+
82
+ context 'when the workflow has not been instantiated for the given version' do
83
+ let(:xml) do
84
+ <<~XML
85
+ <workflow repository="dor" objectId="druid:mw971zk1113" id="assemblyWF">
86
+ <process version="1" laneId="default" elapsed="0.0" attempts="1" datetime="2013-02-18T14:40:25-0800" status="completed" name="start-assembly"/>
87
+ <process version="1" laneId="default" elapsed="0.509" attempts="1" datetime="2013-02-18T14:42:24-0800" status="completed" name="jp2-create"/>
88
+ </workflow>
89
+ XML
90
+ end
91
+
92
+ it 'returns a process' do
93
+ expect(process).to be_kind_of Dor::Workflow::Response::Process
94
+ expect(process.status).to eq 'completed'
95
+ expect(process.name).to eq 'jp2-create'
96
+ end
97
+ end
98
+
99
+ context 'when the workflow has been instantiated for the given version' do
100
+ let(:xml) do
101
+ <<~XML
102
+ <workflow repository="dor" objectId="druid:mw971zk1113" id="assemblyWF">
103
+ <process version="1" laneId="default" elapsed="0.0" attempts="1" datetime="2013-02-18T14:40:25-0800" status="completed" name="start-assembly"/>
104
+ <process version="1" laneId="default" elapsed="0.509" attempts="1" datetime="2013-02-18T14:42:24-0800" status="completed" name="jp2-create"/>
105
+ <process version="2" laneId="default" elapsed="0.509" attempts="1" datetime="2013-02-18T14:42:24-0800" status="waiting" name="jp2-create"/>
106
+ </workflow>
107
+ XML
108
+ end
109
+
110
+ it 'returns a process' do
111
+ expect(process).to be_kind_of Dor::Workflow::Response::Process
112
+ expect(process.status).to eq 'waiting'
113
+ expect(process.name).to eq 'jp2-create'
114
+ end
115
+ end
116
+ end
36
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dor-workflow-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.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-02-01 00:00:00.000000000 Z
12
+ date: 2019-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -258,6 +258,7 @@ files:
258
258
  - bin/console
259
259
  - dor-workflow-service.gemspec
260
260
  - lib/dor-workflow-service.rb
261
+ - lib/dor/models/response/process.rb
261
262
  - lib/dor/models/response/workflow.rb
262
263
  - lib/dor/services/workflow_service.rb
263
264
  - lib/dor/workflow_exception.rb