eco-helpers 3.2.1 → 3.2.3

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +36 -1
  4. data/eco-helpers.gemspec +3 -3
  5. data/lib/eco/api/common/loaders/config/workflow/mailer.rb +1 -0
  6. data/lib/eco/api/common/people/person_entry.rb +6 -1
  7. data/lib/eco/api/common/people/person_parser.rb +1 -0
  8. data/lib/eco/api/microcases/people/manage/cache.rb +21 -16
  9. data/lib/eco/api/microcases/people/manage/filename.rb +29 -0
  10. data/lib/eco/api/microcases/people/manage/load.rb +6 -48
  11. data/lib/eco/api/microcases/people/manage/load_cache.rb +29 -0
  12. data/lib/eco/api/microcases/people/manage/refresh.rb +5 -3
  13. data/lib/eco/api/microcases/people/manage.rb +4 -0
  14. data/lib/eco/api/organization/tag_tree.rb +11 -4
  15. data/lib/eco/api/session/batch/searcher.rb +3 -3
  16. data/lib/eco/api/session/config/people.rb +23 -20
  17. data/lib/eco/api/usecases/default/locations/tagtree_upload_case.rb +20 -2
  18. data/lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb +14 -7
  19. data/lib/eco/api/usecases/graphql/helpers/location/base.rb +1 -1
  20. data/lib/eco/api/usecases/graphql/helpers/location/command/diff/as_update.rb +0 -1
  21. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_archive.rb +0 -1
  22. data/lib/eco/api/usecases/graphql/helpers/location/command/end_points/optimizations.rb +64 -0
  23. data/lib/eco/api/usecases/graphql/helpers/location/command/end_points.rb +96 -0
  24. data/lib/eco/api/usecases/graphql/helpers/location/command/input_unit_response.rb +69 -0
  25. data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +11 -10
  26. data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +120 -63
  27. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +26 -26
  28. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +195 -37
  29. data/lib/eco/api/usecases/graphql/samples/location/command/results.rb +45 -13
  30. data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +0 -51
  31. data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +6 -14
  32. data/lib/eco/api/usecases/graphql/samples/location/command.rb +1 -1
  33. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/inputable.rb +4 -1
  34. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +6 -0
  35. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/input.rb +1 -0
  36. data/lib/eco/api/usecases/lib/error_handling.rb +1 -1
  37. data/lib/eco/api/usecases/ooze_samples/helpers/creatable.rb +1 -0
  38. data/lib/eco/api/usecases/ooze_samples/helpers/rescuable.rb +1 -0
  39. data/lib/eco/api/usecases/samples/drivers/cli/sftp_cli.rb +1 -1
  40. data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +4 -1
  41. data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +12 -9
  42. data/lib/eco/api/usecases/samples/people/filters/cli/require_id_cli.rb +5 -0
  43. data/lib/eco/api/usecases/samples/people/filters/cli/require_min_entries_cli.rb +5 -0
  44. data/lib/eco/api/usecases/samples/people/filters/require_id_sample.rb +61 -0
  45. data/lib/eco/api/usecases/samples/people/filters/require_min_entries_sample.rb +20 -0
  46. data/lib/eco/api/usecases/samples/people/filters.rb +7 -0
  47. data/lib/eco/api/usecases/samples/people.rb +12 -0
  48. data/lib/eco/api/usecases/samples.rb +1 -0
  49. data/lib/eco/cli_default/options.rb +5 -0
  50. data/lib/eco/data/hashes/array_diff.rb +14 -4
  51. data/lib/eco/data/locations/node_base/csv_convert.rb +9 -1
  52. data/lib/eco/data/locations/node_base/tag_validations.rb +2 -2
  53. data/lib/eco/data/locations/node_diff/nodes_diff/diffs_tree.rb +10 -3
  54. data/lib/eco/data/locations/node_diff/nodes_diff.rb +6 -0
  55. data/lib/eco/version.rb +1 -1
  56. metadata +23 -13
  57. data/lib/eco/api/usecases/graphql/helpers/location/command/optimizations.rb +0 -84
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea80ab87a718ddf4e177e212b1f4a5234c96554d67d4781579314d1e58ea821e
4
- data.tar.gz: 835aec5ee8d25e186f3327e97b5ca382a3556c85a8f34bed4e4e3f09b2d201c0
3
+ metadata.gz: b3323b0394649126c76ec4239eade6cca337049bd8f761f96aa7c66034717bd0
4
+ data.tar.gz: 3ddedb00b3b1e7674e014143e54e9cb46e52abb9482e9dfbc65dd4059fd0a70e
5
5
  SHA512:
6
- metadata.gz: 16cd391227194d4e929292ebe775f061f1ba58f592523ff28b32d2d7e92da638c94c0b36fdf2f55f2c38195517f6def5441e8ae15a6a3a516f02b5357540a69b
7
- data.tar.gz: 4bad0d9fa30a1be333b69aa485808961a3ae39259fb42d616457b8cd2b501b808daf60526cf0d4f17540f42036b084b82f40aeae36dd25894df46735b5f1f91e
6
+ metadata.gz: 6b6126ec90b13ef1d2d985b384215a529b5818ff5d8139d96fe80d5c21c6a4a0b367cb9bb7bf8b92ff6ed61f3df525f35e2639b5160693cc0e2fd6109bfb02cb
7
+ data.tar.gz: d4b799b66943fda1cf7340f358520d1f30715e27866ba900615cedc5bab593200a53cb2ef72bb6ff04c8e8b4e7c4b1b6bd1b0240145240364f67f633fbb3fbd6
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 3.2.2
2
+ TargetRubyVersion: 3.2
3
3
  Exclude:
4
4
  - 'config/routes.rb'
5
5
  NewCops: enable
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.2.2] - 2025-05-xx
5
+ ## [3.2.4] - 2025-08-xx
6
6
 
7
7
  ### Added
8
8
 
@@ -10,6 +10,41 @@ All notable changes to this project will be documented in this file.
10
10
 
11
11
  ### Fixed
12
12
 
13
+ ## [3.2.3] - 2025-08-21
14
+
15
+ ### Added
16
+
17
+ - `Person#phone_number`
18
+
19
+ ### Changed
20
+
21
+ - upgraded dependencies
22
+ - `ecoportal-api` gem
23
+
24
+ ### Fixed
25
+
26
+ - Switched to use DRAFTs on RS updates
27
+
28
+ ## [3.2.2] - 2025-06-11
29
+
30
+ ### Added
31
+
32
+ - `PersonEntry#[]` accessor (onto `final_entry`)
33
+ - **Samples**:
34
+ - `require-id`
35
+ - `require-min-entries`
36
+
37
+ ### Changed
38
+
39
+ - upgraded gem dependencies
40
+ - `Session::Batch::Searcher` silence low level messages.
41
+ - And better feedback on search.
42
+ - **Refactored** `Microcases` people get/cache/load helpers to reach a **unique access point** per functionality.
43
+
44
+ ### Fixed
45
+
46
+ - The upgrade of the `ecoportal-api-graphql` **gem** fixes a bug introduced by a native release.
47
+
13
48
  ## [3.2.1] - 2025-05-17
14
49
 
15
50
  ### Changed
data/eco-helpers.gemspec CHANGED
@@ -41,9 +41,9 @@ Gem::Specification.new do |spec|
41
41
  spec.add_dependency 'bcrypt_pbkdf', '~> 1.0'
42
42
  spec.add_dependency 'docx', '>= 0.8.0', '< 0.9'
43
43
  spec.add_dependency 'dotenv', '~> 3'
44
- spec.add_dependency 'ecoportal-api', '~> 0.10', '>= 0.10.11'
45
- spec.add_dependency 'ecoportal-api-graphql', '~> 1.2', '>= 1.2.1'
46
- spec.add_dependency 'ecoportal-api-v2', '~> 3.2', '>= 3.2.1'
44
+ spec.add_dependency 'ecoportal-api', '~> 0.10', '>= 0.10.14'
45
+ spec.add_dependency 'ecoportal-api-graphql', '~> 1.3', '>= 1.3.2'
46
+ spec.add_dependency 'ecoportal-api-v2', '~> 3.3', '>= 3.3.1'
47
47
  spec.add_dependency 'ed25519', '~> 1.2'
48
48
  spec.add_dependency 'fast_excel', '>= 0.5.0', '< 0.6'
49
49
  spec.add_dependency 'fuzzy_match', '>= 2.1.0', '< 2.2'
@@ -75,6 +75,7 @@ class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::W
75
75
  host(io).downcase.start_with?('live.')
76
76
  end
77
77
 
78
+ # @note this initiates a connection to the API (undesired)
78
79
  def host(io)
79
80
  io.session.api.client.host
80
81
  end
@@ -9,7 +9,7 @@ module Eco
9
9
  BOOLEAN_ATTRS = %w[
10
10
  freemium accept_eula archived
11
11
  ].freeze
12
- MULTI_ATTRS = %w[
12
+ MULTI_ATTRS = %w[
13
13
  policy_group_ids filter_tags login_provider_ids starred_ids
14
14
  ].freeze
15
15
  NUMERIC_ATTRS = %w[
@@ -98,6 +98,11 @@ module Eco
98
98
  end
99
99
  end
100
100
 
101
+ # Value on the final entry
102
+ def [](key)
103
+ final_entry[key]
104
+ end
105
+
101
106
  # @note completely serialized entry.
102
107
  # @return [Hash] entry `Hash` with **external** attribute names, and values and types thereof.
103
108
  def external_entry # rubocop:disable Style/TrivialAccessors
@@ -17,6 +17,7 @@ module Eco
17
17
 
18
18
  CORE_ATTRS = %w[
19
19
  id external_id email name
20
+ phone_number
20
21
  supervisor_id filter_tags
21
22
  archived
22
23
  contractor_organization_id
@@ -4,29 +4,34 @@ module Eco
4
4
  module People
5
5
  module Manage
6
6
  module Cache
7
- # Helper to locally cache the people manager.
7
+ # Helper to locally cache the people manager (download via API).
8
8
  # @param filename [String] the name of the file where the data should be cached.
9
9
  # @return [Eco::API::Organization::People] the `People` object with the data.
10
- def people_cache(filename = enviro.config.people.cache)
11
- log(:info) { 'Going to get all the people via API' }
10
+ def people_cache(filename = enviro.config.people.cache, modifier: [:save])
11
+ modifier = [modifier].flatten
12
12
 
13
- start = Time.now
14
- people = session.batch.get_people
15
- secs = (Time.now - start).round(3)
16
- cnt = people.count
17
- per_sec = (cnt.to_f / secs).round(2)
13
+ log(:info) { 'Going to get all the people via API' }
18
14
 
19
- log(:info) {
20
- "Loaded #{cnt} people in #{secs} seconds (#{per_sec} people/sec)"
21
- }
15
+ start = Time.now
16
+ session.batch.get_people.tap do |people|
17
+ secs = (Time.now - start).round(3)
18
+ cnt = people.count
19
+ per_sec = (cnt.to_f / secs).round(2)
22
20
 
23
- file = file_manager.save_json(people, filename, :timestamp)
21
+ log(:info) {
22
+ "Loaded #{cnt} people in #{secs} seconds (#{per_sec} people/sec)"
23
+ }
24
24
 
25
- log(:info) {
26
- "#{people.length} people loaded and saved locally to #{file}."
27
- }
25
+ if modifier.include?(:save)
26
+ file = file_manager.save_json(people, filename, :timestamp)
28
27
 
29
- Eco::API::Organization::People.new(people)
28
+ log(:info) {
29
+ "#{people.length} people loaded and saved locally to #{file}."
30
+ }
31
+ end
32
+ end.then do |people|
33
+ Eco::API::Organization::People.new(people)
34
+ end
30
35
  end
31
36
  end
32
37
  end
@@ -0,0 +1,29 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ module People
5
+ module Manage
6
+ module Filename
7
+ private
8
+
9
+ # Spot the source data file.
10
+ def people_filename(filename = enviro.config.people.cache, newest: false)
11
+ if newest
12
+ # search input file based on pattern (in case the name has a timestamp)
13
+ file_manager.dir.newest_file(file: filename).tap do |file|
14
+ next unless file
15
+
16
+ log(:info) {
17
+ "previous file found: #{file}"
18
+ }
19
+ end
20
+ else
21
+ file_manager.dir.file(filename, should_exist: true)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -22,19 +22,10 @@ module Eco
22
22
  modifier = [modifier].flatten
23
23
  load_file = %i[file newest].any? {|flag| modifier.include?(flag)}
24
24
 
25
- case
26
- when filename && load_file
27
- file = people_load_filename(filename, newest: modifier.include?(:newest))
25
+ if filename && load_file
26
+ load_cache(filename, newest: modifier.include?(:newest)).tap do |people|
27
+ next if people.is_a?(Eco::API::Organization::People)
28
28
 
29
- if file
30
- file_manager.load_json(file).tap do |people|
31
- next unless people.is_a?(Array)
32
-
33
- log(:info) {
34
- "#{people&.length} people loaded from file #{file}"
35
- }
36
- end
37
- else
38
29
  log(:error) {
39
30
  "could not find the file #{file_manager.dir.file(filename)}"
40
31
  }
@@ -43,43 +34,10 @@ module Eco
43
34
 
44
35
  people_load(modifier: modifier - %i[newest file])
45
36
  end
46
- when modifier.include?(:api)
47
- log(:info) { 'Going to get all the people via API (load)' }
48
-
49
- start = Time.now
50
- session.batch.get_people.tap do |people|
51
- secs = (Time.now - start).round(3)
52
- cnt = people.count
53
- per_sec = (cnt.to_f / secs).round(2)
54
-
55
- log(:info) {
56
- "Loaded #{cnt} people in #{secs} seconds (#{per_sec} people/sec)"
57
- }
58
-
59
- if modifier.include?(:save) && people && people.length.positive?
60
- file = file_manager.save_json(people, filename, :timestamp)
61
- log(:info) { "#{people.length} people saved to file #{file}." }
62
- end
63
- end
37
+ elsif modifier.include?(:api)
38
+ people_cache(filename, modifier: modifier)
64
39
  end.then do |people|
65
- Eco::API::Organization::People.new(people)
66
- end
67
- end
68
-
69
- private
70
-
71
- def people_load_filename(filename, newest: false)
72
- if newest
73
- # search input file based on pattern (in case the name has a timestamp)
74
- file_manager.dir.newest_file(file: filename).tap do |file|
75
- next unless file
76
-
77
- log(:info) {
78
- "previous file found: #{file}"
79
- }
80
- end
81
- else
82
- file_manager.dir.file(filename, should_exist: true)
40
+ Eco::API::Organization::People.new(people.to_a)
83
41
  end
84
42
  end
85
43
  end
@@ -0,0 +1,29 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ module People
5
+ module Manage
6
+ module LoadCache
7
+ private
8
+
9
+ # Finds the source data file and loads it.
10
+ # @return [Eco::API::Organization::People] the `People` object with the data.
11
+ def load_cache(filename = enviro.config.people.cache, newest: false)
12
+ return unless (file = people_filename(filename, newest: newest))
13
+
14
+ file_manager.load_json(file).then do |people|
15
+ next unless people.is_a?(Array)
16
+
17
+ log(:info) {
18
+ "#{people&.length} people loaded from file #{file}"
19
+ }
20
+
21
+ Eco::API::Organization::People.new(people)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -5,16 +5,18 @@ module Eco
5
5
  module Manage
6
6
  module Refresh
7
7
  # Helper to obtain all the elements of `people` anew from the _People Manager_.
8
+ # @note it does NOT save to a local file.
8
9
  # @note
9
- # 1. This helper is normally used to run consecutive usecases, where data needs refresh.
10
+ # 1. This helper is normally used to run consecutive usecases,
11
+ # where data needs refresh.
10
12
  # 2. It only includes new people if they are not dirty (they do not have pending updates)
11
13
  # - This contingency wouldn't be necessary if the server worked perfectly.
12
14
  # @param people [Eco::API::Organization::People] the people that needs refresh.
13
15
  # @param include_created [Boolean] include people created during this session? (will check `:create` batch jobs).
14
16
  # @return [Eco::API::Organization::People] the `People` object with the data.
15
17
  def people_refresh(people:, include_created: true) # rubocop:disable Metrics/AbcSize
16
- people = people.newFrom people.select do |person|
17
- !person.new? || !person.dirty?
18
+ people = people.newFrom people.reject do |person|
19
+ person.new? && person.dirty?
18
20
  end
19
21
 
20
22
  ini = people.length
@@ -1,3 +1,5 @@
1
+ require_relative 'manage/filename'
2
+ require_relative 'manage/load_cache'
1
3
  require_relative 'manage/cache'
2
4
  require_relative 'manage/load'
3
5
  require_relative 'manage/search'
@@ -8,6 +10,8 @@ module Eco
8
10
  class MicroCases
9
11
  module People
10
12
  module Manage
13
+ include Filename
14
+ include LoadCache
11
15
  include Cache
12
16
  include Load
13
17
  include Search
@@ -68,7 +68,13 @@ module Eco
68
68
  @path.push(self.id) unless top?
69
69
 
70
70
  @nodes = @raw_nodes.map.with_index do |cnode, idx|
71
- self.class.new(cnode, depth: depth + 1, path: @path.dup, parent: self, _weight: idx)
71
+ self.class.new(
72
+ cnode,
73
+ depth: depth + 1,
74
+ path: @path.dup,
75
+ parent: self,
76
+ _weight: idx
77
+ )
72
78
  end
73
79
 
74
80
  init_hashes
@@ -199,8 +205,9 @@ module Eco
199
205
  # @param max_depth [Boolean] up to what level `depth` nodes should be included.
200
206
  # @return [Array[Hash]] where `Hash` is a `node` (i.e. `{"tag" => TAG, "nodes": Array[Hash]}`)
201
207
  def as_json( # rubocop:disable Metrics/AbcSize
202
- include_children: true, include_archived: true,
203
- max_depth: total_depth,
208
+ include_children: true,
209
+ include_archived: true,
210
+ max_depth: total_depth,
204
211
  &block
205
212
  )
206
213
  max_depth ||= total_depth
@@ -230,7 +237,7 @@ module Eco
230
237
  depth + 1
231
238
  ]
232
239
  node_json = self.class::HEADER.zip(values).to_h
233
- node_json["nodes"] = children_json if include_children
240
+ node_json['nodes'] = children_json if include_children
234
241
  node_json = yield(node_json, self) if block_given?
235
242
  node_json
236
243
  end
@@ -56,7 +56,7 @@ module Eco
56
56
  entries.each_with_index do |entry, i|
57
57
  if (i % 10).zero?
58
58
  percent = i * 100 / entries.length
59
- print "Searching: #{percent.round}% (#{i}/#{entries.length} entries)\r"
59
+ print "Searching in results: #{percent.round}% (#{i}/#{entries.length} entries)\r"
60
60
  $stdout.flush
61
61
  end
62
62
 
@@ -75,7 +75,7 @@ module Eco
75
75
  unless email.empty?
76
76
  people_matching = get(
77
77
  params: params.merge(q: email),
78
- silent: silent,
78
+ silent: true,
79
79
  options: options
80
80
  ).select do |person|
81
81
  person.email == email
@@ -94,7 +94,7 @@ module Eco
94
94
 
95
95
  private
96
96
 
97
- def get(params: {}, silent: false, options: self.options)
97
+ def get(params: {}, silent: true, options: self.options)
98
98
  msg = 'cannot batch get without api connnection, '
99
99
  msg << 'please provide a valid api connection!'
100
100
  fatal msg unless (people_api = api&.people)
@@ -3,69 +3,72 @@ module Eco
3
3
  class Session
4
4
  class Config
5
5
  class People < BaseConfig
6
-
7
6
  def cache=(file)
8
- self["cache"] = file
7
+ self['cache'] = file
9
8
  end
10
9
 
11
10
  def cache
12
- self["cache"] ||= "cache/people.json"
11
+ self['cache'] ||= 'cache/people.json'
13
12
  end
14
13
 
15
14
  def partial_cache
16
- if file = self.cache
17
- File.join(File.dirname(file),
18
- File.basename(file, File.extname(file)) + "_partial" + File.extname(file)
19
- )
20
- end
15
+ return unless (file = self.cache)
16
+
17
+ extension = File.extname(file)
18
+ basename = File.basename(file, extension)
19
+
20
+ File.join(
21
+ File.dirname(file),
22
+ "#{basename}_partial#{extension}"
23
+ )
21
24
  end
22
25
 
23
26
  # specifies if people search should be strict or not
24
27
  def strict_search=(value)
25
- self["strict_search"] = !!value
28
+ self['strict_search'] = !!value
26
29
  end
27
30
 
28
31
  def strict_search?
29
- self["strict_search"]
32
+ self['strict_search']
30
33
  end
31
34
 
32
35
  # api queried logs
33
36
  def requests_folder=(folder)
34
- self["requests_folder"] = folder
37
+ self['requests_folder'] = folder
35
38
  end
36
39
 
37
40
  def requests_folder
38
- self["requests_folder"] ||= "requests"
41
+ self['requests_folder'] ||= 'requests'
39
42
  end
40
43
 
41
44
  # people to exclude from update feeds
42
45
  def discarded_file=(file)
43
- self["discarded_file"] = file
46
+ self['discarded_file'] = file
44
47
  end
45
48
 
46
49
  def discarded_file
47
- self["discarded_file"]
50
+ self['discarded_file']
48
51
  end
49
52
 
50
53
  # with given a person what is the criteria of exclusion
51
54
  def api_excluded(&block)
52
- return self["api_excluded"] unless block_given?
53
- self["api_excluded"] = block
55
+ return self['api_excluded'] unless block_given?
56
+
57
+ self['api_excluded'] = block
54
58
  end
55
59
 
56
60
  # internal-external fields map
57
61
  def fields_mapper=(file)
58
- self["fields_mapper"] = file
62
+ self['fields_mapper'] = file
59
63
  end
60
64
 
61
65
  def fields_mapper
62
- self["fields_mapper"]
66
+ self['fields_mapper']
63
67
  end
64
68
 
65
69
  # person model
66
70
  attr_key :default_usergroup, :default_schema, :default_login_method
67
71
 
68
-
69
72
  def default_usergroup?
70
73
  !!default_usergroup
71
74
  end
@@ -80,7 +83,7 @@ module Eco
80
83
 
81
84
  # @return [Hash] with defined pairs format `key` and Person parsers.
82
85
  def parsers
83
- self["parsers"] ||= {}
86
+ self['parsers'] ||= {}
84
87
  end
85
88
 
86
89
  # The person parser/serializer for a given format (default `csv`).
@@ -1,7 +1,7 @@
1
1
  class Eco::API::UseCases::Default::Locations::TagtreeUpload < Eco::API::UseCases::GraphQL::Samples::Location::Command
2
2
  require_relative 'cli/tagtree_upload_cli'
3
3
 
4
- name "tagtree-upload"
4
+ name 'tagtree-upload'
5
5
  type :other
6
6
 
7
7
  COMMANDS_PER_PAGE = 45
@@ -11,10 +11,28 @@ class Eco::API::UseCases::Default::Locations::TagtreeUpload < Eco::API::UseCases
11
11
  false
12
12
  end
13
13
 
14
+ def compare_live_with_file?
15
+ true
16
+ end
17
+
18
+ # # With given the commands, it generates the input of the endpoint mutation.
19
+ # # @param commands [Array<Hash>]
20
+ # def input(commands, force_continue: force_continue?)
21
+ # {
22
+ # clientMutationId: '',
23
+ # id: target_structure_id,
24
+ # force: force_continue,
25
+ # commands: commands
26
+ # }
27
+ # end
28
+
14
29
  # We only define the `:insert` stage
15
30
  def inputs(force_continue: force_continue?)
16
31
  {}.tap do |stages|
17
- stages[:insert] = input(insert_commands, force_continue: force_continue)
32
+ stages[:insert] = input(
33
+ insert_commands,
34
+ force_continue: force_continue
35
+ )
18
36
  end.each do |stage, input|
19
37
  yield(input, stage) if block_given?
20
38
  end
@@ -29,16 +29,20 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
29
29
  # At any moment we want to know how the live tree is
30
30
  # @note it also does a backup
31
31
  # @return [Eco::API::Organization::TagTree] the latest tree (`current_tree`)
32
- def track_current_tree(tree)
32
+ def track_current_tree(tree) # rubocop:disable Metrics/AbcSize
33
+ return unless track_current_tree?
33
34
  return if simulate?
34
35
  return if tree.nil?
35
36
 
36
- latest_tree = tree if tree.is_a?(Eco::API::Organization::TagTree)
37
- if tree.respond_to?(:treeify) && track_current_tree?
37
+ tree_id = current_tree&.id
38
+ tree_name = current_tree&.name
39
+ tree_id = tree.id if tree.respond_to?(:id)
40
+ tree_name = tree.name if tree.respond_to?(:name)
41
+ latest_tree = tree if tree.is_a?(Eco::API::Organization::TagTree)
42
+
43
+ if tree.respond_to?(:treeify)
38
44
  latest_tree ||= Eco::API::Organization::TagTree.new(
39
- tree.treeify,
40
- id: tree.id,
41
- name: tree.name
45
+ tree.treeify
42
46
  )
43
47
  end
44
48
 
@@ -46,6 +50,9 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
46
50
  next unless latest_tree.is_a?(Eco::API::Organization::TagTree)
47
51
  next if latest_tree.empty?
48
52
 
53
+ latest_tree.id = tree_id if latest_tree.id.nil?
54
+ latest_tree.name = tree_name if latest_tree.name.nil?
55
+
49
56
  # a backup happens:
50
57
  self.current_tree = latest_tree
51
58
  end
@@ -53,7 +60,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
53
60
 
54
61
  # @param tree [Eco::API::Organization::TagTree, Hash, Array]
55
62
  # @return [Boolean] whether or not the backup was created
56
- def backup_tree(tree = current_tree || live_tree)
63
+ def backup_tree(tree = current_tree || live_tree) # rubocop:disable Naming/PredicateMethod
57
64
  return false if simulate?
58
65
  case tree
59
66
  when Eco::API::Organization::TagTree
@@ -22,7 +22,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
22
22
  log(:warn) { msg }
23
23
 
24
24
  # a backup happens:
25
- return nil unless (self.current_tree = session_live_tree)
25
+ return unless (self.current_tree = session_live_tree)
26
26
 
27
27
  @target_structure_id = current_tree.id
28
28
  end
@@ -18,7 +18,6 @@ class Eco::API::UseCases::GraphQL::Helpers::Location::Command::Diff
18
18
  class_ids = class_ids.compact.map {|val| val.split('|')}.flatten.uniq
19
19
  h['classificationIds'] = class_ids
20
20
  end
21
-
22
21
  if archive? || insert?
23
22
  # We assume archives do not have `move` nor update `id` or `name`
24
23
  h['nodeId'] = node_id || node_id_prev
@@ -2,7 +2,6 @@ class Eco::API::UseCases::GraphQL::Helpers::Location::Command::Diffs
2
2
  module Stages
3
3
  module DiffSortable
4
4
  module ForArchive
5
-
6
5
  private
7
6
 
8
7
  def only_first_ancestor_in_chains(raw_diffs)