Class: Dor::WorkflowDs

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

Overview

TODO: class docs

Instance Method Summary collapse

Instance Method Details

#content(refresh = false) ⇒ Object

service. This flag will invalidate the cached content and refetch it from the workflow service directly

Parameters:

  • refresh (Boolean) (defaults to: false)

    The WorkflowDS caches the content retrieved from the workflow



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dor/datastreams/workflow_ds.rb', line 38

def content(refresh = false)
  @content = nil if refresh
  @content ||= Dor::Config.workflow.client.get_workflow_xml 'dor', pid, nil
rescue Dor::WorkflowException
  xml = Nokogiri::XML(%(<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<workflows objectId="#{pid}"/>))
  digital_object.datastreams.keys.each do |dsid|
    next unless dsid =~ /WF$/

    ds_content = Nokogiri::XML(Dor::Config.workflow.client.get_workflow_xml('dor', pid, dsid))
    xml.root.add_child(ds_content.root)
  end
  @content ||= xml.to_xml
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



59
60
61
62
63
64
# File 'lib/dor/datastreams/workflow_ds.rb', line 59

def current_priority
  cp = workflows.detect(&:expedited?)
  return 0 if cp.nil?

  cp.priority.to_i
end

#get_workflow(wf, repo = 'dor') ⇒ Object Also known as: []



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

def get_workflow(wf, repo = 'dor')
  xml = Dor::Config.workflow.client.get_workflow_xml(repo, pid, wf)
  xml = Nokogiri::XML(xml)
  return nil if xml.xpath('workflow').length == 0

  Workflow::Document.new(xml.to_s)
end

#ng_xmlObject



31
32
33
# File 'lib/dor/datastreams/workflow_ds.rb', line 31

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

#prefixObject

maintain AF < 8 indexing behavior



73
74
75
# File 'lib/dor/datastreams/workflow_ds.rb', line 73

def prefix
  ''
end

#to_solr(solr_doc = {}, *args) ⇒ Object



66
67
68
69
70
# File 'lib/dor/datastreams/workflow_ds.rb', line 66

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

#workflowsObject



52
53
54
# File 'lib/dor/datastreams/workflow_ds.rb', line 52

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