eco-helpers 3.0.4 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/CHANGELOG.md +55 -4
  4. data/eco-helpers.gemspec +1 -1
  5. data/lib/eco/api/common/class_helpers.rb +24 -23
  6. data/lib/eco/api/common/class_meta_basics.rb +0 -2
  7. data/lib/eco/api/common/loaders/use_case.rb +1 -0
  8. data/lib/eco/api/common/people/entry_factory.rb +6 -4
  9. data/lib/eco/api/common/people/person_entry.rb +4 -6
  10. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +25 -12
  11. data/lib/eco/api/common/people/person_parser.rb +8 -0
  12. data/lib/eco/api/common/session/base_session.rb +1 -1
  13. data/lib/eco/api/common/session/environment.rb +7 -0
  14. data/lib/eco/api/common/session/file_manager.rb +15 -8
  15. data/lib/eco/api/common/session/logger/cache.rb +14 -10
  16. data/lib/eco/api/common/session/logger/log.rb +8 -7
  17. data/lib/eco/api/common/session/mailer.rb +22 -13
  18. data/lib/eco/api/common/session/s3_uploader.rb +29 -20
  19. data/lib/eco/api/microcases/people_search.rb +1 -1
  20. data/lib/eco/api/organization/login_providers.rb +11 -4
  21. data/lib/eco/api/organization/node_classifications.rb +3 -0
  22. data/lib/eco/api/organization/presets_factory.rb +37 -31
  23. data/lib/eco/api/organization/tag_tree.rb +14 -5
  24. data/lib/eco/api/policies/default_policies/99_user_access_policy.rb +28 -18
  25. data/lib/eco/api/session/batch/errors.rb +38 -20
  26. data/lib/eco/api/session/batch/job.rb +252 -135
  27. data/lib/eco/api/session/batch/status.rb +55 -36
  28. data/lib/eco/api/session/batch.rb +2 -2
  29. data/lib/eco/api/session/config/base_config.rb +12 -11
  30. data/lib/eco/api/session/config/tagtree.rb +10 -14
  31. data/lib/eco/api/session/config/workflow.rb +15 -3
  32. data/lib/eco/api/session/config.rb +19 -26
  33. data/lib/eco/api/session.rb +13 -4
  34. data/lib/eco/api/usecases/cli.rb +4 -0
  35. data/lib/eco/api/usecases/default/locations/cli/codes_to_tags_cli.rb +18 -0
  36. data/lib/eco/api/usecases/default/locations/cli/csv_to_tree_cli.rb +12 -0
  37. data/lib/eco/api/usecases/default/locations/cli/tagtree_paths_cli.rb +12 -0
  38. data/lib/eco/api/usecases/default/locations/codes_to_tags_case.rb +32 -13
  39. data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +15 -5
  40. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +6 -0
  41. data/lib/eco/api/usecases/default/locations/tagtree_paths_case.rb +51 -0
  42. data/lib/eco/api/usecases/default/locations.rb +1 -1
  43. data/lib/eco/api/usecases/default/people/amend/cli/reinvite_sync_cli.rb +8 -0
  44. data/lib/eco/api/usecases/default/people/amend/cli/reinvite_trans_cli.rb +11 -0
  45. data/lib/eco/api/usecases/default/people/amend/cli/restore_db_cli.rb +26 -0
  46. data/lib/eco/api/usecases/default/people/amend/reinvite_sync_case.rb +2 -0
  47. data/lib/eco/api/usecases/default/people/amend/reinvite_trans_case.rb +2 -0
  48. data/lib/eco/api/usecases/default/people/amend/restore_db_case.rb +3 -0
  49. data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +15 -5
  50. data/lib/eco/api/usecases/default/people/treat/cli/analyse_people_cli.rb +66 -0
  51. data/lib/eco/api/usecases/default/people/treat/cli/org_data_convert_cli.rb +35 -0
  52. data/lib/eco/api/usecases/default/people/treat/cli/supers_cyclic_identify_cli.rb +15 -0
  53. data/lib/eco/api/usecases/default/people/treat/cli/supers_hierachy_cli.rb +15 -0
  54. data/lib/eco/api/usecases/default/people/treat/org_data_convert_case.rb +11 -5
  55. data/lib/eco/api/usecases/default/people/treat/supers_cyclic_identify_case.rb +28 -7
  56. data/lib/eco/api/usecases/default/people/treat/supers_hierarchy_case.rb +32 -9
  57. data/lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb +2 -1
  58. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +2 -2
  59. data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +1 -0
  60. data/lib/eco/api/usecases/graphql/helpers/base/error_handling.rb +52 -0
  61. data/lib/eco/api/usecases/graphql/helpers/base.rb +1 -0
  62. data/lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb +5 -0
  63. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +2 -0
  64. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +2 -0
  65. data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +2 -1
  66. data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +3 -0
  67. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +1 -0
  68. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +3 -0
  69. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +19 -18
  70. data/lib/eco/api/usecases/graphql/samples/location/command/results.rb +1 -7
  71. data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +11 -6
  72. data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +3 -8
  73. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +2 -0
  74. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible.rb +5 -2
  75. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +10 -4
  76. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +6 -2
  77. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +2 -0
  78. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list.rb +5 -3
  79. data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +1 -0
  80. data/lib/eco/api/usecases/ooze_samples/helpers_migration/copying.rb +66 -29
  81. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +25 -3
  82. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +10 -0
  83. data/lib/eco/api/usecases/use_case.rb +3 -1
  84. data/lib/eco/cli/config/use_cases.rb +4 -0
  85. data/lib/eco/cli/scripting/args_helpers.rb +3 -2
  86. data/lib/eco/cli/scripting/argument.rb +2 -2
  87. data/lib/eco/cli_default/input.rb +49 -45
  88. data/lib/eco/cli_default/input_filters.rb +32 -17
  89. data/lib/eco/cli_default/options.rb +8 -4
  90. data/lib/eco/cli_default/people.rb +1 -1
  91. data/lib/eco/cli_default/people_filters.rb +32 -24
  92. data/lib/eco/cli_default/usecases.rb +8 -121
  93. data/lib/eco/cli_default/workflow.rb +6 -4
  94. data/lib/eco/csv/split.rb +2 -0
  95. data/lib/eco/csv/table.rb +13 -0
  96. data/lib/eco/data/files/encoding.rb +15 -8
  97. data/lib/eco/data/files/helpers.rb +6 -2
  98. data/lib/eco/data/hashes/diff_result.rb +5 -0
  99. data/lib/eco/data/locations/node_diff/nodes_diff.rb +13 -0
  100. data/lib/eco/data/locations/node_diff.rb +4 -0
  101. data/lib/eco/data/locations/node_level.rb +6 -0
  102. data/lib/eco/language/auxiliar_logger.rb +2 -0
  103. data/lib/eco/version.rb +1 -1
  104. data/lib/eco-helpers.rb +1 -1
  105. metadata +16 -6
  106. data/lib/eco/api/usecases/default/locations/create_tag_paths_case.rb +0 -25
  107. data/lib/eco/api/usecases/default/people/amend/reinvite_trans_cli.rb +0 -4
@@ -0,0 +1,52 @@
1
+ module Eco::API::UseCases::GraphQL::Helpers::Base
2
+ # Basic stuff you would need in any use case
3
+ module ErrorHandling
4
+ include Eco::Language::AuxiliarLogger
5
+
6
+ attr_reader :exception
7
+
8
+ private
9
+
10
+ def interrupted?(err = exception)
11
+ interrupt_errors.any? {|klass| err.is_a?(klass)}
12
+ end
13
+
14
+ def error_raised?
15
+ exception && !interrupted?
16
+ end
17
+
18
+ def rescued
19
+ yield
20
+ rescue StandardError => err
21
+ self.exception ||= err
22
+ log(:error) { err.patch_full_message }
23
+ end
24
+
25
+ def with_error_handling
26
+ @exception = nil
27
+ yield
28
+ rescue SystemExit => sext
29
+ @exception = sext
30
+ exit sext.status
31
+ rescue *interrupt_errors => int
32
+ @exception = int
33
+ raise
34
+ rescue SystemStackError
35
+ puts $! # rubocop:disable Style/SpecialGlobalVars
36
+ puts caller[0..100]
37
+ raise
38
+ rescue StandardError, SignalException => err
39
+ @exception = err
40
+ raise
41
+ end
42
+
43
+ def interrupt_errors
44
+ return @interrupt_errors if @interrupt_errors
45
+
46
+ errs = [Interrupt]
47
+ errs << IRB::Abort if Object.const_defined?(:IRB) && IRB.const_defined?(:Abort)
48
+
49
+ @interrupt_errors = errs
50
+ end
51
+ end
52
+ end
@@ -1,5 +1,6 @@
1
1
  module Eco::API::UseCases::GraphQL::Helpers
2
2
  module Base
3
+ require_relative 'base/error_handling'
3
4
  require_relative 'base/case_env'
4
5
  require_relative 'base/graphql_env'
5
6
 
@@ -10,7 +10,9 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
10
10
  # 2. If the value is wrong, it warns and returns `nil`
11
11
  def to_classification(value)
12
12
  return nil unless node_classifications?
13
+
13
14
  raise ArgumentError, "Expecting a single element. Given: #{value.class}" if value.is_a?(Enumerator)
15
+
14
16
  return nil unless value.is_a?(String)
15
17
 
16
18
  node_classifications.to_id(value).tap do |type|
@@ -28,7 +30,9 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
28
30
  # 2. If the value is wrong, it warns and returns `nil`
29
31
  def to_classification_name(value)
30
32
  return nil unless node_classifications?
33
+
31
34
  raise ArgumentError, "Expecting a single element. Given: #{value.class}" if value.is_a?(Enumerator)
35
+
32
36
  return nil unless value.is_a?(String)
33
37
 
34
38
  node_classifications.to_name(value) do |name|
@@ -46,6 +50,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
46
50
 
47
51
  def unknown_clasification!(value)
48
52
  return if unknown_classifications.include?(value)
53
+
49
54
  unknown_classifications << value
50
55
  log(:warn) {
51
56
  "Unknown location node classification '#{value}'"
@@ -12,6 +12,7 @@ class Eco::API::UseCases::GraphQL::Helpers::Location::Command::Diffs
12
12
  module ClassMethods
13
13
  def stage_command(stage)
14
14
  return :update if stage == :id_name
15
+
15
16
  stage
16
17
  end
17
18
  end
@@ -37,6 +38,7 @@ class Eco::API::UseCases::GraphQL::Helpers::Location::Command::Diffs
37
38
 
38
39
  def stage_diffs(stage)
39
40
  raise "There is NO support for stage '#{stage}'. Please review" unless respond_to?(stage)
41
+
40
42
  sort_diffs(stage) do
41
43
  send(stage)
42
44
  end
@@ -20,6 +20,7 @@ class Eco::API::UseCases::GraphQL::Helpers::Location::Command::Diffs
20
20
  # @yieldreturn [Array<Diff>] the raw diffs of `stage`
21
21
  def sort_diffs(stage)
22
22
  raise ArgumentError, "Expecting block but not given" unless block_given?
23
+
23
24
  raw_diffs = yield
24
25
 
25
26
  case stage
@@ -41,6 +42,7 @@ class Eco::API::UseCases::GraphQL::Helpers::Location::Command::Diffs
41
42
  def uniq_archive_token(raw_diffs, stage)
42
43
  raw_diffs.group_by(&:archived_token_prev).each_with_object([]) do |(token, token_diffs), out|
43
44
  next out.concat(token_diffs) unless token
45
+
44
46
  out << sort_top_to_bottom(token_diffs, stage).first
45
47
  end
46
48
  end
@@ -58,7 +58,8 @@ module Eco::API::UseCases::GraphQL::Helpers::Location::Command
58
58
  end
59
59
 
60
60
  def command_id
61
- return nil unless result
61
+ return unless result
62
+
62
63
  command_result["id"]
63
64
  end
64
65
 
@@ -124,14 +124,17 @@ module Eco::API::UseCases::GraphQL::Helpers::Location::Command
124
124
  # First error is relevant only if request was NOT forced to continue.
125
125
  def first_err_str
126
126
  return '' if force?
127
+
127
128
  pre_str = 'stopped on node'
128
129
  pre_str = 'first error' unless force?
130
+
129
131
  "(#{pre_str}: '#{first_errored&.node_id}' - idx: #{first_errored_idx})"
130
132
  end
131
133
 
132
134
  # Last successfully applied is relevant only if request was NOT forced to continue.
133
135
  def last_okay_str
134
136
  return '' if force?
137
+
135
138
  "(last node done: '#{last_applied&.node_id}' - idx: #{last_applied_idx})"
136
139
  end
137
140
  end
@@ -36,6 +36,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
36
36
  msg = "#{dry_run_msg}No commands for '#{desc}'."
37
37
  msg << " Skipping batch..." unless simulate?
38
38
  log(:info) { msg }
39
+
39
40
  return
40
41
  end
41
42
 
@@ -21,6 +21,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
21
21
  def to_csv(filename)
22
22
  CSV.open(filename, "w") do |fd|
23
23
  fd << %w[src_tags dst_tags]
24
+
24
25
  each do |tags_map|
25
26
  fd << tags_map.to_csv_row
26
27
  end
@@ -64,12 +65,14 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
64
65
 
65
66
  def <<(pair)
66
67
  raise ArgumentError, "Expecting pair of Array in Array. Given: #{pair}" unless self.class.correct_pair?(pair)
68
+
67
69
  add(*pair)
68
70
  end
69
71
 
70
72
  def add(from, to)
71
73
  raise ArgumentError, "Expecting Array. Given: #{from.class}" unless from.is_a?(Array)
72
74
  raise ArgumentError, "Expecting Array. Given: #{to.class}" unless to.is_a?(Array)
75
+
73
76
  new_src TagsMap.new(from, to)
74
77
  end
75
78
 
@@ -24,38 +24,39 @@ class Eco::API::UseCases::GraphQL::Samples::Location
24
24
 
25
25
  # Main processor
26
26
  def process # rubocop:disable Metrics/AbcSize
27
- self.error = false
28
- self.exception = nil
27
+ self.error = false
29
28
 
30
- super if defined?(super)
29
+ with_error_handling do
30
+ super if defined?(super)
31
31
 
32
- # this may trigger a backup of the tagtree
33
- self.current_tree ||= live_tree
32
+ # this may trigger a backup of the tagtree
33
+ self.current_tree ||= live_tree
34
34
 
35
- inputs(force_continue: force_continue?) do |input, stage|
36
- results[stage] ||= []
35
+ inputs(force_continue: force_continue?) do |input, stage|
36
+ results[stage] ||= []
37
37
 
38
- track_mode = batch_tree_track_mode(stage)
38
+ track_mode = batch_tree_track_mode(stage)
39
39
 
40
- # yields the result of each batch
41
- sliced_batches(input, desc: stage, track_tree_mode: track_mode) do |sliced_input, response, page, pages, done, total| # rubocop:disable Metrics/ParameterLists, Layout/LineLength
42
- track_current_tree(response&.structure)
40
+ # yields the result of each batch
41
+ sliced_batches(input, desc: stage, track_tree_mode: track_mode) do |sliced_input, response, page, pages, done, total| # rubocop:disable Metrics/ParameterLists, Layout/LineLength
42
+ track_current_tree(response&.structure)
43
43
 
44
- results[stage] << (page_results = request_results_class.new(sliced_input, response))
45
- update_tags_remap_table(page_results, stage, current_tree)
44
+ results[stage] << (page_results = request_results_class.new(sliced_input, response))
45
+ update_tags_remap_table(page_results, stage, current_tree)
46
+
47
+ self.error = page_errors?(page_results, page, pages, done, total, stage: stage)
48
+ break if error
49
+ end
46
50
 
47
- self.error = page_errors?(page_results, page, pages, done, total, stage: stage)
48
51
  break if error
49
52
  end
50
-
51
- break if error
52
53
  end
53
54
  rescue SystemStackError
54
55
  puts $! # rubocop:disable Style/SpecialGlobalVars
55
56
  puts caller[0..100]
56
57
  raise
57
- rescue StandardError => e
58
- log(:error) { self.exception ||= e.patch_full_message }
58
+ rescue StandardError => err
59
+ log(:error) { err.patch_full_message }
59
60
  raise
60
61
  ensure
61
62
  rescued { self.tags_remap_csv_file = generate_tags_remap_csv }
@@ -3,13 +3,7 @@ class Eco::API::UseCases::GraphQL::Samples::Location
3
3
  module Command::Results
4
4
  include Eco::API::UseCases::GraphQL::Helpers::Base::CaseEnv
5
5
 
6
- attr_accessor :error, :exception
7
-
8
- def rescued
9
- yield
10
- rescue StandardError => e
11
- log(:error) { self.exception ||= e.patch_full_message }
12
- end
6
+ attr_accessor :error
13
7
 
14
8
  def request_results_class
15
9
  Eco::API::UseCases::GraphQL::Helpers::Location::Command::Results
@@ -7,7 +7,7 @@ class Eco::API::UseCases::GraphQL::Samples::Location
7
7
 
8
8
  class << self
9
9
  def included(base)
10
- super(base)
10
+ super
11
11
  base.send :include, Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeDiff
12
12
  base.send :include, Eco::API::UseCases::GraphQL::Samples::Location::Command::DSL
13
13
  base.send :include, Eco::API::UseCases::GraphQL::Utils::Sftp
@@ -17,9 +17,11 @@ class Eco::API::UseCases::GraphQL::Samples::Location
17
17
 
18
18
  module InstanceMethods
19
19
  def process
20
- super
20
+ with_error_handling do
21
+ super
22
+ end
21
23
  ensure
22
- rescued { re_archive }
24
+ rescued { re_archive } unless error_raised?
23
25
  rescued { email_digest('TagTree Update') }
24
26
  end
25
27
 
@@ -28,6 +30,8 @@ class Eco::API::UseCases::GraphQL::Samples::Location
28
30
  # @note this is an additional necessary step
29
31
  def re_archive
30
32
  return if simulate?
33
+ return if error_raised?
34
+
31
35
  stage = :rearchive
32
36
 
33
37
  nodes_diff_class.new(
@@ -75,6 +79,7 @@ class Eco::API::UseCases::GraphQL::Samples::Location
75
79
  # 2. `REMOTE_FOLDER` const
76
80
  def close_handling_tags_remap_csv
77
81
  return false unless super
82
+
78
83
  upload(tags_remap_csv_file) unless remote_subfolder.nil?
79
84
  true
80
85
  end
@@ -83,9 +88,9 @@ class Eco::API::UseCases::GraphQL::Samples::Location
83
88
  return if simulate?
84
89
  return if options.dig(:workflow, :no_email)
85
90
 
86
- digest_msgs = logger.cache.logs(level: %i[info error warn])
87
- exception = exception ? " - Exception!" : ''
88
- subject = "#{config.active_enviro} - #{title}#{exception}"
91
+ digest_msgs = logger.cache.logs(level: %i[info error warn])
92
+ str_exception = exception ? " - Exception!" : ''
93
+ subject = "#{config.active_enviro} - #{title}#{str_exception}"
89
94
  session.mail(subject: subject, body: digest_msgs.join)
90
95
  end
91
96
 
@@ -58,22 +58,17 @@ class Eco::API::UseCases::GraphQL::Samples::Location
58
58
  next if prev_id == new_id
59
59
 
60
60
  tags_remap_table << [[prev_id], [new_id]]
61
-
62
- # next unless ref_tree.is_a?(Eco::API::Organization::TagTree)
63
- # next unless ref_tree.tag?(new_id)
64
-
65
- # msg = "Node '#{prev_id}' was updated to '#{new_id}', "
66
- # msg << "but in current structure '#{new_id}' is not present"
67
- # log(:warn) { msg }
68
61
  end
69
62
  end
70
63
 
71
64
  # Generates the final tags remap file
72
65
  def generate_tags_remap_csv(filename = tags_remap_csv_full_filename)
73
- return nil if tags_remap_table.empty?
66
+ return if tags_remap_table.empty?
67
+
74
68
  timestamp_file(filename).tap do |file|
75
69
  CSV.open(file, 'w') do |csv|
76
70
  csv << %w[prev_node_ids new_node_ids]
71
+
77
72
  tags_remap_table.each do |tags_remap|
78
73
  csv << tags_remap.to_csv_row
79
74
  end
@@ -13,6 +13,7 @@ module Eco::API::UseCases::GraphQL::Samples::Location::Service
13
13
 
14
14
  def transform_classifications(row)
15
15
  return row if node_classifications_maping.empty?
16
+
16
17
  row['classifications'] = into_a(row['classifications']).map do |type|
17
18
  node_classifications_map(type)
18
19
  end.join('|')
@@ -21,6 +22,7 @@ module Eco::API::UseCases::GraphQL::Samples::Location::Service
21
22
  # Helper to map classifications
22
23
  def node_classifications_map(value)
23
24
  return value unless node_classifications_maping.key?(value)
25
+
24
26
  node_classifications_maping[value]
25
27
  end
26
28
 
@@ -8,7 +8,7 @@ module Eco::API::UseCases::GraphQL::Samples::Location::Service
8
8
  module Convertible
9
9
  class << self
10
10
  def included(base)
11
- super(base)
11
+ super
12
12
  base.send :include, Inputable
13
13
  end
14
14
  end
@@ -24,12 +24,15 @@ module Eco::API::UseCases::GraphQL::Samples::Location::Service
24
24
 
25
25
  csv.transform_headers do |name|
26
26
  next name unless header_maps.key?(name)
27
+
27
28
  header_maps[name]
28
29
  end
29
30
  end.then do |csv|
30
31
  transform_input_csv(csv).tap do |res|
31
32
  next if res.is_a?(Eco::CSV::Table)
32
- raise ArgumentError, "Expecting and Eco::CSV::Table. Given: #{res.class}"
33
+
34
+ msg = "Expecting and Eco::CSV::Table. Given: #{res.class}"
35
+ raise ArgumentError, msg
33
36
  end
34
37
  end
35
38
  end
@@ -46,13 +46,15 @@ module Eco::API::UseCases::GraphQL::Samples
46
46
 
47
47
  class << self
48
48
  def included(base)
49
- super(base)
49
+ super
50
50
  base.send :include, Convertible
51
51
  end
52
52
  end
53
53
 
54
54
  def process
55
- compare
55
+ with_error_handling do
56
+ compare
57
+ end
56
58
  end
57
59
 
58
60
  def compare
@@ -92,7 +94,9 @@ module Eco::API::UseCases::GraphQL::Samples
92
94
 
93
95
  def live_nodes_list
94
96
  @live_nodes_list ||= as_nodes_json(input_tagtree).tap do |list|
95
- log(:info) { "Converted live tree to list of #{list.count} hash-nodes" }
97
+ log(:info) {
98
+ "Converted live tree to list of #{list.count} hash-nodes"
99
+ }
96
100
  end
97
101
  end
98
102
 
@@ -103,7 +107,9 @@ module Eco::API::UseCases::GraphQL::Samples
103
107
  # 2. `org_tree` is native from `Eco::Data::Locations::NodeBase::CsvConvert`
104
108
  def file_nodes_list
105
109
  @file_nodes_list ||= as_nodes_json(file_tree).tap do |list|
106
- log(:info) { "Converted input csv file to list of #{list.count} hash-nodes" }
110
+ log(:info) {
111
+ "Converted input csv file to list of #{list.count} hash-nodes"
112
+ }
107
113
  end
108
114
  end
109
115
 
@@ -12,8 +12,10 @@ module Eco::API::UseCases::GraphQL::Samples::Location::Service
12
12
 
13
13
  def node_parser_block
14
14
  return @node_parser_block if instance_variable_defined?(:@node_parser_block)
15
+
15
16
  custom_before = custom_node_parser_before_block
16
17
  custom_after = custom_node_parser_block
18
+
17
19
  @node_parser_block = proc do |node_hash, node|
18
20
  node_hash.tap do
19
21
  custom_before&.call(node_hash, node)
@@ -25,12 +27,14 @@ module Eco::API::UseCases::GraphQL::Samples::Location::Service
25
27
 
26
28
  # Grabs the custom node parser that runs after the generic one
27
29
  def custom_node_parser_block
28
- return nil unless respond_to?(:custom_node_parser, true)
30
+ return unless respond_to?(:custom_node_parser, true)
31
+
29
32
  method(:custom_node_parser)
30
33
  end
31
34
 
32
35
  def custom_node_parser_before_block
33
- return nil unless respond_to?(:custom_node_parser_before, true)
36
+ return unless respond_to?(:custom_node_parser_before, true)
37
+
34
38
  method(:custom_node_parser_before)
35
39
  end
36
40
 
@@ -22,9 +22,11 @@ module Eco::API::UseCases::GraphQL::Samples::Location::Service
22
22
  end.each_with_object([]) do |node, list|
23
23
  list << node.as_json(include_children: false).transform_keys do |key|
24
24
  next key unless node_attr_maps.key?(key)
25
+
25
26
  node_attr_maps[key]
26
27
  end.tap do |node_hash|
27
28
  node_parser_block&.call(node_hash, node)
29
+
28
30
  yield(node_hash, node) if block_given?
29
31
  end
30
32
  end.compact.reject(&:empty?)
@@ -31,10 +31,12 @@ module Eco::API::UseCases::GraphQL::Samples
31
31
  include Converter
32
32
 
33
33
  def process
34
- as_nodes_json(input_tagtree).tap do |list|
35
- next generate_live_nodes_file(list) unless list.empty?
34
+ with_error_handling do
35
+ as_nodes_json(input_tagtree).tap do |list|
36
+ next generate_live_nodes_file(list) unless list.empty?
36
37
 
37
- log(:error) { "There are no location nodes!" }
38
+ log(:error) { "There are no location nodes!" }
39
+ end
38
40
  end
39
41
  end
40
42
  end
@@ -41,6 +41,7 @@ class Eco::API::UseCases::OozeCases::ExportRegisterCase < Eco::API::UseCases::Oo
41
41
  def build_tags_filter(mode = :any)
42
42
  tags = option_tags(mode)
43
43
  return nil if !tags || tags.empty?
44
+
44
45
  tags_filter(tags, any: mode == :any)
45
46
  end
46
47
 
@@ -1,16 +1,21 @@
1
+ # rubocop:disable Lint/DuplicateBranch
1
2
  class Eco::API::UseCases::OozeSamples
2
3
  module HelpersMigration
3
4
  module Copying
5
+ include Eco::Language::AuxiliarLogger
6
+
4
7
  def session
5
8
  defined?(super)? super : @session
6
9
  end
7
10
 
8
- def logger
9
- session.logger
10
- end
11
-
12
11
  def copy_generic_paired_fields(src, dst, src_excluded: [], dst_excluded: [], exclude_ximport: false)
13
- HelpersMigration::TypedFieldsPairing.new(src, dst, src_excluded: src_excluded, dst_excluded: dst_excluded, exclude_ximport: false).tap do |pairing|
12
+ HelpersMigration::TypedFieldsPairing.new(
13
+ src,
14
+ dst,
15
+ src_excluded: src_excluded,
16
+ dst_excluded: dst_excluded,
17
+ exclude_ximport: exclude_ximport
18
+ ).tap do |pairing|
14
19
  pairing.each_pair do |src_fld, dst_fld|
15
20
  copy_field_content(src_fld, dst_fld)
16
21
  yield(src_fld, dst_fld, pairing) if block_given?
@@ -21,18 +26,35 @@ class Eco::API::UseCases::OozeSamples
21
26
  def copy_hooked_fields(src, dst, hook:, type:, fields_tracker: nil, src_excluded: [], dst_excluded: [])
22
27
  case hook
23
28
  when String
24
- with_src_dst_field_pair(src, dst, label: to_regex(hook), type: type, src_excluded: src_excluded, dst_excluded: dst_excluded) do |src_fld, dst_fld|
25
- copy_field_content(src_fld, dst_fld).tap do |result|
26
- fields_tracker.resolve(src_fld, dst_fld) if fields_tracker
29
+ with_src_dst_field_pair(
30
+ src,
31
+ dst,
32
+ label: to_regex(hook),
33
+ type: type,
34
+ src_excluded: src_excluded,
35
+ dst_excluded: dst_excluded
36
+ ) do |src_fld, dst_fld|
37
+ copy_field_content(src_fld, dst_fld).tap do
38
+ fields_tracker&.resolve(src_fld, dst_fld)
27
39
  yield(src_fld, dst_fld, fields_tracker) if block_given?
28
40
  end
29
41
  end
30
42
  when Hash
31
43
  hook.each do |hook_src, hook_dst|
32
- src_lab, dst_lab = to_regex(hook_src), to_regex(hook_dst)
33
- with_src_dst_field_pair(src, dst, label: src_lab, label_dst: dst_lab, type: type, src_excluded: src_excluded, dst_excluded: dst_excluded) do |src_fld, dst_fld|
34
- copy_field_content(src_fld, dst_fld).tap do |result|
35
- fields_tracker.resolve(src_fld, dst_fld) if fields_tracker
44
+ src_lab = to_regex(hook_src)
45
+ dst_lab = to_regex(hook_dst)
46
+
47
+ with_src_dst_field_pair(
48
+ src,
49
+ dst,
50
+ label: src_lab,
51
+ label_dst: dst_lab,
52
+ type: type,
53
+ src_excluded: src_excluded,
54
+ dst_excluded: dst_excluded
55
+ ) do |src_fld, dst_fld|
56
+ copy_field_content(src_fld, dst_fld).tap do
57
+ fields_tracker&.resolve(src_fld, dst_fld)
36
58
  yield(src_fld, dst_fld, fields_tracker) if block_given?
37
59
  end
38
60
  end
@@ -46,60 +68,72 @@ class Eco::API::UseCases::OozeSamples
46
68
 
47
69
  # @note
48
70
  # - When used with `type: nil` it may pair fields of different type. There isn't refinement for this yet.
49
- def with_src_dst_field_pair(src, dst, label: nil, label_dst: label, type: nil, src_excluded: [], dst_excluded: [])
50
- unless respond_to?(:with_fields, true)
51
- raise "These helpers are to be included in class cases inheriting from Eco::API::UseCases::OozeSamples::RegisterUpdateCase"
52
- end
71
+ def with_src_dst_field_pair(src, dst, label: nil, label_dst: label, type: nil, src_excluded: [], dst_excluded: []) # rubocop:disable Metrics/AbcSize
72
+ msg = "These helpers are to be included in class cases inheriting from Eco::API::UseCases::OozeSamples::RegisterUpdateCase"
73
+ raise msg unless respond_to?(:with_fields, true)
74
+
53
75
  src_flds = with_fields(src, label: label, type: type)
54
76
  dst_flds = with_fields(dst, label: label_dst, type: type)
55
- src_fld, dst_fld = src_flds.first, dst_flds.first
77
+ src_fld = src_flds.first
78
+ dst_fld = dst_flds.first
56
79
 
57
80
  # Not found
58
81
  if dst_flds.empty? || src_flds.empty?
59
- msg = "There isn't a '#{type}'"
82
+ msg = "There isn't a '#{type}'"
60
83
  dst_msg = dst_flds.empty?? "destination field named '#{label_dst}'" : nil
61
84
  src_msg = src_flds.empty?? "source field named '#{label}'" : nil
62
- msg << " #{[dst_msg, src_msg].join(" or ")} (source: '#{src.id}')"
63
- logger.warn(msg)
85
+ msg << " #{[dst_msg, src_msg].join(" or ")} (source: '#{src.id}')"
86
+
87
+ log(:warn) { msg }
64
88
  return nil, nil
65
89
  end
66
90
 
67
91
  # Fields exclusion
68
92
  dst_flds -= dst_excluded unless dst_excluded.empty?
69
93
  src_flds -= src_excluded unless src_excluded.empty?
70
- src_fld, dst_fld = src_flds.first, dst_flds.first
94
+
95
+ src_fld = src_flds.first
96
+ dst_fld = dst_flds.first
97
+
71
98
  return src_fld, dst_fld if dst_flds.empty? || src_flds.empty?
72
99
 
73
100
  if dst_flds.count > 1
74
- logger.warn("There are #{dst_flds.count} destination '#{type}' fields named '#{label_dst}' (source: '#{dst.id}'). Using first...")
101
+ log(:warn) {
102
+ msg = "There are #{dst_flds.count} destination '#{type}' fields "
103
+ msg << "named '#{label_dst}' (source: '#{dst.id}'). Using first..."
104
+ msg
105
+ }
75
106
  end
76
107
 
77
108
  if src_flds.count > 1
78
- msg = "There are #{src_flds.count} source '#{type}' fields named '#{label}' (source: '#{src.id}'). "
109
+ msg = "There are #{src_flds.count} source '#{type}' fields named '#{label}' (source: '#{src.id}'). "
79
110
  src_content = src_flds.reject(&:empty?)
111
+
80
112
  if src_content.empty?
81
113
  msg << "None with content. Using first..."
82
114
  else
83
115
  src_fld = src_content.first
116
+
84
117
  if src_content.count == 1
85
118
  msg << "Using the only one with content (idx: #{src_flds.index(src_fld)})..."
86
119
  else
87
120
  msg << "#{src_content.count} have content. Using first..."
88
121
  end
89
122
  end
90
- logger.warn(msg)
123
+
124
+ log(:warn) { msg }
91
125
  end
92
126
 
93
- [src_fld, dst_fld].tap do |(src_fld, dst_fld)|
127
+ [src_fld, dst_fld].tap do
94
128
  yield(src_fld, dst_fld) if block_given?
95
129
  end
96
130
  end
97
131
 
98
- def copy_field_content(src, dst)
132
+ def copy_field_content(src, dst) # rubocop:disable Metrics/AbcSize
99
133
  type = src.type
100
134
  case type
101
135
  when "select"
102
- src.values.each {|val| dst.select(val)}
136
+ src.values.each {|val| dst.select(val)} # rubocop:disable Style/HashEachMethods
103
137
  dst.other_desc = src.other_desc if src.other && src.other_desc && dst.other
104
138
  when "plain_text", "date", "number", "gauge"
105
139
  dst.value = src.value
@@ -110,8 +144,9 @@ class Eco::API::UseCases::OozeSamples
110
144
  when "people"
111
145
  dst.people_ids << src.people_ids.to_a
112
146
  when "geo"
113
- src_coo, dst_coo = src.coordinates, dst.coordinates
114
- dst_coo.lat, dst_coo.lon = src_coo.lat, src_coo.lon
147
+ src_coo = src.coordinates
148
+ dst_coo = dst.coordinates
149
+ dst_coo.lat, dst_coo.lon = src_coo.lat, src_coo.lon # rubocop:disable Style/ParallelAssignment
115
150
  when "file"
116
151
  src.items.each do |src_item|
117
152
  dst.add_file(src_item.file_container_id) do |dst_item|
@@ -149,3 +184,5 @@ class Eco::API::UseCases::OozeSamples
149
184
  end
150
185
  end
151
186
  end
187
+
188
+ # rubocop:enable Lint/DuplicateBranch