eco-helpers 2.6.3 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +95 -0
- data/CHANGELOG.md +135 -2
- data/Rakefile +13 -7
- data/eco-helpers.gemspec +3 -3
- data/lib/eco/api/common/loaders/base.rb +2 -2
- data/lib/eco/api/common/loaders/case_base.rb +1 -1
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +5 -5
- data/lib/eco/api/common/loaders/error_handler.rb +8 -5
- data/lib/eco/api/common/loaders/parser.rb +44 -22
- data/lib/eco/api/common/loaders/policy.rb +6 -4
- data/lib/eco/api/common/loaders/use_case.rb +13 -7
- data/lib/eco/api/common/people/base_parser.rb +0 -2
- data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +0 -1
- data/lib/eco/api/common/people/default_parsers/csv_parser.rb +1 -1
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +64 -12
- data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +0 -1
- data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +13 -5
- data/lib/eco/api/common/people/default_parsers/multi_parser.rb +0 -1
- data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +18 -5
- data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +8 -8
- data/lib/eco/api/common/people/default_parsers/select_parser.rb +50 -26
- data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +6 -6
- data/lib/eco/api/common/people/default_parsers/xls_parser.rb +9 -12
- data/lib/eco/api/common/people/default_parsers.rb +1 -12
- data/lib/eco/api/common/people/entries.rb +13 -13
- data/lib/eco/api/common/people/entry_factory.rb +76 -45
- data/lib/eco/api/common/people/person_attribute_parser.rb +8 -12
- data/lib/eco/api/common/people/person_entry.rb +86 -75
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +60 -44
- data/lib/eco/api/common/people/person_factory.rb +30 -22
- data/lib/eco/api/common/people/person_modifier.rb +11 -13
- data/lib/eco/api/common/people/person_parser.rb +101 -39
- data/lib/eco/api/common/people/supervisor_helpers.rb +25 -26
- data/lib/eco/api/common/session/base_session.rb +9 -9
- data/lib/eco/api/common/session/environment.rb +7 -5
- data/lib/eco/api/common/session/sftp.rb +59 -32
- data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +10 -6
- data/lib/eco/api/common/version_patches/exception.rb +11 -13
- data/lib/eco/api/error.rb +32 -20
- data/lib/eco/api/microcases/set_supervisor.rb +0 -3
- data/lib/eco/api/organization/node_classifications.rb +82 -0
- data/lib/eco/api/organization/policy_groups.rb +4 -6
- data/lib/eco/api/organization/tag_tree.rb +169 -93
- data/lib/eco/api/organization.rb +1 -0
- data/lib/eco/api/session/batch/job.rb +1 -1
- data/lib/eco/api/session/config/tagtree.rb +41 -23
- data/lib/eco/api/session/config/workflow.rb +113 -88
- data/lib/eco/api/session/config.rb +6 -0
- data/lib/eco/api/session.rb +51 -29
- data/lib/eco/api/usecases/base_io.rb +28 -25
- data/lib/eco/api/usecases/default/locations/cli/tagtree_extract_cli.rb +7 -2
- data/lib/eco/api/usecases/default/locations/cli/tagtree_upload_cli.rb +21 -0
- data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +3 -3
- data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +54 -23
- data/lib/eco/api/usecases/default/locations/tagtree_upload_case.rb +87 -0
- data/lib/eco/api/usecases/default/locations.rb +1 -0
- data/lib/eco/api/usecases/default/people/analyse_people_case.rb +60 -56
- data/lib/eco/api/usecases/default/people/change_email_case.rb +8 -9
- data/lib/eco/api/usecases/default/people/clean_unknown_tags_case.rb +13 -11
- data/lib/eco/api/usecases/default/people/clear_abilities_case.rb +2 -2
- data/lib/eco/api/usecases/default/people/org_data_convert_case.rb +25 -27
- data/lib/eco/api/usecases/default/people/refresh_case.rb +2 -2
- data/lib/eco/api/usecases/default/people/reinvite_trans_case.rb +1 -1
- data/lib/eco/api/usecases/default/people/reinvite_trans_cli.rb +0 -1
- data/lib/eco/api/usecases/default/people/restore_db_case.rb +39 -34
- data/lib/eco/api/usecases/default/people/set_default_tag_case.rb +19 -15
- data/lib/eco/api/usecases/default/people/supers_cyclic_identify_case.rb +16 -12
- data/lib/eco/api/usecases/default_cases/hris_case.rb +17 -15
- data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +30 -16
- data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +0 -2
- data/lib/eco/api/usecases/graphql/base.rb +5 -3
- data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +4 -1
- data/lib/eco/api/usecases/graphql/helpers/base/graphql_env.rb +14 -0
- data/lib/eco/api/usecases/graphql/helpers/base.rb +5 -4
- data/lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb +60 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb +72 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base.rb +25 -59
- data/lib/eco/api/usecases/graphql/helpers/location/command/diff/as_update.rb +59 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diff/compare.rb +49 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diff.rb +11 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +46 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_archive.rb +23 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_unarchive.rb +65 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +49 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable/relation_safe_sort.rb +119 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable.rb +59 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages.rb +82 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs.rb +20 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/optimizations.rb +84 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +4 -4
- data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +24 -12
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +21 -24
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb +1 -1
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb +10 -11
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +8 -9
- data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +41 -12
- data/lib/eco/api/usecases/graphql/samples/location/command/results.rb +11 -80
- data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +89 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/service.rb +6 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +89 -0
- data/lib/eco/api/usecases/graphql/samples/location/command.rb +3 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +9 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/heading.rb +18 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/inputable.rb +53 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +34 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/helpers.rb +28 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing.rb +46 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible.rb +38 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +105 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/discarded.rb +16 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/input.rb +15 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/node_attr_maps.rb +22 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +45 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +36 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb +56 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list.rb +41 -0
- data/lib/eco/api/usecases/graphql/samples/location/service.rb +8 -0
- data/lib/eco/api/usecases/graphql/samples/location.rb +1 -0
- data/lib/eco/api/usecases/graphql/utils/sftp.rb +96 -36
- data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +8 -6
- data/lib/eco/api/usecases/ooze_samples/helpers/creatable.rb +4 -3
- data/lib/eco/api/usecases/ooze_samples/helpers/exportable_ooze.rb +39 -25
- data/lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb +13 -15
- data/lib/eco/api/usecases/ooze_samples/helpers/filters.rb +50 -21
- data/lib/eco/api/usecases/ooze_samples/helpers/ooze_handlers.rb +21 -11
- data/lib/eco/api/usecases/ooze_samples/helpers/rescuable.rb +2 -0
- data/lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb +49 -43
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +17 -19
- data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +48 -43
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +34 -34
- data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +8 -10
- data/lib/eco/api/usecases.rb +0 -1
- data/lib/eco/cli/config/use_cases.rb +31 -29
- data/lib/eco/cli_default/input_filters.rb +0 -5
- data/lib/eco/cli_default/people_filters.rb +4 -4
- data/lib/eco/cli_default/workflow.rb +13 -14
- data/lib/eco/csv/table.rb +34 -25
- data/lib/eco/data/hashes/array_diff.rb +24 -35
- data/lib/eco/data/hashes/diff_result/meta.rb +131 -0
- data/lib/eco/data/hashes/diff_result.rb +65 -57
- data/lib/eco/data/hashes/sanke_camel_indifferent_access.rb +278 -0
- data/lib/eco/data/hashes.rb +1 -1
- data/lib/eco/data/locations/convert.rb +1 -1
- data/lib/eco/data/locations/node_base/csv_convert.rb +19 -9
- data/lib/eco/data/locations/node_base/parsing.rb +4 -2
- data/lib/eco/data/locations/node_base/treeify.rb +149 -132
- data/lib/eco/data/locations/node_base.rb +15 -4
- data/lib/eco/data/locations/node_diff/accessors.rb +13 -5
- data/lib/eco/data/locations/node_diff/nodes_diff/clustered_treeify.rb +101 -0
- data/lib/eco/data/locations/node_diff/nodes_diff/diffs_tree.rb +99 -0
- data/lib/eco/data/locations/node_diff/{selectors.rb → nodes_diff/selectors.rb} +1 -1
- data/lib/eco/data/locations/node_diff/nodes_diff.rb +50 -35
- data/lib/eco/data/locations/node_diff.rb +45 -17
- data/lib/eco/data/locations/node_level/parsing.rb +15 -21
- data/lib/eco/data/locations/node_level.rb +66 -22
- data/lib/eco/data/locations/node_plain/parsing.rb +1 -1
- data/lib/eco/data/locations/node_plain.rb +60 -7
- data/lib/eco/data/strings/camel_case.rb +35 -0
- data/lib/eco/data/strings/snake_case.rb +18 -0
- data/lib/eco/data/strings.rb +8 -0
- data/lib/eco/data.rb +1 -0
- data/lib/eco/language/methods/call_detector.rb +11 -0
- data/lib/eco/language/methods/dsl_able.rb +7 -1
- data/lib/eco/language/methods.rb +2 -1
- data/lib/eco/language/models/collection.rb +23 -25
- data/lib/eco/language/models/parser_serializer.rb +24 -5
- data/lib/eco/version.rb +1 -1
- data/lib/eco-helpers.rb +0 -1
- metadata +54 -9
- data/lib/eco/data/hashes/diff_meta.rb +0 -52
@@ -7,13 +7,13 @@ module Eco
|
|
7
7
|
|
8
8
|
WORKFLOW_MODEL = [
|
9
9
|
:options,
|
10
|
-
{load: [{input: [
|
10
|
+
{load: [{input: %i[get filter]}, {people: %i[get filter]}, :filter]},
|
11
11
|
:usecases, :launch_jobs,
|
12
|
-
{post_launch: [
|
12
|
+
{post_launch: %i[usecases launch_jobs]},
|
13
13
|
:report,
|
14
14
|
:end,
|
15
15
|
:close
|
16
|
-
]
|
16
|
+
].freeze
|
17
17
|
|
18
18
|
class << self
|
19
19
|
def stages
|
@@ -40,7 +40,7 @@ module Eco
|
|
40
40
|
self.model = WORKFLOW_MODEL
|
41
41
|
attr_reader :config
|
42
42
|
|
43
|
-
def initialize(name = nil, _parent: self
|
43
|
+
def initialize(name = nil, config:, _parent: self) # rubocop:disable Lint/UnderscorePrefixedVariableName
|
44
44
|
@config = config
|
45
45
|
@name = name
|
46
46
|
|
@@ -97,7 +97,7 @@ module Eco
|
|
97
97
|
# 2. if block is not provided, it returns the **stage** referred by `key`
|
98
98
|
def for(key = nil, &block)
|
99
99
|
raise ArgumentError, "With no 'key', a block should be given." unless key || block_given?
|
100
|
-
|
100
|
+
tap do
|
101
101
|
next yield(self) unless key
|
102
102
|
next stage(key).for(&block) if block_given?
|
103
103
|
return stage(key)
|
@@ -106,7 +106,8 @@ module Eco
|
|
106
106
|
alias_method :with, :for
|
107
107
|
|
108
108
|
# Used in **configuration** time **to define** the **behaviour** the target (sub)stage `key`
|
109
|
-
# @note if a `block` is provided it will **not** `yield` the target stage immediately,
|
109
|
+
# @note if a `block` is provided it will **not** `yield` the target stage immediately,
|
110
|
+
# but when the _workflow_ reaches the stage
|
110
111
|
# @param key [Symbol, nil] cases:
|
111
112
|
# - if `key` is not provided, it targets the _current stage_
|
112
113
|
# - if `key` is provided, it targets the specific _sub-stage_
|
@@ -117,16 +118,18 @@ module Eco
|
|
117
118
|
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
|
118
119
|
def on(key = nil, &block)
|
119
120
|
raise ArgumentError, "A block should be given." unless block_given?
|
120
|
-
if
|
121
|
-
@on = block
|
122
|
-
else
|
121
|
+
if key
|
123
122
|
stage(key).on(&block)
|
123
|
+
else
|
124
|
+
@on = block
|
124
125
|
end
|
125
126
|
self
|
126
127
|
end
|
127
128
|
|
128
|
-
# When there is an `Exception`, you might have defined some `callback`
|
129
|
-
#
|
129
|
+
# When there is an `Exception`, you might have defined some `callback`
|
130
|
+
# to do something with it (i.e. register, email)
|
131
|
+
# @yield [exception, io] the `callback` to do something with
|
132
|
+
# an `Exception` raised within this _workflow_ stage
|
130
133
|
# @yieldparam exception [Exception] the exception object that was raised
|
131
134
|
# @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
|
132
135
|
# @yieldreturn [Eco::API::UseCases::BaseIO] the `io` input/output object carried througout all the _workflow_
|
@@ -146,46 +149,50 @@ module Eco
|
|
146
149
|
self
|
147
150
|
end
|
148
151
|
|
149
|
-
# Used in **configuration** time **add previous** `callbacks`
|
152
|
+
# Used in **configuration** time **add previous** `callbacks`
|
153
|
+
# **before** the `on` _callback_ of the (sub)stage `key` is actually `run`
|
150
154
|
# @note
|
151
155
|
# - it will **not** `yield` it immediately, but when the _workflow_ reaches the target stage
|
152
156
|
# - in this case, you can define multiple `callbacks`
|
153
157
|
# @param key [Symbol, nil] cases:
|
154
158
|
# - if `key` is not provided, it targets the _current stage_
|
155
159
|
# - if `key` is provided, it targets the specific _sub-stage_
|
156
|
-
# @yield [stage_workflow, io] one of the things to do **before** the
|
160
|
+
# @yield [stage_workflow, io] one of the things to do **before** the
|
161
|
+
# `on` _callback_ of the (sub)stage `key` is actually `run`
|
157
162
|
# @yieldparam stage_workflow [Eco::API::Session::Config::Workflow] the _target stage_ referred by `key`
|
158
163
|
# @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
|
159
164
|
# @yieldreturn [Eco::API::UseCases::BaseIO] `io` the input/output object carried througout all the _workflow_
|
160
165
|
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
|
161
166
|
def before(key = nil, &block)
|
162
167
|
raise ArgumentError, "A block should be given." unless block_given?
|
163
|
-
if
|
164
|
-
@before.push(block)
|
165
|
-
else
|
168
|
+
if key
|
166
169
|
stage(key).before(&block)
|
170
|
+
else
|
171
|
+
@before.push(block)
|
167
172
|
end
|
168
173
|
self
|
169
174
|
end
|
170
175
|
|
171
|
-
# Used in **configuration** time **add previous** `callbacks` **after** the `on` _callback_
|
176
|
+
# Used in **configuration** time **add previous** `callbacks` **after** the `on` _callback_
|
177
|
+
# of the (sub)stage `key` is actually `run`
|
172
178
|
# @note
|
173
179
|
# - it will **not** `yield` it immediately, but when the _workflow_ reaches the target stage
|
174
180
|
# - in this case, you can define multiple `callbacks`
|
175
181
|
# @param key [Symbol, nil] cases:
|
176
182
|
# - if `key` is not provided, it targets the _current stage_
|
177
183
|
# - if `key` is provided, it targets the specific _sub-stage_
|
178
|
-
# @yield [stage_workflow, io] one of the things to do **after** the
|
184
|
+
# @yield [stage_workflow, io] one of the things to do **after** the
|
185
|
+
# `on` _callback_ of the (sub)stage `key` is actually `run`
|
179
186
|
# @yieldparam stage_workflow [Eco::API::Session::Config::Workflow] the _target stage_ referred by `key`
|
180
187
|
# @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
|
181
188
|
# @yieldreturn [Eco::API::UseCases::BaseIO] `io` the input/output object carried througout all the _workflow_
|
182
189
|
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
|
183
190
|
def after(key = nil, &block)
|
184
191
|
raise ArgumentError, "A block should be given." unless block_given?
|
185
|
-
if
|
186
|
-
@after.push(block)
|
187
|
-
else
|
192
|
+
if key
|
188
193
|
stage(key).after(&block)
|
194
|
+
else
|
195
|
+
@after.push(block)
|
189
196
|
end
|
190
197
|
self
|
191
198
|
end
|
@@ -202,8 +209,8 @@ module Eco
|
|
202
209
|
# - it will **not** run the `callback` for `on` defined during the configuration time
|
203
210
|
# - it will rather `yield` the target stage after all the `before` _callbacks_ have been run
|
204
211
|
# - aside of this, the rest will be the same as when the _block_ is provided (see previous note)
|
205
|
-
# @note [if the object returned by `before`, `after` and `run` callbacks
|
206
|
-
# the original `io` object will be returned instead.
|
212
|
+
# @note [if the object returned by `before`, `after` and `run` callbacks
|
213
|
+
# is not an `Eco::API::UseCases::BaseIO`, the original `io` object will be returned instead.
|
207
214
|
# @param key [Symbol, nil] cases:
|
208
215
|
# - if `key` is not provided, it targets the _current stage_
|
209
216
|
# - if `key` is provided, it targets the specific _sub-stage_
|
@@ -216,71 +223,81 @@ module Eco
|
|
216
223
|
def run(key = nil, io:, &block)
|
217
224
|
raise "Missing BaseIO object" unless io.is_a?(Eco::API::UseCases::BaseIO)
|
218
225
|
|
219
|
-
|
220
|
-
|
221
|
-
stage(key).run(io: io, &block)
|
222
|
-
end
|
223
|
-
elsif pending?
|
224
|
-
@before.each do |c|
|
226
|
+
rescuable(io) do
|
227
|
+
if key
|
225
228
|
io = io_result(io: io) do
|
226
|
-
|
229
|
+
stage(key).run(io: io, &block)
|
227
230
|
end
|
231
|
+
elsif pending?
|
232
|
+
io = run_before(io)
|
233
|
+
io = run_it(io, &block) unless skip?
|
234
|
+
io = run_after(io)
|
228
235
|
end
|
236
|
+
io
|
237
|
+
ensure
|
238
|
+
@pending = false
|
239
|
+
end
|
240
|
+
end
|
229
241
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
end
|
250
|
-
end
|
251
|
-
@pending = false
|
242
|
+
protected
|
243
|
+
|
244
|
+
def root?
|
245
|
+
@_parent == self
|
246
|
+
end
|
247
|
+
|
248
|
+
def path
|
249
|
+
return name if root?
|
250
|
+
"#{@_parent.path}:#{name}"
|
251
|
+
end
|
252
|
+
|
253
|
+
def ready?
|
254
|
+
!!@on
|
255
|
+
end
|
256
|
+
|
257
|
+
def run_before(io)
|
258
|
+
@before.each do |c|
|
259
|
+
io = io_result(io: io) do
|
260
|
+
io.evaluate(self, io, &c)
|
252
261
|
end
|
262
|
+
end
|
263
|
+
io
|
264
|
+
end
|
265
|
+
|
266
|
+
def run_after(io)
|
267
|
+
@after.each do |c|
|
268
|
+
io = io_result(io: io) do
|
269
|
+
io.evaluate(self, io, &c)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
io
|
273
|
+
end
|
253
274
|
|
254
|
-
|
275
|
+
def run_it(io, &block)
|
276
|
+
io.session.logger.debug("(Workflow: #{path}) running now")
|
277
|
+
if block
|
278
|
+
io = io_result(io: io) do
|
279
|
+
io.evaluate(self, io, &block)
|
280
|
+
end
|
281
|
+
else
|
282
|
+
existing_stages.each do |stg|
|
255
283
|
io = io_result(io: io) do
|
256
|
-
|
284
|
+
stg.run(io: io)
|
257
285
|
end
|
258
286
|
end
|
287
|
+
|
288
|
+
unless ready?
|
289
|
+
msg = "(Workflow: #{path}) 'on' callback is not defined, nor block given"
|
290
|
+
io.session.logger.debug(msg)
|
291
|
+
end
|
292
|
+
io = io_result(io: io) do
|
293
|
+
io.evaluate(self, io, &@on)
|
294
|
+
end
|
259
295
|
end
|
260
296
|
io
|
261
|
-
rescue SystemExit => e
|
262
|
-
io = io_result(io: io) do
|
263
|
-
io.evaluate(e, io, &self.exit_handle)
|
264
|
-
end
|
265
|
-
exit e.status
|
266
|
-
rescue Interrupt => i
|
267
|
-
raise
|
268
|
-
rescue Exception => e
|
269
|
-
# raise unless self.rescue
|
270
|
-
io = io_result(io: io) do
|
271
|
-
io.evaluate(e, io, &self.rescue)
|
272
|
-
end
|
273
|
-
raise
|
274
297
|
ensure
|
275
298
|
@pending = false
|
276
299
|
end
|
277
300
|
|
278
|
-
protected
|
279
|
-
|
280
|
-
def root?
|
281
|
-
@_parent == self
|
282
|
-
end
|
283
|
-
|
284
301
|
# It ensures an `Eco::API::UseCases::BaseIO` is returned
|
285
302
|
# @note it always brings the IO to be a `BaseIO`.
|
286
303
|
# As the `output` and the type is captured, it just cleans usecase related
|
@@ -296,19 +313,6 @@ module Eco
|
|
296
313
|
io.instance_of?(klass) ? io : io.base
|
297
314
|
end
|
298
315
|
|
299
|
-
def path
|
300
|
-
return name if root?
|
301
|
-
"#{@_parent.path}:#{name}"
|
302
|
-
end
|
303
|
-
|
304
|
-
def root?
|
305
|
-
@_parent == self
|
306
|
-
end
|
307
|
-
|
308
|
-
def ready?
|
309
|
-
!!@on
|
310
|
-
end
|
311
|
-
|
312
316
|
def existing_stages
|
313
317
|
# sort defined stages by stage order
|
314
318
|
sorted_keys = self.class.stages & @stages.keys
|
@@ -316,17 +320,38 @@ module Eco
|
|
316
320
|
end
|
317
321
|
|
318
322
|
def ready_stages
|
319
|
-
exiting_stages.select
|
323
|
+
exiting_stages.select(&:ready?)
|
320
324
|
end
|
321
325
|
|
322
326
|
def stages_ready?
|
323
|
-
existing_stages.all?
|
327
|
+
existing_stages.all?(&:ready?)
|
324
328
|
end
|
325
329
|
|
326
330
|
def stage(key)
|
327
331
|
self.class.validate_stage(key)
|
328
332
|
@stages[key] ||= self.class.workflow_class(key).new(key, _parent: self, config: config)
|
329
333
|
end
|
334
|
+
|
335
|
+
# helper to treat trigger the exit and rescue handlers
|
336
|
+
def rescuable(io)
|
337
|
+
yield
|
338
|
+
# rescue SystemStackError => err
|
339
|
+
# puts err.patch_full_message(trace_count: 100)
|
340
|
+
# exit 1
|
341
|
+
rescue SystemExit => err
|
342
|
+
io = io_result(io: io) do
|
343
|
+
io.evaluate(err, io, &exit_handle)
|
344
|
+
end
|
345
|
+
exit err.status
|
346
|
+
rescue Interrupt => _int
|
347
|
+
raise
|
348
|
+
rescue StandardError => err
|
349
|
+
# raise unless self.rescue
|
350
|
+
io = io_result(io: io) do
|
351
|
+
io.evaluate(err, io, &self.rescue)
|
352
|
+
end
|
353
|
+
raise
|
354
|
+
end
|
330
355
|
end
|
331
356
|
end
|
332
357
|
end
|
@@ -238,6 +238,12 @@ module Eco
|
|
238
238
|
tagtree_config.structure_id = value
|
239
239
|
end
|
240
240
|
|
241
|
+
# The location node classifications of the organization
|
242
|
+
# @return [Eco::API::Organization::NodeClassifications]
|
243
|
+
def node_classifications(active: true)
|
244
|
+
tagtree_config.node_classifications(active: active)
|
245
|
+
end
|
246
|
+
|
241
247
|
# It uses the `tagtree.json` file and in its absence, if `graphql` enabled, the largest `life_tagtree`
|
242
248
|
# @note it does NOT include archived nodes by default.
|
243
249
|
# - This is for legacy (most usecases don't)
|
data/lib/eco/api/session.rb
CHANGED
@@ -5,16 +5,24 @@ module Eco
|
|
5
5
|
class Session < Common::Session::BaseSession
|
6
6
|
#@param init [Eco::API::Session::Config, Eco::API::Common::Session::Environment] object to ini the session
|
7
7
|
def initialize(init = {})
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
env = init
|
9
|
+
|
10
|
+
msg = "Expected object Eco::API::Session::Config or Eco::API::Common::Session::Environment. "
|
11
|
+
msg << " Given: #{init}"
|
12
|
+
|
13
|
+
correct_env = env.is_a?(Session::Config) || env.is_a?(Eco::API::Common::Session::Environment)
|
14
|
+
raise ArgumentError, msg unless correct_env
|
15
|
+
|
16
|
+
unless env.is_a?(Eco::API::Common::Session::Environment)
|
17
|
+
env = Eco::API::Common::Session::Environment.new(init, session: self)
|
18
|
+
end
|
19
|
+
|
20
|
+
super(env)
|
13
21
|
|
14
22
|
@entry_factories = {}
|
15
23
|
@person_factories = {}
|
16
24
|
|
17
|
-
logger.debug("LINE COMMAND: #{$0} #{ARGV.join(" ")}")
|
25
|
+
logger.debug("LINE COMMAND: #{$0} #{ARGV.join(" ")}") # rubocop:disable Style/SpecialGlobalVars
|
18
26
|
end
|
19
27
|
|
20
28
|
# @retrun [String] the name of the current environment
|
@@ -24,7 +32,7 @@ module Eco
|
|
24
32
|
|
25
33
|
# @return [Eco::API::Session::Batch] provides helper to launch batch operations.
|
26
34
|
def batch
|
27
|
-
@batch
|
35
|
+
@batch ||= Batch.new(enviro)
|
28
36
|
end
|
29
37
|
|
30
38
|
# @!group Pure organization helpers
|
@@ -39,6 +47,12 @@ module Eco
|
|
39
47
|
config.login_providers
|
40
48
|
end
|
41
49
|
|
50
|
+
# The location node classifications of the organization
|
51
|
+
# @return [Eco::API::Organization::NodeClassifications]
|
52
|
+
def node_classifications(active: true)
|
53
|
+
config.node_classifications(active: active)
|
54
|
+
end
|
55
|
+
|
42
56
|
# @param live [Boolean] states preference of `live` tree if available over file.
|
43
57
|
# @param merge [Boolean] when in `live` mode, if mulitple trees, merge into one.
|
44
58
|
# @see Eco::API::Session::Config#tagtree
|
@@ -79,11 +93,12 @@ module Eco
|
|
79
93
|
end
|
80
94
|
|
81
95
|
# Sets the current target `PersonSchema` of this session.
|
82
|
-
# @note observe that it is essential for the parsers/serialisers to identify
|
83
|
-
#
|
96
|
+
# @note observe that it is essential for the parsers/serialisers to identify
|
97
|
+
# target/present attributes.
|
98
|
+
# @param value [String, Ecoportal::API::V1::PersonSchema] where `String`
|
99
|
+
# can be the _name_ or the _id_ of the schema.
|
84
100
|
def schema=(value)
|
85
101
|
@schema = to_schema(value)
|
86
|
-
self
|
87
102
|
end
|
88
103
|
|
89
104
|
# Helper to state the abilities that a person should have with given their usergroups
|
@@ -95,7 +110,7 @@ module Eco
|
|
95
110
|
def fields_mapper
|
96
111
|
return @fields_mapper if instance_variable_defined?(:@fields_mapper)
|
97
112
|
mappings = []
|
98
|
-
if map_file = config.people.fields_mapper
|
113
|
+
if (map_file = config.people.fields_mapper)
|
99
114
|
mappings = map_file ? file_manager.load_json(map_file) : []
|
100
115
|
end
|
101
116
|
@fields_mapper = Eco::Data::Mapper.new(mappings)
|
@@ -140,7 +155,7 @@ module Eco
|
|
140
155
|
# @param phase [Symbol] the phase when this parser should be active.
|
141
156
|
# @return [Object] the parsed attribute.
|
142
157
|
def parse_attribute(attr, source, phase = :internal, deps: {})
|
143
|
-
unless parsers = entry_factory.person_parser
|
158
|
+
unless (parsers = entry_factory.person_parser)
|
144
159
|
raise "There are no parsers defined"
|
145
160
|
end
|
146
161
|
parsers.parse(attr, source, phase, deps: deps)
|
@@ -182,10 +197,10 @@ module Eco
|
|
182
197
|
# @return [Eco::API::Common::People::Entries] collection of entries.
|
183
198
|
def csv_entries(file, **kargs)
|
184
199
|
kargs.merge!({
|
185
|
-
file:
|
200
|
+
file: file,
|
186
201
|
format: :csv
|
187
202
|
})
|
188
|
-
|
203
|
+
entries(**kargs)
|
189
204
|
end
|
190
205
|
|
191
206
|
# Generates the collection of entries that should be discarded from an update.
|
@@ -193,8 +208,11 @@ module Eco
|
|
193
208
|
# @return [Eco::API::Common::People::Entries] collection of entries.
|
194
209
|
def discarded_entries
|
195
210
|
return @discarded_entries if instance_variable_defined?(:@discarded_entries)
|
211
|
+
|
196
212
|
file = config.people.discarded_file
|
197
|
-
|
213
|
+
file = file_manager.dir.file(file)
|
214
|
+
fatal("You have not specified the 'discarded_people_file'") unless file
|
215
|
+
|
198
216
|
@discarded_entries = csv_entries(file)
|
199
217
|
end
|
200
218
|
# @!endgroup
|
@@ -234,7 +252,7 @@ module Eco
|
|
234
252
|
# @see Eco::API::MicroCases
|
235
253
|
# @return [Eco::API::MicroCases]
|
236
254
|
def micro
|
237
|
-
@micro
|
255
|
+
@micro ||= Eco::API::MicroCases.new(enviro)
|
238
256
|
end
|
239
257
|
|
240
258
|
def post_launch
|
@@ -255,18 +273,23 @@ module Eco
|
|
255
273
|
# It retrives the group of `Batch::Jobs` named `name`. It creates it if it doesn't exist.
|
256
274
|
# @return [Eco::API::Session::Batch::Jobs]
|
257
275
|
def job_group(name, order: :last)
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
else
|
262
|
-
job_groups.new(name, order: order)
|
263
|
-
end
|
276
|
+
return job_groups[name] if job_groups.exists?(name)
|
277
|
+
|
278
|
+
job_groups.new(name, order: order)
|
264
279
|
end
|
265
280
|
|
266
281
|
# Shortcut to create a job of certain type within a group
|
267
282
|
# @param [see @Eco::API::Session::Batch::Jobs#new]
|
268
283
|
# @return [Eco::API::Session::Batch::Job]
|
269
|
-
def new_job(
|
284
|
+
def new_job(
|
285
|
+
group,
|
286
|
+
name,
|
287
|
+
type,
|
288
|
+
usecase,
|
289
|
+
sets = %i[core details account],
|
290
|
+
accept_update_with_no_id = false, # rubocop:disable Style/OptionalBooleanParameter
|
291
|
+
&block
|
292
|
+
)
|
270
293
|
job_group(group).new(name, usecase: usecase, type: type, sets: sets, accept_update_with_no_id: accept_update_with_no_id, &block)
|
271
294
|
end
|
272
295
|
|
@@ -330,10 +353,10 @@ module Eco
|
|
330
353
|
private
|
331
354
|
|
332
355
|
# Comparer to state if 2 schemas are different
|
333
|
-
def same_schema?
|
334
|
-
eq =
|
335
|
-
eq ||=
|
336
|
-
|
356
|
+
def same_schema?(schema_1, schema_2)
|
357
|
+
eq = schema_1&.id == schema_2&.id
|
358
|
+
eq ||= schema_1&.name&.downcase == schema_2&.name&.downcase
|
359
|
+
schema_1 && schema_2 && eq
|
337
360
|
end
|
338
361
|
|
339
362
|
# from schema `id` or `name` to a PersonSchema object
|
@@ -342,7 +365,7 @@ module Eco
|
|
342
365
|
sch = nil
|
343
366
|
case value
|
344
367
|
when String
|
345
|
-
unless sch = schemas.schema(value)
|
368
|
+
unless (sch = schemas.schema(value))
|
346
369
|
fatal "The schema with id or name '#{value}' does not exist."
|
347
370
|
end
|
348
371
|
when Ecoportal::API::V1::PersonSchema
|
@@ -352,7 +375,6 @@ module Eco
|
|
352
375
|
end
|
353
376
|
sch
|
354
377
|
end
|
355
|
-
|
356
378
|
end
|
357
379
|
end
|
358
380
|
end
|
@@ -11,7 +11,7 @@ module Eco
|
|
11
11
|
class MissingParameter < StandardError
|
12
12
|
attr_reader :type, :required, :given
|
13
13
|
|
14
|
-
def initialize(msg = nil,
|
14
|
+
def initialize(msg = nil, required:, given:, type: nil)
|
15
15
|
@type = type
|
16
16
|
@required = required
|
17
17
|
@given = given
|
@@ -23,11 +23,11 @@ module Eco
|
|
23
23
|
|
24
24
|
class << self
|
25
25
|
def input_required?(type)
|
26
|
-
!valid_type?(type) || [
|
26
|
+
!valid_type?(type) || %i[import sync].include?(type)
|
27
27
|
end
|
28
28
|
|
29
29
|
def people_required?(type)
|
30
|
-
!valid_type?(type) || [
|
30
|
+
!valid_type?(type) || %i[filter transform sync error_handler export].include?(type)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -40,10 +40,14 @@ module Eco
|
|
40
40
|
# @param people [Eco::API::Organization::People] people object.
|
41
41
|
# @param session [Eco::API:Session]
|
42
42
|
# @param options [Hash] hash with symbol keys (i.e. behaviour modifiers, cli trackers, filters, etc.)
|
43
|
-
def initialize(
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
def initialize( # rubocop:disable Lint/MissingSuper
|
44
|
+
session:,
|
45
|
+
type: nil, input: nil, people: nil,
|
46
|
+
options: {}, output: nil, validate: true
|
47
|
+
)
|
48
|
+
self.type = type if type
|
49
|
+
|
50
|
+
if self.type && validate # rubocop:disable Style/IfUnlessModifier
|
47
51
|
validate_args(input: input, people: people, session: session, options: options)
|
48
52
|
end
|
49
53
|
|
@@ -64,8 +68,8 @@ module Eco
|
|
64
68
|
# @return [Eco::API::UseCases::BaseIO]
|
65
69
|
def base
|
66
70
|
kargs = params(keyed: true).merge({
|
67
|
-
type:
|
68
|
-
output:
|
71
|
+
type: type,
|
72
|
+
output: output
|
69
73
|
}).slice(:type, :input, :people, :session, :options, :output) # :validate <- ?
|
70
74
|
Eco::API::UseCases::BaseIO.new(**kargs)
|
71
75
|
end
|
@@ -74,12 +78,12 @@ module Eco
|
|
74
78
|
# @return [Eco::API::UseCases::BaseIO]
|
75
79
|
def new(**kargs)
|
76
80
|
default = {
|
77
|
-
type:
|
78
|
-
input:
|
79
|
-
people:
|
80
|
-
session:
|
81
|
-
options:
|
82
|
-
output:
|
81
|
+
type: type,
|
82
|
+
input: input,
|
83
|
+
people: people,
|
84
|
+
session: session,
|
85
|
+
options: options,
|
86
|
+
output: output,
|
83
87
|
validate: true
|
84
88
|
}
|
85
89
|
self.class.new(**default.merge(kargs))
|
@@ -88,7 +92,7 @@ module Eco
|
|
88
92
|
# Helper to build a `Hash` of symbol keys or `Array` with params to do callbacks.
|
89
93
|
def params(keyed: false, all: false)
|
90
94
|
kargs = {}
|
91
|
-
kargs.merge!(input:
|
95
|
+
kargs.merge!(input: input) if input_required? || all
|
92
96
|
kargs.merge!(people: people) if people_required? || all
|
93
97
|
kargs.merge!(session: session, options: options)
|
94
98
|
keyed ? kargs : kargs.values
|
@@ -108,7 +112,7 @@ module Eco
|
|
108
112
|
# provided that it preserves the target parameter
|
109
113
|
# (otherise it would blank it)
|
110
114
|
# @return [Eco::API::UseCases::BaseIO]
|
111
|
-
def chained(as:
|
115
|
+
def chained(as: type) # rubocop:disable Naming/MethodParameterName
|
112
116
|
base.tap do |io_base|
|
113
117
|
next unless io_base.output
|
114
118
|
case as
|
@@ -116,7 +120,7 @@ module Eco
|
|
116
120
|
io_base.output_be_input!
|
117
121
|
when :filter
|
118
122
|
io_base.output_be_people!
|
119
|
-
|
123
|
+
# when :transform, :sync, :export, :error_handler, :other
|
120
124
|
end
|
121
125
|
end
|
122
126
|
end
|
@@ -124,26 +128,25 @@ module Eco
|
|
124
128
|
protected
|
125
129
|
|
126
130
|
def output_be_input!
|
127
|
-
@input, @output = output, nil
|
131
|
+
@input, @output = output, nil # rubocop:disable Style/ParallelAssignment
|
128
132
|
input
|
129
133
|
end
|
130
134
|
|
131
135
|
def output_be_people!
|
132
|
-
@people, @output = output, nil
|
136
|
+
@people, @output = output, nil # rubocop:disable Style/ParallelAssignment
|
133
137
|
people
|
134
138
|
end
|
135
139
|
|
136
140
|
private
|
137
141
|
|
138
142
|
def validate_args(input:, people:, session:, options:)
|
139
|
-
|
140
|
-
when !session.is_a?(Eco::API::Session)
|
143
|
+
if !session.is_a?(Eco::API::Session)
|
141
144
|
raise MissingParameter.new("UseCase", required: :session, given: session.class)
|
142
|
-
|
145
|
+
elsif input_required? && !input
|
143
146
|
raise MissingParameter.new("UseCase", type: type, required: :input, given: input.class)
|
144
|
-
|
147
|
+
elsif people_required? && !people.is_a?(Eco::API::Organization::People)
|
145
148
|
raise MissingParameter.new("UseCase", type: type, required: :people, given: people.class)
|
146
|
-
|
149
|
+
elsif !options || (options && !options.is_a?(Hash))
|
147
150
|
raise MissingParameter.new("Use Case options", required: :Hash, given: options.class)
|
148
151
|
end
|
149
152
|
true
|