Class: Dor::Workflow::Client::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/workflow/client/status.rb

Overview

reveals the status of an object based on the lifecycles

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

Instance Method Summary collapse

Constructor Details

#initialize(druid:, version:, lifecycle_routes:) ⇒ Status

Returns a new instance of Status.

Parameters:

  • druid (String)

    the object identifier

  • version (String)

    the version identifier

  • lifecycle_routes (LifecycleRoutes)

    the lifecycle client



38
39
40
41
42
# File 'lib/dor/workflow/client/status.rb', line 38

def initialize(druid:, version:, lifecycle_routes:)
  @druid = druid
  @version = version
  @lifecycle_routes = lifecycle_routes
end

Instance Method Details

#display(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



75
76
77
78
79
80
81
82
# File 'lib/dor/workflow/client/status.rb', line 75

def display(include_time: false)
  status_time = info[:status_time]

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

#display_simplifiedObject



84
85
86
# File 'lib/dor/workflow/client/status.rb', line 84

def display_simplified
  simplified_status_code(STATUS_CODE_DISP_TXT[status_code])
end

#infoHash{Symbol => Object}

rubocop:disable Metrics/MethodLength

Returns:

  • (Hash{Symbol => Object})

    including :status_code and :status_time



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

def info
  @info ||= begin
    # 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 { 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

    { status_code: status_code, status_time: status_time }
  end
end

#milestonesObject



88
89
90
# File 'lib/dor/workflow/client/status.rb', line 88

def milestones
  @milestones ||= lifecycle_routes.milestones('dor', druid)
end

#status_codeObject

rubocop:enable Metrics/MethodLength



69
70
71
# File 'lib/dor/workflow/client/status.rb', line 69

def status_code
  info.fetch(:status_code)
end