Class: Dor::Workflow::Document

Inherits:
Object
  • Object
show all
Includes:
OM::XML::Document
Defined in:
lib/dor/workflow/document.rb

Constant Summary collapse

@@definitions =
{}

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Document

Returns a new instance of Document.



25
26
27
# File 'lib/dor/workflow/document.rb', line 25

def initialize(node)
  self.ng_xml = Nokogiri::XML(node)
end

Instance Method Details

#[](value) ⇒ Object



53
54
55
# File 'lib/dor/workflow/document.rb', line 53

def [](value)
  processes.find { |p| p.name == value }
end

#definitionDor::WorkflowDefinitionDs



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dor/workflow/document.rb', line 40

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

Returns:

  • (Boolean)


30
31
32
# File 'lib/dor/workflow/document.rb', line 30

def expedited?
  processes.any? { |proc| !proc.completed? && proc.priority.to_i > 0 }
end

#inspectObject



76
77
78
# File 'lib/dor/workflow/document.rb', line 76

def inspect
  "#<#{self.class.name}:#{object_id}>"
end

#priorityInteger

Returns value of the first > 0 priority. Defaults to 0.

Returns:

  • (Integer)

    value of the first > 0 priority. Defaults to 0



35
36
37
# File 'lib/dor/workflow/document.rb', line 35

def priority
  processes.map { |proc| proc.priority.to_i }.detect(0) { |p| p > 0 }
end

#processesObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/dor/workflow/document.rb', line 57

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|
        nodes = ng_xml.xpath("/workflow/process[@name = '#{process.name}']")
        node = nodes.max { |a, b| a.attr('version').to_i <=> b.attr('version').to_i }
        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