Sha256: cf5bdb077a63c8c3edf0864e38a6b0278b53a53f559d2d23a77881f1c5696b09

Contents?: true

Size: 1.8 KB

Versions: 3

Compression:

Stored size: 1.8 KB

Contents

require 'dor/datastreams/workflow_definition_ds'

module Dor
  class WorkflowObject < ::ActiveFedora::Base
    include Identifiable
    include SolrDocHelper
    include Governable
    @@xml_cache = {}

    has_object_type 'workflow'
    has_metadata :name => "workflowDefinition", :type => Dor::WorkflowDefinitionDs, :label => 'Workflow Definition'

    def self.find_by_name(name, opts={})
      Dor.find_all(%{#{Solrizer.solr_name "objectType", :facetable}:"#{self.object_type}" #{Solrizer.solr_name "workflow_name", :symbol}:"#{name}"}, opts).first
    end
    
    # Searches for the workflow definition object in DOR, then 
    # returns an object's initial workflow as defined in the worfklowDefinition datastream
    # It will cache the result for subsequent requests
    # @param [String] name the name of the workflow
    # @return [String] the initial workflow xml
    def self.initial_workflow(name)
      return @@xml_cache[name] if(@@xml_cache.include?(name))

      wobj = self.find_by_name(name)
      wf_xml = wobj.generate_initial_workflow
      @@xml_cache[name] = wf_xml
    end

    def definition
      datastreams['workflowDefinition']
    end
    
    def graph *args
      self.definition.graph *args
    end
    
    def to_solr solr_doc=Hash.new, *args
      super solr_doc, *args
      client = Dor::WorkflowService.workflow_resource
      xml = client["workflow_archive?repository=#{definition.repo}&workflow=#{definition.name}&count-only=true"].get
      count = Nokogiri::XML(xml).at_xpath('/objects/@count').value
      add_solr_value(solr_doc,"#{definition.name}_archived",count,:integer,[:displayable])
      solr_doc
    end

    def generate_initial_workflow
      datastreams['workflowDefinition'].initial_workflow
    end

    alias_method :generate_intial_workflow, :generate_initial_workflow

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dor-services-5.0.2 lib/dor/models/workflow_object.rb
dor-services-5.0.1 lib/dor/models/workflow_object.rb
dor-services-5.0.0 lib/dor/models/workflow_object.rb