eco-helpers 2.6.4 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +95 -0
- data/CHANGELOG.md +128 -2
- data/Rakefile +13 -7
- data/eco-helpers.gemspec +2 -2
- data/lib/eco/api/common/loaders/base.rb +2 -2
- data/lib/eco/api/common/loaders/case_base.rb +1 -1
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +5 -5
- data/lib/eco/api/common/loaders/error_handler.rb +8 -5
- data/lib/eco/api/common/loaders/parser.rb +44 -22
- data/lib/eco/api/common/loaders/policy.rb +6 -4
- data/lib/eco/api/common/loaders/use_case.rb +13 -7
- data/lib/eco/api/common/people/base_parser.rb +0 -2
- data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +0 -1
- data/lib/eco/api/common/people/default_parsers/csv_parser.rb +1 -1
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +64 -12
- data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +0 -1
- data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +13 -5
- data/lib/eco/api/common/people/default_parsers/multi_parser.rb +0 -1
- data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +18 -5
- data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +8 -8
- data/lib/eco/api/common/people/default_parsers/select_parser.rb +50 -26
- data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +6 -6
- data/lib/eco/api/common/people/default_parsers/xls_parser.rb +9 -12
- data/lib/eco/api/common/people/default_parsers.rb +1 -12
- data/lib/eco/api/common/people/entries.rb +13 -13
- data/lib/eco/api/common/people/entry_factory.rb +76 -45
- data/lib/eco/api/common/people/person_attribute_parser.rb +8 -12
- data/lib/eco/api/common/people/person_entry.rb +86 -75
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +60 -44
- data/lib/eco/api/common/people/person_factory.rb +30 -22
- data/lib/eco/api/common/people/person_modifier.rb +11 -13
- data/lib/eco/api/common/people/person_parser.rb +101 -39
- data/lib/eco/api/common/people/supervisor_helpers.rb +25 -26
- data/lib/eco/api/common/session/base_session.rb +9 -9
- data/lib/eco/api/common/session/environment.rb +7 -5
- data/lib/eco/api/common/session/sftp.rb +59 -32
- data/lib/eco/api/common/version_patches/exception.rb +11 -13
- data/lib/eco/api/error.rb +32 -20
- data/lib/eco/api/organization/node_classifications.rb +82 -0
- data/lib/eco/api/organization/policy_groups.rb +4 -6
- data/lib/eco/api/organization/tag_tree.rb +169 -93
- data/lib/eco/api/organization.rb +1 -0
- data/lib/eco/api/session/batch/job.rb +1 -1
- data/lib/eco/api/session/config/tagtree.rb +41 -23
- data/lib/eco/api/session/config/workflow.rb +113 -88
- data/lib/eco/api/session/config.rb +6 -0
- data/lib/eco/api/session.rb +51 -29
- data/lib/eco/api/usecases/base_io.rb +28 -25
- data/lib/eco/api/usecases/default/locations/cli/tagtree_extract_cli.rb +7 -2
- data/lib/eco/api/usecases/default/locations/cli/tagtree_upload_cli.rb +21 -0
- data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +3 -3
- data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +54 -23
- data/lib/eco/api/usecases/default/locations/tagtree_upload_case.rb +87 -0
- data/lib/eco/api/usecases/default/locations.rb +1 -0
- data/lib/eco/api/usecases/default/people/analyse_people_case.rb +60 -56
- data/lib/eco/api/usecases/default/people/change_email_case.rb +8 -9
- data/lib/eco/api/usecases/default/people/clean_unknown_tags_case.rb +13 -11
- data/lib/eco/api/usecases/default/people/clear_abilities_case.rb +2 -2
- data/lib/eco/api/usecases/default/people/org_data_convert_case.rb +25 -27
- data/lib/eco/api/usecases/default/people/refresh_case.rb +2 -2
- data/lib/eco/api/usecases/default/people/reinvite_trans_case.rb +1 -1
- data/lib/eco/api/usecases/default/people/reinvite_trans_cli.rb +0 -1
- data/lib/eco/api/usecases/default/people/restore_db_case.rb +39 -34
- data/lib/eco/api/usecases/default/people/set_default_tag_case.rb +19 -15
- data/lib/eco/api/usecases/default/people/supers_cyclic_identify_case.rb +16 -12
- data/lib/eco/api/usecases/default_cases/hris_case.rb +17 -15
- data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +30 -16
- data/lib/eco/api/usecases/graphql/base.rb +5 -3
- data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +4 -1
- data/lib/eco/api/usecases/graphql/helpers/base/graphql_env.rb +14 -0
- data/lib/eco/api/usecases/graphql/helpers/base.rb +5 -4
- data/lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb +60 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb +72 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base.rb +25 -59
- data/lib/eco/api/usecases/graphql/helpers/location/command/diff/as_update.rb +59 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diff/compare.rb +49 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diff.rb +11 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +46 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_archive.rb +23 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_unarchive.rb +65 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +49 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable/relation_safe_sort.rb +119 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable.rb +59 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages.rb +82 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs.rb +20 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/optimizations.rb +84 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +4 -4
- data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +24 -12
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +21 -24
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb +1 -1
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb +10 -11
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +8 -9
- data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +41 -12
- data/lib/eco/api/usecases/graphql/samples/location/command/results.rb +11 -80
- data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +89 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/service.rb +6 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +89 -0
- data/lib/eco/api/usecases/graphql/samples/location/command.rb +3 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +9 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/heading.rb +18 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/inputable.rb +53 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +34 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/helpers.rb +28 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing.rb +46 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible.rb +38 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +105 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/discarded.rb +16 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/input.rb +15 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/node_attr_maps.rb +22 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +45 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +36 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb +56 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list.rb +41 -0
- data/lib/eco/api/usecases/graphql/samples/location/service.rb +8 -0
- data/lib/eco/api/usecases/graphql/samples/location.rb +1 -0
- data/lib/eco/api/usecases/graphql/utils/sftp.rb +96 -36
- data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +8 -6
- data/lib/eco/api/usecases/ooze_samples/helpers/creatable.rb +4 -3
- data/lib/eco/api/usecases/ooze_samples/helpers/exportable_ooze.rb +39 -25
- data/lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb +13 -15
- data/lib/eco/api/usecases/ooze_samples/helpers/filters.rb +50 -21
- data/lib/eco/api/usecases/ooze_samples/helpers/ooze_handlers.rb +21 -11
- data/lib/eco/api/usecases/ooze_samples/helpers/rescuable.rb +2 -0
- data/lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb +49 -43
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +17 -19
- data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +48 -43
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +33 -34
- data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +8 -10
- data/lib/eco/api/usecases.rb +0 -1
- data/lib/eco/cli/config/use_cases.rb +31 -29
- data/lib/eco/cli_default/workflow.rb +13 -14
- data/lib/eco/csv/table.rb +34 -25
- data/lib/eco/data/hashes/array_diff.rb +24 -35
- data/lib/eco/data/hashes/diff_result/meta.rb +131 -0
- data/lib/eco/data/hashes/diff_result.rb +65 -57
- data/lib/eco/data/hashes/sanke_camel_indifferent_access.rb +278 -0
- data/lib/eco/data/hashes.rb +1 -1
- data/lib/eco/data/locations/convert.rb +1 -1
- data/lib/eco/data/locations/node_base/csv_convert.rb +19 -9
- data/lib/eco/data/locations/node_base/parsing.rb +4 -2
- data/lib/eco/data/locations/node_base/treeify.rb +149 -132
- data/lib/eco/data/locations/node_base.rb +15 -4
- data/lib/eco/data/locations/node_diff/accessors.rb +13 -5
- data/lib/eco/data/locations/node_diff/nodes_diff/clustered_treeify.rb +101 -0
- data/lib/eco/data/locations/node_diff/nodes_diff/diffs_tree.rb +99 -0
- data/lib/eco/data/locations/node_diff/{selectors.rb → nodes_diff/selectors.rb} +1 -1
- data/lib/eco/data/locations/node_diff/nodes_diff.rb +50 -35
- data/lib/eco/data/locations/node_diff.rb +45 -17
- data/lib/eco/data/locations/node_level/parsing.rb +15 -21
- data/lib/eco/data/locations/node_level.rb +66 -22
- data/lib/eco/data/locations/node_plain/parsing.rb +1 -1
- data/lib/eco/data/locations/node_plain.rb +60 -7
- data/lib/eco/data/strings/camel_case.rb +35 -0
- data/lib/eco/data/strings/snake_case.rb +18 -0
- data/lib/eco/data/strings.rb +8 -0
- data/lib/eco/data.rb +1 -0
- data/lib/eco/language/methods/call_detector.rb +11 -0
- data/lib/eco/language/methods/dsl_able.rb +7 -1
- data/lib/eco/language/methods.rb +2 -1
- data/lib/eco/language/models/collection.rb +23 -25
- data/lib/eco/language/models/parser_serializer.rb +24 -5
- data/lib/eco/version.rb +1 -1
- data/lib/eco-helpers.rb +0 -1
- metadata +52 -7
- data/lib/eco/data/hashes/diff_meta.rb +0 -52
@@ -5,9 +5,9 @@ module Eco
|
|
5
5
|
# @attr_reader direct_attrs [Array<String>] only those internal attributes present in the person entry that do **not** have an internal/external name mapping.
|
6
6
|
class PersonEntryAttributeMapper
|
7
7
|
DEBUG = false
|
8
|
-
@@cached_warnings = {}
|
8
|
+
@@cached_warnings = {} # rubocop:disable Style/ClassVars
|
9
9
|
|
10
|
-
attr_reader :
|
10
|
+
attr_reader :direct_attrs
|
11
11
|
|
12
12
|
# Helper class tied to `PersonEntry` that allows to track which attributes of a person entry are present
|
13
13
|
# and how they should be mapped between internal and external names if applicable.
|
@@ -15,14 +15,21 @@ module Eco
|
|
15
15
|
# @note
|
16
16
|
# - if `data` is a `Person` object, its behaviour is `serialise`.
|
17
17
|
# - if `data` is **not** a `Person` object, it does a `parse`.
|
18
|
-
# - currently **in rework**, so there may be subtle differences that make it
|
19
|
-
#
|
20
|
-
# @param
|
21
|
-
#
|
18
|
+
# - currently **in rework**, so there may be subtle differences that make it
|
19
|
+
# temporarily unstable (yet it is reliable).
|
20
|
+
# @param data [Hash, Ecoportal::API::V1::Person] `Person` object to
|
21
|
+
# be serialized or hashed entry to be parsed (note: `CSV::Row` is accepted).
|
22
|
+
# @param person_parser [Common::People::PersonParser] parser/serializer
|
23
|
+
# of person attributes (it contains a set of attribute parsers).
|
24
|
+
# @param attr_map [Eco::Data::Mapper] mapper to translate attribute names
|
25
|
+
# from _external_ to _internal_ names and _vice versa_.
|
22
26
|
# @param logger [Common::Session::Logger, ::Logger] object to manage logs.
|
23
27
|
def initialize(data, person_parser:, attr_map:, logger: ::Logger.new(IO::NULL))
|
24
|
-
|
25
|
-
raise
|
28
|
+
msg = "Constructor needs a PersonParser. Given: #{person_parser.class}"
|
29
|
+
raise ArgumentError, msg unless person_parser.is_a?(Eco::API::Common::People::PersonParser)
|
30
|
+
|
31
|
+
msg = "Expecting Mapper object. Given: #{attr_map.class}"
|
32
|
+
raise ArgumentError, msg if attr_map && !attr_map.is_a?(Eco::Data::Mapper)
|
26
33
|
|
27
34
|
@source = data
|
28
35
|
@person_parser = person_parser
|
@@ -30,15 +37,17 @@ module Eco
|
|
30
37
|
@logger = logger
|
31
38
|
|
32
39
|
if parsing?
|
33
|
-
@external_entry
|
40
|
+
@external_entry = data
|
34
41
|
else # SERIALIZING
|
35
|
-
@person
|
42
|
+
@person = data
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
39
|
-
# @return [Array<String>] only those internal attributes
|
46
|
+
# @return [Array<String>] only those internal attributes
|
47
|
+
# present in the person entry that have an internal/external
|
48
|
+
# name mapping.
|
40
49
|
def aliased_attrs
|
41
|
-
return @aliased_attrs
|
50
|
+
return @aliased_attrs if @aliased_attrs
|
42
51
|
if parsing?
|
43
52
|
init_attr_trackers
|
44
53
|
else
|
@@ -52,16 +61,14 @@ module Eco
|
|
52
61
|
return @internal_attrs unless data || !@internal_attrs
|
53
62
|
if parsing?
|
54
63
|
init_attr_trackers unless @internal_attrs
|
55
|
-
|
56
|
-
|
57
|
-
end
|
64
|
+
|
65
|
+
return data.keys & @person_parser.all_model_attrs if data
|
58
66
|
else
|
59
67
|
@internal_attrs = @person_parser.all_model_attrs
|
60
68
|
end
|
61
69
|
@internal_attrs
|
62
70
|
end
|
63
71
|
|
64
|
-
|
65
72
|
# @return [Array<String>] all the attrs that are present in the person entry.
|
66
73
|
def all_model_attrs(data = nil)
|
67
74
|
core_attrs(data) | account_attrs(data) | details_attrs(data)
|
@@ -115,7 +122,7 @@ module Eco
|
|
115
122
|
def to_internal(value)
|
116
123
|
# TODO: check PersonEntry#to_internal and #to_external in init_attr_trackers
|
117
124
|
# => when attr_map is avoided, it doesn't work as it should
|
118
|
-
return value
|
125
|
+
return value unless @attr_map
|
119
126
|
attr = value
|
120
127
|
case value
|
121
128
|
when Array
|
@@ -123,17 +130,20 @@ module Eco
|
|
123
130
|
to_internal(v)
|
124
131
|
end.compact
|
125
132
|
when String
|
126
|
-
|
127
|
-
when @attr_map.external?(value)
|
133
|
+
if @attr_map.external?(value)
|
128
134
|
attr = @attr_map.to_internal(value)
|
129
|
-
|
135
|
+
elsif @attr_map.external?(value.strip)
|
130
136
|
unless cached_warning("external", "spaces", value)
|
131
|
-
|
137
|
+
msg = "The external person field name '#{value}' contains "
|
138
|
+
msg << "additional spaces in the reference file"
|
139
|
+
logger.warn(msg)
|
132
140
|
end
|
133
141
|
attr = @attr_map.to_internal(value.strip)
|
134
|
-
|
142
|
+
elsif [value, value.strip, value.strip.downcase].any? {|val| @attr_map.internal?(val)}
|
135
143
|
unless cached_warning("external", "reversed", value)
|
136
|
-
|
144
|
+
msg = "The mapper [external, internal] attribute names "
|
145
|
+
msg << "may be declared reversedly for EXTERNAL attribute: '#{value}'"
|
146
|
+
logger.info(msg)
|
137
147
|
end
|
138
148
|
end
|
139
149
|
end
|
@@ -154,7 +164,7 @@ module Eco
|
|
154
164
|
# @param value [String, Array<String>] value(s) to be translated or aliased into external ones.
|
155
165
|
# @return [String, nil, Array<String] the external name(s) of `value`.
|
156
166
|
def to_external(value)
|
157
|
-
return value
|
167
|
+
return value unless @attr_map
|
158
168
|
attr = value
|
159
169
|
case value
|
160
170
|
when Array
|
@@ -162,17 +172,21 @@ module Eco
|
|
162
172
|
to_external(v)
|
163
173
|
end.compact
|
164
174
|
when String
|
165
|
-
|
166
|
-
when @attr_map.internal?(value)
|
175
|
+
if @attr_map.internal?(value)
|
167
176
|
attr = @attr_map.to_external(value)
|
168
|
-
|
177
|
+
elsif @attr_map.internal?(value.strip)
|
169
178
|
unless cached_warning("internal", "spaces", value)
|
170
|
-
|
179
|
+
msg = "The internal person field name '#{value}' contains "
|
180
|
+
msg << "additional spaces in the reference file"
|
181
|
+
logger.warn(msg)
|
171
182
|
end
|
172
183
|
attr = @attr_map.to_external(value.strip)
|
173
|
-
|
184
|
+
elsif [value, value.strip, value.strip.downcase].any? {|val| @attr_map.external?(val)}
|
174
185
|
unless cached_warning("internal", "reversed", value)
|
175
|
-
|
186
|
+
msg = "The mapper [external, internal] attribute names "
|
187
|
+
msg << "may be declared reversedly for "
|
188
|
+
msg << "INTERNAL attribute: '#{value}'"
|
189
|
+
logger.info(msg)
|
176
190
|
end
|
177
191
|
end
|
178
192
|
end
|
@@ -185,22 +199,24 @@ module Eco
|
|
185
199
|
|
186
200
|
# Whether the maps include this `attr` as mapped to itself
|
187
201
|
def self_mapped_attr?(attr)
|
188
|
-
return false
|
202
|
+
return false unless @attr_map
|
189
203
|
@attr_map.self_mapped?(attr)
|
190
204
|
end
|
191
205
|
|
192
206
|
# Whether the maps include this `attr` as mapped from to some other or itself
|
193
207
|
def external_attr?(attr)
|
194
|
-
return false
|
208
|
+
return false unless @attr_map
|
195
209
|
@attr_map.external?(attr)
|
196
210
|
end
|
197
211
|
|
198
212
|
# when parsing:
|
199
|
-
def init_attr_trackers
|
213
|
+
def init_attr_trackers # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
200
214
|
# (def) all internal attributes we can expect
|
201
215
|
def_all_attrs = @person_parser.all_model_attrs
|
202
216
|
# (def) internal attrs with no aliasing nor parser definition (expected to be direct)
|
203
|
-
def_unlinked = @person_parser.undefined_model_attrs.
|
217
|
+
def_unlinked = @person_parser.undefined_model_attrs.reject do |attr|
|
218
|
+
to_external(attr)
|
219
|
+
end
|
204
220
|
|
205
221
|
debug(
|
206
222
|
def_unlinked,
|
@@ -208,7 +224,7 @@ module Eco
|
|
208
224
|
)
|
209
225
|
|
210
226
|
# (data) data attributes (actual attributes of the entry)
|
211
|
-
data_attrs
|
227
|
+
data_attrs = attributes(@external_entry)
|
212
228
|
# (data) attributes of the data that COULD come directly as internal attribute names
|
213
229
|
# => WARNING: this includes ext direct attrs that may be aliased to other int attrs
|
214
230
|
data_direct_attrs_raw = data_attrs & def_all_attrs
|
@@ -223,7 +239,7 @@ module Eco
|
|
223
239
|
|
224
240
|
debug(
|
225
241
|
data_direct_attrs,
|
226
|
-
"(data_direct_attrs) attributes of the data that come directly as internal attribute names (data_direct_attrs_raw - data_direct_renamed)"
|
242
|
+
"(data_direct_attrs) attributes of the data that come directly as internal attribute names (data_direct_attrs_raw - data_direct_renamed)" # rubocop:disable Layout/LineLength
|
227
243
|
)
|
228
244
|
|
229
245
|
# (def) configured as alised (int <-> ext attrs) + accept/include int attrs as ext attrs
|
@@ -233,7 +249,7 @@ module Eco
|
|
233
249
|
# (def) ext attrs of the data's aliasable int attrs (def_int_aliased)
|
234
250
|
def_ext_alias = def_int_aliased.map { |attr| to_external(attr) }
|
235
251
|
# (def) those ext attrs that map to multiple int attrs
|
236
|
-
def_ext_multi_alias = def_ext_alias.detect { |attr| def_ext_alias.count(attr) > 1 }
|
252
|
+
# def_ext_multi_alias = def_ext_alias.detect { |attr| def_ext_alias.count(attr) > 1 }
|
237
253
|
# (def) those ext attrs that are direct, mapt to themselves and some other
|
238
254
|
|
239
255
|
|
@@ -267,7 +283,7 @@ module Eco
|
|
267
283
|
|
268
284
|
debug(
|
269
285
|
def_int_aliased,
|
270
|
-
"(def_int_aliased) aliasable int attrs of the input data (excludes int attrs direct as ext attrs that got renamed)"
|
286
|
+
"(def_int_aliased) aliasable int attrs of the input data (excludes int attrs direct as ext attrs that got renamed)" # rubocop:disable Layout/LineLength
|
271
287
|
)
|
272
288
|
|
273
289
|
debug(
|
@@ -277,7 +293,7 @@ module Eco
|
|
277
293
|
|
278
294
|
debug(
|
279
295
|
data_def_int_aliased,
|
280
|
-
"(data_def_int_aliased) int attrs that come aliased in the current data ((def_int_aliased - data_direct_attrs) | data_direct_self_mapped)"
|
296
|
+
"(data_def_int_aliased) int attrs that come aliased in the current data ((def_int_aliased - data_direct_attrs) | data_direct_self_mapped)" # rubocop:disable Layout/LineLength
|
281
297
|
)
|
282
298
|
|
283
299
|
debug(
|
@@ -287,16 +303,16 @@ module Eco
|
|
287
303
|
|
288
304
|
debug(
|
289
305
|
aliased_attrs,
|
290
|
-
"(aliased_attrs) all internal attributes that come aliased, with given the entry (data_def_int_aliased | data_vi_int_aliased)"
|
306
|
+
"(aliased_attrs) all internal attributes that come aliased, with given the entry (data_def_int_aliased | data_vi_int_aliased)" # rubocop:disable Layout/LineLength
|
291
307
|
)
|
292
308
|
|
293
309
|
# (data) all those ext attrs present that will require aliasing
|
294
|
-
#data_ext_alias_all
|
295
|
-
data_ext_alias_all
|
310
|
+
#data_ext_alias_all = data_def_ext_alias + data_vi_ext_alias
|
311
|
+
data_ext_alias_all = data_ext_alias | data_vi_ext_alias
|
296
312
|
|
297
313
|
debug(
|
298
314
|
data_ext_alias_all,
|
299
|
-
"(data_ext_alias_all) all those ext attrs present that will require aliasing (data_ext_alias | data_vi_ext_alias)"
|
315
|
+
"(data_ext_alias_all) all those ext attrs present that will require aliasing (data_ext_alias | data_vi_ext_alias)" # rubocop:disable Layout/LineLength
|
300
316
|
)
|
301
317
|
|
302
318
|
# those that are direct external to internal:
|
@@ -343,7 +359,7 @@ module Eco
|
|
343
359
|
def cached_warning(*args)
|
344
360
|
unless exists = !!@@cached_warnings.dig(*args)
|
345
361
|
args.reduce(@@cached_warnings) do |cache, level|
|
346
|
-
cache[level] = {}
|
362
|
+
cache[level] = {} unless cache.key?(level)
|
347
363
|
cache[level]
|
348
364
|
end
|
349
365
|
end
|
@@ -2,33 +2,44 @@ module Eco
|
|
2
2
|
module API
|
3
3
|
module Common
|
4
4
|
module People
|
5
|
-
|
6
5
|
# Helper factory to build `Ecoportal::API::V1::Person` or `Ecoportal::API::Internal::Person` objects
|
7
6
|
# @attr_reader schema [Ecoportal::API::V1::PersonSchema] person schema to be used in this person factory
|
8
7
|
# @attr_reader schema_attrs [Array<String>] _inernal names_ of the schema fields/attributes
|
9
8
|
class PersonFactory
|
10
|
-
|
11
9
|
attr_reader :schema, :schema_attrs
|
12
10
|
|
13
11
|
def initialize(person: nil, schema: {}, account: {}, modifier: Common::People::PersonModifier.new)
|
14
|
-
@modifier
|
15
|
-
@person
|
16
|
-
@account
|
17
|
-
@schema
|
18
|
-
@schema_attrs = @schema&.fields&.map
|
12
|
+
@modifier = Common::People::PersonModifier.new(modifier)
|
13
|
+
@person = person
|
14
|
+
@account = account
|
15
|
+
@schema = schema
|
16
|
+
@schema_attrs = @schema&.fields&.map(&:alt_id)
|
19
17
|
end
|
20
18
|
|
21
19
|
def new(person: nil)
|
22
20
|
in_raw_modifier = Common::People::PersonModifier.new.no_details
|
23
|
-
|
21
|
+
|
22
|
+
if person
|
23
|
+
return PersonFactory.new(
|
24
|
+
person: person,
|
25
|
+
schema: @schema,
|
26
|
+
modifier: in_raw_modifier
|
27
|
+
).new
|
28
|
+
end
|
29
|
+
|
24
30
|
person = klass.new(person_hash(@person))
|
25
31
|
person.account = account_hash(@account) if @modifier.add_account? && @modifier.internal?
|
26
32
|
person.add_details(@schema) unless @modifier.no_details?
|
27
33
|
person
|
28
34
|
end
|
29
35
|
|
30
|
-
def new_contact(schema)
|
31
|
-
factory = self.class.new(
|
36
|
+
def new_contact(schema = @schema)
|
37
|
+
factory = self.class.new(
|
38
|
+
@modifier.reset_account,
|
39
|
+
person: @person,
|
40
|
+
schema: schema,
|
41
|
+
account: @account
|
42
|
+
)
|
32
43
|
factory.new
|
33
44
|
end
|
34
45
|
|
@@ -37,7 +48,7 @@ module Eco
|
|
37
48
|
end
|
38
49
|
|
39
50
|
def schema_id
|
40
|
-
nil
|
51
|
+
nil unless @schema
|
41
52
|
@schema['schema_id'] || @schema['id']
|
42
53
|
end
|
43
54
|
|
@@ -53,19 +64,20 @@ module Eco
|
|
53
64
|
|
54
65
|
def new_hash(modifier)
|
55
66
|
modifier = Common::People::PersonModifier.new(modifier)
|
56
|
-
doc
|
67
|
+
doc = person_hash(@person)
|
57
68
|
doc = add_account(doc, @account) if modifier.add_account? && modifier.internal?
|
58
|
-
doc = add_details(doc, @schema)
|
69
|
+
doc = add_details(doc, @schema) unless modifier.no_details?
|
70
|
+
doc
|
59
71
|
end
|
60
72
|
|
61
73
|
def add_details(doc, details)
|
62
|
-
return nil
|
74
|
+
return nil unless doc
|
63
75
|
doc_det = details_hash(details)
|
64
76
|
doc.merge({ "details" => doc_det })
|
65
77
|
end
|
66
78
|
|
67
79
|
def add_account(doc, account)
|
68
|
-
return nil
|
80
|
+
return nil unless doc
|
69
81
|
doc_acc = account_hash(account)
|
70
82
|
doc.merge({ "account" => doc_acc })
|
71
83
|
end
|
@@ -85,10 +97,8 @@ module Eco
|
|
85
97
|
|
86
98
|
def details_hash(details)
|
87
99
|
case details
|
88
|
-
when Ecoportal::API::V1::PersonDetails
|
100
|
+
when Ecoportal::API::V1::PersonDetails, Ecoportal::API::V1::PersonSchema
|
89
101
|
doc = JSON.parse(details.doc.to_json)
|
90
|
-
when Ecoportal::API::V1::PersonSchema
|
91
|
-
doc =JSON.parse(details.doc.to_json)
|
92
102
|
when Hash
|
93
103
|
doc = JSON.parse(details.to_json)
|
94
104
|
doc = doc["details"] if doc.key?("details")
|
@@ -100,17 +110,15 @@ module Eco
|
|
100
110
|
end
|
101
111
|
|
102
112
|
def account_hash(account)
|
103
|
-
|
104
|
-
when account.is_a?(Ecoportal::API::Internal::Account)
|
113
|
+
if account.is_a?(Ecoportal::API::Internal::Account)
|
105
114
|
JSON.parse(account.doc.to_json)
|
106
|
-
|
115
|
+
elsif account.is_a?(Hash)
|
107
116
|
doc = JSON.parse(account.to_json)
|
108
117
|
doc["account"] if doc.key?("account")
|
109
118
|
else
|
110
119
|
{}
|
111
120
|
end
|
112
121
|
end
|
113
|
-
|
114
122
|
end
|
115
123
|
end
|
116
124
|
end
|
@@ -3,24 +3,23 @@ module Eco
|
|
3
3
|
module Common
|
4
4
|
module People
|
5
5
|
class PersonModifier < Eco::Language::Models::Modifier
|
6
|
+
WITH_DETAILS = %i[contact details with_details schema with_schema].freeze
|
7
|
+
NO_DETAILS = %i[no_details only_account].freeze
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
WITH_ACCOUNT = %i[user account with_account].freeze
|
10
|
+
NO_ACCOUNT = %i[no_account only_details].freeze
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
INTERNAL_PERSON = [:internal, :v0]
|
14
|
-
EXTERNAL_PERSON = [:external, :v1]
|
12
|
+
INTERNAL_PERSON = %i[internal v0].freeze
|
13
|
+
EXTERNAL_PERSON = %i[external v1].freeze
|
15
14
|
|
16
15
|
def reset_add_account
|
17
|
-
self <
|
16
|
+
self < mode - (WITH_ACCOUNT | NO_ACCOUNT)
|
18
17
|
end
|
19
18
|
|
20
19
|
def no_details
|
21
|
-
|
20
|
+
push(:no_details)
|
22
21
|
end
|
23
|
-
|
22
|
+
|
24
23
|
def add_account?
|
25
24
|
mode.any? { |m| WITH_ACCOUNT.include?(m) }
|
26
25
|
end
|
@@ -49,11 +48,10 @@ module Eco
|
|
49
48
|
protected
|
50
49
|
|
51
50
|
def resolve_mode
|
52
|
-
modifiers =
|
51
|
+
modifiers = to_a
|
53
52
|
modifiers = resolve(modifiers, WITH_DETAILS | NO_DETAILS)
|
54
53
|
modifiers = resolve(modifiers, WITH_ACCOUNT | NO_ACCOUNT)
|
55
|
-
|
56
|
-
modifiers
|
54
|
+
resolve(modifiers, INTERNAL_PERSON | EXTERNAL_PERSON)
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|