This repository has been archived by the owner on May 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
workflow_ds.rb
97 lines (81 loc) · 3.5 KB
/
workflow_ds.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# frozen_string_literal: true
module Dor
# TODO: class docs
class WorkflowDs < ActiveFedora::OmDatastream
extend Deprecation
self.deprecation_horizon = 'dor-services version 7.0.0'
before_save :build_location
set_terminology do |t|
t.root(path: 'workflows')
t.workflow do
t.workflowId(path: { attribute: 'id' })
t.process do
t.name_(path: { attribute: 'name' }, index_as: %i[displayable not_searchable])
t.status(path: { attribute: 'status' }, index_as: %i[displayable not_searchable])
t.timestamp(path: { attribute: 'datetime' }, index_as: %i[displayable not_searchable]) # , :data_type => :date)
t.elapsed(path: { attribute: 'elapsed' }, index_as: %i[displayable not_searchable])
t.lifecycle(path: { attribute: 'lifecycle' }, index_as: %i[displayable not_searchable])
t.attempts(path: { attribute: 'attempts' }, index_as: %i[displayable not_searchable])
end
end
end
# Called before saving, but after a pid has been assigned
def build_location
return unless new?
self.dsLocation = File.join(Dor::Config.workflow.url, "dor/objects/#{pid}/workflows")
end
# Called by rubydora. This lets us customize the mime-type
def self.default_attributes
super.merge(mimeType: 'application/xml')
end
def get_workflow(wf, repo = 'dor')
xml = Dor::Config.workflow.client.workflow_xml(repo, pid, wf)
xml = Nokogiri::XML(xml)
return nil if xml.xpath('workflow').length == 0
Workflow::Document.new(xml.to_s)
end
deprecation_deprecate get_workflow: 'This has been moved to Argo and will be discontinued'
alias [] get_workflow
deprecation_deprecate :[] => 'This has been moved to Argo and will be discontinued'
def ng_xml
@ng_xml ||= Nokogiri::XML::Document.parse(content)
end
# @param [Boolean] refresh The WorkflowDS caches the content retrieved from the workflow
# service. This flag will invalidate the cached content and refetch it from the workflow
# service directly
def content(refresh = false)
@content = nil if refresh
@content ||= Dor::Config.workflow.client.all_workflows_xml pid
rescue Dor::WorkflowException => e
# TODO: I don't understand when this would be useful as this block ends up calling the workflow service too.
# Why not just raise an exception here?
Dor.logger.warn "Unable to connect to the workflow service #{e}. Falling back to placeholder XML"
xml = Nokogiri::XML(%(<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<workflows objectId="#{pid}"/>))
digital_object.datastreams.keys.each do |dsid|
next unless dsid =~ /WF$/
ds_content = Nokogiri::XML(Dor::Config.workflow.client.workflow_xml('dor', pid, dsid))
xml.root.add_child(ds_content.root)
end
@content ||= xml.to_xml
end
def workflows
@workflows ||= workflow.nodeset.collect { |wf_node| Workflow::Document.new wf_node.to_xml }
end
# Finds the first workflow that is expedited, then returns the value of its priority
#
# @return [Integer] value of the priority. Defaults to 0 if none of the workflows are expedited
def current_priority
cp = workflows.detect(&:expedited?)
return 0 if cp.nil?
cp.priority.to_i
end
def to_solr(solr_doc = {}, *_args)
# noop - indexing is done by the WorkflowsIndexer
solr_doc
end
# maintain AF < 8 indexing behavior
def prefix
''
end
end
end