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) ⇒ Time

Returns the Date for a requested milestone ONLY FROM THE ACTIVE workflow table

Examples:

An example lifecycle xml from the workflow service.

<lifecycle objectId="druid:ct011cv6501">
  <milestone date="2010-04-27T11:34:17-0700">registered</milestone>
  <milestone date="2010-04-29T10:12:51-0700">inprocess</milestone>
  <milestone date="2010-06-15T16:08:58-0700">released</milestone>
</lifecycle>

Parameters:

  • repo (String)

    repository name

  • druid (String)

    object id

  • milestone (String)

    name of the milestone being queried for

Returns:

  • (Time)

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



42
43
44
45
46
47
48
# File 'lib/dor/workflow/client/lifecycle_routes.rb', line 42

def active_lifecycle(repo, druid, milestone)
  doc = query_lifecycle(repo, druid, true)
  milestone = doc.at_xpath("//lifecycle/milestone[text() = '#{milestone}']")
  return Time.parse(milestone['date']) if milestone

  nil
end

#lifecycle(repo, druid, milestone) ⇒ Time

Returns the Date for a requested milestone from workflow lifecycle

Examples:

An example lifecycle xml from the workflow service.

<lifecycle objectId="druid:ct011cv6501">
  <milestone date="2010-04-27T11:34:17-0700">registered</milestone>
  <milestone date="2010-04-29T10:12:51-0700">inprocess</milestone>
  <milestone date="2010-06-15T16:08:58-0700">released</milestone>
</lifecycle>

Parameters:

  • repo (String)

    repository name

  • druid (String)

    object id

  • milestone (String)

    name of the milestone being queried for

Returns:

  • (Time)

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



23
24
25
26
27
28
29
# File 'lib/dor/workflow/client/lifecycle_routes.rb', line 23

def lifecycle(repo, druid, milestone)
  doc = query_lifecycle(repo, druid)
  milestone = doc.at_xpath("//lifecycle/milestone[text() = '#{milestone}']")
  return Time.parse(milestone['date']) if milestone

  nil
end

#milestones(repo, druid) ⇒ Hash

Returns:

  • (Hash)


51
52
53
54
55
56
# File 'lib/dor/workflow/client/lifecycle_routes.rb', line 51

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