eco-helpers 1.0.13 → 1.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eco/api/common/people/entry_factory.rb +3 -1
- data/lib/eco/api/common/people/person_attribute_parser.rb +33 -10
- data/lib/eco/api/common/people/person_entry.rb +1 -1
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +1 -1
- data/lib/eco/api/common/people/person_factory.rb +5 -1
- data/lib/eco/api/common/session/environment.rb +7 -3
- data/lib/eco/api/common/session/mailer.rb +4 -0
- data/lib/eco/api/common/session/sftp.rb +4 -3
- data/lib/eco/api/error.rb +1 -0
- data/lib/eco/api/organization/presets_factory.rb +1 -1
- data/lib/eco/api/organization/tag_tree.rb +1 -1
- data/lib/eco/api/session.rb +119 -74
- data/lib/eco/api/session/batch.rb +23 -25
- data/lib/eco/api/session/batch/base_policy.rb +283 -0
- data/lib/eco/api/session/batch/errors.rb +17 -3
- data/lib/eco/api/session/batch/feedback.rb +112 -0
- data/lib/eco/api/session/batch/job.rb +90 -87
- data/lib/eco/api/session/batch/policies.rb +22 -0
- data/lib/eco/api/session/batch/request_stats.rb +195 -0
- data/lib/eco/api/session/batch/status.rb +66 -19
- data/lib/eco/api/session/config.rb +10 -0
- data/lib/eco/api/session/config/workflow.rb +1 -1
- data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +4 -3
- data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +15 -10
- data/lib/eco/cli/config/default/filters.rb +3 -2
- data/lib/eco/cli/config/default/options.rb +12 -0
- data/lib/eco/cli/config/default/usecases.rb +6 -4
- data/lib/eco/cli/config/default/workflow.rb +3 -2
- data/lib/eco/cli/scripting/args_helpers.rb +1 -1
- data/lib/eco/version.rb +1 -1
- metadata +5 -1
@@ -2,26 +2,36 @@ module Eco
|
|
2
2
|
module API
|
3
3
|
class Session
|
4
4
|
class Batch
|
5
|
-
|
6
|
-
|
5
|
+
# @attr_reader source_queue [Array<Hash>, Array<Ecoportal::API::V1::Person>, Array<Ecoportal::API::Internal::Person>]
|
6
|
+
# The queue as it was originally made (it could contain duplicates)
|
7
|
+
# @attr_reader queue [Array<Hash>, Array<Ecoportal::API::V1::Person>, Array<Ecoportal::API::Internal::Person>]
|
8
|
+
# `source_queue` with no repeated elements (**note**: observe that the elimination of duplicates could fail)
|
9
|
+
# @attr_reader mode [Symbol] the `mode` that the `batch` was run with
|
10
|
+
# @attr_reader root [Eco::API::Session::Job] the `job` that launched the `batch`
|
11
|
+
class Status < Eco::API::Common::Session::BaseSession
|
12
|
+
@modes = [:exact, :search]
|
7
13
|
|
8
14
|
attr_reader :source_queue
|
9
|
-
attr_reader :queue, :method, :
|
15
|
+
attr_reader :queue, :method, :mode
|
10
16
|
attr_reader :root
|
11
17
|
|
12
18
|
class << self
|
13
|
-
attr_reader :
|
19
|
+
attr_reader :modes
|
14
20
|
|
15
|
-
def
|
16
|
-
|
21
|
+
def valid_mode?(value)
|
22
|
+
modes.include?(value)
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
20
|
-
|
26
|
+
# @param e [Eco::API::Common::Session::Environment] requires a session environmen, as any child of `Eco::API::Common::Session::BaseSession`
|
27
|
+
# @param queue [Array<Hash>, Array<Ecoportal::API::V1::Person>, Array<Ecoportal::API::Internal::Person>] the `source_queue`
|
28
|
+
# @param method [Symbol] the type of `batch operation`
|
29
|
+
# @param mode [Symbol] the mode of `batch operation` (search)
|
30
|
+
def initialize(e, queue:, method:, mode: :exact)
|
21
31
|
super(e)
|
22
32
|
fatal("In batch operations you must batch an Enumerable. Received: #{queue}") unless queue && queue.is_a?(Enumerable)
|
23
33
|
|
24
|
-
self.
|
34
|
+
self.mode = mode
|
25
35
|
@method = method
|
26
36
|
@source_queue = queue
|
27
37
|
|
@@ -41,33 +51,58 @@ module Eco
|
|
41
51
|
@people_match = Array.new(@queue.length, [])
|
42
52
|
end
|
43
53
|
|
54
|
+
# Nativelly to this gem, a batch against the server is lauched by an Eco::API::Session::Job.
|
55
|
+
# When the batch returns the `BatchStatus`, the `Job` assigns itself as `root` of it.
|
56
|
+
# @param object [Eco::API::Session::Job]
|
44
57
|
def root=(object)
|
45
58
|
@root = object
|
46
59
|
end
|
47
60
|
|
48
|
-
def
|
49
|
-
fatal("Invalid :
|
50
|
-
@
|
61
|
+
def mode=(value)
|
62
|
+
fatal("Invalid :mode '#{value}. You must specify mode: as one of #{self.class.modes} ") unless self.class.valid_mode?(value)
|
63
|
+
@mode = value
|
51
64
|
end
|
52
65
|
|
66
|
+
# @return [Eco::API::Session::Batch::Errors] errors object helper
|
53
67
|
def errors
|
54
|
-
@errors ||= Batch::Errors.new(status: self)
|
68
|
+
@errors ||= Eco::API::Session::Batch::Errors.new(status: self)
|
55
69
|
end
|
56
70
|
|
71
|
+
# Get the assciated `reponse` of an input entry object `key`
|
72
|
+
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person] these are the **index options**:
|
73
|
+
# 1. `Integer`: index/position of the entry in the final `queue`
|
74
|
+
# 2. `Hash`: entry queries can be raw `Hash` objects
|
75
|
+
# 3. `Person` object: the most common case is to use the person wrapper classes of the `Ecoportal::API` namespace.
|
76
|
+
# @return response key [Ecoportal::API::Common::BatchResponse]
|
57
77
|
def [](key)
|
58
78
|
@responses[to_index(key)]
|
59
79
|
end
|
60
80
|
|
61
|
-
|
81
|
+
# Associates an input entry object `key` to its `response`
|
82
|
+
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
83
|
+
# @see Eco::API::Session::Batch::Status#[] for `key` options
|
84
|
+
# @param response key [Ecoportal::API::Common::BatchResponse]
|
62
85
|
def []=(key, response)
|
63
86
|
@responses[to_index(key)] = response
|
64
87
|
end
|
65
88
|
|
89
|
+
# The _person_ we got from the Server wrapped to the `Person` object for the input entry object `key`
|
90
|
+
# @note it only makes sense when the batch method used was `get`
|
91
|
+
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
92
|
+
# @see Eco::API::Session::Batch::Status#[] for `key` options
|
93
|
+
# return [Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
66
94
|
def person(key)
|
67
95
|
return self[key].result if success?(key)
|
68
96
|
nil
|
69
97
|
end
|
70
98
|
|
99
|
+
# The _person_ we got from the Server wrapped to the `Person` object for the input entry object `key`
|
100
|
+
# @note
|
101
|
+
# - it only makes sense when the _batch method_ used was `get` with `q`
|
102
|
+
# - **found using a search criteria** (`mode` == `:search`), as opposite to find the person directly by `external_id`
|
103
|
+
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
104
|
+
# @see Eco::API::Session::Batch::Status#[] for `key` options
|
105
|
+
# return [Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
71
106
|
def person_match(key)
|
72
107
|
@person_match[to_index(key)]
|
73
108
|
end
|
@@ -84,44 +119,56 @@ module Eco
|
|
84
119
|
@people_match[to_index(key)] = people
|
85
120
|
end
|
86
121
|
|
122
|
+
# Has the _entry_ `key` been queried to the server?
|
123
|
+
# @param key [Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
124
|
+
# @return [Boolean] `true` if input entry `key` has an associated `Ecoportal::API::Common::BatchResponse`
|
87
125
|
def received?(key)
|
88
126
|
!!self[key]
|
89
127
|
end
|
90
128
|
|
129
|
+
# Has the _entry_ `key` 's query to the server been successful
|
130
|
+
# @param key [Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
131
|
+
# @return [Boolean] `true` if input entry `key` has not had a server Error during the query
|
91
132
|
def success?(key)
|
92
133
|
self[key]&.success?
|
93
134
|
end
|
94
135
|
|
136
|
+
# When the batch _method_ has been `get`, it gathers into an `Array` the people found.
|
137
|
+
# @note here is where the used `mode` gets relevance:
|
138
|
+
# - while `:exact` mode will keep the order of found people as per order of final `queue`
|
139
|
+
# - `:search` mode will just gather the results (order won't match)
|
140
|
+
# @raise [Exception] when the `method` of the batch operation was other than `get`
|
141
|
+
# @return [Array<Ecoportal::API::V1::Person>, Array<Ecoportal::API::Internal::Person>] all the people that has been found.
|
95
142
|
def people
|
96
143
|
fatal "This batch wasn't a 'get'. Can't obtain people without 'get' method" unless method == :get
|
97
|
-
|
98
|
-
if type == :exact
|
144
|
+
if mode == :exact
|
99
145
|
out = Array(queue.length)
|
100
146
|
@responses.each_with_index do |response, i|
|
101
|
-
# out = out.merge([response.result]) if respose.success?
|
102
147
|
out[i] = response.result if response.success?
|
103
148
|
end
|
104
|
-
elsif
|
149
|
+
elsif mode == :search
|
105
150
|
out = []
|
106
151
|
queue.each_with_index.map do |entry, i|
|
107
152
|
pers = person(entry)
|
108
153
|
pers ||= person_match(entry)
|
109
154
|
ppl = pers ? [pers] : people_match(entry)
|
110
155
|
out += ppl
|
111
|
-
# out = out.merge(ppl) unless ppl.empty?
|
112
156
|
end
|
113
157
|
end
|
114
158
|
out
|
115
159
|
end
|
116
160
|
|
161
|
+
# Helper to transform any `key` to an `Integer` index
|
162
|
+
# @return [Integer] the index that `key` has in the final `queue`
|
117
163
|
def to_index(key)
|
118
164
|
key.is_a?(Integer) ? valid_index(index: key) : valid_index(entry: key)
|
119
165
|
end
|
120
166
|
|
167
|
+
# _Index_ validator to make this object reliable
|
121
168
|
def valid_index(index: nil, entry: nil)
|
122
169
|
index ||= @hash[entry]
|
123
170
|
unless index && index < @queue.length
|
124
|
-
fatal "You must provide either the index or the original entry object of the batch"
|
171
|
+
fatal "You must provide either the index on the final 'queue' or the original entry object of the batch"
|
125
172
|
end
|
126
173
|
index
|
127
174
|
end
|
@@ -274,6 +274,16 @@ module Eco
|
|
274
274
|
end
|
275
275
|
end
|
276
276
|
|
277
|
+
def batch_policies
|
278
|
+
@batch_policies = self["batch_policies"] ||= Eco::API::Session::Batch::Policies.new("batch_policy")
|
279
|
+
if block_given?
|
280
|
+
yield(@batch_policies)
|
281
|
+
self
|
282
|
+
else
|
283
|
+
@batch_policies
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
277
287
|
def error_handlers
|
278
288
|
@error_handlers = self["error_handlers"] ||= Eco::API::Error::Handlers.new
|
279
289
|
if block_given?
|
@@ -32,7 +32,7 @@ module Eco
|
|
32
32
|
def get_model(key)
|
33
33
|
raise "Expected Symbol. Given: #{key.class}" unless key.is_a?(Symbol)
|
34
34
|
workflow = @workflow[key]
|
35
|
-
raise "Expected
|
35
|
+
raise "Expected Hash. Given #{model.class}" unless !workflow || workflow.is_a?(Hash)
|
36
36
|
|
37
37
|
class_name = titleize(key.to_s)
|
38
38
|
full_class_name = "#{self}::#{class_name}"
|
@@ -14,7 +14,7 @@ module Eco
|
|
14
14
|
msg = "There is no tagtree definition in the configuration files\n" +
|
15
15
|
"For this usecase to work out you need to define it."
|
16
16
|
session.logger.fatal(msg)
|
17
|
-
|
17
|
+
raise msg
|
18
18
|
end
|
19
19
|
|
20
20
|
# IMPORTANT: this two lines ensure that only people to be updated is selected
|
@@ -22,8 +22,9 @@ module Eco
|
|
22
22
|
people = people.account_present
|
23
23
|
|
24
24
|
if people.length <= 0
|
25
|
-
|
26
|
-
|
25
|
+
msg = "There are no people with account... aborting script"
|
26
|
+
session.logger.info(msg)
|
27
|
+
raise msg
|
27
28
|
end
|
28
29
|
|
29
30
|
update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :account)
|
@@ -8,32 +8,37 @@ module Eco
|
|
8
8
|
@cases.define("switch-supervisor", type: :transform) do |people, session, options, usecase|
|
9
9
|
|
10
10
|
unless old_id = options.dig(:super, :old)
|
11
|
-
|
12
|
-
|
11
|
+
msg = "You haven't specified the original supervisor. Aborting..."
|
12
|
+
session.logger.error(msg)
|
13
|
+
exit(1)
|
13
14
|
end
|
14
15
|
|
15
16
|
# we could be setting the supervisor to nil
|
16
17
|
unless options[:super].key?(:new)
|
17
|
-
|
18
|
-
|
18
|
+
msg = "You haven't specified the new supervisor. Aborting..."
|
19
|
+
session.logger.error(msg)
|
20
|
+
exit(1)
|
19
21
|
end
|
20
22
|
|
21
23
|
new_id = options.dig(:super, :new)
|
22
24
|
|
23
25
|
unless old_sup = people.person(id: old_id, external_id: old_id, email: old_id)
|
24
|
-
|
25
|
-
|
26
|
+
msg = "Couldn't find any user with that id (old-super): '#{old_id}'. Aborting..."
|
27
|
+
session.logger.error(msg)
|
28
|
+
exit(1)
|
26
29
|
end
|
27
30
|
|
28
31
|
unless new_sup = people.person(id: new_id, external_id: new_id, email: new_id)
|
29
|
-
|
30
|
-
|
32
|
+
msg = "Couldn't find any user with that id (new-super): '#{new_id}'. Aborting..."
|
33
|
+
session.logger.error(msg)
|
34
|
+
exit(1)
|
31
35
|
end
|
32
36
|
|
33
37
|
people = people.supervisor_id(old_sup.id)
|
34
38
|
unless people.length > 0
|
35
|
-
|
36
|
-
|
39
|
+
msg = "There are no people with supervisor #{old_sup.external_id} (#{old_sup.name} - #{old_sup.email}). Aborting..."
|
40
|
+
session.logger.error(msg)
|
41
|
+
exit(1)
|
37
42
|
end
|
38
43
|
|
39
44
|
session.logger.info("Going to change supervisor '#{old_sup.name}' (#{old_sup.external_id}) to '#{new_sup.name}' (#{new_sup.external_id})")
|
@@ -50,8 +50,9 @@ ASSETS.cli.config do |cnf|
|
|
50
50
|
sch_id = session.schemas.to_id(sch_name)
|
51
51
|
|
52
52
|
unless sch_id
|
53
|
-
|
54
|
-
|
53
|
+
msg = "You need to specify the schema id"
|
54
|
+
session.logger.error(msg)
|
55
|
+
exit(1)
|
55
56
|
end
|
56
57
|
|
57
58
|
options.deep_merge!(people: {filter: {details: {schema_id: sch_id}}})
|
@@ -6,6 +6,18 @@ ASSETS.cli.config do |cnf|
|
|
6
6
|
options[:simulate] = true
|
7
7
|
end
|
8
8
|
|
9
|
+
options_set.add("-skip-batch-policy") do |options|
|
10
|
+
options.deep_merge!(skip: {batch_policy: true})
|
11
|
+
end
|
12
|
+
|
13
|
+
options_set.add("-skip-api-policies") do |options|
|
14
|
+
options.deep_merge!(skip: {api_policies: true})
|
15
|
+
end
|
16
|
+
|
17
|
+
options_set.add("-feed-only-stats") do |options|
|
18
|
+
options.deep_merge!(feedback: {only_stats: true})
|
19
|
+
end
|
20
|
+
|
9
21
|
options[:end_get] = true
|
10
22
|
options_set.add("-no-get") do |options|
|
11
23
|
options[:end_get] = false
|
@@ -21,14 +21,16 @@ ASSETS.cli.config do |cnf|
|
|
21
21
|
cases.add("-set-supervisor-from", :sync, case_name: "set-supervisor")
|
22
22
|
cases.add("-switch-supervisor", :transform, case_name: "switch-supervisor") do |people, session, options|
|
23
23
|
unless old_id = SCR.get_arg("-old-super", with_param: true)
|
24
|
-
|
25
|
-
|
24
|
+
msg = "You must specify an -old-super to target whose supervisor is changing"
|
25
|
+
session.logger.error(msg)
|
26
|
+
exit(1)
|
26
27
|
end
|
27
28
|
options.deep_merge!(super: {old: old_id})
|
28
29
|
|
29
30
|
unless new_id = SCR.get_arg("-new-super", with_param: true)
|
30
|
-
|
31
|
-
|
31
|
+
msg = "You must specify the -new-super id. To reset to nil the supervisor, please, specify nil."
|
32
|
+
session.logger.error(msg)
|
33
|
+
exit(1)
|
32
34
|
end
|
33
35
|
new_id = new_id == "nil"? nil : new_id
|
34
36
|
options.deep_merge!(super: {new: new_id})
|
@@ -32,8 +32,9 @@ ASSETS.cli.config do |config|
|
|
32
32
|
|
33
33
|
wf.on(:usecases) do |wf_cases, io|
|
34
34
|
unless config.usecases.process(io: io)
|
35
|
-
|
36
|
-
|
35
|
+
msg = "No update operation specified... quitting"
|
36
|
+
io.session.logger.warn(msg)
|
37
|
+
exit(1)
|
37
38
|
end
|
38
39
|
io
|
39
40
|
end
|
data/lib/eco/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eco-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
@@ -308,10 +308,14 @@ files:
|
|
308
308
|
- lib/eco/api/policies/policy.rb
|
309
309
|
- lib/eco/api/session.rb
|
310
310
|
- lib/eco/api/session/batch.rb
|
311
|
+
- lib/eco/api/session/batch/base_policy.rb
|
311
312
|
- lib/eco/api/session/batch/errors.rb
|
313
|
+
- lib/eco/api/session/batch/feedback.rb
|
312
314
|
- lib/eco/api/session/batch/job.rb
|
313
315
|
- lib/eco/api/session/batch/jobs.rb
|
314
316
|
- lib/eco/api/session/batch/jobs_groups.rb
|
317
|
+
- lib/eco/api/session/batch/policies.rb
|
318
|
+
- lib/eco/api/session/batch/request_stats.rb
|
315
319
|
- lib/eco/api/session/batch/status.rb
|
316
320
|
- lib/eco/api/session/config.rb
|
317
321
|
- lib/eco/api/session/config/api.rb
|