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(*args) ⇒ 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. rubocop:disable Metrics/MethodLength

Parameters:

  • druid (String)

    object id

  • milestone_name (String)

    the name of the milestone being queried for

  • version (Number)

    the version to query for

Returns:

  • (Time)

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/dor/workflow/client/lifecycle_routes.rb', line 60

def active_lifecycle(*args)
  case args.size
  when 4
    Deprecation.warn(self, 'you provided 4 args, but active_lifecycle now takes kwargs')
    (repo, druid, milestone_name) = args[0..2]
    version = args[3][:version]
  when 3
    Deprecation.warn(self, 'you provided 3 args, but active_lifecycle now takes kwargs')
    (repo, druid, milestone_name) = args
    version = nil
  when 1
    opts = args.first
    repo = opts[:repo]
    druid = opts[:druid]
    milestone_name = opts[:milestone_name]
    version = opts[:version]
  else
    raise ArgumentError, 'wrong number of arguments, must be 1, 3, or 4'
  end

  Deprecation.warn(self, 'passing the repo parameter to active_lifecycle is no longer necessary. This will raise an error in dor-workflow-client version 4') if repo

  lifecycle(druid: druid, milestone_name: milestone_name, version: version, active_only: true)
end

#lifecycle(*args) ⇒ Time

Returns the Date for a requested milestone from workflow lifecycle

rubocop:disable Metrics/AbcSize, Metrics/MethodLength

Parameters:

  • repo (String)

    The repository the object resides in. This parameter is deprecated

  • druid (String)

    object id

  • milestone_name (String)

    the name of the milestone being queried for

  • version (Number)

    the version to query for

  • active_only (Boolean)

    (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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dor/workflow/client/lifecycle_routes.rb', line 22

def lifecycle(*args)
  case args.size
  when 4
    Deprecation.warn(self, 'you provided 4 args, but lifecycle now takes kwargs')
    (repo, druid, milestone_name) = args[0..2]
    version = args[3][:version]
    active_only = args[3][:active_only] || false
  when 3
    Deprecation.warn(self, 'you provided 3 args, but lifecycle now takes kwargs')
    (repo, druid, milestone_name) = args
    version = nil
    active_only = false
  when 1
    opts = args.first
    repo = opts[:repo]
    druid = opts[:druid]
    milestone_name = opts[:milestone_name]
    version = opts[:version]
    active_only = opts[:active_only] || false
  else
    raise ArgumentError, 'wrong number of arguments, must be 1, or 3-5'
  end

  Deprecation.warn(self, 'passing the repo parameter to lifecycle is no longer necessary. This will raise an error in dor-workflow-client version 4') if repo

  filter_milestone(query_lifecycle(druid, version: version, active_only: active_only), milestone_name)
end

#milestones(*args) ⇒ Array<Hash>

Returns:

  • (Array<Hash>)


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/dor/workflow/client/lifecycle_routes.rb', line 87

def milestones(*args)
  case args.size
  when 2
    Deprecation.warn(self, 'you provided 2 args, but active_lifecycle now takes kwargs')
    (repo, druid) = args
  when 1
    opts = args.first
    repo = opts[:repo]
    druid = opts.fetch(:druid)
  else
    raise ArgumentError, 'wrong number of arguments, must be 1-2'
  end

  Deprecation.warn(self, 'passing the repo parameter to active_lifecycle is no longer necessary. This will raise an error in dor-workflow-client version 4') if repo

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