Class: Dor::StatusService

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/services/status_service.rb

Overview

Query the processing status of an item. This has a dependency on the workflow service (app) to get milestones.

Constant Summary collapse

STATUS_CODE_DISP_TXT =

verbiage we want to use to describe an item when it has completed a particular step

{
  0 => 'Unknown Status', # if there are no milestones for the current version, someone likely messed up the versioning process.
  1 => 'Registered',
  2 => 'In accessioning',
  3 => 'In accessioning (described)',
  4 => 'In accessioning (described, published)',
  5 => 'In accessioning (described, published, deposited)',
  6 => 'Accessioned',
  7 => 'Accessioned (indexed)',
  8 => 'Accessioned (indexed, ingested)',
  9 => 'Opened'
}.freeze
STEPS =

milestones from accessioning and the order they happen in

{
  'registered' => 1,
  'submitted' => 2,
  'described' => 3,
  'published' => 4,
  'deposited' => 5,
  'accessioned' => 6,
  'indexed' => 7,
  'shelved' => 8,
  'opened' => 9
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work) ⇒ StatusService

Returns a new instance of StatusService.



43
44
45
# File 'lib/dor/services/status_service.rb', line 43

def initialize(work)
  @work = work
end

Class Method Details

.status(work, include_time = false) ⇒ Object



39
40
41
# File 'lib/dor/services/status_service.rb', line 39

def self.status(work, include_time = false)
  new(work).status(include_time)
end

.status_info(work) ⇒ Hash{Symbol => Object}

Returns including :current_version, :status_code and :status_time.

Returns:

  • (Hash{Symbol => Object})

    including :current_version, :status_code and :status_time



35
36
37
# File 'lib/dor/services/status_service.rb', line 35

def self.status_info(work)
  new(work).status_info
end

Instance Method Details

#milestonesObject



82
83
84
# File 'lib/dor/services/status_service.rb', line 82

def milestones
  @milestones ||= Dor::Config.workflow.client.milestones('dor', work.pid)
end

#status(include_time = false) ⇒ String

Returns single composed status from status_info.

Parameters:

  • include_time (Boolean) (defaults to: false)

Returns:

  • (String)

    single composed status from status_info



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/dor/services/status_service.rb', line 70

def status(include_time = false)
  status_info_hash = status_info
  current_version = status_info_hash[:current_version]
  status_code = status_info_hash[:status_code]
  status_time = status_info_hash[:status_time]

  # use the translation table to get the appropriate verbage for the latest step
  result = "v#{current_version} #{STATUS_CODE_DISP_TXT[status_code]}"
  result += " #{format_date(status_time)}" if include_time
  result
end

#status_infoHash{Symbol => Object}

Returns including :current_version, :status_code and :status_time.

Returns:

  • (Hash{Symbol => Object})

    including :current_version, :status_code and :status_time



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/dor/services/status_service.rb', line 48

def status_info
  # if we have an accessioned milestone, this is the last possible step and should be the status regardless of time stamp
  accessioned_milestones = current_milestones.select { |m| m[:milestone] == 'accessioned' }
  return { current_version: current_version, status_code: STEPS['accessioned'], status_time: accessioned_milestones.last[:at].utc.xmlschema } unless accessioned_milestones.empty?

  status_code = 0
  status_time = nil
  # for each milestone in the current version, see if it comes at the same time or after the current 'last' step, if so, make it the last and record the date/time
  current_milestones.each do |m|
    m_name = m[:milestone]
    m_time = m[:at].utc.xmlschema
    next unless STEPS.key?(m_name) && (!status_time || m_time >= status_time)

    status_code = STEPS[m_name]
    status_time = m_time
  end

  { current_version: current_version, status_code: status_code, status_time: status_time }
end