Class: Dor::WorkflowDefinitionDs
- Inherits:
-
ActiveFedora::OmDatastream
- Object
- ActiveFedora::OmDatastream
- Dor::WorkflowDefinitionDs
- Includes:
- SolrDocHelper
- Defined in:
- lib/dor/datastreams/workflow_definition_ds.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_process(attributes) ⇒ Object
- #configuration ⇒ Object
- #configuration=(hash) ⇒ Object
- #graph(parent = nil) ⇒ Object
-
#initial_workflow ⇒ String
Creates the xml used by Dor::WorkflowService.create_workflow.
- #name ⇒ Object
- #processes ⇒ Object
- #repo ⇒ Object
- #to_solr(solr_doc = Hash.new, *args) ⇒ Object
- #to_yaml ⇒ Object
Methods included from SolrDocHelper
Class Method Details
.xml_template ⇒ Object
33 34 35 |
# File 'lib/dor/datastreams/workflow_definition_ds.rb', line 33 def self.xml_template Nokogiri::XML('<workflow-def/>') end |
Instance Method Details
#add_process(attributes) ⇒ Object
37 38 39 |
# File 'lib/dor/datastreams/workflow_definition_ds.rb', line 37 def add_process(attributes) add_child_node(ng_xml.at_xpath('/workflow-def'), :process, self, attributes) end |
#configuration ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/dor/datastreams/workflow_definition_ds.rb', line 59 def configuration result = ActiveSupport::OrderedHash.new result['repository'] = repo result['name'] = name processes.each { |process| result[process.name] = process.to_hash } result end |
#configuration=(hash) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/dor/datastreams/workflow_definition_ds.rb', line 67 def configuration=(hash) self.ng_xml = Nokogiri::XML(%{<workflow-def id="#{hash['name']}" repository="#{hash['repository']}"/>}) i = 0 hash.each_pair do |k,v| if v.is_a?(Hash) add_process(v.merge({:name => k, :sequence => i+=1})) end end end |
#graph(parent = nil) ⇒ Object
41 42 43 |
# File 'lib/dor/datastreams/workflow_definition_ds.rb', line 41 def graph(parent = nil) Workflow::Graph.from_processes(self.repo, self.name, self.processes, parent) end |
#initial_workflow ⇒ String
Creates the xml used by Dor::WorkflowService.create_workflow
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/dor/datastreams/workflow_definition_ds.rb', line 79 def initial_workflow doc = Nokogiri::XML("<workflow/>") root = doc.root root['id'] = name processes.each { |proc| doc.create_element 'process' do |node| node['name'] = proc.name if(proc.status) node['status'] = proc.status node['attempts'] = '1' else node['status'] = 'waiting' end node['lifecycle'] = proc.lifecycle if proc.lifecycle root.add_child node end } Nokogiri::XML(doc.to_xml) { |x| x.noblanks }.to_xml { |config| config.no_declaration } end |
#name ⇒ Object
51 52 53 |
# File 'lib/dor/datastreams/workflow_definition_ds.rb', line 51 def name ng_xml.at_xpath('/workflow-def/@id').to_s end |
#processes ⇒ Object
45 46 47 48 49 |
# File 'lib/dor/datastreams/workflow_definition_ds.rb', line 45 def processes ng_xml.xpath('/workflow-def/process').collect do |node| Workflow::Process.new(self.repo, self.name, node) end.sort { |a,b| (a.sequence || 0) <=> (b.sequence || 0) } end |
#repo ⇒ Object
55 56 57 |
# File 'lib/dor/datastreams/workflow_definition_ds.rb', line 55 def repo ng_xml.at_xpath('/workflow-def/@repository').to_s end |
#to_solr(solr_doc = Hash.new, *args) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/dor/datastreams/workflow_definition_ds.rb', line 99 def to_solr(solr_doc=Hash.new,*args) super(solr_doc,*args) add_solr_value(solr_doc, "workflow_name", self.name, :symbol, [:searchable]) processes.each do |p| add_solr_value(solr_doc, "process", "#{p.name}|#{p.label}", :symbol, [:displayable]) end solr_doc end |
#to_yaml ⇒ Object
108 109 110 |
# File 'lib/dor/datastreams/workflow_definition_ds.rb', line 108 def to_yaml YAML.dump(self.configuration) end |