eco-helpers 1.5.1 → 1.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +114 -2
- data/LICENSE +21 -0
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api.rb +2 -0
- data/lib/eco/api/common.rb +4 -0
- data/lib/eco/api/common/base_loader.rb +54 -0
- data/lib/eco/api/common/class_auto_loader.rb +109 -0
- data/lib/eco/api/common/class_helpers.rb +33 -0
- data/lib/eco/api/common/class_hierarchy.rb +1 -1
- data/lib/eco/api/common/class_meta_basics.rb +16 -0
- data/lib/eco/api/common/loaders.rb +13 -0
- data/lib/eco/api/common/loaders/error_handler.rb +41 -0
- data/lib/eco/api/common/loaders/parser.rb +127 -0
- data/lib/eco/api/common/loaders/policy.rb +25 -0
- data/lib/eco/api/common/loaders/use_case.rb +40 -0
- data/lib/eco/api/common/people/default_parsers.rb +3 -12
- data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +13 -23
- data/lib/eco/api/common/people/default_parsers/csv_parser.rb +20 -35
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +15 -26
- data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +15 -25
- data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +26 -0
- data/lib/eco/api/common/people/default_parsers/multi_parser.rb +15 -27
- data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +14 -19
- data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +24 -35
- data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +15 -25
- data/lib/eco/api/common/people/entries.rb +54 -24
- data/lib/eco/api/common/people/entry_factory.rb +10 -8
- data/lib/eco/api/common/people/person_attribute_parser.rb +29 -12
- data/lib/eco/api/common/people/person_entry.rb +308 -216
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +3 -2
- data/lib/eco/api/common/people/person_parser.rb +51 -18
- data/lib/eco/api/common/session/logger.rb +4 -0
- data/lib/eco/api/common/version_patches.rb +1 -0
- data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +2 -0
- data/lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb +1 -1
- data/lib/eco/api/common/version_patches/exception.rb +22 -0
- data/lib/eco/api/common/version_patches/object.rb +10 -0
- data/lib/eco/api/custom.rb +13 -0
- data/lib/eco/api/custom/error_handler.rb +20 -0
- data/lib/eco/api/custom/namespace.rb +7 -0
- data/lib/eco/api/custom/parser.rb +50 -0
- data/lib/eco/api/custom/policy.rb +28 -0
- data/lib/eco/api/custom/use_case.rb +16 -0
- data/lib/eco/api/error.rb +1 -0
- data/lib/eco/api/error/handlers.rb +10 -3
- data/lib/eco/api/microcases.rb +17 -13
- data/lib/eco/api/microcases/account_excluded.rb +24 -0
- data/lib/eco/api/microcases/append_usergroups.rb +19 -0
- data/lib/eco/api/microcases/core_excluded.rb +4 -4
- data/lib/eco/api/microcases/{set_default_group.rb → fix_default_group.rb} +10 -9
- data/lib/eco/api/microcases/fix_filter_tags.rb +26 -6
- data/lib/eco/api/microcases/people_cache.rb +17 -0
- data/lib/eco/api/microcases/people_load.rb +59 -0
- data/lib/eco/api/microcases/people_refresh.rb +31 -0
- data/lib/eco/api/microcases/people_search.rb +65 -0
- data/lib/eco/api/microcases/refresh_abilities.rb +19 -0
- data/lib/eco/api/microcases/refresh_default_tag.rb +27 -0
- data/lib/eco/api/microcases/s3upload_targets.rb +39 -0
- data/lib/eco/api/microcases/set_account.rb +7 -19
- data/lib/eco/api/microcases/set_core.rb +5 -5
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +23 -0
- data/lib/eco/api/microcases/set_supervisor.rb +17 -13
- data/lib/eco/api/microcases/strict_search.rb +12 -7
- data/lib/eco/api/microcases/with_each.rb +27 -0
- data/lib/eco/api/microcases/with_each_leaver.rb +24 -0
- data/lib/eco/api/microcases/with_each_present.rb +30 -0
- data/lib/eco/api/microcases/with_each_starter.rb +30 -0
- data/lib/eco/api/microcases/with_each_subordinate.rb +34 -0
- data/lib/eco/api/microcases/with_supervisor.rb +36 -0
- data/lib/eco/api/organization/people.rb +72 -35
- data/lib/eco/api/organization/presets_factory.rb +13 -4
- data/lib/eco/api/policies.rb +11 -7
- data/lib/eco/api/session.rb +54 -24
- data/lib/eco/api/session/batch.rb +1 -1
- data/lib/eco/api/session/batch/base_policy.rb +7 -6
- data/lib/eco/api/session/batch/errors.rb +28 -4
- data/lib/eco/api/session/batch/feedback.rb +7 -1
- data/lib/eco/api/session/batch/job.rb +40 -23
- data/lib/eco/api/session/batch/jobs.rb +9 -4
- data/lib/eco/api/session/batch/jobs_groups.rb +1 -1
- data/lib/eco/api/session/batch/request_stats.rb +95 -58
- data/lib/eco/api/session/batch/status.rb +35 -31
- data/lib/eco/api/session/config.rb +104 -42
- data/lib/eco/api/session/config/api.rb +17 -6
- data/lib/eco/api/session/config/logger.rb +2 -2
- data/lib/eco/api/session/config/post_launch.rb +1 -1
- data/lib/eco/api/session/config/workflow.rb +8 -7
- data/lib/eco/api/usecases.rb +47 -33
- data/lib/eco/api/usecases/backup/append_usergroups_case.rb +36 -0
- data/lib/eco/api/usecases/backup/create_case.rb +104 -0
- data/lib/eco/api/usecases/backup/create_details_case.rb +31 -0
- data/lib/eco/api/usecases/backup/create_details_with_supervisor_case.rb +48 -0
- data/lib/eco/api/usecases/backup/hris_case.rb +124 -0
- data/lib/eco/api/usecases/backup/set_default_tag_case.rb +49 -0
- data/lib/eco/api/usecases/backup/set_supervisor_case.rb +41 -0
- data/lib/eco/api/usecases/backup/transfer_account_case.rb +90 -0
- data/lib/eco/api/usecases/backup/update_case.rb +112 -0
- data/lib/eco/api/usecases/backup/update_details_case.rb +64 -0
- data/lib/eco/api/usecases/backup/upsert_case.rb +114 -0
- data/lib/eco/api/usecases/base_case.rb +2 -0
- data/lib/eco/api/usecases/base_io.rb +3 -3
- data/lib/eco/api/usecases/default_cases.rb +23 -53
- data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +10 -31
- data/lib/eco/api/usecases/default_cases/change_email_case.rb +23 -47
- data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +56 -43
- data/lib/eco/api/usecases/default_cases/create_case.rb +15 -101
- data/lib/eco/api/usecases/default_cases/create_details_case.rb +11 -26
- data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +12 -43
- data/lib/eco/api/usecases/default_cases/delete_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/delete_trans_case.rb +14 -0
- data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +10 -21
- data/lib/eco/api/usecases/default_cases/hris_case.rb +23 -120
- data/lib/eco/api/usecases/default_cases/new_email_case.rb +10 -23
- data/lib/eco/api/usecases/default_cases/new_id_case.rb +11 -25
- data/lib/eco/api/usecases/default_cases/new_id_case0.rb +14 -0
- data/lib/eco/api/usecases/default_cases/org_data_convert_case.rb +101 -0
- data/lib/eco/api/usecases/default_cases/refresh_abilities_case.rb +30 -0
- data/lib/eco/api/usecases/default_cases/refresh_case.rb +7 -20
- data/lib/eco/api/usecases/default_cases/reinvite_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/reinvite_trans_case.rb +17 -0
- data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +17 -0
- data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +9 -19
- data/lib/eco/api/usecases/default_cases/restore_db_case.rb +104 -0
- data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +32 -40
- data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +15 -33
- data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +66 -57
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +36 -44
- data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +40 -55
- data/lib/eco/api/usecases/default_cases/transfer_account_case.rb +264 -84
- data/lib/eco/api/usecases/default_cases/update_case.rb +15 -109
- data/lib/eco/api/usecases/default_cases/update_details_case.rb +14 -61
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +16 -111
- data/lib/eco/api/usecases/use_case.rb +1 -1
- data/lib/eco/api/usecases/use_case_io.rb +9 -10
- data/lib/eco/cli/config.rb +10 -2
- data/lib/eco/cli/config/default.rb +2 -1
- data/lib/eco/cli/config/default/input_filters.rb +58 -0
- data/lib/eco/cli/config/default/options.rb +60 -25
- data/lib/eco/cli/config/default/people.rb +4 -4
- data/lib/eco/cli/config/default/people_filters.rb +108 -0
- data/lib/eco/cli/config/default/usecases.rb +89 -31
- data/lib/eco/cli/config/default/workflow.rb +37 -27
- data/lib/eco/cli/config/filters.rb +50 -0
- data/lib/eco/cli/config/filters/input_filters.rb +29 -0
- data/lib/eco/cli/config/filters/people_filters.rb +29 -0
- data/lib/eco/cli/config/help.rb +49 -0
- data/lib/eco/cli/config/options_set.rb +17 -1
- data/lib/eco/cli/config/use_cases.rb +79 -53
- data/lib/eco/cli/scripting.rb +10 -2
- data/lib/eco/cli/scripting/args_helpers.rb +25 -15
- data/lib/eco/cli/scripting/argument.rb +1 -0
- data/lib/eco/cli/scripting/arguments.rb +1 -1
- data/lib/eco/csv/table.rb +1 -1
- data/lib/eco/data/crypto/encryption.rb +3 -0
- data/lib/eco/language/match.rb +19 -9
- data/lib/eco/language/match_modifier.rb +13 -5
- data/lib/eco/language/models/collection.rb +77 -56
- data/lib/eco/language/models/parser_serializer.rb +39 -15
- data/lib/eco/version.rb +1 -1
- metadata +64 -18
- data/lib/eco/api/microcases/set_default_tag.rb +0 -23
- data/lib/eco/api/session/task.rb +0 -175
- data/lib/eco/api/usecases/default_case.rb +0 -19
- data/lib/eco/api/usecases/default_cases/delete_case.rb +0 -32
- data/lib/eco/api/usecases/default_cases/recover_db_case.rb +0 -99
- data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +0 -26
- data/lib/eco/api/usecases/default_cases/reinvite_case.rb +0 -41
- data/lib/eco/api/usecases/default_cases/remove_account_case.rb +0 -38
- data/lib/eco/api/usecases/microed_cases/hris_case.rb +0 -53
- data/lib/eco/api/usecases/microed_cases/update_case.rb +0 -33
- data/lib/eco/api/usecases/microed_cases/update_details_case.rb +0 -30
- data/lib/eco/api/usecases/microed_cases/upsert_case.rb +0 -36
- data/lib/eco/cli/config/default/filters.rb +0 -70
- data/lib/eco/cli/config/people_filters.rb +0 -38
@@ -42,6 +42,11 @@ module Eco
|
|
42
42
|
compile(*preset_names)
|
43
43
|
end
|
44
44
|
|
45
|
+
# @return [Array<String>] all the abilities
|
46
|
+
def keys
|
47
|
+
@abilities.keys
|
48
|
+
end
|
49
|
+
|
45
50
|
private
|
46
51
|
|
47
52
|
def init_custom(file = DEFAULT_CUSTOM)
|
@@ -104,21 +109,25 @@ module Eco
|
|
104
109
|
|
105
110
|
def compile(*preset_names)
|
106
111
|
fatal("You need to specify an existing file for the custom presets.") if !@presets_custom
|
107
|
-
@presets_custom.values_at(*preset_names).compact.reduce(
|
112
|
+
@presets_custom.values_at(*preset_names).compact.reduce({}) do |p1, p2|
|
108
113
|
merge(p1, p2)
|
109
114
|
end
|
110
115
|
end
|
111
116
|
|
112
117
|
def merge(preset1, preset2)
|
113
|
-
|
118
|
+
keys = preset1.keys | preset2.keys
|
119
|
+
|
120
|
+
@abilities.each_with_object({}) do |(key, values), result|
|
121
|
+
next unless keys.include?(key)
|
114
122
|
idx = [
|
115
123
|
values.index(preset1[key]),
|
116
124
|
values.index(preset2[key])
|
117
125
|
].compact.max
|
118
|
-
[key
|
119
|
-
end
|
126
|
+
result[key] = idx && values[idx]
|
127
|
+
end
|
120
128
|
end
|
121
129
|
|
130
|
+
# unsused: only play with the given abilities
|
122
131
|
def empty_model
|
123
132
|
JSON.parse(@abilities.to_json).transform_values {|v| nil }
|
124
133
|
end
|
data/lib/eco/api/policies.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
|
+
# @todo the autoloading happens on `add`, and there could be multiple pending children to load.
|
4
|
+
# This could translate into the policies not being loaded in order
|
3
5
|
class Policies < Eco::API::UseCases
|
4
|
-
|
6
|
+
autoloads_children_of "Eco::API::Common::Loaders::Policy"
|
7
|
+
autoload_namespace_ignore "Eco::API"
|
5
8
|
|
6
|
-
|
7
|
-
raise "Expected Eco::API::Policies::Policy object. Given: #{policy}" unless policy.is_a?(Eco::API::Policies::Policy)
|
8
|
-
super(policy)
|
9
|
-
end
|
9
|
+
attr_reader :policies
|
10
10
|
|
11
11
|
def define(name, type: :transform, &block)
|
12
12
|
Eco::API::Policies::Policy.new(name, type: type, root: self, &block).tap do |policy|
|
@@ -14,12 +14,16 @@ module Eco
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def add(policy)
|
18
|
+
raise "Expected Eco::API::Policies::Policy object. Given: #{policy}" unless policy.is_a?(Eco::API::Policies::Policy)
|
19
|
+
super(policy)
|
20
|
+
end
|
18
21
|
|
22
|
+
def launch(people:, session:, job:, options: {})
|
19
23
|
args = {
|
20
24
|
people: people,
|
21
25
|
session: session,
|
22
|
-
job:
|
26
|
+
job: job,
|
23
27
|
options: options
|
24
28
|
}
|
25
29
|
|
data/lib/eco/api/session.rb
CHANGED
@@ -17,17 +17,13 @@ module Eco
|
|
17
17
|
logger.debug("LINE COMMAND: #{$0} #{ARGV.join(" ")}")
|
18
18
|
end
|
19
19
|
|
20
|
-
# Helper to perform multiple operations in one go.
|
21
|
-
# @return [Eco::API::Session::Task] provides shortcuts to manage certain kind of operations.
|
22
|
-
def do
|
23
|
-
@task ||= Task.new(enviro)
|
24
|
-
end
|
25
|
-
|
26
20
|
# @return [Eco::API::Session::Batch] provides helper to launch batch operations.
|
27
21
|
def batch
|
28
22
|
@batch ||= Batch.new(enviro)
|
29
23
|
end
|
30
24
|
|
25
|
+
# @!group Pure organization helpers
|
26
|
+
|
31
27
|
# @see Eco::API::Session::Config#policy_groups
|
32
28
|
def policy_groups
|
33
29
|
config.policy_groups
|
@@ -47,6 +43,9 @@ module Eco
|
|
47
43
|
def schemas
|
48
44
|
config.schemas
|
49
45
|
end
|
46
|
+
# @!endgroup
|
47
|
+
|
48
|
+
# @!group People and Input entries helpers
|
50
49
|
|
51
50
|
# @return [String, Ecoportal::API::V1::PersonSchema] current active session's schema
|
52
51
|
def schema
|
@@ -56,7 +55,7 @@ module Eco
|
|
56
55
|
|
57
56
|
# Sets the current target `PersonSchema` of this session.
|
58
57
|
# @note observe that it is essential for the parsers/serialisers to identify target/present attributes.
|
59
|
-
# @param
|
58
|
+
# @param value [String, Ecoportal::API::V1::PersonSchema] where `String` can be the _name_ or the _id_ of the schema.
|
60
59
|
def schema=(value)
|
61
60
|
@schema = to_schema(value)
|
62
61
|
self
|
@@ -64,7 +63,7 @@ module Eco
|
|
64
63
|
|
65
64
|
# Builds the presets using the usergroup ids of the input.
|
66
65
|
# @note for each flag/ability it will take the highest among those mapped for the present usergroups.
|
67
|
-
# @param [Ecoportal::API::Internal::Person, Array<String>] the array should be of usegroup names or ids.
|
66
|
+
# @param input [Ecoportal::API::Internal::Person, Array<String>] the array should be of usegroup names or ids.
|
68
67
|
# @return [Hash] with custom presets.
|
69
68
|
def new_preset(input)
|
70
69
|
case input
|
@@ -77,6 +76,15 @@ module Eco
|
|
77
76
|
end
|
78
77
|
end
|
79
78
|
|
79
|
+
# Helper to state the abilities that a person should have with given their usergroups
|
80
|
+
def presets_factory
|
81
|
+
@presets_factory ||= Eco::API::Organization::PresetsFactory.new({
|
82
|
+
presets_custom: file_manager.dir.file(config.people.presets_custom, should_exist: true),
|
83
|
+
presets_map: file_manager.dir.file(config.people.presets_map, should_exist: true),
|
84
|
+
enviro: enviro
|
85
|
+
})
|
86
|
+
end
|
87
|
+
|
80
88
|
# Helper to obtain a EntryFactory
|
81
89
|
# @param schema [String, Ecoportal::API::V1::PersonSchema] `schema` to which associate the EntryFactory,
|
82
90
|
# where `String` can be the _name_ or the _id_ of the schema.
|
@@ -103,7 +111,7 @@ module Eco
|
|
103
111
|
# @param schema [String, Ecoportal::API::V1::PersonSchema] `schema` to which associate the PersonFactory,
|
104
112
|
# where `String` can be the _name_ or the _id_ of the schema.
|
105
113
|
# @return [Eco::API::Common::People::PersonFactory] associated to `schema`.
|
106
|
-
#
|
114
|
+
# If `schema` is `nil` or not provided it uses the currently associated to the `session`
|
107
115
|
def person_factory(schema: nil)
|
108
116
|
schema = to_schema(schema) || self.schema
|
109
117
|
@person_factories[schema&.id] ||= Eco::API::Common::People::PersonFactory.new(schema: schema)
|
@@ -113,18 +121,22 @@ module Eco
|
|
113
121
|
# @note the use of these method requires to know which is the expected format of `source`
|
114
122
|
# @param attr [String] type (`Symbol`) or attribute (`String`) to target a specific parser.
|
115
123
|
# @param source [Any] source value to be parsed.
|
116
|
-
|
124
|
+
# @param phase [Symbol] the phase when this parser should be active.
|
125
|
+
def parse_attribute(attr, source, phase = :internal)
|
117
126
|
unless parsers = entry_factory.person_parser
|
118
127
|
raise "There are no parsers defined"
|
119
128
|
end
|
120
129
|
parsers.parse(attr, source)
|
121
130
|
end
|
122
131
|
|
132
|
+
# @see Eco::API::Common::People::EntryFactory#export
|
133
|
+
# @param (see Eco::API::Common::People::EntryFactory#export)
|
123
134
|
def export(*args)
|
124
135
|
entry_factory.export(*args)
|
125
136
|
end
|
126
137
|
|
127
138
|
# @see Eco::API::Common::People::EntryFactory#new
|
139
|
+
# @param (see Eco::API::Common::People::EntryFactory#new)
|
128
140
|
# @return [Ecoportal::API::Internal::Person]
|
129
141
|
def new_person(**keyed_args)
|
130
142
|
person_factory.new(**keyed_args)
|
@@ -138,6 +150,7 @@ module Eco
|
|
138
150
|
end
|
139
151
|
|
140
152
|
# @see Eco::API::Common::People::EntryFactory#entries
|
153
|
+
# @param (see Eco::API::Common::People::EntryFactory#entries)
|
141
154
|
# @return [Eco::API::Common::People::Entries] collection of entries.
|
142
155
|
def entries(*args)
|
143
156
|
entry_factory.entries(*args).tap do |collection|
|
@@ -159,33 +172,52 @@ module Eco
|
|
159
172
|
def discarded_entries
|
160
173
|
return @discarded_entries if instance_variable_defined?(:@discarded_entries)
|
161
174
|
file = config.people.discarded_file
|
162
|
-
file = file_manager.dir.file(file)
|
175
|
+
fatal("You have not specified the 'discarded_people_file'") unless file = file_manager.dir.file(file)
|
163
176
|
@discarded_entries = csv_entries(file)
|
164
177
|
end
|
178
|
+
# @!endgroup
|
165
179
|
|
180
|
+
# @!group Session workflow and batch job launces
|
181
|
+
|
182
|
+
# Opens up the `workflow` configuration
|
166
183
|
def workflow(io:)
|
167
184
|
config.workflow.tap do |wf|
|
168
185
|
yield(wf, io) if block_given?
|
169
186
|
end
|
170
187
|
end
|
171
188
|
|
189
|
+
# Does merge `Eco::API::UseCases::DefaultCases` with the custom cases.
|
190
|
+
# @return [Eco::API::UseCases]
|
172
191
|
def usecases
|
173
|
-
@usecases ||=
|
192
|
+
@usecases ||= config.usecases.dup.tap do |cases|
|
193
|
+
all_cases = Eco::API::UseCases::DefaultCases.new.merge(config.usecases)
|
194
|
+
cases.merge(all_cases)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
# Set of helpers to simplify your code
|
199
|
+
# @see Eco::API::MicroCases
|
200
|
+
# @return [Eco::API::MicroCases]
|
201
|
+
def micro
|
202
|
+
@micro ||= Eco::API::MicroCases.new(enviro)
|
174
203
|
end
|
175
204
|
|
176
205
|
def post_launch
|
177
206
|
@post_launch ||= config.post_launch.select(usecases)
|
178
207
|
end
|
179
208
|
|
209
|
+
# @see Eco::API::UseCases::Case#launch
|
180
210
|
def process_case(name, io: nil, type: nil, **params)
|
181
211
|
args = { session: self }.merge(params)
|
182
212
|
usecases.case(name, type: type).launch(io: io, **args)
|
183
213
|
end
|
184
214
|
|
215
|
+
# @return [Eco::API::Session::Batch::JobsGroups]
|
185
216
|
def job_groups
|
186
217
|
@job_groups ||= Batch::JobsGroups.new(enviro)
|
187
218
|
end
|
188
219
|
|
220
|
+
# @return [Eco::API::Session::Batch::Jobs]
|
189
221
|
def job_group(name, order: :last)
|
190
222
|
case
|
191
223
|
when job_groups.exists?(name)
|
@@ -195,21 +227,28 @@ module Eco
|
|
195
227
|
end
|
196
228
|
end
|
197
229
|
|
198
|
-
#
|
230
|
+
# Shortcut to create a job of certain type within a group
|
231
|
+
# @return [Eco::API::Session::Batch::Job]
|
199
232
|
def new_job(group, name, type, usecase, sets = [:core, :details, :account])
|
200
233
|
job_group(group).new(name, usecase: usecase, type: type, sets: sets)
|
201
234
|
end
|
202
235
|
|
236
|
+
# @see Eco::API::Session::Batch::JobsGroups#launch
|
203
237
|
def jobs_launch(simulate: false)
|
204
238
|
job_groups.launch(simulate: simulate)
|
205
239
|
end
|
206
240
|
|
241
|
+
# @see Eco::API::Session::Batch::JobsGroups#summary
|
207
242
|
def summary
|
208
243
|
job_groups.summary
|
209
244
|
end
|
245
|
+
# @!endgroup
|
246
|
+
|
247
|
+
# @!group Additional resources
|
210
248
|
|
211
249
|
# Sends an email
|
212
250
|
# @see Eco::API::Common::Session::Mailer#mail
|
251
|
+
# @param (see Eco::API::Common::Session::Mailer#mail)
|
213
252
|
def mail(**kargs)
|
214
253
|
if mailer?
|
215
254
|
mailer.mail(**kargs)
|
@@ -232,7 +271,7 @@ module Eco
|
|
232
271
|
def s3upload(content: nil, file: nil, directory: nil, recurse: false, link: false)
|
233
272
|
if s3uploader?
|
234
273
|
if content == :target
|
235
|
-
path =
|
274
|
+
path = micro.s3upload_targets
|
236
275
|
elsif content && file
|
237
276
|
path = s3uploader.upload(file, content)
|
238
277
|
elsif file
|
@@ -249,18 +288,10 @@ module Eco
|
|
249
288
|
nil
|
250
289
|
end
|
251
290
|
end
|
291
|
+
# @!endgroup
|
252
292
|
|
253
293
|
private
|
254
294
|
|
255
|
-
# Helper to state the abilities that a person should have with given their usergroups
|
256
|
-
def presets_factory
|
257
|
-
@presets_factory ||= Eco::API::Organization::PresetsFactory.new({
|
258
|
-
presets_custom: file_manager.dir.file(config.people.presets_custom, should_exist: true),
|
259
|
-
presets_map: file_manager.dir.file(config.people.presets_map, should_exist: true),
|
260
|
-
enviro: enviro
|
261
|
-
})
|
262
|
-
end
|
263
|
-
|
264
295
|
# Comparer to state if 2 schemas are different
|
265
296
|
def same_schema? (schema1, schema2)
|
266
297
|
eq = schema1&.id == schema2&.id
|
@@ -291,4 +322,3 @@ end
|
|
291
322
|
|
292
323
|
require_relative 'session/config'
|
293
324
|
require_relative 'session/batch'
|
294
|
-
require_relative 'session/task'
|
@@ -24,7 +24,7 @@ module Eco
|
|
24
24
|
# @option params [String] :q some text to search. Omit this parameter to target all the people.
|
25
25
|
# @return [Array<People>] all the people based on `params`
|
26
26
|
def get_people(people = nil, params: {}, silent: false)
|
27
|
-
return launch(people, method: :get, params: params, silent: silent) if people.is_a?(Enumerable)
|
27
|
+
return launch(people, method: :get, params: params, silent: silent).people if people.is_a?(Enumerable)
|
28
28
|
return get(params: params, silent: silent)
|
29
29
|
end
|
30
30
|
|
@@ -2,7 +2,7 @@ module Eco
|
|
2
2
|
module API
|
3
3
|
class Session
|
4
4
|
class Batch
|
5
|
-
# Helper class to build a
|
5
|
+
# Helper class to build a hierarchical model of policies
|
6
6
|
# @example Usage:
|
7
7
|
# class PolicyModel < Eco::API::Session::Batch::BasePolicy
|
8
8
|
# MODEL = {attr1: ["prop1a", "prop1b", {"prop1c": ["prop1c1"]}]}
|
@@ -37,7 +37,7 @@ module Eco
|
|
37
37
|
end
|
38
38
|
|
39
39
|
# Attributes of this level of the model that should be included
|
40
|
-
# @param
|
40
|
+
# @param attrs [Array<Symbol>, Array<String>] each of the subpolicies of the model that should be available
|
41
41
|
def policy_attrs(*attrs)
|
42
42
|
attrs = attrs.map(&:to_sym)
|
43
43
|
|
@@ -82,14 +82,14 @@ module Eco
|
|
82
82
|
|
83
83
|
# @note if there's no `min` defined, it always returns `true`
|
84
84
|
# @param value [Integer] value to check if it's in the minimum required
|
85
|
-
# @
|
85
|
+
# @return [Boolen] `true` if `value` is grater or equal to `min`
|
86
86
|
def min?(value)
|
87
87
|
!min || !value|| (min <= value)
|
88
88
|
end
|
89
89
|
|
90
90
|
# @note if there's no `max` defined, it always returns `true`
|
91
91
|
# @param value [Integer] value to check if it's in the maximum allowed
|
92
|
-
# @
|
92
|
+
# @return [Boolen] `true` if `value` is lesser or equal to `min`
|
93
93
|
def max?(value)
|
94
94
|
!max || !value || (max >= value)
|
95
95
|
end
|
@@ -109,7 +109,7 @@ module Eco
|
|
109
109
|
!empty?
|
110
110
|
end
|
111
111
|
|
112
|
-
def each(
|
112
|
+
def each(&block)
|
113
113
|
return to_enum(:each) unless block
|
114
114
|
items.each(&block)
|
115
115
|
end
|
@@ -212,7 +212,8 @@ module Eco
|
|
212
212
|
end
|
213
213
|
|
214
214
|
def model_attr(hash)
|
215
|
-
hash[self.attr]
|
215
|
+
return hash[self.attr] if hash.key?(self.attr)
|
216
|
+
hash[self.attr.to_s] if model_attr?(hash)
|
216
217
|
end
|
217
218
|
|
218
219
|
private
|
@@ -2,7 +2,7 @@ module Eco
|
|
2
2
|
module API
|
3
3
|
class Session
|
4
4
|
class Batch
|
5
|
-
# Helper object linked to a `batch status
|
5
|
+
# Helper object linked to a `Batch::Status`. Its aim is to manage the errors of the batch status.
|
6
6
|
class Errors
|
7
7
|
|
8
8
|
# @attr_reader status [Eco::API::Session::Batch::Status] `batch status` this `Errors` object is associated to.
|
@@ -14,6 +14,8 @@ module Eco
|
|
14
14
|
@status = status
|
15
15
|
end
|
16
16
|
|
17
|
+
# @!group Status object shortcuts
|
18
|
+
|
17
19
|
# @see [Eco::API::Session::Batch::Status#queue]
|
18
20
|
def queue
|
19
21
|
status.queue
|
@@ -24,6 +26,7 @@ module Eco
|
|
24
26
|
status.method
|
25
27
|
end
|
26
28
|
|
29
|
+
# @param (see Eco::API::Session::Batch::Status#to_index)
|
27
30
|
# @see [Eco::API::Session::Batch::Status#to_index]
|
28
31
|
def to_index(*args)
|
29
32
|
status.to_index(*args)
|
@@ -37,6 +40,9 @@ module Eco
|
|
37
40
|
def logger
|
38
41
|
status.logger
|
39
42
|
end
|
43
|
+
# @!endgroup
|
44
|
+
|
45
|
+
# @!group Pure errors helper methods
|
40
46
|
|
41
47
|
# Was there any _Sever_ (reply) **error** as a result of this batch?
|
42
48
|
# @return [Boolean] `true` if any of the queried _entries_ got an unsuccessful `Ecoportal::API::Common::BatchResponse`
|
@@ -44,6 +50,11 @@ module Eco
|
|
44
50
|
queue.any? {|query| !status[query].success?}
|
45
51
|
end
|
46
52
|
|
53
|
+
# @return [Integer] the number of `entries` that got error.
|
54
|
+
def count
|
55
|
+
entries.length
|
56
|
+
end
|
57
|
+
|
47
58
|
# Input entries that got **error** response from the _Server_.
|
48
59
|
# @raise [Exception] if there are elements of the final `queue` that did not get response
|
49
60
|
# @note discards those that did not get _response_ from the Server (so those that were not queried)
|
@@ -67,6 +78,11 @@ module Eco
|
|
67
78
|
end.compact
|
68
79
|
end
|
69
80
|
|
81
|
+
# For all the `entries` with errors generates a `Hash` object
|
82
|
+
# @return [Array<Hash>] where each `Hash` has
|
83
|
+
# 1. `:type` -> the error type
|
84
|
+
# 2. `:err` -> the error `class` of that `:type`
|
85
|
+
# 3. `:entry` -> the entry that generated the error
|
70
86
|
def errors
|
71
87
|
entries.each_with_object([]) do |entry, arr|
|
72
88
|
if body = status[entry].body
|
@@ -83,6 +99,9 @@ module Eco
|
|
83
99
|
end
|
84
100
|
end
|
85
101
|
|
102
|
+
# Groups `entries` with error `type`
|
103
|
+
# @return [Hash] where each `key` is a `type` **error** and each value is
|
104
|
+
# an `Array` of `entries` that got that error
|
86
105
|
def by_type
|
87
106
|
errors.group_by do |h|
|
88
107
|
h[:type]
|
@@ -90,11 +109,13 @@ module Eco
|
|
90
109
|
arr.map {|h| h[:entry]}
|
91
110
|
end
|
92
111
|
end
|
112
|
+
# @!endgroup
|
93
113
|
|
94
|
-
|
95
|
-
entries.length
|
96
|
-
end
|
114
|
+
# @!group Messaging methods
|
97
115
|
|
116
|
+
# Generates a `String` specifying the error for the entry `key`.
|
117
|
+
# @param key [Integer, Ecoportal::API::V1::Person]
|
118
|
+
# @return [String] the error description.
|
98
119
|
def str(key)
|
99
120
|
msg = ""
|
100
121
|
unless status.success?(key)
|
@@ -107,6 +128,8 @@ module Eco
|
|
107
128
|
msg
|
108
129
|
end
|
109
130
|
|
131
|
+
# Sorts the entries that got server error by error `type` and generates the error messages.
|
132
|
+
# @return [Array<String>] the errors messages.
|
110
133
|
def strs
|
111
134
|
by_type.values.flatten(1).each_with_object([]) do |query, msgs|
|
112
135
|
msgs.push(str(query))
|
@@ -136,6 +159,7 @@ module Eco
|
|
136
159
|
logger.info("There were no errors for the current batch '#{method}'!! ;)")
|
137
160
|
end
|
138
161
|
end
|
162
|
+
# @!endgroup
|
139
163
|
|
140
164
|
private
|
141
165
|
|