eco-helpers 3.0.20 → 3.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.idea/.gitignore +10 -0
- data/CHANGELOG.md +55 -5
- data/eco-helpers.gemspec +3 -3
- data/lib/eco/api/common/class_hierarchy.rb +6 -9
- data/lib/eco/api/common/loaders/case_base.rb +12 -4
- data/lib/eco/api/common/loaders/config/cli.rb +9 -0
- data/lib/eco/api/common/loaders/config/workflow/cases_extension.rb +53 -0
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +2 -14
- data/lib/eco/api/common/loaders/config/workflow.rb +4 -0
- data/lib/eco/api/common/loaders/config.rb +1 -0
- data/lib/eco/api/common/loaders/error_handler.rb +3 -2
- data/lib/eco/api/common/loaders/policy.rb +3 -2
- data/lib/eco/api/common/loaders/use_case/cli_identify.rb +28 -0
- data/lib/eco/api/common/loaders/use_case/target_model.rb +25 -0
- data/lib/eco/api/common/loaders/use_case/type.rb +37 -0
- data/lib/eco/api/common/loaders/use_case.rb +16 -43
- data/lib/eco/api/common/people/default_parsers/xls_parser.rb +1 -1
- data/lib/eco/api/common/session/logger/cache.rb +10 -4
- data/lib/eco/api/common/session/logger/channels.rb +41 -0
- data/lib/eco/api/common/session/logger.rb +9 -0
- data/lib/eco/api/error/handler.rb +6 -4
- data/lib/eco/api/error/handlers.rb +12 -5
- data/lib/eco/api/microcases/people/apply_changes/set_account/account_excluded.rb +34 -0
- data/lib/eco/api/microcases/people/apply_changes/set_account.rb +28 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +28 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core.rb +27 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core_with_supervisor.rb +38 -0
- data/lib/eco/api/microcases/people/apply_changes/set_supervisor.rb +69 -0
- data/lib/eco/api/microcases/people/apply_changes.rb +19 -0
- data/lib/eco/api/microcases/people/fetch/with_each.rb +109 -0
- data/lib/eco/api/microcases/people/fetch/with_each_leaver.rb +33 -0
- data/lib/eco/api/microcases/people/fetch/with_each_present.rb +42 -0
- data/lib/eco/api/microcases/people/fetch/with_each_starter.rb +43 -0
- data/lib/eco/api/microcases/people/fetch/with_each_subordinate.rb +41 -0
- data/lib/eco/api/microcases/people/fetch/with_supervisor.rb +46 -0
- data/lib/eco/api/microcases/people/fetch.rb +23 -0
- data/lib/eco/api/microcases/people/integrity/fix_default_group.rb +39 -0
- data/lib/eco/api/microcases/people/integrity/fix_filter_tags.rb +55 -0
- data/lib/eco/api/microcases/people/integrity/refresh_default_tag.rb +32 -0
- data/lib/eco/api/microcases/people/integrity.rb +17 -0
- data/lib/eco/api/microcases/people/macro/take_email.rb +141 -0
- data/lib/eco/api/microcases/people/macro.rb +13 -0
- data/lib/eco/api/microcases/people/manage/cache.rb +36 -0
- data/lib/eco/api/microcases/people/manage/load.rb +90 -0
- data/lib/eco/api/microcases/people/manage/refresh.rb +59 -0
- data/lib/eco/api/microcases/people/manage/search.rb +118 -0
- data/lib/eco/api/microcases/people/manage.rb +19 -0
- data/lib/eco/api/microcases/people/preserve/default_tag.rb +29 -0
- data/lib/eco/api/microcases/people/preserve/filter_tags.rb +34 -0
- data/lib/eco/api/microcases/people/preserve/policy_groups.rb +36 -0
- data/lib/eco/api/microcases/people/preserve.rb +17 -0
- data/lib/eco/api/microcases/people.rb +21 -0
- data/lib/eco/api/microcases/person_update.rb +1 -1
- data/lib/eco/api/microcases/s3upload_targets.rb +1 -1
- data/lib/eco/api/microcases/with_each_contractor_present.rb +40 -0
- data/lib/eco/api/microcases.rb +3 -23
- data/lib/eco/api/organization/people/multiple_search_results.rb +48 -0
- data/lib/eco/api/organization/{people_similarity.rb → people/similarity.rb} +89 -72
- data/lib/eco/api/organization/people.rb +40 -66
- data/lib/eco/api/organization.rb +0 -1
- data/lib/eco/api/policies/policy.rb +7 -5
- data/lib/eco/api/policies.rb +9 -4
- data/lib/eco/api/session/batch/feedback/generate.rb +60 -0
- data/lib/eco/api/session/batch/feedback/getters.rb +28 -0
- data/lib/eco/api/session/batch/feedback/identifiers.rb +20 -0
- data/lib/eco/api/session/batch/feedback/job_dependencies.rb +45 -0
- data/lib/eco/api/session/batch/feedback/request_stat.rb +27 -0
- data/lib/eco/api/session/batch/feedback/request_stats.rb +270 -0
- data/lib/eco/api/session/batch/feedback.rb +45 -119
- data/lib/eco/api/session/batch/job/sets.rb +23 -0
- data/lib/eco/api/session/batch/job/type.rb +22 -0
- data/lib/eco/api/session/batch/job.rb +19 -18
- data/lib/eco/api/session/batch/jobs.rb +6 -2
- data/lib/eco/api/session/batch/launcher/mode_size.rb +1 -1
- data/lib/eco/api/session/batch/launcher/retry.rb +4 -4
- data/lib/eco/api/session/batch/launcher.rb +2 -2
- data/lib/eco/api/session/batch/policies.rb +4 -4
- data/lib/eco/api/session/batch/searcher.rb +2 -1
- data/lib/eco/api/session/batch.rb +0 -1
- data/lib/eco/api/session/config/workflow.rb +19 -9
- data/lib/eco/api/usecases/base_case/model.rb +54 -0
- data/lib/eco/api/usecases/base_case/type.rb +52 -0
- data/lib/eco/api/usecases/base_case.rb +5 -29
- data/lib/eco/api/usecases/base_io/chaining.rb +48 -0
- data/lib/eco/api/usecases/base_io/validations.rb +114 -0
- data/lib/eco/api/usecases/base_io.rb +65 -115
- data/lib/eco/api/usecases/cli/dsl.rb +3 -1
- data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +7 -4
- data/lib/eco/api/usecases/default/people/treat/supers_cyclic_identify_case.rb +1 -3
- data/lib/eco/api/usecases/default/people/treat/supers_hierarchy_case.rb +1 -5
- data/lib/eco/api/usecases/default_cases/entries_to_csv_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/hris_case.rb +0 -2
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +3 -6
- data/lib/eco/api/usecases/graphql/base.rb +3 -2
- data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +1 -1
- data/lib/eco/api/usecases/graphql/helpers/base/error_handling.rb +3 -3
- data/lib/eco/api/usecases/graphql/helpers/contractors/base/load.rb +17 -0
- data/lib/eco/api/usecases/graphql/helpers/contractors/base.rb +8 -0
- data/lib/eco/api/usecases/graphql/helpers/contractors.rb +6 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base.rb +5 -4
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +2 -2
- data/lib/eco/api/usecases/graphql/helpers.rb +1 -0
- data/lib/eco/api/usecases/graphql/samples/contractors/dsl.rb +5 -0
- data/lib/eco/api/usecases/graphql/samples/contractors.rb +17 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +1 -1
- data/lib/eco/api/usecases/graphql/samples/location.rb +1 -1
- data/lib/eco/api/usecases/graphql/samples.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +0 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +8 -8
- data/lib/eco/api/usecases/use_case/chainer.rb +12 -0
- data/lib/eco/api/usecases/use_case.rb +32 -23
- data/lib/eco/api/usecases/use_case_chain/chaining.rb +88 -0
- data/lib/eco/api/usecases/use_case_chain.rb +17 -62
- data/lib/eco/api/usecases/use_case_io/chain.rb +24 -0
- data/lib/eco/api/usecases/use_case_io.rb +17 -22
- data/lib/eco/api/usecases.rb +12 -4
- data/lib/eco/assets.rb +1 -1
- data/lib/eco/cli/config/filters/people_filters.rb +6 -5
- data/lib/eco/cli/config/input.rb +6 -2
- data/lib/eco/cli/config/use_cases.rb +4 -2
- data/lib/eco/cli_default/input.rb +49 -29
- data/lib/eco/cli_default/options.rb +4 -1
- data/lib/eco/cli_default/people.rb +102 -47
- data/lib/eco/cli_default/people_filters.rb +5 -1
- data/lib/eco/cli_default/workflow.rb +149 -138
- data/lib/eco/data/mapper.rb +51 -19
- data/lib/eco/language/auxiliar_logger.rb +16 -3
- data/lib/eco/language/basic_logger.rb +1 -0
- data/lib/eco/language/methods/dsl_able.rb +3 -0
- data/lib/eco/version.rb +1 -1
- metadata +68 -33
- data/lib/eco/api/microcases/account_excluded.rb +0 -26
- data/lib/eco/api/microcases/core_excluded.rb +0 -20
- data/lib/eco/api/microcases/fix_default_group.rb +0 -33
- data/lib/eco/api/microcases/fix_filter_tags.rb +0 -49
- data/lib/eco/api/microcases/people_cache.rb +0 -30
- data/lib/eco/api/microcases/people_load.rb +0 -84
- data/lib/eco/api/microcases/people_refresh.rb +0 -53
- data/lib/eco/api/microcases/people_search.rb +0 -112
- data/lib/eco/api/microcases/preserve_default_tag.rb +0 -23
- data/lib/eco/api/microcases/preserve_filter_tags.rb +0 -28
- data/lib/eco/api/microcases/preserve_policy_groups.rb +0 -30
- data/lib/eco/api/microcases/refresh_default_tag.rb +0 -26
- data/lib/eco/api/microcases/set_account.rb +0 -18
- data/lib/eco/api/microcases/set_core.rb +0 -17
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +0 -32
- data/lib/eco/api/microcases/set_supervisor.rb +0 -63
- data/lib/eco/api/microcases/take_email_from_account.rb +0 -129
- data/lib/eco/api/microcases/with_each.rb +0 -103
- data/lib/eco/api/microcases/with_each_leaver.rb +0 -27
- data/lib/eco/api/microcases/with_each_present.rb +0 -36
- data/lib/eco/api/microcases/with_each_starter.rb +0 -37
- data/lib/eco/api/microcases/with_each_subordinate.rb +0 -33
- data/lib/eco/api/microcases/with_supervisor.rb +0 -35
- data/lib/eco/api/session/batch/request_stats.rb +0 -266
@@ -1,43 +1,10 @@
|
|
1
|
+
# rubocop:disable Style/Attr
|
1
2
|
module Eco
|
2
3
|
module API
|
3
4
|
module Organization
|
4
|
-
class People <
|
5
|
-
|
6
|
-
|
7
|
-
class MultipleSearchResults < StandardError
|
8
|
-
attr_reader :candidates, :property
|
9
|
-
# @param msg [String] the basic message error.
|
10
|
-
# @param candiates [Array<Person>] the people that match the same search criterion.
|
11
|
-
# @param property [String] the property of the person model that triggered the error (base of the search criterion).
|
12
|
-
def initialize(msg, candidates: [], property: "email")
|
13
|
-
@candidates = candidates
|
14
|
-
@property = property
|
15
|
-
super(msg + " " + candidates_summary)
|
16
|
-
end
|
17
|
-
|
18
|
-
# @param with_index [Boolean] to add an index to each candidate description.
|
19
|
-
# @return [Array<String>] the `candidates` identified
|
20
|
-
def identify_candidates(with_index: false)
|
21
|
-
candidates.map.each_with_index do |person, i|
|
22
|
-
index = with_index ? "#{i}. " : ""
|
23
|
-
msg = person.account ? (person.account_added? ? "(new user)" : "(user)") : "(no account)"
|
24
|
-
"#{index}#{msg} #{person.identify}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# @return [Person] the `candidate` in the `index` position
|
29
|
-
def candidate(index)
|
30
|
-
candidates[index]
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def candidates_summary
|
36
|
-
lines = ["The following people have the same '#{property}':"]
|
37
|
-
lines.concat(identify_candidates(with_index: true)).join("\n ")
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
5
|
+
class People < Eco::Language::Models::Collection
|
6
|
+
require_relative 'people/multiple_search_results'
|
7
|
+
require_relative 'people/similarity'
|
41
8
|
|
42
9
|
# build the shortcuts of Collection
|
43
10
|
attr_presence :account, :details
|
@@ -84,39 +51,39 @@ module Eco
|
|
84
51
|
def updated_or_created
|
85
52
|
select do |person|
|
86
53
|
!person.as_update(:total).empty?
|
87
|
-
end.
|
54
|
+
end.then do |persons|
|
88
55
|
newFrom persons
|
89
56
|
end
|
90
57
|
end
|
91
58
|
|
92
59
|
def supervisors
|
93
|
-
sup_ids =
|
60
|
+
sup_ids = ids & supervisor_ids
|
94
61
|
sup_ids.map do |id|
|
95
62
|
person(id: id, strict: true)
|
96
|
-
end.
|
63
|
+
end.then do |supervisors|
|
97
64
|
newFrom supervisors
|
98
65
|
end
|
99
66
|
end
|
100
67
|
|
101
68
|
def missing_supervisors_ids
|
102
|
-
sup_ids =
|
103
|
-
sup_ids - (sup_ids &
|
69
|
+
sup_ids = supervisor_ids
|
70
|
+
sup_ids - (sup_ids & ids)
|
104
71
|
end
|
105
72
|
|
106
73
|
def filter_tags_any(tags)
|
107
|
-
attr(
|
74
|
+
attr('filter_tags', tags, default_modifier.any.insensitive)
|
108
75
|
end
|
109
76
|
|
110
77
|
def filter_tags_all(tags)
|
111
|
-
attr(
|
78
|
+
attr('filter_tags', tags, default_modifier.all.insensitive)
|
112
79
|
end
|
113
80
|
|
114
81
|
def policy_group_ids_any(ids)
|
115
|
-
attr(
|
82
|
+
attr('policy_group_ids', ids, default_modifier.any.insensitive)
|
116
83
|
end
|
117
84
|
|
118
85
|
def policy_group_ids_all(ids)
|
119
|
-
attr(
|
86
|
+
attr('policy_group_ids', ids, default_modifier.all.insensitive)
|
120
87
|
end
|
121
88
|
|
122
89
|
# @!endgroup
|
@@ -138,7 +105,8 @@ module Eco
|
|
138
105
|
# @param id [String] the `internal id` of the person
|
139
106
|
# @param external_id [String] the `exernal_id` of the person
|
140
107
|
# @param email [String] the `email` of the person
|
141
|
-
# @param strict [Boolean] if should perform a `:soft` or a `:strict` search.
|
108
|
+
# @param strict [Boolean] if should perform a `:soft` or a `:strict` search.
|
109
|
+
# `strict` will avoid repeated email addresses.
|
142
110
|
# @return [Person, nil] the person we were searching, or `nil` if not found.
|
143
111
|
def person(id: nil, external_id: nil, email: nil, strict: false)
|
144
112
|
init_caches
|
@@ -155,9 +123,9 @@ module Eco
|
|
155
123
|
|
156
124
|
# @see Eco::API::Organization::People#person
|
157
125
|
def find(object, strict: false)
|
158
|
-
id = attr_value(object,
|
159
|
-
external_id = attr_value(object,
|
160
|
-
email = attr_value(object,
|
126
|
+
id = attr_value(object, 'id')
|
127
|
+
external_id = attr_value(object, 'external_id')
|
128
|
+
email = attr_value(object, 'email')
|
161
129
|
person(id: id, external_id: external_id, email: email, strict: strict)
|
162
130
|
end
|
163
131
|
# @!endgroup
|
@@ -168,19 +136,20 @@ module Eco
|
|
168
136
|
to_a.to_json
|
169
137
|
end
|
170
138
|
|
171
|
-
def newFrom(data)
|
139
|
+
def newFrom(data) # rubocop:disable Naming/MethodName
|
172
140
|
self.class.new(data, klass: @klass)
|
173
141
|
end
|
174
142
|
|
175
143
|
def uniq(strict: false, include_unsearchable: false)
|
176
144
|
unsearchable = []
|
145
|
+
|
177
146
|
to_a.each_with_object([]) do |person, people|
|
178
|
-
if found = find(person, strict: strict)
|
147
|
+
if (found = find(person, strict: strict))
|
179
148
|
people << found
|
180
149
|
else
|
181
150
|
unsearchable << person
|
182
151
|
end
|
183
|
-
end.
|
152
|
+
end.then do |found|
|
184
153
|
found += unsearchable if include_unsearchable
|
185
154
|
newFrom found
|
186
155
|
end
|
@@ -203,7 +172,7 @@ module Eco
|
|
203
172
|
def exclude_people(list, strict: false)
|
204
173
|
list.map do |person|
|
205
174
|
find(person, strict: strict)
|
206
|
-
end.compact.
|
175
|
+
end.compact.then do |discarded|
|
207
176
|
newFrom to_a - discarded
|
208
177
|
end
|
209
178
|
end
|
@@ -212,7 +181,7 @@ module Eco
|
|
212
181
|
# @!group Groupping methods
|
213
182
|
|
214
183
|
def email_id_maps
|
215
|
-
users.group_by(:email).transform_values
|
184
|
+
users.group_by(:email).transform_values(&:id)
|
216
185
|
end
|
217
186
|
|
218
187
|
def group_by_supervisor
|
@@ -221,18 +190,20 @@ module Eco
|
|
221
190
|
|
222
191
|
def group_by_schema
|
223
192
|
to_h do |person|
|
224
|
-
|
193
|
+
next unless (details = person.details)
|
194
|
+
|
195
|
+
details.schema_id
|
225
196
|
end
|
226
197
|
end
|
227
198
|
|
228
|
-
def to_h(attr =
|
229
|
-
super(attr ||
|
199
|
+
def to_h(attr = 'id')
|
200
|
+
super(attr || 'id')
|
230
201
|
end
|
231
202
|
# @!endgroup
|
232
203
|
|
233
204
|
# @!group Helper methods
|
234
205
|
def similarity
|
235
|
-
Eco::API::Organization::
|
206
|
+
Eco::API::Organization::People::Similarity.new(to_a)
|
236
207
|
end
|
237
208
|
# @!endgroup
|
238
209
|
|
@@ -245,21 +216,22 @@ module Eco
|
|
245
216
|
private
|
246
217
|
|
247
218
|
def person_by_email(email, prevent_duplicates: true)
|
248
|
-
return
|
219
|
+
return unless email
|
249
220
|
|
250
221
|
candidates = @by_non_users_email[email] || []
|
251
222
|
email_users = @by_users_email[email] || []
|
252
223
|
|
253
|
-
if pers = email_users.first
|
224
|
+
if (pers = email_users.first)
|
254
225
|
return pers if candidates.empty?
|
226
|
+
|
255
227
|
candidates = [pers] + candidates
|
256
228
|
elsif candidates.length == 1
|
257
229
|
return candidates.first
|
258
230
|
end
|
259
231
|
|
260
232
|
if prevent_duplicates && !candidates.empty?
|
261
|
-
msg =
|
262
|
-
raise MultipleSearchResults.new(msg, candidates: candidates, property:
|
233
|
+
msg = 'Multiple search results match the criteria.'
|
234
|
+
raise MultipleSearchResults.new(msg, candidates: candidates, property: 'email')
|
263
235
|
end
|
264
236
|
|
265
237
|
@by_external_id[email]&.first
|
@@ -267,6 +239,7 @@ module Eco
|
|
267
239
|
|
268
240
|
def init_caches
|
269
241
|
return if @caches_init
|
242
|
+
|
270
243
|
@by_id = no_nil_key(to_h)
|
271
244
|
@by_external_id = no_nil_key(to_h('external_id'))
|
272
245
|
@by_users_email = no_nil_key(existing_users.to_h('email'))
|
@@ -276,15 +249,16 @@ module Eco
|
|
276
249
|
end
|
277
250
|
|
278
251
|
def existing_users
|
279
|
-
|
252
|
+
usrs = users.reject {|u| u.account_added?(:original)}
|
253
|
+
newFrom usrs
|
280
254
|
end
|
281
255
|
|
282
256
|
def no_nil_key(hash)
|
283
257
|
hash.tap {|h| h.delete(nil)}
|
284
258
|
end
|
285
|
-
|
286
|
-
|
287
259
|
end
|
288
260
|
end
|
289
261
|
end
|
290
262
|
end
|
263
|
+
|
264
|
+
# rubocop:enable Style/Attr
|
data/lib/eco/api/organization.rb
CHANGED
@@ -10,7 +10,6 @@ require_relative 'organization/tag_tree'
|
|
10
10
|
require_relative 'organization/presets_factory'
|
11
11
|
require_relative 'organization/preferences'
|
12
12
|
require_relative 'organization/people'
|
13
|
-
require_relative 'organization/people_similarity'
|
14
13
|
require_relative 'organization/person_schemas'
|
15
14
|
require_relative 'organization/policy_groups'
|
16
15
|
require_relative 'organization/login_providers'
|
@@ -2,17 +2,19 @@ module Eco
|
|
2
2
|
module API
|
3
3
|
class Policies
|
4
4
|
class Policy < Eco::API::UseCases::UseCase
|
5
|
-
|
6
|
-
|
5
|
+
TYPES = [:transform].freeze
|
6
|
+
|
7
7
|
def initialize(name, type: :transform, root:, &block)
|
8
|
-
super
|
8
|
+
super
|
9
9
|
end
|
10
10
|
|
11
11
|
def root=(value)
|
12
|
-
|
12
|
+
msg = "Root should be a Eco::API::Policies object. "
|
13
|
+
msg << "Given: #{value.class}"
|
14
|
+
raise ArgumentError, msg unless value.is_a?(Eco::API::Policies)
|
15
|
+
|
13
16
|
@root = value
|
14
17
|
end
|
15
|
-
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
data/lib/eco/api/policies.rb
CHANGED
@@ -9,21 +9,26 @@ module Eco
|
|
9
9
|
attr_reader :policies
|
10
10
|
|
11
11
|
def define(name, type: :transform, &block)
|
12
|
-
Eco::API::Policies::Policy.new(
|
12
|
+
Eco::API::Policies::Policy.new(
|
13
|
+
name,
|
14
|
+
type: type,
|
15
|
+
root: self,
|
16
|
+
&block
|
17
|
+
).tap do |policy|
|
13
18
|
add(policy)
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def add(policy)
|
18
|
-
msg = "Expected Eco::API::Policies::Policy object. Given: #{policy}"
|
23
|
+
msg = "Expected Eco::API::Policies::Policy object. Given: #{policy.class}"
|
19
24
|
raise ArgumentError, msg unless policy.is_a?(Eco::API::Policies::Policy)
|
20
25
|
|
21
26
|
super
|
22
27
|
end
|
23
28
|
|
24
|
-
def launch(
|
29
|
+
def launch(data:, session:, job:, options: {})
|
25
30
|
args = {
|
26
|
-
|
31
|
+
data: data,
|
27
32
|
session: session,
|
28
33
|
job: job,
|
29
34
|
options: options
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class Session
|
4
|
+
class Batch
|
5
|
+
class Feedback
|
6
|
+
module Generate
|
7
|
+
include Feedback::JobDependencies
|
8
|
+
include Feedback::RequestStat
|
9
|
+
|
10
|
+
# @!group Pure feedback methods
|
11
|
+
|
12
|
+
# Generates the lines of feedback of the current requests
|
13
|
+
# @note if `requests` is not provided, it uses the last requests of the parent `Batch::Job` `job`
|
14
|
+
# @param requests [Enumerable<Hash>] raw requests as they would be sent to the _Server_
|
15
|
+
# @param max_chars [Integer] the max number of characters for the current feedback message
|
16
|
+
# @param only_stats [Boolean] whether or not should only include a brief summary of stats
|
17
|
+
# @return [String] the feedback message
|
18
|
+
def generate(requests = nil, max_chars: 800, only_stats: false) # rubocop:disable Metrics/AbcSize
|
19
|
+
requests ||= job_requests
|
20
|
+
|
21
|
+
[].tap do |msg|
|
22
|
+
if !requests || !requests.is_a?(Enumerable) || requests.empty?
|
23
|
+
msg << "#{'*' * 10} Nothing for #{signature} so far :) #{'*' * 10}"
|
24
|
+
else
|
25
|
+
header = "#{'*' * 10} #{signature} - Feedback Sample #{'*' * 10}"
|
26
|
+
msg << header unless only_stats
|
27
|
+
|
28
|
+
unless only_stats
|
29
|
+
sample_length = 1
|
30
|
+
sample = requests.slice(0, 20).map do |request|
|
31
|
+
max_chars -= request.pretty_inspect.length
|
32
|
+
sample_length += 1 if max_chars.positive?
|
33
|
+
request
|
34
|
+
end
|
35
|
+
|
36
|
+
msg << sample.slice(0, sample_length).pretty_inspect
|
37
|
+
end
|
38
|
+
|
39
|
+
stats_str = "#{'+' * 3} "
|
40
|
+
stats_str << "#{type.to_s.upcase} length: #{requests.length} "
|
41
|
+
stats_str << "#{'+' * 3} "
|
42
|
+
stats_str << "STATS (job '#{name}') "
|
43
|
+
stats_str << ('+' * 3)
|
44
|
+
|
45
|
+
msg << ('-' * stats_str.length) if only_stats
|
46
|
+
msg << stats_str
|
47
|
+
msg << request_stats(requests).message.to_s
|
48
|
+
msg << ('-' * stats_str.length) if only_stats
|
49
|
+
msg << ('*' * header.length) unless only_stats
|
50
|
+
end
|
51
|
+
end.join("\n")
|
52
|
+
end
|
53
|
+
|
54
|
+
# @!endgroup
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class Session
|
4
|
+
class Batch
|
5
|
+
class Feedback
|
6
|
+
module Getters
|
7
|
+
def get_attr(entry, attr)
|
8
|
+
if entry.respond_to?(attr.to_sym)
|
9
|
+
entry.public_send(attr.to_sym)
|
10
|
+
elsif entry.is_a?(Hash)
|
11
|
+
entry[attr_to_s]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_row(value)
|
16
|
+
case value
|
17
|
+
when Eco::API::Common::People::PersonEntry
|
18
|
+
value.idx
|
19
|
+
when Ecoportal::API::V1::Person
|
20
|
+
get_row(value.entry)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class Session
|
4
|
+
class Batch
|
5
|
+
class Feedback
|
6
|
+
module Identifiers
|
7
|
+
def person_ref(entry)
|
8
|
+
row_str = (row = get_row(entry)) ? "(row: #{row}) " : ''
|
9
|
+
row_str << "(id: '#{get_attr(entry, :id)}') "
|
10
|
+
row_str << "'#{get_attr(entry, :name)}' "
|
11
|
+
row_str << "('#{get_attr(entry, :external_id)}': "
|
12
|
+
row_str << "'#{get_attr(entry, :email)}')"
|
13
|
+
row_str
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class Session
|
4
|
+
class Batch
|
5
|
+
class Feedback
|
6
|
+
module JobDependencies
|
7
|
+
def job
|
8
|
+
@job
|
9
|
+
end
|
10
|
+
|
11
|
+
# @!group Job shortcut methods
|
12
|
+
|
13
|
+
# @see Eco::API::Session::Batch::Job#name
|
14
|
+
# @return [String] name of the `batch job`
|
15
|
+
def name
|
16
|
+
job.name
|
17
|
+
end
|
18
|
+
|
19
|
+
# @see Eco::API::Session::Batch::Job#type
|
20
|
+
def type
|
21
|
+
job.type
|
22
|
+
end
|
23
|
+
|
24
|
+
# @see Eco::API::Session::Batch::Job#sets
|
25
|
+
def sets
|
26
|
+
job.sets
|
27
|
+
end
|
28
|
+
|
29
|
+
# @see Eco::API::Session::Batch::Job#options
|
30
|
+
def options
|
31
|
+
job.options
|
32
|
+
end
|
33
|
+
|
34
|
+
# @see Eco::API::Session::Batch::Job#requests
|
35
|
+
def job_requests
|
36
|
+
job.requests
|
37
|
+
end
|
38
|
+
|
39
|
+
# @!endgroup
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class Session
|
4
|
+
class Batch
|
5
|
+
class Feedback
|
6
|
+
module RequestStat
|
7
|
+
include Feedback::JobDependencies
|
8
|
+
|
9
|
+
# @!group Pure feedback methods
|
10
|
+
|
11
|
+
# @note if `requests` is not provided, it uses the last requests of the parent `Batch::Job` `job`
|
12
|
+
# @param requests [Enumerable<Hash>] raw requests as they would be sent to the _Server_
|
13
|
+
# @return [Eco::API::Session::Batch::Feedback::RequestStats] the stats object of the current requests
|
14
|
+
def request_stats(requests = nil)
|
15
|
+
requests ||= job_requests
|
16
|
+
return @request_stats if @request_stats && requests == job.requests
|
17
|
+
|
18
|
+
@request_stats ||= Eco::API::Session::Batch::Feedback::RequestStats.new(type: type, requests: requests)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @!endgroup
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|