Class: Dor::Workflow::Client::Status
- Inherits:
-
Object
- Object
- Dor::Workflow::Client::Status
- 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
-
#display(include_time: false) ⇒ String
Single composed status from status_info.
- #display_simplified ⇒ Object
-
#info ⇒ Hash{Symbol => Object}
rubocop:disable Metrics/MethodLength.
-
#initialize(druid:, version:, lifecycle_routes:) ⇒ Status
constructor
A new instance of Status.
- #milestones ⇒ Object
-
#status_code ⇒ Object
rubocop:enable Metrics/MethodLength.
Constructor Details
#initialize(druid:, version:, lifecycle_routes:) ⇒ Status
Returns a new instance of Status.
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.
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_simplified ⇒ Object
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 |
#info ⇒ Hash{Symbol => Object}
rubocop:disable Metrics/MethodLength
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 |
#milestones ⇒ Object
88 89 90 |
# File 'lib/dor/workflow/client/status.rb', line 88 def milestones @milestones ||= lifecycle_routes.milestones('dor', druid) end |
#status_code ⇒ Object
rubocop:enable Metrics/MethodLength
69 70 71 |
# File 'lib/dor/workflow/client/status.rb', line 69 def status_code info.fetch(:status_code) end |