eco-helpers 1.5.0 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +147 -2
- data/LICENSE +21 -0
- data/eco-helpers.gemspec +11 -10
- data/lib/eco/api.rb +3 -0
- data/lib/eco/api/common.rb +5 -1
- 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 +5 -10
- 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 +20 -0
- 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 +31 -0
- data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +15 -24
- data/lib/eco/api/common/people/entries.rb +54 -24
- data/lib/eco/api/common/people/entry_factory.rb +18 -15
- 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 +5 -2
- data/lib/eco/api/common/people/person_parser.rb +52 -19
- data/lib/eco/api/common/session/base_session.rb +3 -6
- data/lib/eco/api/common/session/environment.rb +2 -23
- 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 +9 -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 +35 -0
- 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 +20 -0
- data/lib/eco/api/microcases/fix_default_group.rb +34 -0
- data/lib/eco/api/microcases/fix_filter_tags.rb +42 -0
- 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 +20 -0
- data/lib/eco/api/microcases/set_core.rb +18 -0
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +23 -0
- data/lib/eco/api/microcases/set_supervisor.rb +30 -0
- data/lib/eco/api/microcases/strict_search.rb +19 -0
- 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/organization/presets_values.json +1 -0
- data/lib/eco/api/policies.rb +11 -7
- data/lib/eco/api/session.rb +62 -29
- data/lib/eco/api/session/batch.rb +2 -45
- 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 +106 -44
- data/lib/eco/api/session/config/api.rb +132 -7
- data/lib/eco/api/session/config/apis.rb +24 -25
- 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 +83 -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 +92 -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_io.rb +9 -9
- 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 +69 -32
- 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 +149 -62
- 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 -98
- 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/cli/config/default/filters.rb +0 -70
- data/lib/eco/cli/config/people_filters.rb +0 -38
@@ -0,0 +1,28 @@
|
|
1
|
+
# Helper class to create a custom `Policy`
|
2
|
+
# @example Example of usage:
|
3
|
+
# class Custom::Policy::StartersNLeavers < Eco::API::Custom::Policy
|
4
|
+
# name "starters'n'leavers"
|
5
|
+
#
|
6
|
+
# INACTIVE = "Non active"
|
7
|
+
#
|
8
|
+
# def main(people, session, options, policy, job)
|
9
|
+
# people.each do |person|
|
10
|
+
# next unless details = person.details
|
11
|
+
# # starters
|
12
|
+
# if person.new?
|
13
|
+
# details["status"] = "Active"
|
14
|
+
# details["hris-managed"] = true unless options.dig(:include, :excluded)
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # leavers: native job queue to remove account
|
18
|
+
# if job.name == "leavers"
|
19
|
+
# details["status"] = INACTIVE
|
20
|
+
# person.external_id = person.name
|
21
|
+
# details["staff-id"] = person.name
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# end
|
27
|
+
class Eco::API::Custom::Policy < Eco::API::Common::Loaders::Policy
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Helper class to create a custom `UseCase`
|
2
|
+
# @example Example of usage:
|
3
|
+
# class Custom::UseCase::Sync < Eco::API::Custom::UseCase
|
4
|
+
# name "custom-case"
|
5
|
+
# type :sync
|
6
|
+
#
|
7
|
+
# def main(entries, people, session, options, usecase)
|
8
|
+
# update = session.new_job("main", "update", :update, usecase)
|
9
|
+
# session.micro.with_each(entries, people, options) do |entry, person|
|
10
|
+
# # update some data in person using data from entry
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# end
|
15
|
+
class Eco::API::Custom::UseCase < Eco::API::Common::Loaders::UseCase
|
16
|
+
end
|
data/lib/eco/api/error.rb
CHANGED
@@ -2,12 +2,14 @@ module Eco
|
|
2
2
|
module API
|
3
3
|
class Error
|
4
4
|
class Handlers < Eco::API::UseCases
|
5
|
+
autoloads_children_of "Eco::API::Common::Loaders::ErrorHandler"
|
6
|
+
autoload_namespace_ignore "Eco::API"
|
5
7
|
|
6
|
-
def
|
7
|
-
raise "
|
8
|
-
super(handler)
|
8
|
+
def define(*args)
|
9
|
+
raise "Missusage. You should use 'on' method instead"
|
9
10
|
end
|
10
11
|
|
12
|
+
# @param klass_err [Eco::API::Error] the specific error class that triggers this handler.
|
11
13
|
def on(klass_err, type: :error_handler, retry: true, &block)
|
12
14
|
Eco::API::Error.validate_err_class(klass_err)
|
13
15
|
raise "Expected block but not given" unless block
|
@@ -16,6 +18,11 @@ module Eco
|
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
21
|
+
def add(handler)
|
22
|
+
raise "Expected Eco::API::Error::Handler object. Given: #{policy}" unless handler.is_a?(Eco::API::Error::Handler)
|
23
|
+
super(handler)
|
24
|
+
end
|
25
|
+
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases < Eco::API::Common::Session::BaseSession
|
4
|
+
|
5
|
+
def micro
|
6
|
+
self
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require_relative 'microcases/account_excluded'
|
14
|
+
require_relative 'microcases/append_usergroups'
|
15
|
+
require_relative 'microcases/core_excluded'
|
16
|
+
require_relative 'microcases/fix_default_group'
|
17
|
+
require_relative 'microcases/fix_filter_tags'
|
18
|
+
require_relative 'microcases/people_cache'
|
19
|
+
require_relative 'microcases/people_load'
|
20
|
+
require_relative 'microcases/people_refresh'
|
21
|
+
require_relative 'microcases/people_search'
|
22
|
+
require_relative 'microcases/refresh_abilities'
|
23
|
+
require_relative 'microcases/set_account'
|
24
|
+
require_relative 'microcases/set_core_with_supervisor'
|
25
|
+
require_relative 'microcases/set_core'
|
26
|
+
require_relative 'microcases/refresh_default_tag'
|
27
|
+
require_relative 'microcases/set_supervisor'
|
28
|
+
require_relative 'microcases/strict_search'
|
29
|
+
require_relative 'microcases/s3upload_targets'
|
30
|
+
require_relative 'microcases/with_each'
|
31
|
+
require_relative 'microcases/with_each_leaver'
|
32
|
+
require_relative 'microcases/with_each_present'
|
33
|
+
require_relative 'microcases/with_each_starter'
|
34
|
+
require_relative 'microcases/with_each_subordinate'
|
35
|
+
require_relative 'microcases/with_supervisor'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
5
|
+
# @param options [Hash] the options.
|
6
|
+
# @return [Array<String>] the account parameters that should not be included.
|
7
|
+
def account_excluded(person, options)
|
8
|
+
[].tap do |account_excluded|
|
9
|
+
unless person.new?
|
10
|
+
if options.dig(:exclude, :policy_groups)
|
11
|
+
account_excluded.push("policy_group_ids")
|
12
|
+
end
|
13
|
+
if options.dig(:exclude, :default_tag)
|
14
|
+
account_excluded.push("default_tag")
|
15
|
+
end
|
16
|
+
if options.dig(:exclude, :login_providers)
|
17
|
+
account_excluded.push("login_provider_ids")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# It preserves the usergroups of `person` and appends those defined in `policy_group_ids` of the `entry`
|
5
|
+
# @param entry [PersonEntry] the input entry with the data we should set on person.
|
6
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
7
|
+
# @param options [Hash] the options.
|
8
|
+
def append_usergroups(entry, person, options)
|
9
|
+
unless options.dig(:exclude, :account)
|
10
|
+
if person.account
|
11
|
+
person.account.policy_group_ids |= entry.policy_group_ids
|
12
|
+
micro.refresh_abilities(person, options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# @note by default `supervisor_id` is always excluded.
|
5
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
6
|
+
# @param options [Hash] the options.
|
7
|
+
# @return [Array<String>] the core parameters that should not be included.
|
8
|
+
def core_excluded(person, options)
|
9
|
+
["supervisor_id"].tap do |core_excluded|
|
10
|
+
unless person.new?
|
11
|
+
exclusions = ["name", "external_id", "email", "filter_tags"].select do |attr|
|
12
|
+
options.dig(:exclude, attr.to_sym)
|
13
|
+
end
|
14
|
+
core_excluded.concat(exclusions)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# If defined, it sets the default usergroup, only when the `policy_group_ids` was not part of the input data.
|
5
|
+
# @param entry [PersonEntry] the input entry with the data we should set on person.
|
6
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
7
|
+
# @param options [Hash] the options.
|
8
|
+
def fix_default_group(entry, person, options)
|
9
|
+
unless options.dig(:exclude, :account)
|
10
|
+
unless options.dig(:exclude, :policy_groups) && !person.new?
|
11
|
+
end_pg_ids = person.account.policy_group_ids
|
12
|
+
|
13
|
+
if person.account_added? && __def_usergroup_id && !entry.policy_group_ids?
|
14
|
+
# on account creation, if missing policy_group_ids column in the input
|
15
|
+
# use default_usergroup, if it's defined
|
16
|
+
end_pg_ids = [__def_usergroup_id]
|
17
|
+
end
|
18
|
+
|
19
|
+
person.account.policy_group_ids = end_pg_ids
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def __def_usergroup_id
|
27
|
+
@def_usergroup_id ||= if session.config.people.default_usergroup?
|
28
|
+
session.policy_groups.to_id(session.config.people.default_usergroup)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# Helper that makes sure the **custom `tags`** are preserved.
|
5
|
+
# @note
|
6
|
+
# - this feature is essential to preserve custom `tags` in users that have register tags.
|
7
|
+
# - for this to work out, it requires a `tagtree` to be defined.
|
8
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes already done.
|
9
|
+
# @param options [Hash] the options.
|
10
|
+
# @option options [Hash<Symbol, Object>] :filter_tags options around `filter_tags`.
|
11
|
+
# * `:preserve_custom` (Boolean) [true] indicates if original tags that are not in the tree should be added/preserved.
|
12
|
+
# * `:add_custom` (Boolean) [true] indicates if target tags that are not in the tree should be really added.
|
13
|
+
def fix_filter_tags(person, options)
|
14
|
+
if session.tagtree
|
15
|
+
unless !person.new? && (options.dig(:exclude, :core) || options.dig(:exclude, :filter_tags))
|
16
|
+
person.filter_tags = session.tagtree.user_tags(
|
17
|
+
initial: person.original_doc["filter_tags"] || [],
|
18
|
+
final: person.filter_tags,
|
19
|
+
preserve_custom: _fix_filter_tags_preserve_custom?(options),
|
20
|
+
add_custom: _fix_filter_tags_add_custom?(options)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# default `true`
|
29
|
+
def _fix_filter_tags_preserve_custom?(options)
|
30
|
+
key_defined = options.key?(:filter_tags) && options[:filter_tags].key?(:preserve_custom)
|
31
|
+
!key_defined || options.dig(:filter_tags, :preserve_custom)
|
32
|
+
end
|
33
|
+
|
34
|
+
# default `true`
|
35
|
+
def _fix_filter_tags_add_custom?(options)
|
36
|
+
key_defined = options.key?(:filter_tags) && options[:filter_tags].key?(:add_custom)
|
37
|
+
!key_defined || options.dig(:filter_tags, :add_custom)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# Helper to locally cache the people manager.
|
5
|
+
# @param filename [String] the name of the file where the data should be cached.
|
6
|
+
# @return [Eco::API::Organization::People] the `People` object with the data.
|
7
|
+
def people_cache(filename = enviro.config.people.cache)
|
8
|
+
logger.info("Going to get all the people via API")
|
9
|
+
people = session.batch.get_people
|
10
|
+
file = file_manager.save_json(people, filename, :timestamp)
|
11
|
+
logger.info("#{people.length} people loaded and saved locally to #{file}.")
|
12
|
+
Eco::API::Organization::People.new(people)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# Helper to load `People` that works in different phases:
|
5
|
+
# 1. first tries to get the newest cached file that follows `filename` pattern
|
6
|
+
# - if not the newest, it tries to find the specific filename
|
7
|
+
# 2. if it succeeds to identif a cached file, it loads it
|
8
|
+
# - if it fails, it tries to get people from the server
|
9
|
+
# @note
|
10
|
+
# - `filename` will be relative to the working directory (the one of the session `enviro` set by the user).
|
11
|
+
# @param filename [String] the name of the file where the cached data is to be found.
|
12
|
+
# @param modifier [Array<Symbol>] modifiers to specify how this function should proceed:
|
13
|
+
# - `:newest` if it should try to find the newest file (pattern alike).
|
14
|
+
# - `:api` if it should try to get people from the server in case there's no cache.
|
15
|
+
# - `:file` if it is supposed to load people from a file.
|
16
|
+
# - `:save` if it is supposed to cache/save the data locally once obtained people from the server (`:api`)
|
17
|
+
# @return [Eco::API::Organization::People] the `People` object with the data.
|
18
|
+
def people_load(filename = enviro.config.people.cache, modifier: [:newest, :api])
|
19
|
+
modifier = [modifier].flatten
|
20
|
+
load_file = [:file, :newest].any? {|flag| modifier.include?(flag)}
|
21
|
+
people = case
|
22
|
+
when filename && load_file
|
23
|
+
if file = people_load_filename(filename, newest: modifier.include?(:newest))
|
24
|
+
file_manager.load_json(file).tap do |people|
|
25
|
+
logger.info("#{people&.length} people loaded from file #{file}") if people.is_a?(Array)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
logger.error("could not find the file #{file_manager.dir.file(filename)}")
|
29
|
+
exit unless modifier.include?(:api)
|
30
|
+
people_load(modifier: modifier - [:newest, :file])
|
31
|
+
end
|
32
|
+
when modifier.include?(:api)
|
33
|
+
logger.info("Going to get all the people via API")
|
34
|
+
session.batch.get_people.tap do |people|
|
35
|
+
if modifier.include?(:save) && people && people.length > 0
|
36
|
+
file = file_manager.save_json(people, filename, :timestamp)
|
37
|
+
logger.info("#{people.length } people saved to file #{file}.")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
Eco::API::Organization::People.new(people)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def people_load_filename(filename, newest: false)
|
47
|
+
if newest
|
48
|
+
# search input file based on pattern (in case the name has a timestamp)
|
49
|
+
file_manager.dir.newest_file(file: filename).tap do |file|
|
50
|
+
logger.info("previous file found: #{file}") if file
|
51
|
+
end
|
52
|
+
else
|
53
|
+
file_manager.dir.file(filename, should_exist: true)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# Helper to obtain all the elements of `people` anew from the _People Manager_.
|
5
|
+
# @note this helper is normally used to run consecutive usecases, where data needs refresh.
|
6
|
+
# @param people [Eco::API::Organization::People] the people that needs refresh.
|
7
|
+
# @param include_created [Boolean] include people created during this session? (will check `:create` batch jobs).
|
8
|
+
# @return [Eco::API::Organization::People] the `People` object with the data.
|
9
|
+
def people_refresh(people:, include_created: true)
|
10
|
+
ini = people.length
|
11
|
+
if include_created
|
12
|
+
session.job_groups.find_jobs(type: :create).map do |job|
|
13
|
+
people = people.merge(job.people)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
created = people.length - ini
|
18
|
+
msg = "Going to refresh #{people.length} people with server data"
|
19
|
+
msg += " (including #{created} that were created)" if created > 0
|
20
|
+
logger.info(msg)
|
21
|
+
entries = session.batch.get_people(people, silent: true)
|
22
|
+
|
23
|
+
missing = people.length - entries.length
|
24
|
+
logger.error("Missed to obtain #{missing} people during the refresh") if missing > 0
|
25
|
+
|
26
|
+
Eco::API::Organization::People.new(entries)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# Helper to search/obtain people from `data` against the server (_People Manager_).
|
5
|
+
# @note
|
6
|
+
# - this helper is normally used to **get partial** part of the people manager.
|
7
|
+
# - therefore, normally used with _**delta** input files_ (files with only the differences).
|
8
|
+
# @param data [Eco::API::Organization::People, Enumerable<Person>, Enumerable<Hash>] `People` to search against the server.
|
9
|
+
# @param options [Hash] the options.
|
10
|
+
# @param silent [Boolean] `false` if low level search messages should be shown.
|
11
|
+
# @return [Eco::API::Organization::People] the `People` object with the found persons.
|
12
|
+
def people_search(data, options: {}, silent: true)
|
13
|
+
session.logger.info("Going to api get #{data.length} entries...")
|
14
|
+
status = session.batch.search(data, silent: silent)
|
15
|
+
people = Eco::API::Organization::People.new(status.people)
|
16
|
+
session.logger.info("... could get #{people.length} people (out of #{data.length} entries)")
|
17
|
+
|
18
|
+
# get the supervisors of found people (current supervisors)
|
19
|
+
supers = people_search_prepare_supers_request(people)
|
20
|
+
if supers.length > 0
|
21
|
+
session.logger.info(" Going to api get #{supers.length} current supervisors...")
|
22
|
+
status = session.batch.search(supers, silent: silent)
|
23
|
+
people = people.merge(status.people, strict: micro.strict_search?(options))
|
24
|
+
end
|
25
|
+
|
26
|
+
# get the supervisors referred in the input data (future supervisors)
|
27
|
+
supers = people_search_prepare_supers_request(data, people)
|
28
|
+
if supers.length > 0
|
29
|
+
session.logger.info(" Going to api get #{supers.length} supervisors as per entries...")
|
30
|
+
status = session.batch.search(supers, silent: silent)
|
31
|
+
people = people.merge(status.people, strict: micro.strict_search?(options))
|
32
|
+
end
|
33
|
+
|
34
|
+
session.logger.info("Finally got #{people.length} people (out of #{data.length} entries)")
|
35
|
+
people
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# Prepares a unique request with only the supervisor ids missing in `people`
|
41
|
+
def people_search_prepare_supers_request(data, people = data)
|
42
|
+
data.each_with_object([]) do |entry, request|
|
43
|
+
spr = {"id" => (sup_id = people_search_super_id(entry))}
|
44
|
+
unless !sup_id || request.include?(spr)
|
45
|
+
micro.with_supervisor(sup_id, people) do |supervisor|
|
46
|
+
request.push(spr) unless supervisor
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Gets the `supervisor_id` from `value`
|
53
|
+
def people_search_super_id(value)
|
54
|
+
sup_id = if value.respond_to?(:supervisor_id)
|
55
|
+
value.supervisor_id
|
56
|
+
elsif value.is_a?(Hash) && value.key("supervisor_id")
|
57
|
+
value["supervisor_id"]
|
58
|
+
end
|
59
|
+
sup_id = nil if sup_id.to_s.strip.empty?
|
60
|
+
sup_id
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|