Class: Dor::WorkflowDs
- Inherits:
-
ActiveFedora::OmDatastream
- Object
- ActiveFedora::OmDatastream
- Dor::WorkflowDs
- Defined in:
- lib/dor/datastreams/workflow_ds.rb
Instance Method Summary collapse
- #[](wf) ⇒ Object
- #content ⇒ Object
-
#current_priority ⇒ Integer
Finds the first workflow that is expedited, then returns the value of its priority.
- #ensure_xml_loaded ⇒ Object
- #get_workflow(wf, repo = 'dor') ⇒ Object
- #graph(dir = nil) ⇒ Object
- #ng_xml ⇒ Object
- #to_solr(solr_doc = Hash.new, *args) ⇒ Object
- #workflows ⇒ Object
Instance Method Details
#[](wf) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/dor/datastreams/workflow_ds.rb', line 26 def [](wf) xml = Dor::WorkflowService.get_workflow_xml('dor', self.pid, wf) xml = Nokogiri::XML(xml) return nil if xml.xpath('workflow').length == 0 Workflow::Document.new(xml.to_s) end |
#content ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dor/datastreams/workflow_ds.rb', line 42 def content @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| next unless dsid =~ /WF$/ ds_content = Nokogiri::XML(Dor::WorkflowService.get_workflow_xml 'dor', self.pid, dsid) xml.root.add_child(ds_content.root) end @content ||= xml.to_xml end |
#current_priority ⇒ Integer
Finds the first workflow that is expedited, then returns the value of its priority
72 73 74 75 76 |
# File 'lib/dor/datastreams/workflow_ds.rb', line 72 def current_priority cp = workflows.detect { |wf| wf.expedited? } return 0 if cp.nil? cp.priority.to_i end |
#ensure_xml_loaded ⇒ Object
33 34 35 36 |
# File 'lib/dor/datastreams/workflow_ds.rb', line 33 def ensure_xml_loaded ng_xml self.xml_loaded = true end |
#get_workflow(wf, repo = 'dor') ⇒ Object
19 20 21 22 23 24 |
# 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) return nil if xml.xpath('workflow').length == 0 Workflow::Document.new(xml.to_s) end |
#graph(dir = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dor/datastreams/workflow_ds.rb', line 58 def graph(dir = nil) result = GraphViz.digraph(self.pid) sg = result.add_graph('rank') { |g| g[:rank => 'same'] } workflows.reject(&:nil?).each do |wf| g = wf.graph(result) sg.add_node(g.root.id) unless g.nil? end result['rankdir'] = dir || 'TB' result end |
#ng_xml ⇒ Object
38 39 40 |
# File 'lib/dor/datastreams/workflow_ds.rb', line 38 def ng_xml @ng_xml ||= Nokogiri::XML::Document.parse(content) end |
#to_solr(solr_doc = Hash.new, *args) ⇒ Object
78 79 80 81 82 |
# File 'lib/dor/datastreams/workflow_ds.rb', line 78 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 |
#workflows ⇒ Object
54 55 56 |
# File 'lib/dor/datastreams/workflow_ds.rb', line 54 def workflows @workflows ||= self.workflow.nodeset.collect { |wf_node| Workflow::Document.new wf_node.to_xml } end |