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
28
# File 'lib/dor/workflow/document.rb', line 25

def initialize(node)
  Deprecation.warn(self, 'Dor::Workflow::Document is deprecated and will be removed from dor-services version 9')
  self.ng_xml = Nokogiri::XML(node)
end

Instance Method Details

#[](value) ⇒ Object



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

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

#definitionDor::WorkflowDefinitionDs



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

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



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

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

#processesObject



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

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