Class: Dor::WorkflowDs

Inherits:
ActiveFedora::OmDatastream
  • Object
show all
Defined in:
lib/dor/datastreams/workflow_ds.rb

Instance Method Summary collapse

Instance Method Details

#[](wf) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/dor/datastreams/workflow_ds.rb', line 29

def [](wf)
  xml=Dor::WorkflowService.get_workflow_xml('dor', self.pid, wf)
  xml=Nokogiri::XML(xml)
  if xml.xpath('workflow').length == 0
    nil
  else
    Workflow::Document.new(xml.to_s)
  end
end

#contentObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dor/datastreams/workflow_ds.rb', line 48

def content
  begin
    @content ||= Dor::WorkflowService.get_workflow_xml 'dor', self.pid, nil
  rescue RestClient::ResourceNotFound
    xml = Nokogiri::XML(%{<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<workflows objectId="#{self.pid}"/>})
    self.digital_object.datastreams.keys.each do |dsid|
      if dsid =~ /WF$/
        ds_content = Nokogiri::XML(Dor::WorkflowService.get_workflow_xml 'dor', self.pid, dsid)
        xml.root.add_child(ds_content.root)
      end
    end
    @content ||= xml.to_xml
  end
end

#current_priorityInteger

Finds the first workflow that is expedited, then returns the value of its priority

Returns:

  • (Integer)

    value of the priority. Defaults to 0 if none of the workflows are expedited



84
85
86
87
88
# File 'lib/dor/datastreams/workflow_ds.rb', line 84

def current_priority
  cp = workflows.detect {|wf| wf.expedited? }
  return 0 if(cp.nil?)
  cp.priority.to_i
end

#ensure_xml_loadedObject



39
40
41
42
# File 'lib/dor/datastreams/workflow_ds.rb', line 39

def ensure_xml_loaded
  ng_xml
  self.xml_loaded = true
end

#get_workflow(wf, repo = 'dor') ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/dor/datastreams/workflow_ds.rb', line 19

def get_workflow (wf,repo='dor')
  xml=Dor::WorkflowService.get_workflow_xml(repo, self.pid, wf)
  xml=Nokogiri::XML(xml)
  if xml.xpath('workflow').length == 0
    nil
  else
    Workflow::Document.new(xml.to_s)
  end
end

#graph(dir = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/dor/datastreams/workflow_ds.rb', line 67

def graph(dir=nil)
  result = GraphViz.digraph(self.pid)
  sg = result.add_graph('rank') { |g| g[:rank => 'same'] }
  workflows.each do |wf|
    wf_name = wf.workflowId.first
    unless wf.nil?
      g = wf.graph(result)
      sg.add_node(g.root.id) unless g.nil?
    end
  end
  result['rankdir'] = dir || 'TB'
  result
end

#ng_xmlObject



44
45
46
# File 'lib/dor/datastreams/workflow_ds.rb', line 44

def ng_xml
  @ng_xml ||= Nokogiri::XML::Document.parse(content)
end

#to_solr(solr_doc = Hash.new, *args) ⇒ Object



90
91
92
93
94
# File 'lib/dor/datastreams/workflow_ds.rb', line 90

def to_solr(solr_doc=Hash.new, *args)
#    super solr_doc, *args
  self.workflows.each { |wf| wf.to_solr(solr_doc, *args) }
  solr_doc
end

#workflowsObject



63
64
65
# File 'lib/dor/datastreams/workflow_ds.rb', line 63

def workflows
  @workflows ||= self.workflow.nodeset.collect { |wf_node| Workflow::Document.new wf_node.to_xml }
end