Class: Dor::Workflow::Document
- Inherits:
-
Object
- Object
- Dor::Workflow::Document
- Includes:
- OM::XML::Document, SolrDocHelper
- Defined in:
- lib/dor/workflow/document.rb
Constant Summary collapse
- @@definitions =
{}
Instance Method Summary collapse
- #[](value) ⇒ Object
-
#active? ⇒ Boolean
If any process node does not have version, returns true, false otherwise (all processes have version).
- #definition ⇒ Dor::WorkflowDefinitionDs
-
#expedited? ⇒ Boolean
is this an incomplete workflow with steps that have a priority > 0.
- #graph(parent = nil, dir = nil) ⇒ Object
-
#initialize(node) ⇒ Document
constructor
A new instance of Document.
- #inspect ⇒ Object
-
#priority ⇒ Integer
Value of the first > 0 priority.
- #processes ⇒ Object
- #to_solr(solr_doc = {}, *args) ⇒ Object
- #workflow_should_show_completed?(processes) ⇒ Boolean
Methods included from SolrDocHelper
Constructor Details
#initialize(node) ⇒ Document
Returns a new instance of Document.
24 25 26 |
# File 'lib/dor/workflow/document.rb', line 24 def initialize(node) self.ng_xml = Nokogiri::XML(node) end |
Instance Method Details
#[](value) ⇒ Object
64 65 66 |
# File 'lib/dor/workflow/document.rb', line 64 def [](value) processes.find { |p| p.name == value } end |
#active? ⇒ Boolean
Returns if any process node does not have version, returns true, false otherwise (all processes have version).
39 40 41 |
# File 'lib/dor/workflow/document.rb', line 39 def active? ng_xml.at_xpath('/workflow/process[not(@version)]') ? true : false end |
#definition ⇒ Dor::WorkflowDefinitionDs
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dor/workflow/document.rb', line 44 def definition @definition ||= begin if @@definitions.key? workflowId.first @@definitions[workflowId.first] else wfo = Dor::WorkflowObject.find_by_name(workflowId.first) wf_def = wfo ? wfo.definition : nil @@definitions[workflowId.first] = wf_def wf_def end end end |
#expedited? ⇒ Boolean
is this an incomplete workflow with steps that have a priority > 0
29 30 31 |
# File 'lib/dor/workflow/document.rb', line 29 def expedited? processes.any? { |proc| !proc.completed? && proc.priority.to_i > 0 } end |
#graph(parent = nil, dir = nil) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/dor/workflow/document.rb', line 57 def graph(parent = nil, dir = nil) wf_definition = definition result = wf_definition ? Workflow::Graph.from_processes(wf_definition.repo, wf_definition.name, processes, parent) : nil result['rankdir'] = dir || 'TB' unless result.nil? result end |
#inspect ⇒ Object
132 133 134 |
# File 'lib/dor/workflow/document.rb', line 132 def inspect "#<#{self.class.name}:#{object_id}>" end |
#priority ⇒ Integer
Returns value of the first > 0 priority. Defaults to 0.
34 35 36 |
# File 'lib/dor/workflow/document.rb', line 34 def priority processes.map {|proc| proc.priority.to_i }.detect(0) {|p| p > 0} end |
#processes ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/dor/workflow/document.rb', line 68 def processes # if the workflow service didnt return any processes, dont return any processes from the reified wf return [] if ng_xml.search('/workflow/process').length == 0 @processes ||= if definition definition.processes.collect do |process| node = ng_xml.at("/workflow/process[@name = '#{process.name}']") process.update!(node, self) end else find_by_terms(:workflow, :process).collect do |x| pnode = Dor::Workflow::Process.new(repository, workflowId, {}) pnode.update!(x, self) end.sort_by(&:datetime) end end |
#to_solr(solr_doc = {}, *args) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/dor/workflow/document.rb', line 89 def to_solr(solr_doc = {}, *args) wf_name = workflowId.first repo = repository.first wf_solr_type = :string wf_solr_attrs = [:symbol] add_solr_value(solr_doc, 'wf', wf_name, wf_solr_type, wf_solr_attrs) add_solr_value(solr_doc, 'wf_wps', wf_name, wf_solr_type, wf_solr_attrs) add_solr_value(solr_doc, 'wf_wsp', wf_name, wf_solr_type, wf_solr_attrs) status = processes.empty? ? 'empty' : (workflow_should_show_completed?(processes) ? 'completed' : 'active') errors = processes.count(&:error?) add_solr_value(solr_doc, 'workflow_status', [wf_name, status, errors, repo].join('|'), wf_solr_type, wf_solr_attrs) processes.each do |process| next unless process.status.present? # add a record of the robot having operated on this item, so we can track robot activity if !process.date_time.blank? && process.status && (process.status == 'completed' || process.status == 'error') solr_doc["wf_#{wf_name}_#{process.name}_dttsi"] = Time.parse(process.date_time).utc.iso8601 end # index the error message without the druid so we hopefully get some overlap add_solr_value(solr_doc, 'wf_error', "#{wf_name}:#{process.name}:#{process.}", wf_solr_type, wf_solr_attrs) if process. add_solr_value(solr_doc, 'wf_wsp', "#{wf_name}:#{process.status}", wf_solr_type, wf_solr_attrs) add_solr_value(solr_doc, 'wf_wsp', "#{wf_name}:#{process.status}:#{process.name}", wf_solr_type, wf_solr_attrs) add_solr_value(solr_doc, 'wf_wps', "#{wf_name}:#{process.name}", wf_solr_type, wf_solr_attrs) add_solr_value(solr_doc, 'wf_wps', "#{wf_name}:#{process.name}:#{process.status}", wf_solr_type, wf_solr_attrs) add_solr_value(solr_doc, 'wf_swp', "#{process.status}", wf_solr_type, wf_solr_attrs) add_solr_value(solr_doc, 'wf_swp', "#{process.status}:#{wf_name}", wf_solr_type, wf_solr_attrs) add_solr_value(solr_doc, 'wf_swp', "#{process.status}:#{wf_name}:#{process.name}", wf_solr_type, wf_solr_attrs) next unless process.state != process.status add_solr_value(solr_doc, 'wf_wsp', "#{wf_name}:#{process.state}:#{process.name}", wf_solr_type, wf_solr_attrs) add_solr_value(solr_doc, 'wf_wps', "#{wf_name}:#{process.name}:#{process.state}", wf_solr_type, wf_solr_attrs) add_solr_value(solr_doc, 'wf_swp', "#{process.state}", wf_solr_type, wf_solr_attrs) add_solr_value(solr_doc, 'wf_swp', "#{process.state}:#{wf_name}", wf_solr_type, wf_solr_attrs) add_solr_value(solr_doc, 'wf_swp', "#{process.state}:#{wf_name}:#{process.name}", wf_solr_type, wf_solr_attrs) end solr_doc[Solrizer.solr_name('wf_wps', :symbol)].uniq! if solr_doc[Solrizer.solr_name('wf_wps', :symbol)] solr_doc[Solrizer.solr_name('wf_wsp', :symbol)].uniq! if solr_doc[Solrizer.solr_name('wf_wsp', :symbol)] solr_doc[Solrizer.solr_name('wf_swp', :symbol)].uniq! if solr_doc[Solrizer.solr_name('wf_swp', :symbol)] solr_doc['workflow_status'].uniq! if solr_doc['workflow_status'] solr_doc end |
#workflow_should_show_completed?(processes) ⇒ Boolean
85 86 87 |
# File 'lib/dor/workflow/document.rb', line 85 def workflow_should_show_completed?(processes) processes.all? {|p| ['skipped', 'completed', '', nil].include?(p.status)} end |