eco-helpers 2.7.2 → 2.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -3
  3. data/eco-helpers.gemspec +1 -1
  4. data/lib/eco/api/common/loaders/base.rb +4 -3
  5. data/lib/eco/api/common/loaders/config/workflow/mailer.rb +2 -2
  6. data/lib/eco/api/common/loaders/parser.rb +1 -0
  7. data/lib/eco/api/common/people/default_parsers/csv_parser.rb +47 -33
  8. data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +1 -1
  9. data/lib/eco/api/common/people/default_parsers/xls_parser.rb +8 -2
  10. data/lib/eco/api/common/people/default_parsers.rb +0 -11
  11. data/lib/eco/api/common/people/person_attribute_parser.rb +2 -1
  12. data/lib/eco/api/common/people/person_entry.rb +4 -2
  13. data/lib/eco/api/session/batch/errors.rb +43 -44
  14. data/lib/eco/api/session.rb +9 -2
  15. data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +1 -1
  16. data/lib/eco/api/usecases/default/people/set_default_tag_case.rb +2 -2
  17. data/lib/eco/api/usecases/default/people/supers_cyclic_identify_case.rb +15 -17
  18. data/lib/eco/api/usecases/default/people/switch_supervisor_case.rb +26 -20
  19. data/lib/eco/api/usecases/default/people/transfer_account_case.rb +86 -70
  20. data/lib/eco/api/usecases/default_cases/hris_case.rb +1 -1
  21. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +7 -7
  22. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +1 -1
  23. data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +73 -65
  24. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +7 -1
  25. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb +1 -0
  26. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list.rb +1 -0
  27. data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +1 -1
  28. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +13 -9
  29. data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +4 -4
  30. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +9 -6
  31. data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +5 -5
  32. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +7 -5
  33. data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +2 -2
  34. data/lib/eco/api/usecases.rb +19 -13
  35. data/lib/eco/cli/scripting/args_helpers.rb +2 -0
  36. data/lib/eco/data/files/helpers.rb +25 -12
  37. data/lib/eco/data/hashes/sanke_camel_indifferent_access.rb +0 -5
  38. data/lib/eco/language/models/parser_serializer.rb +4 -2
  39. data/lib/eco/version.rb +1 -1
  40. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80de08cdef4ada108f4853214720d30985461e43309b9d442932975e7400bf20
4
- data.tar.gz: c9174f97cd87f2c092f3ec892397fa53711a7efd61d8bbd456b3e68d62d8cf03
3
+ metadata.gz: f5417454380ab9a37757721abd2b66a9097eac191ae435336fb436caeabfac49
4
+ data.tar.gz: fe83f4f50b5053050f8ff15dd43c224130a8e0bb7ece5e44aaa8e91f20c7ab77
5
5
  SHA512:
6
- metadata.gz: dfc1092476a865d1902eaf1d241b27f4a141b72d287524f41107d13b9e447a1a83d04f278e1a04046e1435b7ce5b919e597a030c7c4eb8ccadb9431e90ace039
7
- data.tar.gz: 4bf36063e2b8eca6051343a9b18ecbe61ac3e04c1789be8dc269d59f36c444690475ff0fdf42113ca74e035a41bef0d12e6d574a9845966ebbb73d4b303ef47d
6
+ metadata.gz: 8576cbd86fadc000127e2f83396e5cbf2d4b7196150fe3a7ff78c3ce987850ebe73758622678492811350434981cfa1962796dc847b39475e80b8ef61e09c6da
7
+ data.tar.gz: c6517c924dee344f9445e7213c404f7295f45ff9c41ff45b2fbad437becfd2ea8aaadc95b82b2e0189e0ade9bef299826f56910704a16954a59c0a91930133bb
data/CHANGELOG.md CHANGED
@@ -1,14 +1,34 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.7.2] - 2024-04-xx
4
+ ## [2.7.5] - 2024-05-xx
5
5
 
6
6
  ### Added
7
- - **Parsers**
8
- - Native **number parser**, added _warning_ when number cannot be parsed
7
+ ### Changed
8
+ ### Fixed
9
+ - Loading of tree diff / update service
10
+
11
+ ## [2.7.4] - 2024-05-07
12
+
13
+ ### Fixed
14
+ - Loading of tree diff / update service
15
+
16
+ ## [2.7.3] - 2024-05-07
9
17
 
10
18
  ### Changed
19
+ - upgraded `ecoportal-api-graphql`
20
+ - Mailer
21
+ - heading of errors and warnings: added **ALL** to state clearly that all warnings and errors come thereon
22
+ - Batch Errors: removed _batch_ wording, as it refers to a single action in the batch
23
+
11
24
  ### Fixed
25
+ - Tree diff helpers loading (load as if concern)
26
+
27
+ ## [2.7.2] - 2024-04-23
28
+
29
+ ### Added
30
+ - **Parsers**
31
+ - Native **number parser**, added _warning_ when number cannot be parsed
12
32
 
13
33
  ## [2.7.1] - 2024-04-23
14
34
 
data/eco-helpers.gemspec CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_dependency 'ecoportal-api', '>= 0.9.7', '< 0.10'
34
34
  spec.add_dependency 'ecoportal-api-v2', '>= 1.1.8', '< 1.2'
35
- spec.add_dependency 'ecoportal-api-graphql', '>= 0.3.15', '< 0.4'
35
+ spec.add_dependency 'ecoportal-api-graphql', '>= 0.3.16', '< 0.4'
36
36
  spec.add_dependency 'aws-sdk-s3', '>= 1.142.0', '< 2'
37
37
  spec.add_dependency 'aws-sdk-ses', '>= 1.58.0', '< 2'
38
38
  spec.add_dependency 'dotenv', '>= 2.8.1', '< 3'
@@ -54,9 +54,10 @@ module Eco
54
54
  end
55
55
 
56
56
  def abort(msg, raising: true)
57
- logger.error(msg)
58
- raise msg if raising
59
- exit 1
57
+ log(:error) { msg }
58
+ exit(1) unless raising
59
+
60
+ raise msg
60
61
  end
61
62
  end
62
63
  end
@@ -48,7 +48,7 @@ class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::W
48
48
  end
49
49
 
50
50
  def some_update?(io)
51
- cli.config.usecases.active(io: io).any? do |usecase, data|
51
+ cli.config.usecases.active(io: io).any? do |usecase, _data|
52
52
  %i[transform sync].any? { |type| usecase.type == type }
53
53
  end
54
54
  end
@@ -64,7 +64,7 @@ class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::W
64
64
  def log_err_n_warn(io)
65
65
  warn_errors = io.logger.cache.logs(level: %i[error warn])
66
66
  return if warn_errors.empty?
67
- "WARNINGS & ERRORS:\n#{warn_errors.join('')}\n"
67
+ "ALL WARNINGS & ERRORS:\n#{warn_errors.join}\n"
68
68
  end
69
69
 
70
70
  def error_message
@@ -15,6 +15,7 @@ module Eco
15
15
 
16
16
  def missing(*input_attrs)
17
17
  return [] if input_attrs.include?(attr)
18
+
18
19
  match = input_attrs & attrs
19
20
  miss = attrs - match
20
21
  return [] if miss.empty?
@@ -14,7 +14,7 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
14
14
  end
15
15
  end
16
16
 
17
- def serializer(array_hash, deps)
17
+ def serializer(array_hash, _deps)
18
18
  arr_rows = []
19
19
  unless array_hash.empty?
20
20
  header = array_hash.first.keys
@@ -27,19 +27,22 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
27
27
 
28
28
  private
29
29
 
30
- def abort(message)
31
- logger.error(message)
32
- exit(1)
30
+ def abort(msg)
31
+ super(msg, raising: false)
33
32
  end
34
33
 
35
34
  def require_headers!(table)
36
35
  headers = table.headers
37
- abort("Missing headers in CSV") unless headers && !headers.empty?
36
+
37
+ abort("Missing headers in CSV") unless headers&.any?
38
+
38
39
  empty = []
39
40
  headers.each_with_index do |header, idx|
40
41
  empty << idx if header.to_s.strip.empty?
41
42
  end
42
- abort("Empty headers in column(s): #{empty.join(', ')}") unless empty.empty?
43
+
44
+ abort("Empty headers in column(s): #{empty.join(', ')}") if empty.any?
45
+
43
46
  true
44
47
  end
45
48
 
@@ -58,12 +61,13 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
58
61
  end
59
62
 
60
63
  def null?(value)
61
- return true if !value
64
+ return true unless value
65
+
62
66
  str = value.strip.upcase
63
67
  ["NULL"].any? {|token| str == token}
64
68
  end
65
69
 
66
- def check_headers(table)
70
+ def check_headers(table) # rubocop:disable Metrics/AbcSize
67
71
  headers = table.headers
68
72
  unmatch = []
69
73
  unmatch = unmatched_headers(headers) if options.dig(:input, :header_check, :order)
@@ -72,7 +76,7 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
72
76
  criteria = [unknown, missing[:direct], missing[:indirect], unmatch]
73
77
  return if criteria.all?(&:empty?)
74
78
 
75
- msg = "Detected possible HEADER ISSUES !!!\n"
79
+ msg = "Detected possible HEADER ISSUES !!!\n"
76
80
 
77
81
  # requires exact match
78
82
  unless unmatch.empty?
@@ -86,9 +90,11 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
86
90
  msg << " - #{missed.join("\n - ")}\n"
87
91
  end
88
92
  end
93
+
89
94
  msg << "Missing or Wrong HEADER names in the CSV file:\n"
90
95
  msg << " * UNKNOWN (or not used?): #{unknown}\n" unless unknown.empty?
91
96
  msg << " * MISSING HEADER: #{missing[:direct]}\n" unless missing[:direct].empty?
97
+
92
98
  unless (data = missing[:indirect]).empty?
93
99
  msg << " * MISSING INDIRECTLY:\n"
94
100
  data.each do |ext, info|
@@ -99,13 +105,16 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
99
105
  elsif status == :active
100
106
  "there could be missing info in: #{attrs}"
101
107
  end
102
- end.compact.join("; ") + "\n"
108
+ end.compact.join("; ")
109
+ msg << "\n"
103
110
  end
104
111
  end
105
- logger.warn(msg)
106
- if options.dig(:input, :header_check, :must_be_valid)
107
- abort("There were issues identified on the CSV header names. Aborting...")
108
- end
112
+
113
+ log(:warn) { msg }
114
+
115
+ msg = "There were issues identified on the CSV header names. Aborting..."
116
+ abort(msg) if options.dig(:input, :header_check, :must_be_valid)
117
+
109
118
  sleep(2)
110
119
  end
111
120
 
@@ -119,13 +128,14 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
119
128
  (headers - known_headers) - all_internal_attrs
120
129
  end
121
130
 
122
- def missing_headers(headers)
131
+ def missing_headers(headers) # rubocop:disable Metrics/AbcSize
123
132
  int_head = internal_present_or_active(headers)
124
- ext = headers.select do |e|
133
+ external = headers.select do |e|
125
134
  i = fields_mapper.to_internal(e)
126
135
  int_head.include?(i)
127
136
  end
128
- ext_present = known_headers_present(int_head) | ext
137
+
138
+ ext_present = known_headers_present(int_head) | external
129
139
  ext_miss = known_headers - ext_present
130
140
 
131
141
  {
@@ -133,7 +143,8 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
133
143
  indirect: {}
134
144
  }.tap do |missing|
135
145
  ext_miss.each do |ext|
136
- next unless int = fields_mapper.to_internal(ext)
146
+ next unless (int = fields_mapper.to_internal(ext))
147
+
137
148
  missing[:direct] << ext if all_internal_attrs.include?(int)
138
149
  related_attrs_requirements = required_attrs.values.select do |req|
139
150
  dep = req.dependant?(int)
@@ -141,10 +152,13 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
141
152
  in_header = int_head.include?(req.attr)
142
153
  affects || (dep && !in_header)
143
154
  end
155
+
144
156
  next if related_attrs_requirements.empty?
157
+
145
158
  data = missing[:indirect][ext] = {}
146
159
  data[:int] = int
147
160
  data[:attrs] = {}
161
+
148
162
  related_attrs_requirements.each_with_object(data[:attrs]) do |req, attrs|
149
163
  status = req.active?(*int_head) ? :active : :inactive
150
164
  attrs[status] ||= []
@@ -155,32 +169,33 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
155
169
  end
156
170
 
157
171
  def known_headers_present(headers_internal)
158
- @known_internal ||= known_headers.select do |ext|
172
+ known_headers.select do |ext|
159
173
  int = fields_mapper.to_internal(ext)
160
174
  headers_internal.include?(int)
161
175
  end
162
176
  end
163
177
 
164
178
  # Scopes what internal attrs appear in headers as they are
165
- def internal_present_or_active(headers, inactive_requirements = {})
179
+ def internal_present_or_active(headers, inactive_requirements = {}) # rubocop:disable Metrics/AbcSize
166
180
  # internal attrs that are not being mapped
167
- int_all = all_internal_attrs.reject {|i| fields_mapper.external?(i)}
168
- hint = headers & int_all
169
- hext = headers - hint
181
+ int_all = all_internal_attrs.reject {|i| fields_mapper.external?(i)}
182
+ hint = headers & int_all
183
+ hext = headers - hint
170
184
  int_present = hint + hext.map {|e| fields_mapper.to_internal(e)}.compact
171
185
 
172
- update_inactive = Proc.new do
186
+ update_inactive = proc do
173
187
  inactive_requirements.dup.each do |attr, req|
174
- if req.active?(*int_present)
175
- inactive_requirements.delete(attr)
176
- int_present << attr
177
- update_inactive.call
178
- end
188
+ next unless req.active?(*int_present)
189
+
190
+ inactive_requirements.delete(attr)
191
+ int_present << attr
192
+ update_inactive.call
179
193
  end
180
194
  end
181
195
 
182
- required_attrs.values.each do |req|
196
+ required_attrs.each_value do |req|
183
197
  next if int_present.include?(req)
198
+
184
199
  if req.active?(*int_present)
185
200
  inactive_requirements.delete(req.attr)
186
201
  int_present << req.attr
@@ -189,6 +204,7 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
189
204
  inactive_requirements[req.attr] = req
190
205
  end
191
206
  end
207
+
192
208
  int_present
193
209
  end
194
210
 
@@ -202,9 +218,7 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
202
218
  end
203
219
 
204
220
  def required_attrs
205
- @required_attrs ||= person_parser.required_attrs.each_with_object({}) do |ra, out|
206
- out[ra.attr] = ra
207
- end
221
+ @required_attrs ||= person_parser.required_attrs.to_h {|ra| [ra.attr, ra]}
208
222
  end
209
223
 
210
224
  def all_internal_attrs
@@ -8,7 +8,7 @@ class Eco::API::Common::People::DefaultParsers::LoginProvidersParser < Eco::API:
8
8
  login_providers.to_id(name&.downcase&.strip).tap do |known|
9
9
  unless !name || known || unknown_pgs.include?(name)
10
10
  unknown_pgs.push(name)
11
- logger.warn("Unknown Login Provider: '#{name}'")
11
+ log(:warn) { "Unknown Login Provider: '#{name}'" }
12
12
  end
13
13
  end
14
14
  end.compact
@@ -29,7 +29,9 @@ class Eco::API::Common::People::DefaultParsers::XLSParser < Eco::API::Common::Lo
29
29
  end
30
30
 
31
31
  def headers
32
- logger.warn("Headers detection is using your fields_map.json file (native behaviour)")
32
+ log(:warn) {
33
+ "Headers detection is using your fields_map.json file (native behaviour)"
34
+ }
33
35
  session.fields_mapper.list(:external).uniq
34
36
  end
35
37
 
@@ -50,7 +52,11 @@ class Eco::API::Common::People::DefaultParsers::XLSParser < Eco::API::Common::Lo
50
52
  spreadheet.parse(header_search: target, clean: true)
51
53
  rescue Roo::HeaderRowNotFoundError => e
52
54
  missing = JSON.parse(e.message)
53
- logger.warn("The input file is missing these headers: #{missing}")
55
+
56
+ log(:warn) {
57
+ "The input file is missing these headers: #{missing}"
58
+ }
59
+
54
60
  present = target - missing
55
61
  rows(present)
56
62
  end
@@ -6,17 +6,6 @@ module Eco
6
6
  class DefaultParsers < PersonParser
7
7
  autoloads_children_of "Eco::API::Common::Loaders::Parser"
8
8
  autoload_namespace "Eco::API::Common::People::DefaultParsers"
9
-
10
- def initialize(**kargs)
11
- super(**kargs)
12
- define_defaults
13
- end
14
-
15
- private
16
-
17
- def define_defaults
18
- # SelectParser.new(self, select_hashes: select_tables).process
19
- end
20
9
  end
21
10
  end
22
11
  end
@@ -77,7 +77,8 @@ module Eco
77
77
  end
78
78
 
79
79
  # Helper to obtain the current internal named attributes of the data
80
- # @param source_data [Array<String>, Hash] if `Array` those are already the `keys`, if `Hash` it gets the `keys`
80
+ # @param source_data [Array<String>, Hash] if `Array` those are already the `keys`,
81
+ # if `Hash` it gets the `keys`
81
82
  # @return [Array<String>] `keys` of `source_data`
82
83
  def data_keys(source_data)
83
84
  case source_data
@@ -5,11 +5,13 @@ module Eco
5
5
  class PersonEntry
6
6
  DEBUG = false
7
7
 
8
- # This class is meant to provide a common interface to access entries of source data that come in different formats.
8
+ # This class is meant to provide a common interface to access entries of source data that come in
9
+ # different formats.
9
10
  # @note
10
11
  # - if `data` is a `Person` object, its behaviour is `serialise`.
11
12
  # - if `data` is **not** a `Person` object, it does a `parse`.
12
- # - currently **in rework**, so there may be subtle differences that make it temporarily unstable (yet it is reliable).
13
+ # - currently **in rework**, so there may be subtle differences that make it temporarily unstable
14
+ # (yet it is reliable).
13
15
  # @param data [Hash, Ecoportal::API::V1::Person] `Person` object
14
16
  # to be serialized or hashed entry (`CSV::Row` is accepted).
15
17
  # @param person_parser [Common::People::PersonParser] parser/serializer
@@ -4,7 +4,6 @@ module Eco
4
4
  class Batch
5
5
  # Helper object linked to a `Batch::Status`. Its aim is to manage the errors of the batch status.
6
6
  class Errors
7
-
8
7
  # @attr_reader status [Eco::API::Session::Batch::Status] `batch status` this `Errors` object is associated to.
9
8
  attr_reader :status
10
9
 
@@ -12,7 +11,9 @@ module Eco
12
11
 
13
12
  # @param status [Eco::API::Session::Batch::Status] `batch status` this `Errors` object is associated to.
14
13
  def initialize(status:)
15
- "Expected Batch::Status as root. Given: #{status.class}" unless status.is_a?(Eco::API::Session::Batch::Status)
14
+ msg = "Expected Batch::Status as root. Given: #{status.class}"
15
+ raise ArgumentError msg unless status.is_a?(Eco::API::Session::Batch::Status)
16
+
16
17
  @status = status
17
18
  end
18
19
 
@@ -52,7 +53,8 @@ module Eco
52
53
  end
53
54
 
54
55
  # Was there any _Sever_ (reply) **error** as a result of this batch?
55
- # @return [Boolean] `true` if any of the queried _entries_ got an unsuccessful `Ecoportal::API::Common::BatchResponse`
56
+ # @return [Boolean] `true` if any of the queried _entries_ got
57
+ # an unsuccessful `Ecoportal::API::Common::BatchResponse`
56
58
  def any?
57
59
  queue.any? {|query| !status[query].success?}
58
60
  end
@@ -62,14 +64,10 @@ module Eco
62
64
  # 1. `entries` that got that error, if `only_entries` is `true`
63
65
  # 2. `ErrorCache` objects, if `only_entries` is `false`
64
66
  def by_type(only_entries: true)
65
- errors.group_by do |e|
66
- e.type
67
- end.transform_values do |arr|
68
- if only_entries
69
- arr.map {|e| e.entry}
70
- else
71
- arr
72
- end
67
+ errors.group_by(&:type).transform_values do |arr|
68
+ next arr unless only_entries
69
+
70
+ arr.map(&:entry)
73
71
  end
74
72
  end
75
73
  # @!endgroup
@@ -83,27 +81,28 @@ module Eco
83
81
  def errors
84
82
  entries.each_with_object([]) do |entry, arr|
85
83
  response = status[entry]
86
- if body = response.body
87
- errs = []
88
- case body
89
- when Hash
90
- if errs = (body["errors"] || body["error"])
91
- errs = [errs].flatten(1).compact
92
- end
93
- if errs.empty? && !response.success?
94
- errs = [body["response"]].flatten(1).compact
95
- end
96
- when String
97
- errs = [body]
98
- end
99
- errs.each do |msg|
100
- arr.push(ErrorCache.new(
101
- klass = Eco::API::Error.get_type(msg),
102
- klass.new(err_msg: msg, entry: entry, session: session),
103
- entry,
104
- response
105
- ))
106
- end
84
+ next unless (body = response.body)
85
+
86
+ errs = []
87
+ case body
88
+ when Hash
89
+ body_errs = body["errors"] || body["error"]
90
+ errs = [body_errs].flatten(1).compact if body_errs
91
+
92
+ response_errs = errs.empty? && !response.success?
93
+ errs = [body["response"]].flatten(1).compact if response_errs
94
+ when String
95
+ errs = [body]
96
+ end
97
+
98
+ errs.each do |msg|
99
+ err_cache = ErrorCache.new(
100
+ klass = Eco::API::Error.get_type(msg),
101
+ klass.new(err_msg: msg, entry: entry, session: session),
102
+ entry,
103
+ response
104
+ )
105
+ arr.push(err_cache)
107
106
  end
108
107
  end
109
108
  end
@@ -112,19 +111,19 @@ module Eco
112
111
 
113
112
  def message
114
113
  msgs = strs
115
- if msgs.length > 0
116
- "There were #{msgs.length} errors:\n" + msgs.join("\n")
117
- else
114
+ if msgs.empty?
118
115
  "There were no errors for the current batch '#{method}'!! ;)"
116
+ else
117
+ "There were #{msgs.length} errors:\n" + msgs.join("\n")
119
118
  end
120
119
  end
121
120
 
122
121
  def print
123
122
  msgs = strs
124
- if msgs.length > 0
125
- logger.error("There were #{msgs.length} errors:\n" + msgs.join("\n"))
126
- else
123
+ if msgs.empty?
127
124
  logger.info("There were no errors for the current batch '#{method}'!! ;)")
125
+ else
126
+ logger.error("There were #{msgs.length} errors:\n" + msgs.join("\n"))
128
127
  end
129
128
  end
130
129
  # @!endgroup
@@ -142,12 +141,12 @@ module Eco
142
141
  # @return [Array<Hash>, Array<Ecoportal::API::V1::Person>, Array<Ecoportal::API::Internal::Person>]
143
142
  def entries
144
143
  queue.select.with_index do |query, i|
145
- unless response = status[i]
144
+ unless (response = status[i])
146
145
  msg = "Error: query with no response. You might have duplicated entries in your queue.\n"
147
146
  msg += "Queue length: #{queue.length}; Queue elements class: #{queue.first.class}\n"
148
147
  msg += "Query with no response. Person: #{person_ref(query)}\n"
149
148
  queue.map do |entry|
150
- if [:id, :external_id, :email].any? {|attr| (v = get_attr(entry, attr)) && v == get_attr(query, attr)}
149
+ if %i[id external_id email].any? {|attr| (v = get_attr(entry, attr)) && v == get_attr(query, attr)}
151
150
  msg += "It could be this peson entry (idx: #{to_index(entry)}): #{person_ref(entry)}\n"
152
151
  end
153
152
  end
@@ -184,15 +183,15 @@ module Eco
184
183
  entry = queue.to_a[i]
185
184
  response = status[i]
186
185
  msg = "Error #{response.status}: #{response.body}\n"
187
- msg += "-- Failed to batch #{method}. Person: #{person_ref(entry)}"
186
+ msg += "-- Failed to #{method}. Person: #{person_ref(entry)}"
188
187
  end
189
188
  msg
190
189
  end
191
190
 
192
191
  def print_one(key)
193
- unless status.success?(key)
194
- logger.error(str(key))
195
- end
192
+ return if status.success?(key)
193
+
194
+ logger.error(str(key))
196
195
  end
197
196
  end
198
197
  end
@@ -281,7 +281,7 @@ module Eco
281
281
  # Shortcut to create a job of certain type within a group
282
282
  # @param [see @Eco::API::Session::Batch::Jobs#new]
283
283
  # @return [Eco::API::Session::Batch::Job]
284
- def new_job(
284
+ def new_job( # rubocop:disable Metrics/ParameterLists
285
285
  group,
286
286
  name,
287
287
  type,
@@ -290,7 +290,14 @@ module Eco
290
290
  accept_update_with_no_id = false, # rubocop:disable Style/OptionalBooleanParameter
291
291
  &block
292
292
  )
293
- job_group(group).new(name, usecase: usecase, type: type, sets: sets, accept_update_with_no_id: accept_update_with_no_id, &block)
293
+ job_group(group).new(
294
+ name,
295
+ usecase: usecase,
296
+ type: type,
297
+ sets: sets,
298
+ accept_update_with_no_id: accept_update_with_no_id,
299
+ &block
300
+ )
294
301
  end
295
302
 
296
303
  # @see Eco::API::Session::Batch::JobsGroups#launch
@@ -13,7 +13,7 @@ class Eco::API::UseCases::Default::Locations::CsvToTree < Eco::API::Common::Load
13
13
  File.open(output_file, "w") do |fd|
14
14
  fd << tree_struct.as_json.to_json
15
15
  end
16
- logger.info("Saved structure in '#{output_file}'")
16
+ log(:info) { "Saved structure in '#{output_file}'" }
17
17
  end
18
18
 
19
19
  private
@@ -6,7 +6,7 @@ class Eco::API::UseCases::Default::People::SetDefaultTagCase < Eco::API::Common:
6
6
  # different options (several nodes at the same depth):
7
7
  # => take the common node between them (i.e. you have Hamilton and Auckland -> take New Zealand)
8
8
  # => if there's no common node between them, take the `first` (unless they are at top level of the tree)
9
- def main(people, session, options, usecase)
9
+ def main(_people, session, options, usecase)
10
10
  tagtree_present!
11
11
  users = users_present!
12
12
  update = session.new_job("main", "update", :update, usecase, :account)
@@ -22,7 +22,7 @@ class Eco::API::UseCases::Default::People::SetDefaultTagCase < Eco::API::Common:
22
22
  def tagtree_present!
23
23
  return unless tagtree?
24
24
 
25
- msg = "There is no locs struct defined. Aborting..."
25
+ msg = "There is no locs struct defined. Aborting..."
26
26
  logger.fatal(msg)
27
27
  raise msg
28
28
  end
@@ -4,7 +4,7 @@ class Eco::API::UseCases::Default::People::SupersCyclicIdentify < Eco::API::Comm
4
4
 
5
5
  attr_reader :people
6
6
 
7
- def main(people, session, options, usecase)
7
+ def main(_people, _session, options, _usecase)
8
8
  options[:end_get] = false
9
9
  save!(cyclic_sets)
10
10
  end
@@ -21,25 +21,23 @@ class Eco::API::UseCases::Default::People::SupersCyclicIdentify < Eco::API::Comm
21
21
 
22
22
  def save!(data)
23
23
  if data.empty?
24
- session.logger.info("There were no cyclic supervisors identified!!")
24
+ log(:info) { "There were no cyclic supervisors identified!!" }
25
25
  return
26
26
  end
27
27
 
28
28
  ext = File.extname(file).downcase.delete(".")
29
29
 
30
- File.open(file, "w") do |fd|
31
- case ext
32
- when "txt"
33
- create_file(data, file: file, format: :txt)
34
- when "html"
35
- log(:warn) { "html is still not supported" }
36
- exit(1)
37
- # create_file(data, file: file, format: :html)
38
- when "json"
39
- log(:warn) { "json is still not supported" }
40
- exit(1)
41
- # create_file(data, file: file, format: :json)
42
- end
30
+ case ext
31
+ when "txt"
32
+ create_file(data, file: file, format: :txt)
33
+ when "html"
34
+ log(:warn) { "html is still not supported" }
35
+ exit(1)
36
+ # create_file(data, file: file, format: :html)
37
+ when "json"
38
+ log(:warn) { "json is still not supported" }
39
+ exit(1)
40
+ # create_file(data, file: file, format: :json)
43
41
  end
44
42
  end
45
43
 
@@ -64,8 +62,8 @@ class Eco::API::UseCases::Default::People::SupersCyclicIdentify < Eco::API::Comm
64
62
 
65
63
  "".tap do |str|
66
64
  entry = set.shift
67
- str << "#{" " * lev}"
68
- str << lev > 0 ? "+-#{lev}- " : ""
65
+ str << " " * lev
66
+ str << lev&.positive? ? "+-#{lev}- " : ""
69
67
  str << entry.name
70
68
  str << " (#{entry.external_id}|#{entry.email}|#{entry.id})\n"
71
69
  next unless set && !set.empty?