eco-helpers 2.0.8 → 2.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 507156a88f88bc8227f255251d1f8861f486a23a0fe3b23e003706dfe708507b
4
- data.tar.gz: '07952da6db5134dfecc5461d41ad4ce0e264c0eaaec3d9ec55d9d42b41b2620b'
3
+ metadata.gz: 726f5a5930889b9fd59b4acc4ce7b938e3c6011909c2f5a5bb1a105a36df4d9b
4
+ data.tar.gz: 804bc3ae796491543ec3615e9f11308333e7ea6fc9a10f943778f66922aa4a25
5
5
  SHA512:
6
- metadata.gz: fcfa79dfa92123af03399391797013e7a23a032504570d8cc2cfcb890f8a93ece62a7acbbd43b2fbd70a4de20c28baa60635536d9b431ac260de2905db825332
7
- data.tar.gz: 0e63f504d100e5647e9b48eceeebda57814d1dda0ce3d8c0147cb58ce7c40bf5e1225bc261d207d531af22611dc4fd0461461f70016647cda0eaf1147e653c12
6
+ metadata.gz: f2e1c852b4660ae1bdc3e94bab274f3d4b7168c6affef57315b370af102b71cff19cdb0c2de0b59899f82b7f2f8b0478688cf018f3c52f26c1f1d891ed19cd65
7
+ data.tar.gz: 032a93267eb45f7550fbdad7805d0f472a0ea1a98353b089147bd71de785cdeaa4933b233bdd22d4ab69f7a85bfa65ec1f0850fe82e446dcf4d5f503ba1f191b
data/CHANGELOG.md CHANGED
@@ -1,24 +1,61 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.0.8] - 2021-03-xx
4
+ ## [2.0.13] - 2021-03-31
5
5
 
6
6
  ### Added
7
+ - Stats on the `Eco::API::Session::Batch`
8
+ - Allow to inherit and re-use the `Eco::API::UseCases::DefaultCase::HrisCase`
9
+
7
10
  ### Changed
11
+
8
12
  ### Fixed
9
- - `Ecoportal::API::External::Person#identity` adjust behaviour
10
-
11
- ## [2.0.7] - 2021-03-09
13
+ - Ensure auto-loading for `Eco::API::UseCases`
14
+
15
+ ## [2.0.12] - 2021-03-29
16
+
17
+ ### Changed
18
+ - `Eco::CLI#run` it does include any defined states on the workflow
19
+
20
+
21
+ ## [2.0.11] - 2021-03-29
22
+
23
+ ### Fixed
24
+ - `Eco::API::Session::Batch:Errors#errors` changed `Array#filter` call to `Array#select` call
25
+
26
+ ## [2.0.10] - 2021-03-26
12
27
 
13
28
  ### Added
29
+ - `Eco::API::Common::People::PersonParser`
30
+ - `#defined_attrs`: list of all attribute defined parsers (regardless they belong to the model)
31
+ - `Eco::API::Organization::TagTree` methods
32
+ - `#total_depth` to know the total depth of a tree
33
+ - `#flat?` to know if the tagtree has only 1 level
34
+
14
35
  ### Changed
36
+ - `Eco::API::Common::People::PersonParser`
37
+ - Renamed `#all_attrs` to `#all_model_attrs`
38
+ - Ranamed `#defined_attrs` to `#defined_model_attrs`
39
+ - Ranamed `#undefined_attrs` to `#undefined_model_attrs`
40
+
41
+ ## [2.0.9] - 2021-03-19
42
+
43
+ ### Changed
44
+ - `Eco::API::Session::Batch:Errors#person_ref` moved to the public method
45
+
46
+ ## [2.0.8] - 2021-03-09
47
+
48
+ ### Fixed
49
+ - `Ecoportal::API::V1::Person#identity` adjust behavior
50
+
51
+ ## [2.0.7] - 2021-03-09
52
+
15
53
  ### Fixed
16
54
  - `Eco::API::Session::Batch::JobsGroups` and `Eco::API::Session::Batch::Jobs`: when new `Batch::Job`s are creating during launch, they remained unlaunched
17
55
  - this fix makes `#launch` method to iterate until there are no pending
18
56
 
19
57
  ## [2.0.6] - 2021-03-08
20
58
 
21
- ### Added
22
59
  ### Changed
23
60
  - `Eco::API::Session::Batch:Errors` moved some methods to be private
24
61
  ### Fixed
@@ -26,46 +63,33 @@ All notable changes to this project will be documented in this file.
26
63
 
27
64
  ## [2.0.5] - 2021-02-24
28
65
 
29
- ### Added
30
- ### Changed
31
66
  ### Fixed
32
67
  - `Eco::API::Common::People::PersonParser#symbol_keys` to use `Array#select`
33
68
  - as `Array#filter` was introduced in ruby `2.5.5`
34
69
 
35
70
  ## [2.0.4] - 2021-02-23
36
71
 
37
- ### Added
38
72
  ### Changed
39
73
  - `Eco::API::Common::People::PersonParser#defined_attrs` to include virtual attributes
40
74
 
41
- ### Fixed
42
-
43
75
  ## [2.0.3] - 2021-02-23
44
76
 
45
77
  ### Added
46
78
  - `Eco::API::UseCases::OozeSamples::OozeUpdateCase`: added integration to update page instances (non-templates)
47
79
 
48
- ### Changed
49
80
  ### Fixed
50
81
  - `Eco::API::Policies::DefaultPolicies::UserAccess` complete default policy code.
51
82
 
52
83
  ## [2.0.2] - 2021-02-22
53
84
 
54
- ### Added
55
85
  ### Changed
56
86
  - upgraded dependencies with `ecoportal-api`
57
87
 
58
- ### Fixed
59
-
60
-
61
88
  ## [2.0.1] - 2021-02-22
62
89
 
63
- ### Added
64
90
  ### Changed
65
91
  - upgraded dependencies with `ecoportal-api-oozes` to `ecoportal-api-v2`
66
92
 
67
- ### Fixed
68
-
69
93
  ## [1.5.15] - 2021-02-17
70
94
 
71
95
  ### Added
@@ -79,7 +103,6 @@ All notable changes to this project will be documented in this file.
79
103
  - `Eco::API::MicroCases#people_search`
80
104
  - `Eco::API::MicroCases#refresh`
81
105
 
82
- ### Changed
83
106
  ### Fixed
84
107
  - `Eco::API::Policies::DefaultPolicies::UserAccess` typos in default api policy
85
108
 
@@ -101,11 +124,8 @@ All notable changes to this project will be documented in this file.
101
124
  - `Eco::API::Common::People::PersonEntry` add error log when wrong email error is detected
102
125
  - previously it would have crashed
103
126
 
104
- ### Fixed
105
-
106
127
  ## [1.5.13] - 2021-02-01
107
128
 
108
- ### Added
109
129
  ### Changed
110
130
  - upgraded dependency with `ecoportal-api-oozes`
111
131
 
@@ -121,23 +141,16 @@ All notable changes to this project will be documented in this file.
121
141
  ### Changed
122
142
  - upgraded `ecoportal-api` dependency
123
143
 
124
- ### Fixed
125
-
126
-
127
144
  ## [1.5.11] - 2021-01-25
128
145
 
129
146
  ### Added
130
147
  - `Eco::API::Organization::TagTree#subtag?` to check if the tag is in any subtree.
131
148
 
132
- ### Changed
133
-
134
149
  ### Fixed
135
150
  - `Eco::API::MicroCases#set_supervisor` shouldn't set it if the entry does not have it.
136
151
 
137
152
  ## [1.5.10] - 2021-01-19
138
153
 
139
- ### Added
140
- ### Changed
141
154
  ### Fixed
142
155
  - `Eco::API::Session::Batch::Errors#print` show the row number of the input data.
143
156
 
@@ -146,14 +159,8 @@ All notable changes to this project will be documented in this file.
146
159
  ### Added
147
160
  - `Eco::API::Organization::TagTree#subtags` to get all the tags but those of the highest level.
148
161
 
149
- ### Changed
150
- ### Fixed
151
-
152
-
153
162
  ## [1.5.8] - 2021-01-05
154
163
 
155
- ### Added
156
- ### Changed
157
164
  ### Fixed
158
165
  - `Eco::API::Session::Batch::Jobs#job` shouldn't be calling the post-launch callback function on creation.
159
166
  - `Eco::API::Session#new_job` should include a `&block` parameter.
@@ -161,15 +168,11 @@ All notable changes to this project will be documented in this file.
161
168
 
162
169
  ## [1.5.7] - 2020-12-17
163
170
 
164
- ### Added
165
- ### Changed
166
171
  ### Fixed
167
172
  - `Eco::API::Sesssion#parse_attribute` was not using phase argument
168
173
 
169
174
  ## [1.5.6] - 2020-12-04
170
175
 
171
- ### Added
172
- ### Changed
173
176
  ### Fixed
174
177
  - `Eco::API::UseCases::DefaultCases::RestoreDBCase` fixed typo and slightly improved
175
178
  - fixed some back-end errors when chaining usecases
@@ -177,8 +180,6 @@ All notable changes to this project will be documented in this file.
177
180
 
178
181
  ## [1.5.5] - 2020-12-03
179
182
 
180
- ### Added
181
- ### Changed
182
183
  ### Fixed
183
184
  - rubies previous to `2.5` do not have `yield_self`
184
185
 
@@ -186,14 +187,11 @@ All notable changes to this project will be documented in this file.
186
187
 
187
188
  ### Added
188
189
  - update `ecoportal-api` dependency
189
- ### Changed
190
190
  ### Fixed
191
191
  - `Eco::API::MicroCases#people_refresh` typo
192
192
 
193
193
  ## [1.5.3] - 2020-11-30
194
194
 
195
- ### Added
196
- ### Changed
197
195
  ### Fixed
198
196
  - `Eco::API::Session::Batch::RequestStats#blanked_value?` better blank detection
199
197
  - `Eco::API::MicroCases#with_each_starter` rectified typo
@@ -334,14 +332,11 @@ All notable changes to this project will be documented in this file.
334
332
 
335
333
  ## [1.4.2] - 2020-07-23
336
334
 
337
- ### Added
338
- ### Changed
339
335
  ### Fixed
340
336
  - preserve backtrace on logging
341
337
 
342
338
  ## [1.4.0] - 2020-07-14
343
339
 
344
- ### Added
345
340
  ### Changed
346
341
  - change abilities to align with ecoPortal release `1.5.0`
347
342
  - remove some patches on `ecoportal-api`
@@ -351,22 +346,17 @@ All notable changes to this project will be documented in this file.
351
346
 
352
347
  ## [1.3.19] - 2020-07-23
353
348
 
354
- ### Added
355
- ### Changed
356
349
  ### Fixed
357
350
  - preserve backtrace on logging
358
351
 
359
352
  ## [1.3.18] - 2020-07-08
360
353
 
361
- ### Added
362
- ### Changed
363
354
  ### Fixed
364
355
  - the `update` case was missing the code to use the `default_usergroup`
365
356
 
366
357
 
367
358
  ## [1.3.17] - 2020-07-06
368
359
 
369
- ### Added
370
360
  ### Changed
371
361
  - the `hris` case should not only include as `leavers` those that have account, but anyone that leaves
372
362
  * as we could have active people with no account
@@ -389,7 +379,6 @@ All notable changes to this project will be documented in this file.
389
379
  ### Added
390
380
  - default usecase to export to `csv` (`-detailed`) now includes `"Supervisor Name"` column
391
381
  ### Changed
392
- ### Fixed
393
382
 
394
383
  ## [1.3.14] - 2020-06-10
395
384
 
@@ -397,33 +386,24 @@ All notable changes to this project will be documented in this file.
397
386
  - `Eco::API::Common::People::SupervisorHelpers` now has its methods as class methods
398
387
  ### Changed
399
388
  - upgraded `ecoportal-api` gem dependency to minimum version `0.5.6`
400
- ### Fixed
401
389
 
402
390
 
403
391
  ## [1.3.13] - 2020-05-29
404
392
 
405
- ### Added
406
- ### Changed
407
393
  ### Fixed
408
394
  - `Eco::API::Organization::TagTree#tag?` to accept `nil` by returning `false`
409
395
  - `Eco::API::Common::People::DefaultParsers::DateParser` will parse to `Date` class
410
396
  * it was parsing to `Time` class, while the native gem `ecoportal-api` parses as `Date` ([reference](https://gitlab.com/ecoPortal/ecoportal-api/-/blob/master/lib/ecoportal/api/v1/schema_field.rb))
411
397
  ## [1.3.12] - 2020-05-19
412
398
 
413
- ### Added
414
399
  ### Changed
415
400
  - stop using `email` as `external_id` on `People#person` & `People#find`
416
401
  * this should result in more accurate searches when using `:strict` options
417
- ### Fixed
418
-
419
402
 
420
403
  ## [1.3.11] - 2020-05-12
421
404
 
422
- ### Added
423
405
  ### Changed
424
406
  - remove popping up comments on `Eco::API::Organization::PolicyGroups#`
425
- ### Fixed
426
-
427
407
 
428
408
  ## [1.3.10] - 2020-05-12
429
409
 
@@ -432,14 +412,11 @@ All notable changes to this project will be documented in this file.
432
412
  - `config.people.default_usergroup`, when defined, will have effect on usecases: `update` (this case was missing the change)
433
413
  * on account creation, if the input file did not specify `policy_group_ids`
434
414
 
435
- ### Changed
436
415
  ### Fixed
437
416
  - `upsert`, `hris` and `create` usecases: fixed condition for use of default_usergroup
438
417
 
439
418
  ## [1.3.9] - 2020-05-12
440
419
 
441
- ### Added
442
- ### Changed
443
420
  ### Fixed
444
421
 
445
422
  - `usecase` callback was not receiving `usecase` paramater
@@ -8,7 +8,7 @@ module Eco
8
8
  # @return [Symbol] the `type` of usecase (i.e. `:sync`, `:transform`, `:import`, `:other`)
9
9
  def type(value = nil)
10
10
  unless value
11
- return @type || raise("You should specify a type of case [:sync, :transform, :import, :other] for #{self.class}")
11
+ return @type || raise("You should specify a type of case [:sync, :transform, :import, :other] for #{self}")
12
12
  end
13
13
  @type = value
14
14
  end
@@ -256,7 +256,7 @@ module Eco
256
256
  # @param mapped_entry [Hash] that with **internal** names but **external** values and types.
257
257
  # @return [Hash] with **external** names, values and types.
258
258
  def _external_serializing(mapped_entry)
259
- target_attrs = @emap.all_attrs | @emap.aliased_attrs
259
+ target_attrs = @emap.all_model_attrs | @emap.aliased_attrs
260
260
  rest_keys = mapped_entry.keys - target_attrs
261
261
  target_attrs -= ["send_invites"]
262
262
  external_entry = target_attrs.each_with_object({}) do |attr, hash|
@@ -6,14 +6,14 @@ module Eco
6
6
  # @attr_reader core_attrs [Array<String>] core attributes that are present in the person entry.
7
7
  # @attr_reader details_attrs [Array<String>] schema details attributes that are present in the person entry.
8
8
  # @attr_reader account_attrs [Array<String>] account attributes that are present in the person entry.
9
- # @attr_reader all_attrs [Array<String>] all the attrs that are present in the person entry.
9
+ # @attr_reader all_model_attrs [Array<String>] all the attrs that are present in the person entry.
10
10
  # @attr_reader internal_attrs [Array<String>] all the internally named attributes that the person entry has.
11
11
  # @attr_reader aliased_attrs [Array<String>] only those internal attributes present in the person entry that have an internal/external name mapping.
12
12
  # @attr_reader direct_attrs [Array<String>] only those internal attributes present in the person entry that do **not** have an internal/external name mapping.
13
13
  class PersonEntryAttributeMapper
14
14
  @@cached_warnings = {}
15
15
 
16
- attr_reader :core_attrs, :details_attrs, :account_attrs, :all_attrs
16
+ attr_reader :core_attrs, :details_attrs, :account_attrs, :all_model_attrs
17
17
  attr_reader :internal_attrs, :aliased_attrs, :direct_attrs
18
18
 
19
19
  # Helper class tied to `PersonEntry` that allows to track which attributes of a person entry are present
@@ -41,14 +41,14 @@ module Eco
41
41
  init_attr_trackers
42
42
  else # SERIALIZING
43
43
  @person = data
44
- @internal_attrs = @person_parser.all_attrs
44
+ @internal_attrs = @person_parser.all_model_attrs
45
45
  @aliased_attrs = @attr_map.list(:internal)
46
46
  end
47
47
 
48
48
  @core_attrs = @person_parser.target_attrs_core(@internal_attrs)
49
49
  @details_attrs = @person_parser.target_attrs_details(@internal_attrs)
50
50
  @account_attrs = @person_parser.target_attrs_account(@internal_attrs)
51
- @all_attrs = @core_attrs | @account_attrs | @details_attrs
51
+ @all_model_attrs = @core_attrs | @account_attrs | @details_attrs
52
52
  end
53
53
 
54
54
  # To know if currently the object is in parse or serialize mode.
@@ -98,7 +98,7 @@ module Eco
98
98
  end
99
99
  end
100
100
 
101
- return nil unless @person_parser.all_attrs.include?(attr)
101
+ return nil unless @person_parser.all_model_attrs.include?(attr)
102
102
  end
103
103
 
104
104
  # Serializing helper also used to do a reverse mapping when parsing:
@@ -146,9 +146,9 @@ module Eco
146
146
  # when parsing:
147
147
  def init_attr_trackers
148
148
  # (def) all internal attributes we can expect
149
- def_all_attrs = @person_parser.all_attrs
149
+ def_all_attrs = @person_parser.all_model_attrs
150
150
  # (def) internal attrs with no aliasing nor parser definition (expected to be direct)
151
- def_unlinked = @person_parser.undefined_attrs.select { |attr| !to_external(attr) }
151
+ def_unlinked = @person_parser.undefined_model_attrs.select { |attr| !to_external(attr) }
152
152
  # (def) those with parser or alias:
153
153
  def_linked = def_all_attrs - def_unlinked
154
154
 
@@ -168,7 +168,7 @@ module Eco
168
168
  # (data) virtual internal attrs (the internal names of those virtual attrs)
169
169
  data_vi_int_aliased = data_vi_ext_alias.map do |attr|
170
170
  # to_internal(attr) can't be used here, becauase virtual fields would get filtered out,
171
- # as they are not recognized by @parser.all_attrs.include?(attr)
171
+ # as they are not recognized by @parser.all_model_attrs.include?(attr)
172
172
  @attr_map.to_internal(attr)
173
173
  end.compact
174
174
 
@@ -7,7 +7,7 @@ module Eco
7
7
  #
8
8
  # @attr_reader schema [Ecoportal::API::V1::PersonSchema, nil] schema of person details that this parser will be based upon.
9
9
  # @attr_reader details_attrs [Array<String>] internal names of schema details attributes.
10
- # @attr_reader all_attrs [Array<String>] all the internal name attributes, including _core_, _account_ and _details_.
10
+ # @attr_reader all_model_attrs [Array<String>] all the internal name attributes, including _core_, _account_ and _details_.
11
11
  class PersonParser
12
12
  extend Eco::API::Common::ClassAutoLoader
13
13
  autoloads_children_of "Eco::API::Common::Loaders::Parser"
@@ -19,8 +19,7 @@ module Eco
19
19
  FORMAT = [:csv, :xml, :json]
20
20
 
21
21
  attr_reader :schema
22
- attr_reader :details_attrs, :all_attrs
23
- attr_reader :defined_attrs
22
+ attr_reader :details_attrs, :all_model_attrs
24
23
  attr_reader :patch_version
25
24
 
26
25
  # @example Example of usage:
@@ -46,7 +45,7 @@ module Eco
46
45
  @details_attrs = @schema&.fields.map { |fld| fld.alt_id }
47
46
  end
48
47
 
49
- @all_attrs = CORE_ATTRS + ACCOUNT_ATTRS + @details_attrs
48
+ @all_model_attrs = CORE_ATTRS + ACCOUNT_ATTRS + @details_attrs
50
49
  self.class.autoload_children(self)
51
50
  end
52
51
 
@@ -60,6 +59,11 @@ module Eco
60
59
 
61
60
  # @!group Scopping attributes (identifying, presence & active)
62
61
 
62
+ # All the internal name attributes, including _core_, _account_ and _details_.
63
+ def all_attrs(include_defined_parsers: false)
64
+ all_model_attrs | defined_model_attrs
65
+ end
66
+
63
67
  # Scopes `source_attrs` using the _**core** attributes_.
64
68
  # @note use this helper to know which among your attributes are **core** ones.
65
69
  # @param source_attrs [Array<String>]
@@ -93,14 +97,21 @@ module Eco
93
97
  @parsers.keys
94
98
  end
95
99
 
100
+ # Returns a list of all the internal attributes that have a parser defined.
101
+ # @note These attributes do not necessarily belong to the model. They could be virtual attributes
102
+ # @return [Array<String>] list of all attribute defined parsers.
103
+ def defined_attrs
104
+ defined_list - symbol_keys
105
+ end
106
+
96
107
  # Returns a list of all the internal attributes of the model that have a parser defined.
97
108
  # @note
98
109
  # - it excludes any parser that is not in the model, such as type parsers (i.e. `:boolean`, `:multiple`)
99
110
  # - the list is sorted according `CORE_ATTRS` + `ACCOUNT_ATTRS` + schema attrs
100
- # @return [Array<String>] list of all attribute defined parsers.
101
- def defined_attrs
111
+ # @return [Array<String>] list of all attribute defined parsers in the model.
112
+ def defined_model_attrs
102
113
  defined = @parsers.keys
103
- defined = (all_attrs | defined) & defined
114
+ defined = (all_model_attrs | defined) & defined
104
115
  defined - symbol_keys
105
116
  end
106
117
 
@@ -118,7 +129,7 @@ module Eco
118
129
  # @param process [Symbol] either `:parse` or `:serialize`, depending if we want to parse or serialize the `attr`.
119
130
  # @return [Array<String>] list of all attribute defined parsers that should be active for the given `source_data`.
120
131
  def active_attrs(source_data, phase = :any, process: :parse)
121
- defined_attrs.select do |attr|
132
+ defined_model_attrs.select do |attr|
122
133
  if process == :serialize
123
134
  @parsers[attr].serializer_active?(phase)
124
135
  else
@@ -130,8 +141,8 @@ module Eco
130
141
  # Returns a list of all the internal attributes of the model that do **not** have a parser defined.
131
142
  # @note it excludes any parser that is **not** in the model, such as type parsers (i.e. :boolean, :multiple)
132
143
  # @return [Array<String>] list of all attributes without a defined parser.
133
- def undefined_attrs
134
- all_attrs - defined_attrs
144
+ def undefined_model_attrs
145
+ all_model_attrs - defined_model_attrs
135
146
  end
136
147
 
137
148
  # @param attr [String] internal name of an attribute.
@@ -238,7 +249,7 @@ module Eco
238
249
  end
239
250
 
240
251
  def valid_attr?(attr)
241
- attr.is_a?(String) && (!@schema || @all_attrs.include?(attr))
252
+ attr.is_a?(String) && (!@schema || @all_model_attrs.include?(attr))
242
253
  end
243
254
 
244
255
  def valid_type?(attr)
@@ -4,7 +4,7 @@ module Eco
4
4
 
5
5
  # Provides helpers to deal with tagtrees.
6
6
  class TagTree
7
- attr_reader :tag, :nodes
7
+ attr_reader :tag, :nodes, :children_count
8
8
  attr_reader :depth, :path
9
9
  attr_reader :enviro
10
10
 
@@ -37,6 +37,7 @@ module Eco
37
37
 
38
38
  nodes = @source.is_a?(Array) ? @source : @source.dig('nodes') || []
39
39
  @nodes = nodes.map {|cnode| TagTree.new(cnode, depth: @depth + 1, path: @path.dup, enviro: @enviro)}
40
+ @children_count = @nodes.count
40
41
 
41
42
  init_hashes
42
43
  end
@@ -46,6 +47,21 @@ module Eco
46
47
  @has_tags.empty?
47
48
  end
48
49
 
50
+ # @return [Integer] the highest `depth` of all the children.
51
+ def total_depth
52
+ @total_depth ||= if children_count > 0
53
+ deepest_node = nodes.max_by {|node| node.total_depth}
54
+ deepest_node.depth
55
+ else
56
+ depth
57
+ end
58
+ end
59
+
60
+ # @return [Integer] if there's only top level.
61
+ def flat?
62
+ self.total_depth <= 0
63
+ end
64
+
49
65
  # Gets all the tags of the current node tree.
50
66
  # @note
51
67
  # - this will include the upper level tag(s) as well
@@ -147,7 +163,8 @@ module Eco
147
163
  # * take the deepest tag (the one that is further down in the tree)
148
164
  # * if there are different options (several nodes at the same depth):
149
165
  # * take the common node between them (i.e. you have Hamilton and Auckland -> take New Zealand)
150
- # * if there's no common node between them, take the `first` (unless they are at top level of the tree)
166
+ # * if there's no common node between them, take the `first`, unless they are at top level of the tree
167
+ # * to the above, take the `first` also on top level, but only if there's 1 level for the entire tree
151
168
  # @param [Array<String>] values list of tags.
152
169
  # @return [String] default tag.
153
170
  def default_tag(*values)
@@ -169,7 +186,7 @@ module Eco
169
186
  common = nodes.reduce(self.tags.reverse) {|com, cnode| com & cnode.path.reverse}
170
187
  default_tag = common.first if common.length > 0 && depth > 0
171
188
  end
172
- default_tag = nodes.first&.tag if !default_tag && depth > 0
189
+ default_tag = nodes.first&.tag if !default_tag && ( (depth > 0) || flat?)
173
190
  default_tag
174
191
  end
175
192
 
@@ -105,10 +105,15 @@ module Eco
105
105
  iterations = (data.length.to_f / per_page).ceil
106
106
 
107
107
  Eco::API::Session::Batch::Status.new(enviro, queue: data, method: method).tap do |status|
108
+ start_time = Time.now
109
+ start_slice = Time.now; slice = []
108
110
  data.each_slice(per_page) do |slice|
109
- msg = "starting batch '#{method}' iteration #{iteration}/#{iterations}, with #{slice.length} entries of #{data.length} -- #{done} done"
111
+ msg = "starting batch '#{method}' iteration #{iteration}/#{iterations},"
112
+ msg += " with #{slice.length} entries of #{data.length} -- #{done} done"
113
+ msg += " (last: #{str_stats(start_slice, slice.length)}; total: #{str_stats(start_time, done)})"
110
114
  logger.info(msg) unless silent
111
115
 
116
+ start_slice = Time.now
112
117
  people_api.batch do |batch|
113
118
  slice.each do |person|
114
119
  batch.public_send(method, person) do |response|
@@ -118,12 +123,23 @@ module Eco
118
123
  end
119
124
  end # next batch
120
125
 
121
- iteration += 1
122
- done += slice.length
126
+ iteration += 1
127
+ done += slice.length
123
128
  end # next slice
124
129
  end
125
130
  end
126
131
 
132
+ def str_stats(start, count)
133
+ now = Time.now
134
+ secs = (now - start).round(3)
135
+ if secs > 0.0
136
+ per_sec = (count.to_f / secs).round(2)
137
+ "#{secs}s -> #{per_sec} people/s"
138
+ else
139
+ " -- "
140
+ end
141
+ end
142
+
127
143
  end
128
144
  end
129
145
  end
@@ -111,6 +111,11 @@ module Eco
111
111
  end
112
112
  # @!endgroup
113
113
 
114
+ def person_ref(entry)
115
+ row_str = (row = get_row(entry)) ? "(row: #{row}) " : nil
116
+ "#{row_str}(id: '#{get_attr(entry, :id)}') '#{get_attr(entry, :name)}' ('#{get_attr(entry, :external_id)}': '#{get_attr(entry, :email)}')"
117
+ end
118
+
114
119
  private
115
120
 
116
121
  # Input entries that got **error** response from the _Server_.
@@ -119,7 +124,7 @@ module Eco
119
124
  # - please, observe that this can only happen if there were repeated entries in the `source_queue`
120
125
  # @return [Array<Hash>, Array<Ecoportal::API::V1::Person>, Array<Ecoportal::API::Internal::Person>]
121
126
  def entries
122
- queue.filter.with_index do |query, i|
127
+ queue.select.with_index do |query, i|
123
128
  unless response = status[i]
124
129
  msg = "Error: query with no response. You might have duplicated entries in your queue.\n"
125
130
  msg += "Queue length: #{queue.length}; Queue elements class: #{queue.first.class}\n"
@@ -136,11 +141,6 @@ module Eco
136
141
  end
137
142
  end
138
143
 
139
- def person_ref(entry)
140
- row_str = (row = get_row(entry)) ? "(row: #{row}) " : nil
141
- "#{row_str}(id: '#{get_attr(entry, :id)}') '#{get_attr(entry, :name)}' ('#{get_attr(entry, :external_id)}': '#{get_attr(entry, :email)}')"
142
- end
143
-
144
144
  def get_attr(entry, attr)
145
145
  if entry.respond_to?(attr.to_sym)
146
146
  entry.public_send(attr.to_sym)
@@ -45,25 +45,22 @@ module Eco
45
45
  # @!group Pure feedback methods
46
46
 
47
47
  # Slightly modifies the behaviour of `Ecoportal::API::Common::BaseModel#as_update`, so schema details fields show the `alt_id`
48
+ # It also fixes possible patch updates that are incomplete or unnecessary.
48
49
  # @note for better feedback
49
50
  # @param entry [Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
50
- def as_update(entry)
51
+ # @param add_feedback [Boolean] if `true` it tweak the hash update with additional data.
52
+ def as_update(entry, add_feedback: true)
51
53
  case
52
54
  when entry.is_a?(Hash)
53
55
  hash = entry
54
56
  else #entry.is_a?(Ecoportal::API::V1::Person)
55
57
  if only_ids?
56
- hash = {
57
- "id" => entry.id,
58
- "external_id" => entry.external_id,
59
- "email" => entry.email
60
- }
61
58
  hash = entry.as_json.slice("id", "external_id", "email")
62
59
  else
63
60
  hash = entry.as_update
64
- #if entry.details
65
- if hash["details"]
66
- if hfields = hash.dig("details", "fields")
61
+
62
+ if add_feedback && details = hash["details"]
63
+ if hfields = details["fields"]
67
64
  hfields.each do |fld|
68
65
  fld.merge!("alt_id" => entry.details.get_field(fld["id"]).alt_id)
69
66
  end
@@ -169,7 +169,8 @@ module Eco
169
169
 
170
170
  unless simulate
171
171
  if pqueue.length > 0
172
- backup_update(requests)
172
+ req_backup = pqueue.map {|e| as_update(e, add_feedback: false)}
173
+ backup_update(req_backup)
173
174
  session.batch.launch(pqueue, method: type).tap do |job_status|
174
175
  @status = job_status
175
176
  status.root = self
@@ -217,7 +218,7 @@ module Eco
217
218
  [].tap do |msg|
218
219
  subjobs.map {|subjob| msg << subjob.summary}
219
220
  end.join("\n")
220
- end
221
+ end
221
222
 
222
223
  def as_update(*args)
223
224
  feedback.as_update(*args)
@@ -30,6 +30,7 @@ module Eco
30
30
  @usecases = {}
31
31
  @cache_init = false
32
32
  @cases_by_name = {}
33
+ init_caches
33
34
  end
34
35
 
35
36
  def length
@@ -79,6 +80,7 @@ module Eco
79
80
 
80
81
  # @return [Eco::API::UseCases] a copy of instance object of `self`.
81
82
  def dup
83
+ init_caches
82
84
  self.class.new.merge(self)
83
85
  end
84
86
 
@@ -2,18 +2,17 @@ class Eco::API::UseCases::DefaultCases::HrisCase < Eco::API::Common::Loaders::Us
2
2
  name "hris"
3
3
  type :sync
4
4
 
5
+ attr_reader :creation, :update, :supers, :leavers
6
+
5
7
  def main(entries, people, session, options, usecase)
6
8
  micro = session.micro
7
- creation = session.new_job("main", "create", :create, usecase)
8
- update = session.new_job("main", "update", :update, usecase)
9
- supers = session.new_job("post", "supers", :update, usecase, :core)
10
- leavers = session.new_job("post", "leavers", :update, usecase, :account)
9
+ @creation = session.new_job("main", "create", :create, usecase)
10
+ @update = session.new_job("main", "update", :update, usecase)
11
+ @supers = session.new_job("post", "supers", :update, usecase, :core)
12
+ @leavers = session.new_job("post", "leavers", :update, usecase, :account)
11
13
 
12
14
  micro.with_each_leaver(entries, people, options) do |person|
13
- leavers.add(person) do |person|
14
- person.supervisor_id = nil
15
- person.account = nil if person.account
16
- end
15
+ leavers.add(person, &method(:leavers_callback))
17
16
  end
18
17
 
19
18
  micro.with_each(entries, people, options) do |entry, person|
@@ -24,4 +23,11 @@ class Eco::API::UseCases::DefaultCases::HrisCase < Eco::API::Common::Loaders::Us
24
23
  end
25
24
  end
26
25
 
26
+ private
27
+
28
+ def leavers_callback(person)
29
+ person.supervisor_id = nil
30
+ person.account = nil if person.account
31
+ end
32
+
27
33
  end
data/lib/eco/cli.rb CHANGED
@@ -22,16 +22,17 @@ module Eco
22
22
 
23
23
  def run(session:)
24
24
  io = Eco::API::UseCases::BaseIO.new(session: session, options: options)
25
- #session.workflow.run(io: io)
26
- session.workflow(io: io) do |wf, io|
27
- io = wf.run(:options, io: io)
28
- io = wf.run(:load, io: io)
29
- io = wf.run(:usecases, io: io)
30
- io = wf.run(:launch_jobs, io: io)
31
- io = wf.run(:post_launch, io: io)
32
- io = wf.run(:end, io: io)
33
- io = wf.run(:close, io: io)
34
- end
25
+ session.workflow(io: io).run(io: io)
26
+ #session.workflow(io: io) do |wf, io|
27
+ # io = wf.run(:options, io: io)
28
+ # io = wf.run(:load, io: io)
29
+ # io = wf.run(:usecases, io: io)
30
+ # io = wf.run(:launch_jobs, io: io)
31
+ # io = wf.run(:post_launch, io: io)
32
+ # io = wf.run(:report, io: io)
33
+ # io = wf.run(:end, io: io)
34
+ # io = wf.run(:close, io: io)
35
+ #end
35
36
  end
36
37
 
37
38
  end
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.0.8"
2
+ VERSION = "2.0.13"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura