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



43
44
45
# File 'lib/dor/workflow/document.rb', line 43

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

#definitionDor::WorkflowDefinitionDs



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dor/workflow/document.rb', line 30

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

#inspectObject



66
67
68
# File 'lib/dor/workflow/document.rb', line 66

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

#processesObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/dor/workflow/document.rb', line 47

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