eco-helpers 3.0.3 → 3.0.6
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 +4 -0
- data/CHANGELOG.md +45 -1
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api/common/class_helpers.rb +24 -23
- data/lib/eco/api/common/class_meta_basics.rb +0 -2
- data/lib/eco/api/common/loaders/use_case.rb +1 -0
- data/lib/eco/api/common/people/entry_factory.rb +6 -4
- data/lib/eco/api/common/people/person_entry.rb +4 -6
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +25 -12
- data/lib/eco/api/common/people/person_parser.rb +9 -0
- data/lib/eco/api/common/session/base_session.rb +1 -1
- data/lib/eco/api/common/session/environment.rb +7 -0
- data/lib/eco/api/common/session/file_manager.rb +15 -8
- data/lib/eco/api/common/session/logger/cache.rb +14 -10
- data/lib/eco/api/common/session/logger/log.rb +8 -7
- data/lib/eco/api/common/session/mailer.rb +22 -13
- data/lib/eco/api/common/session/s3_uploader.rb +29 -20
- data/lib/eco/api/microcases/people_search.rb +1 -1
- data/lib/eco/api/organization/login_providers.rb +11 -4
- data/lib/eco/api/organization/node_classifications.rb +3 -0
- data/lib/eco/api/organization/presets_factory.rb +37 -31
- data/lib/eco/api/organization/tag_tree.rb +14 -5
- data/lib/eco/api/policies/default_policies/99_user_access_policy.rb +28 -18
- data/lib/eco/api/session/batch/errors.rb +38 -20
- data/lib/eco/api/session/batch/job.rb +252 -135
- data/lib/eco/api/session/batch/status.rb +55 -36
- data/lib/eco/api/session/batch.rb +2 -2
- data/lib/eco/api/session/config/base_config.rb +12 -11
- data/lib/eco/api/session/config/tagtree.rb +10 -14
- data/lib/eco/api/session/config/workflow.rb +15 -3
- data/lib/eco/api/session/config.rb +19 -26
- data/lib/eco/api/session.rb +13 -4
- data/lib/eco/api/usecases/cli.rb +4 -0
- data/lib/eco/api/usecases/default/locations/cli/codes_to_tags_cli.rb +18 -0
- data/lib/eco/api/usecases/default/locations/cli/csv_to_tree_cli.rb +12 -0
- data/lib/eco/api/usecases/default/locations/cli/tagtree_paths_cli.rb +12 -0
- data/lib/eco/api/usecases/default/locations/codes_to_tags_case.rb +32 -13
- data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +15 -5
- data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +6 -0
- data/lib/eco/api/usecases/default/locations/tagtree_paths_case.rb +51 -0
- data/lib/eco/api/usecases/default/locations.rb +1 -1
- data/lib/eco/api/usecases/default/people/amend/cli/reinvite_sync_cli.rb +8 -0
- data/lib/eco/api/usecases/default/people/amend/cli/reinvite_trans_cli.rb +11 -0
- data/lib/eco/api/usecases/default/people/amend/cli/restore_db_cli.rb +26 -0
- data/lib/eco/api/usecases/default/people/amend/reinvite_sync_case.rb +2 -0
- data/lib/eco/api/usecases/default/people/amend/reinvite_trans_case.rb +2 -0
- data/lib/eco/api/usecases/default/people/amend/restore_db_case.rb +3 -0
- data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +15 -5
- data/lib/eco/api/usecases/default/people/treat/cli/analyse_people_cli.rb +66 -0
- data/lib/eco/api/usecases/default/people/treat/cli/org_data_convert_cli.rb +35 -0
- data/lib/eco/api/usecases/default/people/treat/cli/supers_cyclic_identify_cli.rb +15 -0
- data/lib/eco/api/usecases/default/people/treat/cli/supers_hierachy_cli.rb +15 -0
- data/lib/eco/api/usecases/default/people/treat/org_data_convert_case.rb +11 -5
- data/lib/eco/api/usecases/default/people/treat/supers_cyclic_identify_case.rb +28 -7
- data/lib/eco/api/usecases/default/people/treat/supers_hierarchy_case.rb +32 -9
- data/lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb +2 -1
- data/lib/eco/api/usecases/default/utils/split_csv_case.rb +9 -2
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +2 -2
- data/lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb +5 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +2 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +2 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +2 -1
- data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +3 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +1 -0
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +3 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +2 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +1 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +2 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +6 -2
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +6 -2
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +2 -0
- data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples/helpers_migration/copying.rb +66 -29
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +25 -3
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +10 -0
- data/lib/eco/api/usecases/use_case.rb +3 -1
- data/lib/eco/cli/config/use_cases.rb +4 -0
- data/lib/eco/cli/scripting/args_helpers.rb +3 -2
- data/lib/eco/cli/scripting/argument.rb +2 -2
- data/lib/eco/cli_default/input.rb +49 -45
- data/lib/eco/cli_default/input_filters.rb +32 -17
- data/lib/eco/cli_default/options.rb +8 -4
- data/lib/eco/cli_default/people.rb +1 -1
- data/lib/eco/cli_default/people_filters.rb +32 -24
- data/lib/eco/cli_default/usecases.rb +8 -121
- data/lib/eco/cli_default/workflow.rb +6 -4
- data/lib/eco/csv/split.rb +22 -5
- data/lib/eco/csv/table.rb +13 -0
- data/lib/eco/csv.rb +4 -2
- data/lib/eco/data/files/encoding.rb +15 -8
- data/lib/eco/data/files/helpers.rb +6 -2
- data/lib/eco/data/hashes/diff_result.rb +5 -0
- data/lib/eco/data/locations/node_diff/nodes_diff.rb +13 -0
- data/lib/eco/data/locations/node_diff.rb +4 -0
- data/lib/eco/data/locations/node_level.rb +6 -0
- data/lib/eco/language/auxiliar_logger.rb +2 -0
- data/lib/eco/version.rb +1 -1
- data/lib/eco-helpers.rb +1 -1
- metadata +15 -6
- data/lib/eco/api/usecases/default/locations/create_tag_paths_case.rb +0 -25
- data/lib/eco/api/usecases/default/people/amend/reinvite_trans_cli.rb +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 18d17b73673167619a4e704756a4e59f5d81d61a97e495721e100fe3e10d2374
|
|
4
|
+
data.tar.gz: a873e8e8970c5d67aa224ac226bec8194f81e2025bcd434b4f1005b8ddba21a3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 362fa919cbbdd98a7d69e99fa793f42a31fd790513d4d0e62db1e5838bf4937526fceb03139f394c069fd376d7a10c2cfcedf7207cda9377838b441022fa1a2f
|
|
7
|
+
data.tar.gz: 95064a493e111f68cf5da145f6322e9a30d1c7a2ce48c022b776109fc581ba7c1fd63dbb0a26dae7dcbd0c67086ec5ee0c7c507deae55cf45aa8ed73704ecb4c
|
data/.rubocop.yml
CHANGED
|
@@ -33,6 +33,8 @@ Style/BlockDelimiters:
|
|
|
33
33
|
Style/HashSyntax:
|
|
34
34
|
EnforcedShorthandSyntax: either
|
|
35
35
|
EnforcedStyle: no_mixed_keys
|
|
36
|
+
Style/ArgumentsForwarding:
|
|
37
|
+
UseAnonymousForwarding: false
|
|
36
38
|
Style/ClassAndModuleChildren:
|
|
37
39
|
Enabled: false
|
|
38
40
|
Style/FrozenStringLiteralComment:
|
|
@@ -96,3 +98,5 @@ Naming/MethodParameterName:
|
|
|
96
98
|
AllowedNames: ['x', 'y', 'i', 'j', 'id', 'io', 'to']
|
|
97
99
|
Naming/RescuedExceptionsVariableName:
|
|
98
100
|
Enabled: false
|
|
101
|
+
Naming/BlockForwarding:
|
|
102
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
-
## [3.0.
|
|
5
|
+
## [3.0.7] - 2024-08-xx
|
|
6
6
|
|
|
7
7
|
### Added
|
|
8
8
|
|
|
@@ -10,6 +10,50 @@ All notable changes to this project will be documented in this file.
|
|
|
10
10
|
|
|
11
11
|
### Fixed
|
|
12
12
|
|
|
13
|
+
## [3.0.6] - 2024-08-26
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- `Eco::API::Microcases#people_search`
|
|
20
|
+
- Change to `silence: false` by default
|
|
21
|
+
- `Eco::Language::AuxiliarLogger#log`
|
|
22
|
+
- prevent call if `logger` object doesn't have method
|
|
23
|
+
- Various refactors
|
|
24
|
+
- Upgrade `ecoportal-api-v2` **gem**
|
|
25
|
+
- `Eco::API::UseCases::Cli`
|
|
26
|
+
- Made **inheritable** the class vars: `description`, `cli_name`, `callback`, and `options`
|
|
27
|
+
- Move case options to self-contained **cli** class
|
|
28
|
+
- `-restore-db`
|
|
29
|
+
- `-reinvite`, `-reinvite-from`
|
|
30
|
+
- `-codes-to-tags`
|
|
31
|
+
- `-tagtree-paths` (prev: `-create-tag-paths`)
|
|
32
|
+
- `-analyse-people`
|
|
33
|
+
- `-org-data-convert`
|
|
34
|
+
- `-identify-cyclic-supers`
|
|
35
|
+
- `-supers-hierarchy`
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
|
|
39
|
+
- `Eco::API::Common::People::PersonEntryAttributeMapper`
|
|
40
|
+
- method `#to_internal`, was missing to correcty return `attr`
|
|
41
|
+
- `Eco::Csv::Split`
|
|
42
|
+
- missing attr writers for `total_count` and `copy_count`
|
|
43
|
+
- CLI **suggestions**: when no suggestions / corrections, show still the unknown option.
|
|
44
|
+
- `Eco::API::Organization::TagTree`
|
|
45
|
+
- fix paths tracking
|
|
46
|
+
- `Eco::API::Organization::LoginProviders`
|
|
47
|
+
- identify `magic_link`
|
|
48
|
+
|
|
49
|
+
## [3.0.4] - 2024-08-14
|
|
50
|
+
|
|
51
|
+
### Added
|
|
52
|
+
|
|
53
|
+
- `Eco::Csv::Split` add `total_count` and `copy_count`
|
|
54
|
+
- `Eco::API::Common::People::PersonParser`
|
|
55
|
+
- added core attribute `brand_id`
|
|
56
|
+
|
|
13
57
|
## [3.0.3] - 2024-08-13
|
|
14
58
|
|
|
15
59
|
### Added
|
data/eco-helpers.gemspec
CHANGED
|
@@ -41,7 +41,7 @@ Gem::Specification.new do |spec|
|
|
|
41
41
|
spec.add_dependency 'dotenv', '~> 3'
|
|
42
42
|
spec.add_dependency 'ecoportal-api', '~> 0.10'
|
|
43
43
|
spec.add_dependency 'ecoportal-api-graphql', '~> 0.4', '>= 0.4.1'
|
|
44
|
-
spec.add_dependency 'ecoportal-api-v2', '~> 2.0', '>= 2.0.
|
|
44
|
+
spec.add_dependency 'ecoportal-api-v2', '~> 2.0', '>= 2.0.9'
|
|
45
45
|
spec.add_dependency 'ed25519', '~> 1.2'
|
|
46
46
|
spec.add_dependency 'fast_excel', '>= 0.5.0', '< 0.6'
|
|
47
47
|
spec.add_dependency 'fuzzy_match', '>= 2.1.0', '< 2.2'
|
|
@@ -2,7 +2,6 @@ module Eco
|
|
|
2
2
|
module API
|
|
3
3
|
module Common
|
|
4
4
|
module ClassHelpers
|
|
5
|
-
|
|
6
5
|
# Creates a class and instance object methods with name `name` to resolve `klass` name
|
|
7
6
|
def class_resolver(name, klass)
|
|
8
7
|
define_singleton_method(name) { resolve_class(klass) }
|
|
@@ -15,18 +14,18 @@ module Eco
|
|
|
15
14
|
@resolved ||= {}
|
|
16
15
|
@resolved[klass] ||=
|
|
17
16
|
case klass
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
when Class
|
|
18
|
+
klass
|
|
19
|
+
when String
|
|
20
|
+
begin
|
|
21
|
+
Kernel.const_get(klass)
|
|
22
|
+
rescue NameError
|
|
23
|
+
raise if exception
|
|
24
|
+
end
|
|
25
|
+
when Symbol
|
|
26
|
+
resolve_class(self.send(klass))
|
|
27
|
+
else
|
|
28
|
+
raise "Unknown class: #{klass}" if exception
|
|
30
29
|
end
|
|
31
30
|
end
|
|
32
31
|
|
|
@@ -34,9 +33,9 @@ module Eco
|
|
|
34
33
|
# @param key [String, Symbol] to be normalized
|
|
35
34
|
# @return [String] a correct constant name
|
|
36
35
|
def to_constant(key)
|
|
37
|
-
|
|
36
|
+
key.to_s.strip.split(/[\-\_ ]/i).compact.map do |str|
|
|
38
37
|
str.slice(0).upcase + str.slice(1..-1).downcase
|
|
39
|
-
end.join
|
|
38
|
+
end.join
|
|
40
39
|
end
|
|
41
40
|
|
|
42
41
|
# Helper to create an instance variable `name`
|
|
@@ -61,7 +60,7 @@ module Eco
|
|
|
61
60
|
parent_space = parent_space ? resolve_class(parent_space) : self
|
|
62
61
|
full_class_name = "#{parent_space}::#{class_name}"
|
|
63
62
|
|
|
64
|
-
unless target_class = resolve_class(full_class_name, exception: false)
|
|
63
|
+
unless (target_class = resolve_class(full_class_name, exception: false))
|
|
65
64
|
target_class = Class.new(inherits)
|
|
66
65
|
parent_space.const_set class_name, target_class
|
|
67
66
|
end
|
|
@@ -81,9 +80,9 @@ module Eco
|
|
|
81
80
|
return [] if scope.empty?
|
|
82
81
|
scope.select do |klass|
|
|
83
82
|
klass < parent_class
|
|
84
|
-
end.sort do |
|
|
85
|
-
next -1 if
|
|
86
|
-
next 1 if
|
|
83
|
+
end.sort do |k_1, k_2|
|
|
84
|
+
next -1 if k_2 < k_1
|
|
85
|
+
next 1 if k_1 < k_2
|
|
87
86
|
0
|
|
88
87
|
end.tap do |siblings|
|
|
89
88
|
if direct
|
|
@@ -98,7 +97,7 @@ module Eco
|
|
|
98
97
|
# @param direct [Boolean] it will only include direct child classes.
|
|
99
98
|
# @return [Boolean] `true` if the current class has child classes, and `false` otherwise.
|
|
100
99
|
def descendants?(parent_class: self, direct: false)
|
|
101
|
-
descendants(parent_class: parent_class, direct: direct).length
|
|
100
|
+
descendants(parent_class: parent_class, direct: direct).length.positive?
|
|
102
101
|
end
|
|
103
102
|
|
|
104
103
|
# Keeps track on class instance variables that should be inherited by child classes.
|
|
@@ -106,18 +105,20 @@ module Eco
|
|
|
106
105
|
# - subclasses will inherit the value as is at that moment
|
|
107
106
|
# - any change afterwards will be only on the specific class (in line with class instance variables)
|
|
108
107
|
# - adapted from https://stackoverflow.com/a/10729812/4352306
|
|
109
|
-
# TODO: this separates the logic of the method to the instance var.
|
|
108
|
+
# TODO: this separates the logic of the method to the instance var.
|
|
109
|
+
# Think if would be possible to join them somehow.
|
|
110
110
|
def inheritable_class_vars(*vars)
|
|
111
111
|
@inheritable_class_vars ||= [:inheritable_class_vars]
|
|
112
112
|
@inheritable_class_vars += vars
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
-
# Builds the attr_reader and attr_writer of `attrs` and registers
|
|
115
|
+
# Builds the attr_reader and attr_writer of `attrs` and registers
|
|
116
|
+
# the associated instance variable as inheritable.
|
|
116
117
|
def inheritable_attrs(*attrs)
|
|
117
118
|
attrs.each do |attr|
|
|
118
119
|
class_eval %(
|
|
119
120
|
class << self; attr_accessor :#{attr} end
|
|
120
|
-
)
|
|
121
|
+
), __FILE__, __LINE__ - 2
|
|
121
122
|
end
|
|
122
123
|
inheritable_class_vars(*attrs)
|
|
123
124
|
end
|
|
@@ -2,14 +2,12 @@ module Eco
|
|
|
2
2
|
module API
|
|
3
3
|
module Common
|
|
4
4
|
module ClassMetaBasics
|
|
5
|
-
|
|
6
5
|
# Helps to define methods and keep track on them
|
|
7
6
|
def define(name, &block)
|
|
8
7
|
name = name.to_sym
|
|
9
8
|
@helpers[name] = block
|
|
10
9
|
define_method(name.to_sym, &block)
|
|
11
10
|
end
|
|
12
|
-
|
|
13
11
|
end
|
|
14
12
|
end
|
|
15
13
|
end
|
|
@@ -128,7 +128,7 @@ module Eco
|
|
|
128
128
|
# Support for multiple file
|
|
129
129
|
if file.is_a?(Array)
|
|
130
130
|
return file.each_with_object([]) do |f, out|
|
|
131
|
-
|
|
131
|
+
log(:info) { "Parsing file '#{f}'" }
|
|
132
132
|
curr = to_array_of_hashes(**kargs.merge(file: f))
|
|
133
133
|
out.concat(curr)
|
|
134
134
|
end
|
|
@@ -141,7 +141,9 @@ module Eco
|
|
|
141
141
|
|
|
142
142
|
case content
|
|
143
143
|
when Hash
|
|
144
|
-
|
|
144
|
+
log(:error) {
|
|
145
|
+
"Input data as 'Hash' not supported. Expecting 'Enumerable' or 'String'"
|
|
146
|
+
}
|
|
145
147
|
exit(1)
|
|
146
148
|
when String
|
|
147
149
|
deps = {check_headers: true} if kargs[:check_headers]
|
|
@@ -221,12 +223,12 @@ module Eco
|
|
|
221
223
|
private
|
|
222
224
|
|
|
223
225
|
def abort(message)
|
|
224
|
-
|
|
226
|
+
log(:error) { message }
|
|
225
227
|
exit(1)
|
|
226
228
|
end
|
|
227
229
|
|
|
228
230
|
def fatal(msg)
|
|
229
|
-
|
|
231
|
+
log(:fatal) { msg }
|
|
230
232
|
raise msg
|
|
231
233
|
end
|
|
232
234
|
end
|
|
@@ -4,6 +4,7 @@ module Eco
|
|
|
4
4
|
module People
|
|
5
5
|
class PersonEntry
|
|
6
6
|
DEBUG = false
|
|
7
|
+
include Eco::Language::AuxiliarLogger
|
|
7
8
|
|
|
8
9
|
# This class is meant to provide a common interface to access entries of source data that come in
|
|
9
10
|
# different formats.
|
|
@@ -217,7 +218,8 @@ module Eco
|
|
|
217
218
|
set_part(person, attr, value)
|
|
218
219
|
rescue StandardError => e
|
|
219
220
|
raise unless attr == "email"
|
|
220
|
-
|
|
221
|
+
|
|
222
|
+
log(:error) { "#{e} - setting blank email instead." }
|
|
221
223
|
set_part(person, attr, nil)
|
|
222
224
|
end
|
|
223
225
|
end
|
|
@@ -515,12 +517,8 @@ module Eco
|
|
|
515
517
|
end
|
|
516
518
|
|
|
517
519
|
# LOGGER
|
|
518
|
-
def logger
|
|
519
|
-
@logger || ::Logger.new(IO::NULL)
|
|
520
|
-
end
|
|
521
|
-
|
|
522
520
|
def fatal(msg)
|
|
523
|
-
|
|
521
|
+
log(:fatal) { msg }
|
|
524
522
|
raise msg
|
|
525
523
|
end
|
|
526
524
|
|
|
@@ -2,8 +2,12 @@ module Eco
|
|
|
2
2
|
module API
|
|
3
3
|
module Common
|
|
4
4
|
module People
|
|
5
|
-
# @attr_reader direct_attrs [Array<String>] only those
|
|
5
|
+
# @attr_reader direct_attrs [Array<String>] only those
|
|
6
|
+
# internal attributes present in the person entry that
|
|
7
|
+
# do **not** have an internal/external name mapping.
|
|
6
8
|
class PersonEntryAttributeMapper
|
|
9
|
+
include Eco::Language::AuxiliarLogger
|
|
10
|
+
|
|
7
11
|
DEBUG = false
|
|
8
12
|
@@cached_warnings = {} # rubocop:disable Style/ClassVars
|
|
9
13
|
|
|
@@ -11,7 +15,8 @@ module Eco
|
|
|
11
15
|
|
|
12
16
|
# Helper class tied to `PersonEntry` that allows to track which attributes of a person entry are present
|
|
13
17
|
# and how they should be mapped between internal and external names if applicable.
|
|
14
|
-
# This class is meant to help in providing a common interface to access entries of source
|
|
18
|
+
# This class is meant to help in providing a common interface to access entries of source
|
|
19
|
+
# data that come in different formats.
|
|
15
20
|
# @note
|
|
16
21
|
# - if `data` is a `Person` object, its behaviour is `serialise`.
|
|
17
22
|
# - if `data` is **not** a `Person` object, it does a `parse`.
|
|
@@ -116,13 +121,15 @@ module Eco
|
|
|
116
121
|
# 2. if it doesn't exist, returns `nil`.
|
|
117
122
|
# @note
|
|
118
123
|
# 1. the **scope of attributes** is based on all the attributes recognized by the person parser.
|
|
119
|
-
# 2. the attributes recognized by the person parser are those of of the `Person` model
|
|
124
|
+
# 2. the attributes recognized by the person parser are those of of the `Person` model
|
|
125
|
+
# (where details attributes depend on the `schema`).
|
|
120
126
|
# @param value [String, Array<String>] value(s) to be translated into internal names.
|
|
121
127
|
# @return [String, nil, Array<String] the internal name(s) of `value`.
|
|
122
128
|
def to_internal(value)
|
|
123
129
|
# TODO: check PersonEntry#to_internal and #to_external in init_attr_trackers
|
|
124
130
|
# => when attr_map is avoided, it doesn't work as it should
|
|
125
131
|
return value unless @attr_map
|
|
132
|
+
|
|
126
133
|
attr = value
|
|
127
134
|
case value
|
|
128
135
|
when Array
|
|
@@ -136,19 +143,21 @@ module Eco
|
|
|
136
143
|
unless cached_warning("external", "spaces", value)
|
|
137
144
|
msg = "The external person field name '#{value}' contains "
|
|
138
145
|
msg << "additional spaces in the reference file"
|
|
139
|
-
|
|
146
|
+
log(:warn) { msg }
|
|
140
147
|
end
|
|
148
|
+
|
|
141
149
|
attr = @attr_map.to_internal(value.strip)
|
|
142
150
|
elsif [value, value.strip, value.strip.downcase].any? {|val| @attr_map.internal?(val)}
|
|
143
151
|
unless cached_warning("external", "reversed", value)
|
|
144
152
|
msg = "The mapper [external, internal] attribute names "
|
|
145
153
|
msg << "may be declared reversedly for EXTERNAL attribute: '#{value}'"
|
|
146
|
-
|
|
154
|
+
log(:info) { msg }
|
|
147
155
|
end
|
|
148
156
|
end
|
|
149
157
|
end
|
|
150
158
|
|
|
151
|
-
return
|
|
159
|
+
return unless @person_parser.all_model_attrs.include?(attr)
|
|
160
|
+
attr
|
|
152
161
|
end
|
|
153
162
|
|
|
154
163
|
# Serializing helper also used to do a reverse mapping when parsing:
|
|
@@ -160,11 +169,13 @@ module Eco
|
|
|
160
169
|
# 2. if it doesn't exist, returns `nil`.
|
|
161
170
|
# @note
|
|
162
171
|
# 1. the **scope of attributes** is based on all the attributes defined in the current entry.
|
|
163
|
-
# 2. the attributes recognized by the person parser are those of of the `Person` model
|
|
172
|
+
# 2. the attributes recognized by the person parser are those of of the `Person` model
|
|
173
|
+
# (where details attributes depend on the `schema`).
|
|
164
174
|
# @param value [String, Array<String>] value(s) to be translated or aliased into external ones.
|
|
165
175
|
# @return [String, nil, Array<String] the external name(s) of `value`.
|
|
166
176
|
def to_external(value)
|
|
167
177
|
return value unless @attr_map
|
|
178
|
+
|
|
168
179
|
attr = value
|
|
169
180
|
case value
|
|
170
181
|
when Array
|
|
@@ -178,7 +189,7 @@ module Eco
|
|
|
178
189
|
unless cached_warning("internal", "spaces", value)
|
|
179
190
|
msg = "The internal person field name '#{value}' contains "
|
|
180
191
|
msg << "additional spaces in the reference file"
|
|
181
|
-
|
|
192
|
+
log(:warn) { msg }
|
|
182
193
|
end
|
|
183
194
|
attr = @attr_map.to_external(value.strip)
|
|
184
195
|
elsif [value, value.strip, value.strip.downcase].any? {|val| @attr_map.external?(val)}
|
|
@@ -186,12 +197,12 @@ module Eco
|
|
|
186
197
|
msg = "The mapper [external, internal] attribute names "
|
|
187
198
|
msg << "may be declared reversedly for "
|
|
188
199
|
msg << "INTERNAL attribute: '#{value}'"
|
|
189
|
-
|
|
200
|
+
log(:info) { msg }
|
|
190
201
|
end
|
|
191
202
|
end
|
|
192
203
|
end
|
|
193
204
|
|
|
194
|
-
return
|
|
205
|
+
return unless !@external_entry || attributes(@external_entry).include?(attr)
|
|
195
206
|
attr
|
|
196
207
|
end
|
|
197
208
|
|
|
@@ -200,12 +211,14 @@ module Eco
|
|
|
200
211
|
# Whether the maps include this `attr` as mapped to itself
|
|
201
212
|
def self_mapped_attr?(attr)
|
|
202
213
|
return false unless @attr_map
|
|
214
|
+
|
|
203
215
|
@attr_map.self_mapped?(attr)
|
|
204
216
|
end
|
|
205
217
|
|
|
206
218
|
# Whether the maps include this `attr` as mapped from to some other or itself
|
|
207
219
|
def external_attr?(attr)
|
|
208
220
|
return false unless @attr_map
|
|
221
|
+
|
|
209
222
|
@attr_map.external?(attr)
|
|
210
223
|
end
|
|
211
224
|
|
|
@@ -357,7 +370,7 @@ module Eco
|
|
|
357
370
|
end
|
|
358
371
|
|
|
359
372
|
def cached_warning(*args)
|
|
360
|
-
unless exists = !!@@cached_warnings.dig(*args)
|
|
373
|
+
unless (exists = !!@@cached_warnings.dig(*args)) # rubocop:disable Style/DoubleNegation
|
|
361
374
|
args.reduce(@@cached_warnings) do |cache, level|
|
|
362
375
|
cache[level] = {} unless cache.key?(level)
|
|
363
376
|
cache[level]
|
|
@@ -367,7 +380,7 @@ module Eco
|
|
|
367
380
|
end
|
|
368
381
|
|
|
369
382
|
def fatal(msg)
|
|
370
|
-
|
|
383
|
+
log(:fatal) { msg }
|
|
371
384
|
raise msg
|
|
372
385
|
end
|
|
373
386
|
|
|
@@ -19,6 +19,7 @@ module Eco
|
|
|
19
19
|
id external_id email name
|
|
20
20
|
supervisor_id filter_tags
|
|
21
21
|
contractor_organization_id freemium
|
|
22
|
+
brand_id
|
|
22
23
|
].freeze
|
|
23
24
|
ACCOUNT_ATTRS = %w[
|
|
24
25
|
policy_group_ids default_tag
|
|
@@ -52,6 +53,7 @@ module Eco
|
|
|
52
53
|
def initialize(schema: nil)
|
|
53
54
|
msg = "Constructor needs a PersonSchema. Given: #{schema.class}"
|
|
54
55
|
raise msg if schema && !schema.is_a?(Ecoportal::API::V1::PersonSchema)
|
|
56
|
+
|
|
55
57
|
@details_attrs = []
|
|
56
58
|
@parsers = {}
|
|
57
59
|
@patch_version = 0
|
|
@@ -102,6 +104,7 @@ module Eco
|
|
|
102
104
|
# All the internal name attributes, including _core_, _account_ and _details_.
|
|
103
105
|
def all_attrs(include_defined_parsers: false)
|
|
104
106
|
return all_model_attrs | defined_model_attrs if include_defined_parsers
|
|
107
|
+
|
|
105
108
|
all_model_attrs
|
|
106
109
|
end
|
|
107
110
|
|
|
@@ -113,6 +116,7 @@ module Eco
|
|
|
113
116
|
# if `source_attrs` is not `nil`. All the _core attributes_, otherwise.
|
|
114
117
|
def target_attrs_core(source_attrs = nil)
|
|
115
118
|
return CORE_ATTRS unless source_attrs
|
|
119
|
+
|
|
116
120
|
scoped_attrs(source_attrs, CORE_ATTRS)
|
|
117
121
|
end
|
|
118
122
|
|
|
@@ -124,6 +128,7 @@ module Eco
|
|
|
124
128
|
# if `source_attrs` is not `nil`. All the _details attributes_, otherwise.
|
|
125
129
|
def target_attrs_details(source_attrs = nil)
|
|
126
130
|
return @details_attrs unless source_attrs
|
|
131
|
+
|
|
127
132
|
scoped_attrs(source_attrs, @details_attrs)
|
|
128
133
|
end
|
|
129
134
|
|
|
@@ -135,6 +140,7 @@ module Eco
|
|
|
135
140
|
# All the _account attributes_, otherwise.
|
|
136
141
|
def target_attrs_account(source_attrs = nil)
|
|
137
142
|
return ACCOUNT_ATTRS unless source_attrs
|
|
143
|
+
|
|
138
144
|
scoped_attrs(source_attrs, ACCOUNT_ATTRS)
|
|
139
145
|
end
|
|
140
146
|
|
|
@@ -212,6 +218,7 @@ module Eco
|
|
|
212
218
|
# @return [Eco::API::Common::People::PersonParser] the current object (to ease chainig).
|
|
213
219
|
def merge(parser)
|
|
214
220
|
return self unless parser
|
|
221
|
+
|
|
215
222
|
msg = "Expected a PersonParser object. Given #{parser.class}"
|
|
216
223
|
raise msg unless parser.is_a?(PersonParser)
|
|
217
224
|
|
|
@@ -236,10 +243,12 @@ module Eco
|
|
|
236
243
|
msg << "not match any type: #{@details_attrs}"
|
|
237
244
|
raise msg
|
|
238
245
|
end
|
|
246
|
+
|
|
239
247
|
Eco::API::Common::People::PersonAttributeParser.new(attr, dependencies: dependencies).tap do |parser|
|
|
240
248
|
@parsers[attr] = parser
|
|
241
249
|
definition.call(parser)
|
|
242
250
|
end
|
|
251
|
+
|
|
243
252
|
patched!
|
|
244
253
|
self
|
|
245
254
|
end
|
|
@@ -59,6 +59,13 @@ module Eco
|
|
|
59
59
|
def api?(version:)
|
|
60
60
|
config.apis.active_api.version_available?(version)
|
|
61
61
|
end
|
|
62
|
+
|
|
63
|
+
# Shortcut to logger.
|
|
64
|
+
def log(level, &block)
|
|
65
|
+
return unless logger.respond_to?(:level)
|
|
66
|
+
|
|
67
|
+
logger&.send(level, &block)
|
|
68
|
+
end
|
|
62
69
|
end
|
|
63
70
|
end
|
|
64
71
|
end
|
|
@@ -4,6 +4,7 @@ module Eco
|
|
|
4
4
|
module Session
|
|
5
5
|
class FileManager
|
|
6
6
|
include Eco::Data::Files
|
|
7
|
+
include Eco::Language::AuxiliarLogger
|
|
7
8
|
|
|
8
9
|
attr_reader :dir, :dir_path
|
|
9
10
|
attr_accessor :timestamp_pattern
|
|
@@ -20,11 +21,13 @@ module Eco
|
|
|
20
21
|
@dir = Eco::Data::Files::Directory.new(value)
|
|
21
22
|
@dir_path = @dir.create
|
|
22
23
|
rescue StandardError => err
|
|
23
|
-
|
|
24
|
+
log(:error) {
|
|
25
|
+
"could not create or make any sense of directory '#{value}': #{err}"
|
|
26
|
+
}
|
|
24
27
|
end
|
|
25
28
|
|
|
26
29
|
def logger
|
|
27
|
-
@enviro&.logger ||
|
|
30
|
+
@enviro&.logger || super
|
|
28
31
|
end
|
|
29
32
|
|
|
30
33
|
##### FILE #####
|
|
@@ -40,11 +43,13 @@ module Eco
|
|
|
40
43
|
file = dir.file(filename, should_exist: true)
|
|
41
44
|
|
|
42
45
|
unless file
|
|
43
|
-
|
|
46
|
+
log(:error) {
|
|
47
|
+
"Can't read from file '#{filename}' because it does not exist."
|
|
48
|
+
}
|
|
44
49
|
return nil
|
|
45
50
|
end
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
log(:debug) { "Reading from file '#{file}'" }
|
|
48
53
|
mode ? File.read(file, mode: mode) : File.read(file)
|
|
49
54
|
end
|
|
50
55
|
|
|
@@ -52,7 +57,9 @@ module Eco
|
|
|
52
57
|
file = dir.file(filename, should_exist: true)
|
|
53
58
|
|
|
54
59
|
unless file
|
|
55
|
-
|
|
60
|
+
log(:error) {
|
|
61
|
+
"Can't read from file '#{filename}' because it does not exist."
|
|
62
|
+
}
|
|
56
63
|
return nil
|
|
57
64
|
end
|
|
58
65
|
|
|
@@ -77,7 +84,7 @@ module Eco
|
|
|
77
84
|
FileManager.file_fullpath(file)
|
|
78
85
|
)
|
|
79
86
|
|
|
80
|
-
|
|
87
|
+
log(:debug) { "Writting to file '#{file}'" }
|
|
81
88
|
|
|
82
89
|
mode = mode == :binary ? 'wb' : 'w'
|
|
83
90
|
|
|
@@ -103,7 +110,7 @@ module Eco
|
|
|
103
110
|
FileManager.file_fullpath(file)
|
|
104
111
|
)
|
|
105
112
|
|
|
106
|
-
|
|
113
|
+
log(:debug) { "Writting to file '#{file}'" }
|
|
107
114
|
|
|
108
115
|
mode = mode == :binary ? 'wb' : 'w'
|
|
109
116
|
File.open(file, mode) { |fd| fd << content }
|
|
@@ -114,7 +121,7 @@ module Eco
|
|
|
114
121
|
def append(content, filename, mode: :string)
|
|
115
122
|
file = dir.file(filename)
|
|
116
123
|
|
|
117
|
-
|
|
124
|
+
log(:debug) { "Appending to file '#{file}'" }
|
|
118
125
|
|
|
119
126
|
mode = mode == :binary ? 'ab' : 'a'
|
|
120
127
|
File.open(file, mode) { |fd| fd << "#{content}\n" }
|
|
@@ -4,7 +4,7 @@ module Eco
|
|
|
4
4
|
module Session
|
|
5
5
|
class Logger
|
|
6
6
|
class Cache
|
|
7
|
-
LEVELS = [
|
|
7
|
+
LEVELS = %w[UNKNOWN FATAL ERROR WARN INFO DEBUG].freeze
|
|
8
8
|
|
|
9
9
|
def initialize
|
|
10
10
|
reset
|
|
@@ -44,10 +44,11 @@ module Eco
|
|
|
44
44
|
private
|
|
45
45
|
|
|
46
46
|
def where(start_time, end_time)
|
|
47
|
-
tstart
|
|
48
|
-
tend
|
|
49
|
-
condition =
|
|
47
|
+
tstart = to_datetime(start_time)
|
|
48
|
+
tend = to_datetime(end_time)
|
|
49
|
+
condition = proc do |log|
|
|
50
50
|
next true unless tstart || tend
|
|
51
|
+
|
|
51
52
|
log.after?(tstart) && log.before?(tend)
|
|
52
53
|
end
|
|
53
54
|
|
|
@@ -61,7 +62,9 @@ module Eco
|
|
|
61
62
|
|
|
62
63
|
def to_levels(value)
|
|
63
64
|
levels = [value].flatten.map {|v| to_level(v)}.compact
|
|
64
|
-
levels
|
|
65
|
+
return levels unless levels.empty?
|
|
66
|
+
|
|
67
|
+
LEVELS
|
|
65
68
|
end
|
|
66
69
|
|
|
67
70
|
def to_level(value)
|
|
@@ -71,18 +74,19 @@ module Eco
|
|
|
71
74
|
end
|
|
72
75
|
|
|
73
76
|
def valid_level!(str)
|
|
74
|
-
return true
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
return true unless str
|
|
78
|
+
return true if LEVELS.any? {|lev| str == lev}
|
|
79
|
+
|
|
80
|
+
msg = "Unknown level #{str}. Should be one of #{LEVELS}"
|
|
81
|
+
raise ArgumentError, msg
|
|
78
82
|
end
|
|
79
83
|
|
|
80
84
|
def nil_or_upcase(value)
|
|
81
85
|
value = value.to_s.upcase if value
|
|
82
86
|
return yield(value) if block_given?
|
|
87
|
+
|
|
83
88
|
value
|
|
84
89
|
end
|
|
85
|
-
|
|
86
90
|
end
|
|
87
91
|
end
|
|
88
92
|
end
|