Class: Dor::WorkflowDs

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

Overview

TODO: class docs

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_attributesObject

Called by rubydora. This lets us customize the mime-type



33
34
35
# File 'lib/dor/datastreams/workflow_ds.rb', line 33

def self.default_attributes
  super.merge(mimeType: 'application/xml')
end

Instance Method Details

#build_locationObject

Called before saving, but after a pid has been assigned



26
27
28
29
30
# File 'lib/dor/datastreams/workflow_ds.rb', line 26

def build_location
  return unless new?

  self.dsLocation = File.join(Dor::Config.workflow.url, "dor/objects/#{pid}/workflows")
end

#content(refresh = false) ⇒ Object

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



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dor/datastreams/workflow_ds.rb', line 56

def content(refresh = false)
  @content = nil if refresh
  @content ||= Dor::Config.workflow.client.all_workflows_xml pid
rescue Dor::WorkflowException => e
  # TODO: I don't understand when this would be useful as this block ends up calling the workflow service too.
  # Why not just raise an exception here?
  Dor.logger.warn "Unable to connect to the workflow service #{e}. Falling back to placeholder XML"
  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.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



80
81
82
83
84
85
# File 'lib/dor/datastreams/workflow_ds.rb', line 80

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: []



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

def get_workflow(wf, repo = 'dor')
  xml = Dor::Config.workflow.client.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



49
50
51
# File 'lib/dor/datastreams/workflow_ds.rb', line 49

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

#prefixObject

maintain AF < 8 indexing behavior



93
94
95
# File 'lib/dor/datastreams/workflow_ds.rb', line 93

def prefix
  ''
end

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



87
88
89
90
# File 'lib/dor/datastreams/workflow_ds.rb', line 87

def to_solr(solr_doc = {}, *_args)
  # noop - indexing is done by the WorkflowsIndexer
  solr_doc
end

#workflowsObject



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

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