eco-helpers 3.0.37 → 3.1.2
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/.rubocop.yml +1 -0
- data/CHANGELOG.md +132 -1
- data/lib/eco/api/common/loaders/base.rb +2 -2
- data/lib/eco/api/common/loaders/case_base.rb +2 -0
- data/lib/eco/api/common/loaders/config/block.rb +78 -0
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +49 -6
- data/lib/eco/api/common/loaders/config.rb +3 -26
- data/lib/eco/api/common/loaders/error_handler.rb +2 -0
- data/lib/eco/api/common/loaders/parser.rb +1 -4
- data/lib/eco/api/common/people/entries.rb +23 -6
- data/lib/eco/api/common/people/entry_factory.rb +1 -1
- data/lib/eco/api/common/people/person_entry.rb +104 -27
- data/lib/eco/api/common/people/person_parser.rb +50 -16
- data/lib/eco/api/common/people/supervisor_helpers.rb +12 -6
- data/lib/eco/api/common/session/base_session.rb +75 -81
- data/lib/eco/api/common/session/environment.rb +70 -70
- data/lib/eco/api/common/session/file_manager.rb +132 -135
- data/lib/eco/api/common/session/helpers/prompt_user.rb +23 -30
- data/lib/eco/api/common/session/helpers.rb +10 -15
- data/lib/eco/api/common/session/logger/cache.rb +94 -96
- data/lib/eco/api/common/session/logger/channels.rb +24 -32
- data/lib/eco/api/common/session/logger/log.rb +38 -46
- data/lib/eco/api/common/session/logger.rb +50 -54
- data/lib/eco/api/common/session/mailer/aws_provider.rb +64 -71
- data/lib/eco/api/common/session/mailer/provider_base.rb +43 -48
- data/lib/eco/api/common/session/mailer/sendgrid_provider.rb +101 -109
- data/lib/eco/api/common/session/mailer.rb +78 -83
- data/lib/eco/api/common/session/s3_uploader.rb +132 -138
- data/lib/eco/api/common/session/sftp.rb +202 -208
- data/lib/eco/api/common.rb +0 -3
- data/lib/eco/api/custom/mailer.rb +4 -2
- data/lib/eco/api/error/handlers.rb +1 -1
- data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +8 -2
- data/lib/eco/api/microcases/people/manage/search.rb +2 -2
- data/lib/eco/api/organization/people/similarity.rb +3 -3
- data/lib/eco/api/organization/people.rb +2 -2
- data/lib/eco/api/session/batch/base_policy.rb +42 -27
- data/lib/eco/api/session/batch/launcher/mode_size.rb +6 -1
- data/lib/eco/api/session/batch/launcher.rb +16 -3
- data/lib/eco/api/session/config/api.rb +4 -3
- data/lib/eco/api/session/config/apis/one_off.rb +1 -1
- data/lib/eco/api/session/config/files.rb +13 -12
- data/lib/eco/api/session/config/workflow.rb +1 -373
- data/lib/eco/api/session/config.rb +45 -10
- data/lib/eco/api/session.rb +7 -9
- data/lib/eco/api/usecases/base_case/model.rb +6 -6
- data/lib/eco/api/usecases/base_case.rb +1 -1
- data/lib/eco/api/usecases/cli.rb +1 -1
- data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +22 -13
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -1
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +6 -3
- data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +2 -2
- data/lib/eco/api/usecases/lib/base/env.rb +21 -23
- data/lib/eco/api/usecases/lib/files/file_pattern.rb +41 -14
- data/lib/eco/api/usecases/lib/files/input_file.rb +110 -0
- data/lib/eco/api/usecases/lib/files/sftp.rb +5 -2
- data/lib/eco/api/usecases/lib/files.rb +1 -0
- data/lib/eco/api/usecases/lib/locations/base.rb +23 -0
- data/lib/eco/api/usecases/lib/locations/mapping.rb +94 -0
- data/lib/eco/api/usecases/lib/locations.rb +7 -0
- data/lib/eco/api/usecases/lib/people/base.rb +20 -0
- data/lib/eco/api/usecases/lib/people.rb +6 -0
- data/lib/eco/api/usecases/lib.rb +2 -0
- data/lib/eco/api/usecases/ooze_cases.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb +3 -3
- data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +4 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_update_case.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +6 -2
- data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +7 -6
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +14 -4
- data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +11 -8
- data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +2 -0
- data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +8 -2
- data/lib/eco/api/usecases/service/sftp/with_target_config.rb +0 -33
- data/lib/eco/api/usecases/service/sftp.rb +7 -1
- data/lib/eco/api/usecases/use_case.rb +3 -2
- data/lib/eco/api/usecases/workflow.rb +5 -0
- data/lib/eco/api/usecases.rb +12 -5
- data/lib/eco/cli/scripting/args_helpers.rb +1 -9
- data/lib/eco/cli_default/options.rb +98 -68
- data/lib/eco/cli_default/workflow/end.rb +22 -0
- data/lib/eco/cli_default/workflow/launch_jobs.rb +14 -0
- data/lib/eco/cli_default/workflow/load/data.rb +27 -0
- data/lib/eco/cli_default/workflow/load/input.rb +28 -0
- data/lib/eco/cli_default/workflow/load.rb +13 -0
- data/lib/eco/cli_default/workflow/options.rb +18 -0
- data/lib/eco/cli_default/workflow/post_launch.rb +65 -0
- data/lib/eco/cli_default/workflow/report.rb +17 -0
- data/lib/eco/cli_default/workflow/rescued_exception.rb +21 -0
- data/lib/eco/cli_default/workflow/usecases.rb +23 -0
- data/lib/eco/cli_default/workflow.rb +24 -180
- data/lib/eco/data/count_trace.rb +51 -0
- data/lib/eco/data/files/content.rb +39 -0
- data/lib/eco/data/files/directory.rb +78 -45
- data/lib/eco/data/files/encoding.rb +12 -21
- data/lib/eco/data/files/file_pattern.rb +15 -8
- data/lib/eco/data/files/folder.rb +196 -0
- data/lib/eco/data/files/relative_path.rb +54 -0
- data/lib/eco/data/files/timestamp.rb +18 -0
- data/lib/eco/data/files.rb +46 -5
- data/lib/eco/data/fuzzy_match.rb +1 -1
- data/lib/eco/data/hashes/array_diff.rb +11 -5
- data/lib/eco/data/hashes/diff_result/meta.rb +12 -4
- data/lib/eco/data/locations/node_diff/accessors.rb +1 -1
- data/lib/eco/data/mapper.rb +8 -1
- data/lib/eco/data.rb +1 -0
- data/lib/eco/language/auxiliar_logger.rb +6 -11
- data/lib/eco/language/delegation/delegating_missing.rb +1 -1
- data/lib/eco/language/delegation/delegating_missing_const.rb +1 -1
- data/lib/eco/language/delegation/delegating_missing_on_class.rb +1 -1
- data/lib/eco/language/delegation/for_delegator/delegated_class.rb +1 -1
- data/lib/eco/language/klass/auto_loader.rb +129 -0
- data/lib/eco/language/klass/builder.rb +6 -6
- data/lib/eco/language/klass/const.rb +19 -0
- data/lib/eco/language/klass/helpers_built.rb +3 -1
- data/lib/eco/language/klass/hierarchy.rb +5 -1
- data/lib/eco/language/klass/naming.rb +5 -2
- data/lib/eco/language/klass/resolver.rb +21 -6
- data/lib/eco/language/klass/uid.rb +12 -0
- data/lib/eco/language/klass/when_inherited.rb +30 -6
- data/lib/eco/language/klass.rb +5 -2
- data/lib/eco/language/methods/access_modifier.rb +23 -0
- data/lib/eco/language/methods/instance_method_helpers.rb +6 -1
- data/lib/eco/language/methods.rb +1 -0
- data/lib/eco/language/models/hierarchy.rb +41 -0
- data/lib/eco/language/models/workflow.rb +385 -0
- data/lib/eco/language/models.rb +2 -1
- data/lib/eco/version.rb +1 -1
- metadata +31 -7
- data/lib/eco/api/common/class_auto_loader.rb +0 -114
- data/lib/eco/api/common/class_helpers.rb +0 -9
- data/lib/eco/api/common/class_hierarchy.rb +0 -45
- data/lib/eco/data/files/helpers.rb +0 -152
- data/lib/eco/language/models/class_helpers.rb +0 -136
@@ -17,8 +17,8 @@ class Eco::API::UseCases::GraphQL::Samples::Location
|
|
17
17
|
# end
|
18
18
|
# end
|
19
19
|
def inputs(*_args, force_continue: force_continue?, **_kargs, &_block) # rubocop:disable Lint/UnusedMethodArgument
|
20
|
-
msg = "You should implement this method in your child class.\n
|
21
|
-
msg << 'Which should yield the input Hash and the stage or descriptor.
|
20
|
+
msg = "You should implement this method in your child class.\n"
|
21
|
+
msg << 'Which should yield the input Hash and the stage or descriptor.'
|
22
22
|
raise Eco::API::UseCases::GraphQL::Base::NotImplementedMethod, msg
|
23
23
|
end
|
24
24
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Eco::API::UseCases::Lib::Base
|
2
2
|
# Basic stuff you would need in any use case
|
3
|
-
# @note this is intended to be at the foremost part upfront
|
3
|
+
# @note this is intended to be at the foremost part upfront: with **prepend**.
|
4
4
|
module Env
|
5
5
|
class << self
|
6
6
|
def included(base)
|
@@ -14,32 +14,30 @@ module Eco::API::UseCases::Lib::Base
|
|
14
14
|
module InstanceMethods
|
15
15
|
private
|
16
16
|
|
17
|
-
def config
|
18
|
-
session.config
|
19
|
-
end
|
20
|
-
|
21
17
|
def session(required: true)
|
22
|
-
if instance_variable_defined?(:@session) && !@session.nil?
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
elsif required
|
29
|
-
raise 'Missing session object'
|
30
|
-
end
|
18
|
+
return @session if instance_variable_defined?(:@session) && !@session.nil?
|
19
|
+
return super() if defined?(super()) && !super().nil?
|
20
|
+
return ASSETS.session if Object.const_defined?(:ASSETS)
|
21
|
+
return unless required
|
22
|
+
|
23
|
+
raise 'Missing session object'
|
31
24
|
end
|
32
25
|
|
33
26
|
def options(required: true)
|
34
|
-
if instance_variable_defined?(:@options) && !@options.nil?
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
27
|
+
return @options if instance_variable_defined?(:@options) && !@options.nil?
|
28
|
+
return super() if defined?(super()) && !super().nil?
|
29
|
+
return ASSETS.cli.options if Object.const_defined?(:ASSETS)
|
30
|
+
return unless required
|
31
|
+
|
32
|
+
raise 'Missing options object'
|
33
|
+
end
|
34
|
+
|
35
|
+
def config
|
36
|
+
session.config
|
37
|
+
end
|
38
|
+
|
39
|
+
def micro
|
40
|
+
session.micro
|
43
41
|
end
|
44
42
|
end
|
45
43
|
end
|
@@ -10,7 +10,7 @@ module Eco::API::UseCases::Lib::Files
|
|
10
10
|
|
11
11
|
# Can't pass this via CLI option, as it breaks the regular expression
|
12
12
|
def file_pattern(required: true)
|
13
|
-
fpc =
|
13
|
+
fpc = file_pattern_from_const
|
14
14
|
return fpc if fpc
|
15
15
|
return unless required
|
16
16
|
|
@@ -19,21 +19,48 @@ module Eco::API::UseCases::Lib::Files
|
|
19
19
|
raise WrongConst, msg
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
22
|
+
def file_pattern_from_const
|
23
|
+
as_regex(insensitive: true) do
|
24
|
+
value = fetch_pattern_const(file_pattern_const_from_options)
|
25
|
+
|
26
|
+
next value unless value.nil?
|
27
|
+
next self.class::FILE_PATTERN if self.class.const_defined?(:FILE_PATTERN)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def file_pattern_const_from_options
|
32
|
+
return unless (fpc = options.dig(:sftp, :file_pattern_const))
|
33
|
+
|
34
|
+
fpc
|
35
|
+
end
|
36
|
+
|
37
|
+
def fetch_pattern_const(name, exception: true)
|
38
|
+
return if name.to_s.strip.empty?
|
39
|
+
|
40
|
+
msg = "(#{self.class}) Invalid file pattern const referral: #{name}"
|
41
|
+
raise WrongConst, msg unless name.match(CONST_REFERRAL)
|
42
|
+
|
43
|
+
begin
|
44
|
+
self.eval(name)
|
45
|
+
rescue NameError
|
46
|
+
self.class.const_get(name)
|
34
47
|
end
|
35
48
|
rescue NameError
|
36
|
-
raise WrongConst, "(#{self.class}) Unknown constant: #{
|
49
|
+
raise WrongConst, "(#{self.class}) Unknown constant: #{name}" if exception
|
50
|
+
end
|
51
|
+
|
52
|
+
def as_regex(value = nil, insensitive: true)
|
53
|
+
value = yield if block_given?
|
54
|
+
|
55
|
+
case value
|
56
|
+
when Regexp
|
57
|
+
value
|
58
|
+
when String
|
59
|
+
esub = Regexp.escape(value)
|
60
|
+
return /#{esub}/i if insensitive
|
61
|
+
|
62
|
+
/#{esub}/
|
63
|
+
end
|
37
64
|
end
|
38
65
|
end
|
39
66
|
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Eco::API::UseCases::Lib::Files
|
2
|
+
# @note Assumes that, if **Cli** invoked, there could be **Cli** `options` defined
|
3
|
+
# under `:input` `:file`:
|
4
|
+
# - `:name`
|
5
|
+
# - `:format` (overriding `INPUT_FORMAT` const)
|
6
|
+
# - `:encoding`
|
7
|
+
# - `:pattern` (target pattern const)
|
8
|
+
# @note it includes and extends `FilePattern`:
|
9
|
+
# - `file_pattern_from_const` would prioritize constants as accepted
|
10
|
+
# in `INPUT_FILENAME_CONSTS`
|
11
|
+
# - `file_pattern_const_from_options` would prioritize `:input` `:file` `:pattern`
|
12
|
+
module InputFile
|
13
|
+
INPUT_FILENAME_CONSTS = %i[
|
14
|
+
INPUT_FILENAME IN_FILENAME INPUT_FILE_PATTERN IN_FILE_PATTERN
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def included(base)
|
19
|
+
super
|
20
|
+
|
21
|
+
base.send :include, Eco::API::UseCases::Lib::Base::Env unless base.include?(Eco::API::UseCases::Lib::Base::Env)
|
22
|
+
base.send :extend, Eco::Data::Files::Folder
|
23
|
+
base.send :include, Eco::API::UseCases::Lib::Files::FilePattern
|
24
|
+
base.send :include, InstanceMethods
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module InstanceMethods
|
29
|
+
private
|
30
|
+
|
31
|
+
# @todo REVIEW: in practice, it collides with Sftp#local_folder
|
32
|
+
# @todo it is not clear if it should join onto `config.active_enviro`
|
33
|
+
def input_folder
|
34
|
+
File.join(
|
35
|
+
config.active_enviro,
|
36
|
+
self.class::IN_FOLDER
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def input_file
|
41
|
+
@input_file ||= (input_file_from_options || newest_file).tap do |file|
|
42
|
+
if file
|
43
|
+
log(:info) { "Using input file '#{file}'" }
|
44
|
+
else
|
45
|
+
log(:warn) { 'Could not find any input file' }
|
46
|
+
exit 0
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def input_file_from_options
|
52
|
+
options.dig(:input, :file, :name)
|
53
|
+
end
|
54
|
+
|
55
|
+
# @note assuming filenames hold a name pattern `YYYY-MM-dd`.
|
56
|
+
def newest_file
|
57
|
+
@newest_file ||= input_files.last
|
58
|
+
end
|
59
|
+
|
60
|
+
# @note based on `input_folder` && `input_file_pattern`
|
61
|
+
# @todo it some cases it has been used/defined as csv_files
|
62
|
+
def input_files(&block)
|
63
|
+
self.class.folder_files(
|
64
|
+
input_folder,
|
65
|
+
input_format,
|
66
|
+
regexp: input_file_pattern,
|
67
|
+
&block
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def input_encoding
|
72
|
+
options.dig(:input, :file, :encoding) || 'utf-8'
|
73
|
+
end
|
74
|
+
|
75
|
+
# It helps to identify the extension of the input file.
|
76
|
+
# @note it may not be essential, but good practice as a safe-guard.
|
77
|
+
def input_format
|
78
|
+
frm = options.dig(:input, :file, :format)
|
79
|
+
return frm if frm
|
80
|
+
return self.class::INPUT_FORMAT.to_sym if self.class.const_defined?(:INPUT_FORMAT)
|
81
|
+
|
82
|
+
:csv
|
83
|
+
end
|
84
|
+
|
85
|
+
def input_file_pattern
|
86
|
+
file_pattern
|
87
|
+
end
|
88
|
+
|
89
|
+
# Overrides to FilePattern
|
90
|
+
|
91
|
+
def file_pattern_from_const
|
92
|
+
as_regex(insensitive: true) do
|
93
|
+
value = INPUT_FILENAME_CONSTS.detect do |const|
|
94
|
+
next self.class.const_get(const) if self.class.const_defined?(const)
|
95
|
+
end
|
96
|
+
|
97
|
+
next value if value
|
98
|
+
|
99
|
+
super
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def file_pattern_const_from_options
|
104
|
+
return super unless (fpc = options.dig(:input, :file, :pattern))
|
105
|
+
|
106
|
+
fpc
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -74,10 +74,10 @@ module Eco::API::UseCases::Lib::Files
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
def sftp_archive_file!(filename,
|
77
|
+
def sftp_archive_file!(filename, subfolder: 'Archive')
|
78
78
|
basename = File.basename(filename)
|
79
79
|
remote_file = to_remote_path(basename)
|
80
|
-
archive_folder = to_remote_path(
|
80
|
+
archive_folder = to_remote_path(subfolder)
|
81
81
|
archived_file = "#{archive_folder}/#{basename}"
|
82
82
|
|
83
83
|
sftp_move_file(remote_file, archived_file)
|
@@ -124,6 +124,9 @@ module Eco::API::UseCases::Lib::Files
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
+
# @note it can be used for both:
|
128
|
+
# - for pulling files to
|
129
|
+
# - and for pushing files from
|
127
130
|
def local_folder
|
128
131
|
return super if defined?(super) && !super.nil?
|
129
132
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Eco::API::UseCases::Lib::Locations
|
2
|
+
module Base
|
3
|
+
class << self
|
4
|
+
def included(base)
|
5
|
+
super
|
6
|
+
|
7
|
+
base.send :include, Eco::API::UseCases::Lib::Base::Env unless base.included?(Eco::API::UseCases::Lib::Base::Env)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def location?(value)
|
14
|
+
locations.tag?(value)
|
15
|
+
end
|
16
|
+
alias_method :tag?, :location?
|
17
|
+
|
18
|
+
def locations
|
19
|
+
config.tagtree
|
20
|
+
end
|
21
|
+
alias_method :tagtree, :locations
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Eco::API::UseCases::Lib::Locations
|
2
|
+
module Mapping
|
3
|
+
LOCATION_MAPPING = true
|
4
|
+
LOCATION_MAPS_FILE = nil
|
5
|
+
LOCATION_MAPS_INTERNAL = :first
|
6
|
+
LOCATION_MAPS_INSENSITIVE = true
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def included(base)
|
10
|
+
super
|
11
|
+
|
12
|
+
base.send :include, Locations::Base
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def unknown_locations
|
17
|
+
@unknown_locations ||=
|
18
|
+
Eco::Data::CountTrace.new(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def report_unknown_locations!(msg: nil, level: :warn)
|
22
|
+
unknown_locations.report!(msg: msg, level: level)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def to_location(value)
|
28
|
+
value = value.to_s.strip
|
29
|
+
return if value.empty?
|
30
|
+
|
31
|
+
if location_mapping? && locations_mapper.external?(value)
|
32
|
+
locations_mapper.to_internal(value)
|
33
|
+
elsif location?(value)
|
34
|
+
value
|
35
|
+
else
|
36
|
+
unknown_locations.trace!(value)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
alias_method :to_tag, :to_location
|
40
|
+
|
41
|
+
def to_location_code(value)
|
42
|
+
value = value.to_s.strip
|
43
|
+
return if value.empty?
|
44
|
+
|
45
|
+
if location_mapping? && locations_mapper.internal?(value)
|
46
|
+
locations_mapper.to_external(value)
|
47
|
+
else
|
48
|
+
value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def locations_mapper(
|
53
|
+
internal: loc_maps_internal_order,
|
54
|
+
insensitive: loc_maps_insensitive,
|
55
|
+
maps_file: loc_maps_file
|
56
|
+
)
|
57
|
+
return @locations_mapper if instance_variable_defined?(:@locations_mapper)
|
58
|
+
|
59
|
+
@locations_mapper = config.locations_mapper(
|
60
|
+
internal: internal,
|
61
|
+
insensitive: insensitive,
|
62
|
+
maps_file: maps_file
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def location_mapping?
|
67
|
+
return false unless self.class::LOCATION_MAPPING
|
68
|
+
return false unless loc_maps_file
|
69
|
+
return false unless locations_mapper
|
70
|
+
return false unless locatoins_mapper.empty?
|
71
|
+
|
72
|
+
true
|
73
|
+
end
|
74
|
+
|
75
|
+
def loc_maps_file
|
76
|
+
return @loc_maps_file if instance_variable_defined?(:@loc_maps_file)
|
77
|
+
|
78
|
+
@loc_maps_file = loc_maps_file_const
|
79
|
+
@loc_maps_file ||= config.locations_map_file
|
80
|
+
end
|
81
|
+
|
82
|
+
def loc_maps_file_const
|
83
|
+
self.class::LOCATION_MAPS_FILE if self.class.const_defined?(:MAPS_FILE)
|
84
|
+
end
|
85
|
+
|
86
|
+
def loc_maps_internal_order
|
87
|
+
self.class::LOCATION_MAPS_INTERNAL
|
88
|
+
end
|
89
|
+
|
90
|
+
def loc_maps_insensitive
|
91
|
+
self.class::LOCATION_MAPS_INSENSITIVE
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Eco::API::UseCases::Lib::People
|
2
|
+
module Base
|
3
|
+
class << self
|
4
|
+
def included(base)
|
5
|
+
super
|
6
|
+
|
7
|
+
base.send :include, Eco::API::UseCases::Lib::Base::Env unless base.included?(Eco::API::UseCases::Lib::Base::Env)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def people
|
14
|
+
return @people if instance_variable_defined?(:@people) && !@people.nil?
|
15
|
+
return super if defined?(super) && !super.nil?
|
16
|
+
|
17
|
+
@people ||= micro.people_load(modifier: %i[newest save])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/eco/api/usecases/lib.rb
CHANGED
@@ -190,7 +190,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
|
|
190
190
|
def new_target(object, warn_pending_changes: true)
|
191
191
|
if dirty?(target)
|
192
192
|
if warn_pending_changes
|
193
|
-
msg =
|
193
|
+
msg = "You you are switching to a new target #{object_reference(object)}"
|
194
194
|
msg << " after doing unsaved changes to #{object_reference(target)}"
|
195
195
|
log(:warn) { msg }
|
196
196
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Use case to abstract FORM from word document
|
2
2
|
class Eco::API::UseCases::OozeSamples::OozeFromDocCase < Eco::API::UseCases::OozeSamples::OozeUpdateCase
|
3
|
-
name
|
3
|
+
name 'ooze-forms-case'
|
4
4
|
type :other
|
5
5
|
|
6
6
|
private
|
@@ -16,7 +16,7 @@ class Eco::API::UseCases::OozeSamples::OozeFromDocCase < Eco::API::UseCases::Ooz
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def with_tables
|
19
|
-
raise "There are no tables in the doc" unless table_count
|
19
|
+
raise "There are no tables in the doc" unless table_count.positive?
|
20
20
|
i = 0
|
21
21
|
doc.tables.each do |table|
|
22
22
|
yield(table, i) if block_given?
|
@@ -29,7 +29,7 @@ class Eco::API::UseCases::OozeSamples::OozeFromDocCase < Eco::API::UseCases::Ooz
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def tables?
|
32
|
-
table_count
|
32
|
+
table_count.positive?
|
33
33
|
end
|
34
34
|
|
35
35
|
def doc
|
@@ -57,7 +57,10 @@ class Eco::API::UseCases::OozeSamples::OozeRunBaseCase < Eco::API::UseCases::Ooz
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def prompt_to_confirm!
|
60
|
-
micro.prompt_user(
|
60
|
+
micro.prompt_user(
|
61
|
+
'Do you want to proceed (y/N)?',
|
62
|
+
default: 'Y'
|
63
|
+
) do |response|
|
61
64
|
exit(1) unless response.upcase.start_with?('Y')
|
62
65
|
end
|
63
66
|
end
|
@@ -8,7 +8,7 @@ class Eco::API::UseCases::OozeSamples::OozeUpdateCase < Eco::API::UseCases::Ooze
|
|
8
8
|
fld = nil
|
9
9
|
fld ||= value if value.is_a?(Ecoportal::API::V2::Page::Component)
|
10
10
|
fld ||= target.components.get_by_id(value)
|
11
|
-
fld ||= target.components.select {|
|
11
|
+
fld ||= target.components.select {|field| same_name?(field.label, value)} # rubocop:disable Lint/UselessAssignment
|
12
12
|
#fld ||= value.reference if value.is_a?(Ecoportal::API::V2::Page::Force::Binding)
|
13
13
|
end
|
14
14
|
end
|
@@ -9,6 +9,7 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
|
|
9
9
|
def batch_size(size = nil)
|
10
10
|
@batch_size ||= 25
|
11
11
|
return @batch_size unless size
|
12
|
+
|
12
13
|
@batch_size = size
|
13
14
|
end
|
14
15
|
end
|
@@ -34,7 +35,9 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
|
|
34
35
|
|
35
36
|
# Write here your script
|
36
37
|
def process_ooze(ooze = target)
|
37
|
-
|
38
|
+
msg = "You need to inherit from this class ('#{self.class}') and call super with a block"
|
39
|
+
raise ArgumentError, msg unless block_given?
|
40
|
+
|
38
41
|
yield(ooze)
|
39
42
|
end
|
40
43
|
|
@@ -94,7 +97,7 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
|
|
94
97
|
|
95
98
|
def batched_search_results
|
96
99
|
msg = "Missing block. It yields in slices of #{self.class.batch_size} results"
|
97
|
-
raise msg unless block_given?
|
100
|
+
raise ArgumentError, msg unless block_given?
|
98
101
|
|
99
102
|
results_preview
|
100
103
|
results = []
|
@@ -145,6 +148,7 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
|
|
145
148
|
end
|
146
149
|
end
|
147
150
|
end
|
151
|
+
|
148
152
|
exit_error "Stage '#{id_name}' doesn't exist in ooze '#{ooze_id}'"
|
149
153
|
end
|
150
154
|
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# Use case to offer the basics to migrate a register by creating new entries
|
2
2
|
# @note
|
3
3
|
# - You can define methods `filters` and `search` to change the target entries of the register
|
4
|
-
# - You can define a json file named after your use case file (i.e. new_training.json)
|
4
|
+
# - You can define a json file named after your use case file (i.e. new_training.json)
|
5
|
+
# to pair source-destination fields:
|
5
6
|
# - This file format expects an object {} where keys are field types (i.e. "select", "plain_text")
|
6
7
|
# and the value is an array with either:
|
7
8
|
# 1. field label name (String or RegExp body/source),
|
@@ -20,7 +21,7 @@
|
|
20
21
|
# - This is specially useful to discard rich text field guidelines (i.e. `{"rich_text" => [".*guideline:"]}`)
|
21
22
|
# This case expects `options[:source][:register_id]`
|
22
23
|
class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCases::OozeSamples::RegisterUpdateCase
|
23
|
-
name
|
24
|
+
name 'register-migration-case'
|
24
25
|
type :other
|
25
26
|
|
26
27
|
#batch_size 2
|
@@ -45,7 +46,7 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
|
|
45
46
|
def main(session, options, usecase, &block)
|
46
47
|
if options[:dry_run]
|
47
48
|
@csv = []
|
48
|
-
super
|
49
|
+
super
|
49
50
|
else
|
50
51
|
CSV.open(out_csv_filename, 'w') do |csv|
|
51
52
|
@csv = csv
|
@@ -136,7 +137,7 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
|
|
136
137
|
|
137
138
|
def script_fullname
|
138
139
|
msg = "You should define this method in the child class with this content:\n"
|
139
|
-
msg <<
|
140
|
+
msg << ' @script_fullname||= File.expand_path(__FILE__)'
|
140
141
|
raise msg
|
141
142
|
end
|
142
143
|
|
@@ -180,7 +181,7 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
|
|
180
181
|
end
|
181
182
|
|
182
183
|
def name_timestamp
|
183
|
-
@name_timestamp ||= Time.now.strftime(
|
184
|
+
@name_timestamp ||= Time.now.strftime('%Y%m%d%H%M%S')
|
184
185
|
end
|
185
186
|
|
186
187
|
def field_maps
|
@@ -196,7 +197,7 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
|
|
196
197
|
end
|
197
198
|
|
198
199
|
def script_basename
|
199
|
-
@script_basename ||= File.basename(script_fullname,
|
200
|
+
@script_basename ||= File.basename(script_fullname, '_case.rb')
|
200
201
|
end
|
201
202
|
|
202
203
|
def script_dirname
|
@@ -11,6 +11,7 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
|
|
11
11
|
def batch_size(size = nil)
|
12
12
|
@batch_size ||= 25
|
13
13
|
return @batch_size unless size
|
14
|
+
|
14
15
|
@batch_size = size
|
15
16
|
end
|
16
17
|
end
|
@@ -33,7 +34,9 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
|
|
33
34
|
process_ooze(&block)
|
34
35
|
end
|
35
36
|
elsif mode == :delegate
|
36
|
-
|
37
|
+
msg = 'You need to pass a block when running main in `:delegate` mode'
|
38
|
+
raise ArgumentError, msg unless block_given?
|
39
|
+
|
37
40
|
yield
|
38
41
|
end
|
39
42
|
end
|
@@ -80,8 +83,10 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
|
|
80
83
|
|
81
84
|
if (pending = queue_shift(page_result.id)) && dirty?(pending)
|
82
85
|
msg = 'Inconsistent search results. '
|
83
|
-
msg << "Launching update on '#{object_reference(pending)}'
|
86
|
+
msg << "Launching update on '#{object_reference(pending)}' "
|
87
|
+
msg << 'to be able to queue it back'
|
84
88
|
log(:warn) { msg }
|
89
|
+
|
85
90
|
update_ooze(pending)
|
86
91
|
end
|
87
92
|
|
@@ -101,11 +106,13 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
|
|
101
106
|
return unless object.respond_to?(:id)
|
102
107
|
|
103
108
|
unless object.is_a?(Ecoportal::API::V2::Page) or object.is_a?(Ecoportal::API::V2::Pages::PageStage)
|
104
|
-
|
109
|
+
msg = "Queuing is just for entries. Expecting Page or PageStage. Given: #{object.class}"
|
110
|
+
raise ArgumentError, msg
|
105
111
|
end
|
106
112
|
|
107
113
|
if (elem = queue_get(object.id))
|
108
114
|
msg = "Something is wrong. Native case 'RegisterUpdateCase' is "
|
115
|
+
|
109
116
|
if (elem != object) && dirty?(elem)
|
110
117
|
msg << "trying to queue different objects with same page id:\n"
|
111
118
|
msg << " * already queued (changes will go): #{object_reference(elem)}\n"
|
@@ -134,11 +141,13 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
|
|
134
141
|
end
|
135
142
|
|
136
143
|
def batched_search_results
|
137
|
-
|
144
|
+
msg = "Missing block. It yields in slices of #{self.class.batch_size} results"
|
145
|
+
raise ArgumentError, msg unless block_given?
|
138
146
|
|
139
147
|
results_preview
|
140
148
|
|
141
149
|
results = []
|
150
|
+
|
142
151
|
apiv2.registers.search(register_id, search_options) do |page_result|
|
143
152
|
results << page_result
|
144
153
|
if results.length >= self.class.batch_size
|
@@ -182,6 +191,7 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
|
|
182
191
|
end
|
183
192
|
end
|
184
193
|
end
|
194
|
+
|
185
195
|
batched_oozes.clear
|
186
196
|
end
|
187
197
|
|