eco-helpers 3.0.4 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/CHANGELOG.md +44 -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/location/base/classifications_parser.rb +5 -0
  60. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +2 -0
  61. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +2 -0
  62. data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +2 -1
  63. data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +3 -0
  64. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +1 -0
  65. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +3 -0
  66. data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +2 -0
  67. data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +1 -0
  68. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +2 -0
  69. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +6 -2
  70. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +6 -2
  71. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +2 -0
  72. data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +1 -0
  73. data/lib/eco/api/usecases/ooze_samples/helpers_migration/copying.rb +66 -29
  74. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +25 -3
  75. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +10 -0
  76. data/lib/eco/api/usecases/use_case.rb +3 -1
  77. data/lib/eco/cli/config/use_cases.rb +4 -0
  78. data/lib/eco/cli/scripting/args_helpers.rb +3 -2
  79. data/lib/eco/cli/scripting/argument.rb +2 -2
  80. data/lib/eco/cli_default/input.rb +49 -45
  81. data/lib/eco/cli_default/input_filters.rb +32 -17
  82. data/lib/eco/cli_default/options.rb +8 -4
  83. data/lib/eco/cli_default/people.rb +1 -1
  84. data/lib/eco/cli_default/people_filters.rb +32 -24
  85. data/lib/eco/cli_default/usecases.rb +8 -121
  86. data/lib/eco/cli_default/workflow.rb +6 -4
  87. data/lib/eco/csv/split.rb +2 -0
  88. data/lib/eco/csv/table.rb +13 -0
  89. data/lib/eco/data/files/encoding.rb +15 -8
  90. data/lib/eco/data/files/helpers.rb +6 -2
  91. data/lib/eco/data/hashes/diff_result.rb +5 -0
  92. data/lib/eco/data/locations/node_diff/nodes_diff.rb +13 -0
  93. data/lib/eco/data/locations/node_diff.rb +4 -0
  94. data/lib/eco/data/locations/node_level.rb +6 -0
  95. data/lib/eco/language/auxiliar_logger.rb +2 -0
  96. data/lib/eco/version.rb +1 -1
  97. data/lib/eco-helpers.rb +1 -1
  98. metadata +15 -6
  99. data/lib/eco/api/usecases/default/locations/create_tag_paths_case.rb +0 -25
  100. data/lib/eco/api/usecases/default/people/amend/reinvite_trans_cli.rb +0 -4
@@ -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
 
@@ -28,6 +28,7 @@ class Eco::API::UseCases::GraphQL::Samples::Location
28
28
  # @note this is an additional necessary step
29
29
  def re_archive
30
30
  return if simulate?
31
+
31
32
  stage = :rearchive
32
33
 
33
34
  nodes_diff_class.new(
@@ -75,6 +76,7 @@ class Eco::API::UseCases::GraphQL::Samples::Location
75
76
  # 2. `REMOTE_FOLDER` const
76
77
  def close_handling_tags_remap_csv
77
78
  return false unless super
79
+
78
80
  upload(tags_remap_csv_file) unless remote_subfolder.nil?
79
81
  true
80
82
  end
@@ -71,6 +71,7 @@ class Eco::API::UseCases::GraphQL::Samples::Location
71
71
  # Generates the final tags remap file
72
72
  def generate_tags_remap_csv(filename = tags_remap_csv_full_filename)
73
73
  return nil if tags_remap_table.empty?
74
+
74
75
  timestamp_file(filename).tap do |file|
75
76
  CSV.open(file, 'w') do |csv|
76
77
  csv << %w[prev_node_ids new_node_ids]
@@ -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
 
@@ -92,7 +92,9 @@ module Eco::API::UseCases::GraphQL::Samples
92
92
 
93
93
  def live_nodes_list
94
94
  @live_nodes_list ||= as_nodes_json(input_tagtree).tap do |list|
95
- log(:info) { "Converted live tree to list of #{list.count} hash-nodes" }
95
+ log(:info) {
96
+ "Converted live tree to list of #{list.count} hash-nodes"
97
+ }
96
98
  end
97
99
  end
98
100
 
@@ -103,7 +105,9 @@ module Eco::API::UseCases::GraphQL::Samples
103
105
  # 2. `org_tree` is native from `Eco::Data::Locations::NodeBase::CsvConvert`
104
106
  def file_nodes_list
105
107
  @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" }
108
+ log(:info) {
109
+ "Converted input csv file to list of #{list.count} hash-nodes"
110
+ }
107
111
  end
108
112
  end
109
113
 
@@ -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?)
@@ -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
@@ -14,6 +14,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
14
14
  def main(_session, options, _usecase)
15
15
  options[:end_get] = false
16
16
  raise "You need to inherit from this class ('#{self.class}') and call super with a block" unless block_given?
17
+
17
18
  @target = nil
18
19
  yield
19
20
  end
@@ -22,6 +23,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
22
23
  def process_ooze(ooz = target)
23
24
  ooz ||= ooze
24
25
  raise "You need to inherit from this class ('#{self.class}') and call super with a block" unless block_given?
26
+
25
27
  yield(ooz)
26
28
  update_ooze(ooz)
27
29
  end
@@ -33,15 +35,18 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
33
35
  end
34
36
 
35
37
  def create_page(page = nil, template_id: nil, retrieve: false)
36
- template_id = template_id.id if template_id.is_a?(Ecoportal::API::V2::Page)
37
- template_id ||= page.template_id if page.respond_to?(:template_id)
38
+ template_id = template_id.id if template_id.is_a?(Ecoportal::API::V2::Page)
39
+ template_id ||= page.template_id if page.respond_to?(:template_id)
38
40
  template_id ||= page["template_id"] if page.is_a?(Hash)
39
- page = new_page(template_id) unless page || !template_id
41
+ page = new_page(template_id) unless page || !template_id
42
+
40
43
  yield(page) if block_given?
44
+
41
45
  reference = apiv2.pages.create(page, from: template_id)
42
46
  ooze_id = reference.page_id
43
47
  stage_id = reference.active_stage_id
44
48
  return [ooze_id, stage_id] unless retrieve
49
+
45
50
  ooze(ooze_id, stage_id: stage_id)
46
51
  end
47
52
 
@@ -49,6 +54,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
49
54
  unless section.is_a?(Ecoportal::API::V2::Page::Section)
50
55
  raise "You need to specify a section for a new field. Given: #{section.class}"
51
56
  end
57
+
52
58
  entry.components.add(doc: doc) do |field|
53
59
  section.add_component(field, after: after, before: before, side: side)
54
60
  end.tap do |field|
@@ -60,6 +66,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
60
66
  unless section.is_a?(Ecoportal::API::V2::Page::Section)
61
67
  raise "You need to specify a section for a new field. Given: #{section.class}"
62
68
  end
69
+
63
70
  entry.components.add(label: name, type: type) do |field|
64
71
  section.add_component(field, after: after, before: before, side: side)
65
72
  end.tap do |field|
@@ -69,6 +76,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
69
76
 
70
77
  def with_fields(entry = target, type: nil, label: nil)
71
78
  flds = entry.components
79
+
72
80
  if type
73
81
  if flds.respond_to?(:get_by_type)
74
82
  flds = flds.get_by_type(type)
@@ -76,6 +84,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
76
84
  flds = flds.select {|fld| fld.type == type}
77
85
  end
78
86
  end
87
+
79
88
  flds.select do |fld|
80
89
  value = label == :unnamed ? nil : label
81
90
  !label || same_string?(fld.label, value)
@@ -87,6 +96,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
87
96
  def with_sections(entry = target, type: nil, heading: nil)
88
97
  secs = entry.sections
89
98
  secs = secs.get_by_type(type) if type
99
+
90
100
  secs.select do |sec|
91
101
  value = heading == :unnamed ? nil : heading
92
102
  !heading || same_string?(sec.heading, value)
@@ -97,6 +107,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
97
107
 
98
108
  def with_stage(name:)
99
109
  return unless (stage = target.stages.get_by_name(name))
110
+
100
111
  yield(stage) if block_given?
101
112
  stage
102
113
  end
@@ -110,7 +121,9 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
110
121
 
111
122
  def ooze(ooze_id = nil, stage_id: nil)
112
123
  return target unless ooze_id
124
+
113
125
  before_loading_new_target(ooze_id)
126
+
114
127
  apiv2.pages.get(ooze_id, stage_id: stage_id).tap do |ooze|
115
128
  if ooze
116
129
  new_target(ooze)
@@ -130,7 +143,9 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
130
143
 
131
144
  if (stg = ooze.stages[id_name] || ooze.stages.get_by_name(id_name))
132
145
  return ooze if ooze.respond_to?(:current_stage_id) && (ooze.current_stage_id == stg.id)
146
+
133
147
  before_loading_new_target(ooze_id)
148
+
134
149
  return apiv2.pages.get(ooze_id, stage_id: stg.id).tap do |stage|
135
150
  if stage
136
151
  new_target(stage)
@@ -142,6 +157,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
142
157
  end
143
158
  end
144
159
  end
160
+
145
161
  exit_error "Stage '#{id_name}' doesn't exist in ooze '#{ooze_id}'"
146
162
  end
147
163
 
@@ -178,8 +194,10 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
178
194
  msg += " after doing unsaved changes to #{object_reference(target)}"
179
195
  log(:warn) { msg }
180
196
  end
197
+
181
198
  yield(target) if block_given?
182
199
  end
200
+
183
201
  @target = object
184
202
  end
185
203
 
@@ -206,6 +224,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
206
224
  def display_patch(entry = target)
207
225
  return if options.dig(:feedback, :only_stats)
208
226
  return unless (patch = (patch_doc(entry) || {})["page"])
227
+
209
228
  pp patch
210
229
  end
211
230
 
@@ -222,12 +241,15 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
222
241
  entry.validate.tap do |validation|
223
242
  log(:error) { validation } if validation.is_a?(String)
224
243
  end
244
+
225
245
  display_patch(entry)
226
246
  backup_patch!(entry)
247
+
227
248
  if dirty?(entry) && dry_count > self.class::DRY_COUNT
228
249
  log(:info) { "Reached #{self.class::DRY_COUNT} dry-run samples." }
229
250
  exit(0)
230
251
  end
252
+
231
253
  false
232
254
  end
233
255
 
@@ -49,6 +49,7 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
49
49
 
50
50
  def before_loading_new_target(ooze_id)
51
51
  return unless (pending = queue_shift(ooze_id))
52
+
52
53
  update_ooze(pending).tap do |result|
53
54
  if result.is_a?(Ecoportal::API::Common::Response)
54
55
  if result.success?
@@ -83,6 +84,7 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
83
84
  log(:warn) { msg }
84
85
  update_ooze(pending)
85
86
  end
87
+
86
88
  if (ooz = ooze(page_result.id))
87
89
  @retrieved_oozes += 1
88
90
  yield(ooz)
@@ -97,9 +99,11 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
97
99
 
98
100
  def enqueue(object)
99
101
  return unless object.respond_to?(:id)
102
+
100
103
  unless object.is_a?(Ecoportal::API::V2::Page) or object.is_a?(Ecoportal::API::V2::Pages::PageStage)
101
104
  raise "Queuing is just for entries. Expecting Page or PageStage. Given: #{object.class}"
102
105
  end
106
+
103
107
  if (elem = queue_get(object.id))
104
108
  msg = "Something is wrong. Native case 'RegisterUpdateCase' is "
105
109
  if (elem != object) && dirty?(elem)
@@ -131,7 +135,9 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
131
135
 
132
136
  def batched_search_results
133
137
  raise "Missing block. It yields in slices of #{self.class.batch_size} results" unless block_given?
138
+
134
139
  results_preview
140
+
135
141
  results = []
136
142
  apiv2.registers.search(register_id, search_options) do |page_result|
137
143
  results << page_result
@@ -140,6 +146,7 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
140
146
  results = []
141
147
  end
142
148
  end
149
+
143
150
  yield(results) unless results.empty?
144
151
  end
145
152
 
@@ -180,6 +187,7 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
180
187
 
181
188
  def backup_patch!(ooze = target)
182
189
  return if (patch_doc(ooze) || {})["page"]
190
+
183
191
  log(:info) {
184
192
  "No changes to update for #{object_reference(ooze)}."
185
193
  }
@@ -188,8 +196,10 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
188
196
  def results_preview
189
197
  apiv2.registers.search(register_id, search_options.merge(only_first: true)).tap do |search_results|
190
198
  @total_search_oozes = search_results.total
199
+
191
200
  str_results = "Total target entries: #{search_results.total} (out of #{search_results.total_before_filtering})"
192
201
  default_answer = session.config.run_mode_remote?? "Y" : "N"
202
+
193
203
  session.prompt_user(
194
204
  "Do you want to proceed (y/N):",
195
205
  explanation: str_results,
@@ -58,7 +58,9 @@ module Eco
58
58
 
59
59
  UseCaseIO.new(**kargs).tap do |uio|
60
60
  @options = uio.options
61
- uio.session.logger.debug("#{self.class}: going to process '#{name}'")
61
+ uio.session.log(:debug) {
62
+ "#{self.class}: going to process '#{name}'"
63
+ }
62
64
 
63
65
  set_session_n_options(uio) if callback_from_loader?
64
66
 
@@ -28,13 +28,16 @@ module Eco
28
28
  # @return [String] summary of the use cases.
29
29
  def help(refine: nil)
30
30
  refinement = refine.is_a?(String)? " (containing: '#{refine}')" : ""
31
+
31
32
  ["The following are the available use cases#{refinement}:"].then do |lines|
32
33
  max_len = keys_max_len(@linked_cases.keys)
34
+
33
35
  @linked_cases.keys.sort.select do |key|
34
36
  !refine.is_a?(String) || key.include?(refine)
35
37
  end.each do |option_case|
36
38
  lines << help_line(option_case, @linked_cases[option_case].description, max_len)
37
39
  end
40
+
38
41
  lines
39
42
  end.join("\n")
40
43
  end
@@ -150,6 +153,7 @@ module Eco
150
153
 
151
154
  def validate_io!(io)
152
155
  return if io.is_a?(Eco::API::UseCases::BaseIO)
156
+
153
157
  raise ArgumentError, "You need to provide Eco::API::UseCases::BaseIO object. Given: #{io.class}"
154
158
  end
155
159
  end