Class: Dor::Workflow::Client::LifecycleRoutes

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

Overview

Makes requests relating to a lifecycle

Instance Method Summary collapse

Constructor Details

#initialize(requestor:) ⇒ LifecycleRoutes

Returns a new instance of LifecycleRoutes.



8
9
10
# File 'lib/dor/workflow/client/lifecycle_routes.rb', line 8

def initialize(requestor:)
  @requestor = requestor
end

Instance Method Details

#active_lifecycle(repo, druid, milestone_name, version: nil) ⇒ Time

Returns the Date for a requested milestone ONLY for the current version. This is slow as the workflow server will query dor-services-app for the version. A better approach is #lifecycle with the version tag.

Parameters:

  • repo (String)

    repository name

  • druid (String)

    object id

  • milestone_name (String)

    the name of the milestone being queried for

  • version (Number) (defaults to: nil)

    the version to query for

Returns:

  • (Time)

    when the milestone was achieved. Returns nil if the milestone does not exis



33
34
35
# File 'lib/dor/workflow/client/lifecycle_routes.rb', line 33

def active_lifecycle(repo, druid, milestone_name, version: nil)
  lifecycle(repo, druid, milestone_name, version: version, active_only: true)
end

#lifecycle(repo, druid, milestone_name, version: nil, active_only: false) ⇒ Time

Returns the Date for a requested milestone from workflow lifecycle

Parameters:

  • repo (String)

    repository name

  • druid (String)

    object id

  • milestone_name (String)

    the name of the milestone being queried for

  • version (Number) (defaults to: nil)

    the version to query for

  • active_only (Boolean) (defaults to: false)

    (false) if true, return only lifecycle steps for versions that have all processes complete

Returns:

  • (Time)

    when the milestone was achieved. Returns nil if the milestone does not exist



20
21
22
# File 'lib/dor/workflow/client/lifecycle_routes.rb', line 20

def lifecycle(repo, druid, milestone_name, version: nil, active_only: false)
  filter_milestone(query_lifecycle(repo, druid, version: version, active_only: active_only), milestone_name)
end

#milestones(repo, druid) ⇒ Hash

Returns:

  • (Hash)


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

def milestones(repo, druid)
  doc = query_lifecycle(repo, druid, active_only: false)
  doc.xpath('//lifecycle/milestone').collect do |node|
    { milestone: node.text, at: Time.parse(node['date']), version: node['version'] }
  end
end