Class: Dor::WorkflowObject

Inherits:
Abstract
  • Object
show all
Defined in:
lib/dor/models/workflow_object.rb

Constant Summary collapse

@@xml_cache =
{}
@@repo_cache =
{}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#adapt_to_cmodel, #add_collection, #allows_modification?, assign_pid, #current_version, #druid_regex, has_object_type, #pid_regex, #read_rights=, #reapply_admin_policy_object_defaults, #remove_collection, #remove_druid_prefix, #to_solr

Class Method Details

.find_and_cache_workflow_xml_and_repo(name) ⇒ Object

Searches DOR for the workflow definition object. It then caches the workflow repository and xml

Parameters:

  • name (String)

    the name of the workflow

Returns:

  • (Object)

    a Dor::xxxx object, e.g. a Dor::Item object



64
65
66
67
68
69
70
71
# File 'lib/dor/models/workflow_object.rb', line 64

def self.find_and_cache_workflow_xml_and_repo(name)
  wobj = find_by_name(name)
  raise "Failed to find workflow via find_by_name('#{name}')" if wobj.nil?

  @@repo_cache[name] = wobj.definition.repo
  @@xml_cache[name]  = wobj.generate_initial_workflow
  wobj
end

.find_by_name(name) ⇒ Object



21
22
23
# File 'lib/dor/models/workflow_object.rb', line 21

def self.find_by_name(name)
  Dor::WorkflowObject.where(Solrizer.solr_name('workflow_name', :symbol) => name).first
end

.initial_repo(name) ⇒ String

Returns the repository attribute from the workflow definition It will cache the result for subsequent requests

Parameters:

  • name (String)

    the name of the workflow

Returns:

  • (String)

    the initial workflow xml



42
43
44
45
46
47
48
# File 'lib/dor/models/workflow_object.rb', line 42

def self.initial_repo(name)
  Deprecation.warn(self, 'WorkflowObject#initial_repo is deprecated and will be removed in dor-services 8.0')
  return @@repo_cache[name] if @@repo_cache.include?(name)

  find_and_cache_workflow_xml_and_repo name
  @@repo_cache[name]
end

.initial_workflow(name) ⇒ String

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

Parameters:

  • name (String)

    the name of the workflow

Returns:

  • (String)

    the initial workflow xml



30
31
32
33
34
35
36
# File 'lib/dor/models/workflow_object.rb', line 30

def self.initial_workflow(name)
  Deprecation.warn(self, 'WorkflowObject#initial_workflow is deprecated and will be removed in dor-services 8.0')
  return @@xml_cache[name] if @@xml_cache.include?(name)

  find_and_cache_workflow_xml_and_repo name
  @@xml_cache[name]
end

Instance Method Details

#definitionDor::WorkflowDefinitionDs



51
52
53
# File 'lib/dor/models/workflow_object.rb', line 51

def definition
  datastreams['workflowDefinition']
end

#generate_initial_workflowObject Also known as: generate_intial_workflow



55
56
57
# File 'lib/dor/models/workflow_object.rb', line 55

def generate_initial_workflow
  datastreams['workflowDefinition'].initial_workflow
end