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}
Including :status_code and :status_time.
-
#initialize(druid:, version:, lifecycle_routes:) ⇒ Status
constructor
A new instance of Status.
- #milestones ⇒ Object
- #status_code ⇒ Object
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.to_s @lifecycle_routes = lifecycle_routes end |
Instance Method Details
#display(include_time: false) ⇒ String
Returns single composed status from status_info.
73 74 75 76 77 78 79 80 |
# File 'lib/dor/workflow/client/status.rb', line 73 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
82 83 84 |
# File 'lib/dor/workflow/client/status.rb', line 82 def display_simplified simplified_status_code(STATUS_CODE_DISP_TXT[status_code]) end |
#info ⇒ Hash{Symbol => Object}
Returns including :status_code and :status_time.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/dor/workflow/client/status.rb', line 45 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
86 87 88 |
# File 'lib/dor/workflow/client/status.rb', line 86 def milestones @milestones ||= lifecycle_routes.milestones(druid: druid) end |
#status_code ⇒ Object
67 68 69 |
# File 'lib/dor/workflow/client/status.rb', line 67 def status_code info.fetch(:status_code) end |