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
@@ -0,0 +1,24 @@
|
|
1
|
+
class Eco::API::UseCases::UseCaseIO
|
2
|
+
module Chain
|
3
|
+
def chain(usecase:)
|
4
|
+
msg = "It should be a Eco::API::UseCases::UseCase. Given: #{usecase.class}"
|
5
|
+
raise ArgumentError, msg unless usecase.is_a?(Eco::API::UseCases::UseCase)
|
6
|
+
|
7
|
+
#aux_io = self.class.new(input: input, data: data, session: session, options: options, usecase: usecase)
|
8
|
+
#kargs = aux_io.params(keyed: true)
|
9
|
+
kargs = params(keyed: true, all: true).merge(usecase: usecase)
|
10
|
+
kargs.delete(:job)
|
11
|
+
|
12
|
+
case type
|
13
|
+
when :import
|
14
|
+
kargs[:input] = output
|
15
|
+
when :filter
|
16
|
+
kargs[:data] = output
|
17
|
+
when :transform, :sync, :export, :error_handler, :other
|
18
|
+
# no redirections => should it redirect the input?
|
19
|
+
end
|
20
|
+
|
21
|
+
self.class.new(**kargs)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -7,7 +7,8 @@ module Eco
|
|
7
7
|
# - provides a helper to `chain` InputOutput between usecases
|
8
8
|
# @attr_reader usecase [Eco::API::UseCases::UseCase] the usecase this InputOuput is linked to
|
9
9
|
class UseCaseIO < BaseIO
|
10
|
-
|
10
|
+
require_relative 'use_case_io/chain'
|
11
|
+
include Chain
|
11
12
|
|
12
13
|
attr_reader :usecase
|
13
14
|
|
@@ -31,17 +32,28 @@ module Eco
|
|
31
32
|
|
32
33
|
# @param value [Eco::API::UseCases::UseCase] the usecase this InputOuput should be linked to
|
33
34
|
def usecase=(value)
|
34
|
-
|
35
|
+
msg = "It should be a Eco::API::UseCases::UseCase. Given: #{value}"
|
36
|
+
raise ArgumentError, msg unless value.is_a?(Eco::API::UseCases::UseCase)
|
37
|
+
|
35
38
|
@usecase = value
|
36
39
|
end
|
37
40
|
|
38
41
|
# @return [Symbol] the `type` of the UseCase this InputOuput is linked to
|
39
42
|
def type
|
40
|
-
|
43
|
+
usecase.type
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Symbol] the `model` of the UseCase this InputOuput is linked to
|
47
|
+
def model
|
48
|
+
usecase.model
|
49
|
+
end
|
50
|
+
|
51
|
+
def type=(_value)
|
52
|
+
raise "Can't modify type: depends on the usecase linked to this IO object"
|
41
53
|
end
|
42
54
|
|
43
|
-
def
|
44
|
-
raise "Can't modify
|
55
|
+
def model=(_value)
|
56
|
+
raise "Can't modify model: depends on the usecase linked to this IO object"
|
45
57
|
end
|
46
58
|
|
47
59
|
# @see Eco::API::UseCases::BaseIO#params
|
@@ -57,23 +69,6 @@ module Eco
|
|
57
69
|
end
|
58
70
|
end
|
59
71
|
end
|
60
|
-
|
61
|
-
def chain(usecase:)
|
62
|
-
raise "It should be a UseCase. Given: #{usecase}" if !usecase.is_a?(UseCase)
|
63
|
-
#aux_io = self.class.new(input: input, people: people, session: session, options: options, usecase: usecase)
|
64
|
-
#kargs = aux_io.params(keyed: true)
|
65
|
-
kargs = params(keyed: true, all: true).merge(usecase: usecase)
|
66
|
-
kargs.delete(:job)
|
67
|
-
case self.type
|
68
|
-
when :import
|
69
|
-
kargs[:input] = output
|
70
|
-
when :filter
|
71
|
-
kargs[:people] = output
|
72
|
-
when :transform, :sync, :export, :error_handler, :other
|
73
|
-
# no redirections => should it redirect the input?
|
74
|
-
end
|
75
|
-
self.class.new(**kargs)
|
76
|
-
end
|
77
72
|
end
|
78
73
|
end
|
79
74
|
end
|
data/lib/eco/api/usecases.rb
CHANGED
@@ -42,6 +42,7 @@ module Eco
|
|
42
42
|
|
43
43
|
def each(&block)
|
44
44
|
return to_enum(:each) unless block
|
45
|
+
|
45
46
|
items.each(&block)
|
46
47
|
end
|
47
48
|
|
@@ -59,8 +60,14 @@ module Eco
|
|
59
60
|
end
|
60
61
|
|
61
62
|
# @return [Eco::API::UseCases::UseCase] the `name` usecase of type `type` with the defined `block`.
|
62
|
-
def define(name, type:, &block)
|
63
|
-
Eco::API::UseCases::UseCase.new(
|
63
|
+
def define(name, type:, model: nil, &block)
|
64
|
+
Eco::API::UseCases::UseCase.new(
|
65
|
+
name,
|
66
|
+
type: type,
|
67
|
+
model: model,
|
68
|
+
root: self,
|
69
|
+
&block
|
70
|
+
).tap do |usecase|
|
64
71
|
add(usecase)
|
65
72
|
end
|
66
73
|
end
|
@@ -69,11 +76,12 @@ module Eco
|
|
69
76
|
# @param usecase [Eco::API::UseCases::UseCase] the usecase to be added.
|
70
77
|
def add(usecase)
|
71
78
|
msg = "Expected Eco::API::UseCases::UseCase object. Given: #{usecase.class}"
|
72
|
-
raise ArgumentError, msg
|
79
|
+
raise ArgumentError, msg unless usecase.is_a?(Eco::API::UseCases::UseCase)
|
73
80
|
|
74
81
|
name = usecase.name
|
75
82
|
type = usecase.type
|
76
83
|
puts "Warning: overriding '#{type}' case #{name}" if self.defined?(name, type: type)
|
84
|
+
|
77
85
|
to_h[key(name, type)] = usecase
|
78
86
|
@cache_init = false
|
79
87
|
usecase
|
@@ -107,7 +115,7 @@ module Eco
|
|
107
115
|
end
|
108
116
|
|
109
117
|
def types(name)
|
110
|
-
return
|
118
|
+
return unless name?(name)
|
111
119
|
|
112
120
|
by_name[name].map(&:type)
|
113
121
|
end
|
data/lib/eco/assets.rb
CHANGED
@@ -3,23 +3,24 @@ module Eco
|
|
3
3
|
class Config
|
4
4
|
class Filters
|
5
5
|
class PeopleFilters < Eco::CLI::Config::Filters
|
6
|
-
|
7
6
|
def help(refine: nil)
|
8
7
|
refinement = refine.is_a?(String)? " (containing: '#{refine}')" : ""
|
9
8
|
super("The following are the available filters on people#{refinement}:", refine: refine)
|
10
9
|
end
|
11
10
|
|
12
11
|
def process(io:)
|
13
|
-
unless io
|
12
|
+
unless io.is_a?(Eco::API::UseCases::BaseIO)
|
14
13
|
raise "You need to provide Eco::API::UseCases::BaseIO object. Given: #{io.class}"
|
15
14
|
end
|
16
15
|
|
17
16
|
io = io.new(type: :transform)
|
17
|
+
|
18
18
|
@filters.each do |arg, callback|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
next unless SCR.get_arg(arg)
|
20
|
+
|
21
|
+
io = io.new(data: callback.call(*io.params))
|
22
22
|
end
|
23
|
+
|
23
24
|
io.people
|
24
25
|
end
|
25
26
|
end
|
data/lib/eco/cli/config/input.rb
CHANGED
@@ -17,8 +17,12 @@ module Eco
|
|
17
17
|
|
18
18
|
def define(option: nil, &block)
|
19
19
|
option ||= default_option
|
20
|
-
|
21
|
-
|
20
|
+
|
21
|
+
msg = "Missing option to identify the input (no default defined)"
|
22
|
+
raise ArgumentError, msg unless option
|
23
|
+
|
24
|
+
msg = "Missing block to define the input obtention process"
|
25
|
+
raise ArgumentError, msg unless block_given?
|
22
26
|
|
23
27
|
@callbacks[option] = block
|
24
28
|
end
|
@@ -57,7 +57,7 @@ module Eco
|
|
57
57
|
# @param desc [String] description of the case.
|
58
58
|
# @param case_name [String, nil] the name of the usecase as defined.
|
59
59
|
def add(option_case, type, desc = nil, case_name: nil, &callback)
|
60
|
-
Eco::API::UseCases::UseCase.validate_type(type)
|
60
|
+
Eco::API::UseCases::UseCase.validate_type!(type)
|
61
61
|
|
62
62
|
unless block_given?
|
63
63
|
raise "You must specify a valid 'case_name' when no block is provided" unless case_name
|
@@ -154,7 +154,9 @@ module Eco
|
|
154
154
|
def validate_io!(io)
|
155
155
|
return if io.is_a?(Eco::API::UseCases::BaseIO)
|
156
156
|
|
157
|
-
|
157
|
+
msg = "You need to provide Eco::API::UseCases::BaseIO object. "
|
158
|
+
msg << "Given: #{io.class}"
|
159
|
+
raise ArgumentError, msg
|
158
160
|
end
|
159
161
|
end
|
160
162
|
end
|
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
formats = {
|
1
|
+
class Eco::CliDefault::Input < Eco::API::Common::Loaders::CliConfig
|
2
|
+
FORMATS = {
|
4
3
|
csv: {
|
5
4
|
option: ["-csv"],
|
6
5
|
extname: [".csv", ".txt"]
|
@@ -17,51 +16,74 @@ ASSETS.cli.config do |cnf|
|
|
17
16
|
option: ["-json"],
|
18
17
|
extname: [".json"]
|
19
18
|
}
|
20
|
-
}
|
19
|
+
}.freeze
|
21
20
|
|
22
|
-
|
23
|
-
|
21
|
+
class << self
|
22
|
+
attr_reader :options, :session
|
24
23
|
|
24
|
+
def encoding
|
25
|
+
options.dig(:input, :file, :encoding)
|
26
|
+
end
|
27
|
+
|
28
|
+
def format_by_cli
|
29
|
+
FORMATS.reduce(nil) do |matched, (frm, selectors)|
|
30
|
+
next matched if matched
|
31
|
+
|
32
|
+
used = selectors[:option].reduce(false) do |us, option|
|
33
|
+
SCR.get_arg(option) || us
|
34
|
+
end
|
35
|
+
|
36
|
+
next frm if used
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def format_by_ext(ext)
|
41
|
+
FORMATS.reduce(nil) do |matched, (frm, selectors)|
|
42
|
+
next matched if matched
|
43
|
+
next frm if selectors[:extname].any? {|e| ext == e}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
input(default_option: "-entries-from") do |session, str_opt, options|
|
49
|
+
@options = options
|
50
|
+
@session = session
|
51
|
+
input = []
|
25
52
|
next input unless SCR.get_arg(str_opt)
|
26
53
|
|
27
54
|
file = SCR.get_file(str_opt, required: true)
|
28
55
|
|
29
56
|
# Command line check
|
30
|
-
format =
|
31
|
-
used = selectors[:option].reduce(false) {|us, option| SCR.get_arg(option) || us}
|
32
|
-
next matched if matched
|
33
|
-
next frm if used
|
34
|
-
end
|
57
|
+
format = format_by_cli
|
35
58
|
|
36
59
|
# File/Folder check
|
37
60
|
file = File.expand_path(file)
|
61
|
+
|
38
62
|
if File.directory?(file)
|
39
63
|
folder = file
|
40
64
|
file = Dir.glob("#{file}/*").reject {|f| File.directory?(f)}
|
41
|
-
ext = (format
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
65
|
+
ext = FORMATS.dig(format, :extname)
|
66
|
+
ext ||= [File.extname(file.first)]
|
67
|
+
file = file.select do |f|
|
68
|
+
ext.any? {|e| File.extname(f) == e}
|
69
|
+
end.tap do |files|
|
70
|
+
next unless files.empty?
|
71
|
+
|
72
|
+
session.log(:error) {
|
73
|
+
"Could not find any file with extension: #{ext} in folder '#{folder}'"
|
74
|
+
}
|
75
|
+
exit(1)
|
49
76
|
end
|
50
77
|
else
|
51
|
-
ext = File.extname(file)
|
78
|
+
ext = [File.extname(file)]
|
52
79
|
end
|
53
80
|
|
54
|
-
format ||=
|
55
|
-
next matched if matched
|
56
|
-
next frm if selectors[:extname].any? {|e| ext == e}
|
57
|
-
end
|
81
|
+
format ||= format_by_ext(ext.first)
|
58
82
|
format ||= :csv
|
59
83
|
|
60
|
-
options.deep_merge!(input: {file: {name:
|
84
|
+
options.deep_merge!(input: {file: {name: file}})
|
61
85
|
options.deep_merge!(input: {file: {format: format}})
|
62
86
|
|
63
|
-
encoding = options.dig(:input, :file, :encoding)
|
64
|
-
|
65
87
|
case format
|
66
88
|
when :xml
|
67
89
|
[file].flatten.each {|f| session.config.files.validate(:xml, f)}
|
@@ -83,5 +105,3 @@ ASSETS.cli.config do |cnf|
|
|
83
105
|
input
|
84
106
|
end
|
85
107
|
end
|
86
|
-
|
87
|
-
# rubocop:enable Metrics/BlockLength
|
@@ -69,7 +69,10 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
|
|
69
69
|
sch_id = session.schemas.to_id(sch_name)
|
70
70
|
|
71
71
|
unless sch_id
|
72
|
-
msg = "You need to specify a correct schema id or name.
|
72
|
+
msg = "You need to specify a correct schema id or name. "
|
73
|
+
msg << "'#{sch_name}' does not exist. Correct options are: "
|
74
|
+
msg << session.schemas.map(&:name).join(", ")
|
75
|
+
|
73
76
|
session.log(:error) { msg }
|
74
77
|
exit(1)
|
75
78
|
end
|
@@ -1,69 +1,124 @@
|
|
1
|
-
|
1
|
+
class Eco::CliDefault::People < Eco::API::Common::Loaders::CliConfig
|
2
|
+
MAX_GET_PARTIAL = 12_000
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
get = {} if get.nil?
|
4
|
+
class << self
|
5
|
+
attr_reader :options, :session
|
6
|
+
attr_writer :get_full, :get_partial
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
def get_options # rubocop:disable Naming/AccessorMethodName
|
9
|
+
get = options.dig(:people, :get)
|
10
|
+
get = {} if get.nil?
|
11
|
+
get
|
12
|
+
end
|
13
|
+
|
14
|
+
def no_get?
|
15
|
+
get_options == false
|
16
|
+
end
|
10
17
|
|
11
|
-
|
12
|
-
|
13
|
-
|
18
|
+
def from_remote?
|
19
|
+
return false unless get_options
|
20
|
+
|
21
|
+
get_options[:from] == :remote
|
22
|
+
end
|
23
|
+
|
24
|
+
def from_local?
|
25
|
+
return false unless get_options
|
26
|
+
|
27
|
+
get_options[:from] == :local
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_full?
|
31
|
+
return @get_full if instance_variable_defined?(:@get_full)
|
32
|
+
return false unless from_remote?
|
33
|
+
|
34
|
+
get_options[:type] == :full
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_partial?
|
38
|
+
return @get_partial if instance_variable_defined?(:@get_partial)
|
39
|
+
return false unless from_remote?
|
40
|
+
|
41
|
+
@get_partial = (get_options[:type] == :partial)
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_by_file?
|
45
|
+
return false unless from_local?
|
46
|
+
|
47
|
+
get_options[:type] == :file
|
48
|
+
end
|
49
|
+
|
50
|
+
def source_file
|
51
|
+
return unless get_by_file?
|
52
|
+
|
53
|
+
get_options[:file]
|
54
|
+
end
|
55
|
+
|
56
|
+
def switch_to_full_remote!
|
57
|
+
self.get_full = true
|
58
|
+
self.get_partial = false
|
59
|
+
|
60
|
+
options.deep_merge!(people: {
|
61
|
+
get: {
|
62
|
+
from: :remote,
|
63
|
+
type: :full
|
64
|
+
}
|
65
|
+
})
|
66
|
+
end
|
67
|
+
|
68
|
+
def switch_to_full_local!
|
69
|
+
self.get_full = true
|
70
|
+
self.get_partial = false
|
71
|
+
|
72
|
+
options.deep_merge!(people: {
|
73
|
+
get: {
|
74
|
+
from: :local,
|
75
|
+
type: :full
|
76
|
+
}
|
77
|
+
})
|
78
|
+
end
|
79
|
+
|
80
|
+
def optimize_get_partial!(input)
|
81
|
+
return unless get_partial?
|
14
82
|
|
15
|
-
# -get-partial: validate input present and under max
|
16
|
-
if get_partial
|
17
83
|
msg = "To use -get-partial (partial updates), you need to use -entries-from"
|
18
84
|
raise msg unless input.is_a?(Enumerable)
|
19
85
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
options.deep_merge!(people: {
|
31
|
-
get: {
|
32
|
-
from: :remote,
|
33
|
-
type: :full
|
34
|
-
}
|
35
|
-
})
|
36
|
-
end
|
86
|
+
return unless input.count > MAX_GET_PARTIAL
|
87
|
+
|
88
|
+
msg = "(Optimization) "
|
89
|
+
msg << "Switching from partial to full people download. "
|
90
|
+
msg << "Input (#{input.count}) surpases MAX_GET_PARTIAL "
|
91
|
+
msg << "(#{MAX_GET_PARTIAL}) entries."
|
92
|
+
session.log(:info) { msg }
|
93
|
+
|
94
|
+
switch_to_full_remote!
|
37
95
|
end
|
96
|
+
end
|
97
|
+
|
98
|
+
people do |input, session, options|
|
99
|
+
@options = options
|
100
|
+
@session = session
|
38
101
|
|
39
|
-
|
102
|
+
# -get-partial: validate input present and under max
|
103
|
+
optimize_get_partial!(input) if get_partial?
|
104
|
+
|
105
|
+
if no_get?
|
40
106
|
Eco::API::Organization::People.new([])
|
41
|
-
elsif get_full
|
107
|
+
elsif get_full?
|
42
108
|
# -get-people
|
43
109
|
session.micro.people_cache
|
44
|
-
elsif get_partial
|
110
|
+
elsif get_partial?
|
45
111
|
# -get-partial
|
46
112
|
session.micro.people_search(input, options: options)
|
47
|
-
elsif get_by_file
|
113
|
+
elsif get_by_file?
|
48
114
|
# -people-from-backup
|
49
|
-
session.micro.people_load(
|
115
|
+
session.micro.people_load(source_file, modifier: :file)
|
50
116
|
else
|
51
|
-
|
52
|
-
get: {
|
53
|
-
from: :local,
|
54
|
-
type: :full
|
55
|
-
}
|
56
|
-
})
|
57
|
-
|
117
|
+
switch_to_full_local!
|
58
118
|
people = session.micro.people_load(modifier: %i[newest save])
|
59
119
|
|
60
120
|
if people.empty?
|
61
|
-
|
62
|
-
get: {
|
63
|
-
from: :remote,
|
64
|
-
type: :full
|
65
|
-
}
|
66
|
-
})
|
121
|
+
switch_to_full_remote!
|
67
122
|
people = session.micro.people_cache
|
68
123
|
end
|
69
124
|
|
@@ -92,7 +92,10 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
|
|
92
92
|
sch_id = session.schemas.to_id(sch_name)
|
93
93
|
|
94
94
|
unless sch_id
|
95
|
-
msg = "You need to specify a correct schema id or name.
|
95
|
+
msg = "You need to specify a correct schema id or name. "
|
96
|
+
msg << "'#{sch_name}' does not exist. Correct options are: "
|
97
|
+
msg << session.schemas.map(&:name).join(", ")
|
98
|
+
|
96
99
|
session.log(:error) { msg }
|
97
100
|
exit(1)
|
98
101
|
end
|
@@ -108,6 +111,7 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
|
|
108
111
|
session.log(:info) {
|
109
112
|
"Filtered #{filtered.count} people out of #{people.count} total"
|
110
113
|
}
|
114
|
+
|
111
115
|
people.newFrom filtered
|
112
116
|
end
|
113
117
|
end
|