eco-helpers 2.6.3 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +95 -0
  4. data/CHANGELOG.md +135 -2
  5. data/Rakefile +13 -7
  6. data/eco-helpers.gemspec +3 -3
  7. data/lib/eco/api/common/loaders/base.rb +2 -2
  8. data/lib/eco/api/common/loaders/case_base.rb +1 -1
  9. data/lib/eco/api/common/loaders/config/workflow/mailer.rb +5 -5
  10. data/lib/eco/api/common/loaders/error_handler.rb +8 -5
  11. data/lib/eco/api/common/loaders/parser.rb +44 -22
  12. data/lib/eco/api/common/loaders/policy.rb +6 -4
  13. data/lib/eco/api/common/loaders/use_case.rb +13 -7
  14. data/lib/eco/api/common/people/base_parser.rb +0 -2
  15. data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +0 -1
  16. data/lib/eco/api/common/people/default_parsers/csv_parser.rb +1 -1
  17. data/lib/eco/api/common/people/default_parsers/date_parser.rb +64 -12
  18. data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +0 -1
  19. data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +13 -5
  20. data/lib/eco/api/common/people/default_parsers/multi_parser.rb +0 -1
  21. data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +18 -5
  22. data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +8 -8
  23. data/lib/eco/api/common/people/default_parsers/select_parser.rb +50 -26
  24. data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +6 -6
  25. data/lib/eco/api/common/people/default_parsers/xls_parser.rb +9 -12
  26. data/lib/eco/api/common/people/default_parsers.rb +1 -12
  27. data/lib/eco/api/common/people/entries.rb +13 -13
  28. data/lib/eco/api/common/people/entry_factory.rb +76 -45
  29. data/lib/eco/api/common/people/person_attribute_parser.rb +8 -12
  30. data/lib/eco/api/common/people/person_entry.rb +86 -75
  31. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +60 -44
  32. data/lib/eco/api/common/people/person_factory.rb +30 -22
  33. data/lib/eco/api/common/people/person_modifier.rb +11 -13
  34. data/lib/eco/api/common/people/person_parser.rb +101 -39
  35. data/lib/eco/api/common/people/supervisor_helpers.rb +25 -26
  36. data/lib/eco/api/common/session/base_session.rb +9 -9
  37. data/lib/eco/api/common/session/environment.rb +7 -5
  38. data/lib/eco/api/common/session/sftp.rb +59 -32
  39. data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +10 -6
  40. data/lib/eco/api/common/version_patches/exception.rb +11 -13
  41. data/lib/eco/api/error.rb +32 -20
  42. data/lib/eco/api/microcases/set_supervisor.rb +0 -3
  43. data/lib/eco/api/organization/node_classifications.rb +82 -0
  44. data/lib/eco/api/organization/policy_groups.rb +4 -6
  45. data/lib/eco/api/organization/tag_tree.rb +169 -93
  46. data/lib/eco/api/organization.rb +1 -0
  47. data/lib/eco/api/session/batch/job.rb +1 -1
  48. data/lib/eco/api/session/config/tagtree.rb +41 -23
  49. data/lib/eco/api/session/config/workflow.rb +113 -88
  50. data/lib/eco/api/session/config.rb +6 -0
  51. data/lib/eco/api/session.rb +51 -29
  52. data/lib/eco/api/usecases/base_io.rb +28 -25
  53. data/lib/eco/api/usecases/default/locations/cli/tagtree_extract_cli.rb +7 -2
  54. data/lib/eco/api/usecases/default/locations/cli/tagtree_upload_cli.rb +21 -0
  55. data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +3 -3
  56. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +54 -23
  57. data/lib/eco/api/usecases/default/locations/tagtree_upload_case.rb +87 -0
  58. data/lib/eco/api/usecases/default/locations.rb +1 -0
  59. data/lib/eco/api/usecases/default/people/analyse_people_case.rb +60 -56
  60. data/lib/eco/api/usecases/default/people/change_email_case.rb +8 -9
  61. data/lib/eco/api/usecases/default/people/clean_unknown_tags_case.rb +13 -11
  62. data/lib/eco/api/usecases/default/people/clear_abilities_case.rb +2 -2
  63. data/lib/eco/api/usecases/default/people/org_data_convert_case.rb +25 -27
  64. data/lib/eco/api/usecases/default/people/refresh_case.rb +2 -2
  65. data/lib/eco/api/usecases/default/people/reinvite_trans_case.rb +1 -1
  66. data/lib/eco/api/usecases/default/people/reinvite_trans_cli.rb +0 -1
  67. data/lib/eco/api/usecases/default/people/restore_db_case.rb +39 -34
  68. data/lib/eco/api/usecases/default/people/set_default_tag_case.rb +19 -15
  69. data/lib/eco/api/usecases/default/people/supers_cyclic_identify_case.rb +16 -12
  70. data/lib/eco/api/usecases/default_cases/hris_case.rb +17 -15
  71. data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +30 -16
  72. data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +0 -2
  73. data/lib/eco/api/usecases/graphql/base.rb +5 -3
  74. data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +4 -1
  75. data/lib/eco/api/usecases/graphql/helpers/base/graphql_env.rb +14 -0
  76. data/lib/eco/api/usecases/graphql/helpers/base.rb +5 -4
  77. data/lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb +60 -0
  78. data/lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb +72 -0
  79. data/lib/eco/api/usecases/graphql/helpers/location/base.rb +25 -59
  80. data/lib/eco/api/usecases/graphql/helpers/location/command/diff/as_update.rb +59 -0
  81. data/lib/eco/api/usecases/graphql/helpers/location/command/diff/compare.rb +49 -0
  82. data/lib/eco/api/usecases/graphql/helpers/location/command/diff.rb +11 -0
  83. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +46 -0
  84. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_archive.rb +23 -0
  85. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_unarchive.rb +65 -0
  86. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +49 -0
  87. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable/relation_safe_sort.rb +119 -0
  88. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable.rb +59 -0
  89. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages.rb +82 -0
  90. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs.rb +20 -0
  91. data/lib/eco/api/usecases/graphql/helpers/location/command/optimizations.rb +84 -0
  92. data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +4 -4
  93. data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +24 -12
  94. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +21 -24
  95. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb +1 -1
  96. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb +10 -11
  97. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +8 -9
  98. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +41 -12
  99. data/lib/eco/api/usecases/graphql/samples/location/command/results.rb +11 -80
  100. data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +89 -0
  101. data/lib/eco/api/usecases/graphql/samples/location/command/service.rb +6 -0
  102. data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +89 -0
  103. data/lib/eco/api/usecases/graphql/samples/location/command.rb +3 -0
  104. data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +9 -0
  105. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/heading.rb +18 -0
  106. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/inputable.rb +53 -0
  107. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +34 -0
  108. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/helpers.rb +28 -0
  109. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing.rb +46 -0
  110. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible.rb +38 -0
  111. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +105 -0
  112. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/discarded.rb +16 -0
  113. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/input.rb +15 -0
  114. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/node_attr_maps.rb +22 -0
  115. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +45 -0
  116. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +36 -0
  117. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb +56 -0
  118. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list.rb +41 -0
  119. data/lib/eco/api/usecases/graphql/samples/location/service.rb +8 -0
  120. data/lib/eco/api/usecases/graphql/samples/location.rb +1 -0
  121. data/lib/eco/api/usecases/graphql/utils/sftp.rb +96 -36
  122. data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +8 -6
  123. data/lib/eco/api/usecases/ooze_samples/helpers/creatable.rb +4 -3
  124. data/lib/eco/api/usecases/ooze_samples/helpers/exportable_ooze.rb +39 -25
  125. data/lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb +13 -15
  126. data/lib/eco/api/usecases/ooze_samples/helpers/filters.rb +50 -21
  127. data/lib/eco/api/usecases/ooze_samples/helpers/ooze_handlers.rb +21 -11
  128. data/lib/eco/api/usecases/ooze_samples/helpers/rescuable.rb +2 -0
  129. data/lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb +49 -43
  130. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +17 -19
  131. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +48 -43
  132. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +34 -34
  133. data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +8 -10
  134. data/lib/eco/api/usecases.rb +0 -1
  135. data/lib/eco/cli/config/use_cases.rb +31 -29
  136. data/lib/eco/cli_default/input_filters.rb +0 -5
  137. data/lib/eco/cli_default/people_filters.rb +4 -4
  138. data/lib/eco/cli_default/workflow.rb +13 -14
  139. data/lib/eco/csv/table.rb +34 -25
  140. data/lib/eco/data/hashes/array_diff.rb +24 -35
  141. data/lib/eco/data/hashes/diff_result/meta.rb +131 -0
  142. data/lib/eco/data/hashes/diff_result.rb +65 -57
  143. data/lib/eco/data/hashes/sanke_camel_indifferent_access.rb +278 -0
  144. data/lib/eco/data/hashes.rb +1 -1
  145. data/lib/eco/data/locations/convert.rb +1 -1
  146. data/lib/eco/data/locations/node_base/csv_convert.rb +19 -9
  147. data/lib/eco/data/locations/node_base/parsing.rb +4 -2
  148. data/lib/eco/data/locations/node_base/treeify.rb +149 -132
  149. data/lib/eco/data/locations/node_base.rb +15 -4
  150. data/lib/eco/data/locations/node_diff/accessors.rb +13 -5
  151. data/lib/eco/data/locations/node_diff/nodes_diff/clustered_treeify.rb +101 -0
  152. data/lib/eco/data/locations/node_diff/nodes_diff/diffs_tree.rb +99 -0
  153. data/lib/eco/data/locations/node_diff/{selectors.rb → nodes_diff/selectors.rb} +1 -1
  154. data/lib/eco/data/locations/node_diff/nodes_diff.rb +50 -35
  155. data/lib/eco/data/locations/node_diff.rb +45 -17
  156. data/lib/eco/data/locations/node_level/parsing.rb +15 -21
  157. data/lib/eco/data/locations/node_level.rb +66 -22
  158. data/lib/eco/data/locations/node_plain/parsing.rb +1 -1
  159. data/lib/eco/data/locations/node_plain.rb +60 -7
  160. data/lib/eco/data/strings/camel_case.rb +35 -0
  161. data/lib/eco/data/strings/snake_case.rb +18 -0
  162. data/lib/eco/data/strings.rb +8 -0
  163. data/lib/eco/data.rb +1 -0
  164. data/lib/eco/language/methods/call_detector.rb +11 -0
  165. data/lib/eco/language/methods/dsl_able.rb +7 -1
  166. data/lib/eco/language/methods.rb +2 -1
  167. data/lib/eco/language/models/collection.rb +23 -25
  168. data/lib/eco/language/models/parser_serializer.rb +24 -5
  169. data/lib/eco/version.rb +1 -1
  170. data/lib/eco-helpers.rb +0 -1
  171. metadata +54 -9
  172. data/lib/eco/data/hashes/diff_meta.rb +0 -52
@@ -14,5 +14,4 @@ class Eco::API::Common::People::DefaultParsers::BooleanParser < Eco::API::Common
14
14
  def truthy(value)
15
15
  %w[true y yes x].include?(value.to_s.strip.downcase)
16
16
  end
17
-
18
17
  end
@@ -36,7 +36,7 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
36
36
  headers = table.headers
37
37
  abort("Missing headers in CSV") unless headers && !headers.empty?
38
38
  empty = []
39
- with_value = headers.each_with_index do |header, idx|
39
+ headers.each_with_index do |header, idx|
40
40
  empty << idx if header.to_s.strip.empty?
41
41
  end
42
42
  abort("Empty headers in column(s): #{empty.join(', ')}") unless empty.empty?
@@ -1,32 +1,84 @@
1
1
  class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::Loaders::Parser
2
2
  attribute :date
3
3
 
4
+ MIN_DATE = '1901-01-02'.freeze
5
+ MAX_DATE = '2099-12-31'.freeze
6
+
4
7
  def parser(value, deps)
5
- value.is_a?(Array) ? value.map { |v| parse_date(v) } : parse_date(value)
8
+ parse_date(value, attr: deps['attr'])
6
9
  end
7
10
 
8
- def serializer(value, deps)
9
- value.is_a?(Array) ? value.map { |d| serialize_date(d) } : serialize_date(value)
11
+ def serializer(value, _deps)
12
+ serialize_date(value)
10
13
  end
11
14
 
12
15
  private
13
16
 
14
- def parse_date(value)
15
- begin
16
- (value.to_s.empty?) ? nil : Date.parse(value)
17
- rescue
17
+ def parse_date(value, attr:)
18
+ return value.map {|val| parse_date(val, attr: attr)}.compact if value.is_a?(Enumerable)
19
+
20
+ return nil if value.nil?
21
+ value = value.to_s.strip
22
+ return nil if value.empty?
23
+
24
+ if date?(value)
25
+ Date.parse(value).then do |date|
26
+ next date if valid_range?(date)
27
+ wrong!(value, attr: attr, desc: 'Date out of range (1900-2099). Given: ')
28
+ nil
29
+ end
30
+ else
31
+ wrong!(value, attr: attr)
18
32
  nil
19
33
  end
34
+ rescue TypeError, Date::Error
35
+ nil
20
36
  end
21
37
 
22
38
  def serialize_date(value)
39
+ return value.map {|val| serialize_date(val)}.compact if value.is_a?(Enumerable)
40
+
41
+ return nil if value.nil?
42
+ return nil if value.to_s.strip.empty?
23
43
  return value if value.is_a?(String)
24
- begin
25
- value && value.strftime('%Y-%m-%d')
26
- rescue
27
- nil
28
- end
44
+ return nil unless [Date, Time].any? {|type| value.is_a?(type)}
45
+ value&.strftime('%Y-%m-%d')
46
+ rescue TypeError, Date::Error
47
+ nil
48
+ end
49
+
50
+ def wrong!(value, attr:, desc: "Can't make a date out of")
51
+ return if wrong(attr).key?(value)
52
+ wrong(attr)[value] = value
53
+ log(:warn) { "#{desc} '#{value}' for '#{attr}'" }
29
54
  end
30
55
 
56
+ def wrong(attr = nil)
57
+ @wrong ||= {}
58
+ return @wrong if attr.nil?
59
+ @wrong[attr] ||= {}
60
+ end
61
+
62
+ def date?(value)
63
+ return true if value.nil?
64
+ return true if value.to_s.strip.empty?
65
+ Date.parse(value)
66
+ true
67
+ rescue TypeError, Date::Error
68
+ false
69
+ end
70
+
71
+ def valid_range?(date)
72
+ return true if date.nil?
73
+ return false unless min_date <= date
74
+ max_date >= date
75
+ end
76
+
77
+ def min_date
78
+ @min_date ||= Date.parse(MIN_DATE)
79
+ end
31
80
 
81
+ def max_date
82
+ @max_date ||= Date.parse(MAX_DATE)
83
+ end
32
84
  end
@@ -16,5 +16,4 @@ class Eco::API::Common::People::DefaultParsers::FreemiumParser < Eco::API::Commo
16
16
  def truthy (value)
17
17
  %w[true y yes x].include?(value.to_s&.downcase)
18
18
  end
19
-
20
19
  end
@@ -3,14 +3,19 @@ class Eco::API::Common::People::DefaultParsers::LoginProvidersParser < Eco::API:
3
3
  parsing_phase :final
4
4
  serializing_phase :final
5
5
 
6
- def parser(hash, deps)
6
+ def parser(hash, _deps)
7
7
  hash["login_provider_ids"].map do |name|
8
- login_providers.to_id(name&.downcase.strip)
8
+ login_providers.to_id(name&.downcase&.strip).tap do |known|
9
+ unless !name || known || unknown_pgs.include?(name)
10
+ unknown_pgs.push(name)
11
+ logger.warn("Unknown Login Provider: '#{name}'")
12
+ end
13
+ end
9
14
  end.compact
10
15
  end
11
16
 
12
- def serializer(hash, deps)
13
- if ids = hash["login_provider_ids"]
17
+ def serializer(hash, _deps)
18
+ if (ids = hash["login_provider_ids"])
14
19
  login_providers.to_name(ids)
15
20
  else
16
21
  []
@@ -19,8 +24,11 @@ class Eco::API::Common::People::DefaultParsers::LoginProvidersParser < Eco::API:
19
24
 
20
25
  private
21
26
 
27
+ def unknown_pgs
28
+ @unknown_pgs ||= []
29
+ end
30
+
22
31
  def login_providers
23
32
  @login_providers ||= config.login_providers
24
33
  end
25
-
26
34
  end
@@ -17,5 +17,4 @@ class Eco::API::Common::People::DefaultParsers::MultiParser < Eco::API::Common::
17
17
  return value.split("|") if value.is_a?(String) && value.include?("|")
18
18
  [].push(value)
19
19
  end
20
-
21
20
  end
@@ -1,18 +1,31 @@
1
1
  class Eco::API::Common::People::DefaultParsers::NumericParser < Eco::API::Common::Loaders::Parser
2
2
  attribute :number
3
3
 
4
- def parser(value, deps)
5
- value.is_a?(Array) ? value.map { |v| parse_number(v) } : parse_number(value)
4
+ def parser(value, _deps)
5
+ parse_number(value)
6
6
  end
7
7
 
8
- def serializer(value, deps)
9
- value.is_a?(Array) ? value.map { |v| v.to_s } : value.to_s
8
+ def serializer(value, _deps)
9
+ value.is_a?(Array) ? value.map(&:to_s) : value.to_s
10
10
  end
11
11
 
12
12
  private
13
13
 
14
14
  def parse_number(value)
15
- value.to_s.strip.empty? ? nil : (value.to_f rescue nil)
15
+ return value.map {|val| parse_number(val)}.compact if value.is_a?(Enumerable)
16
+
17
+ return nil if value.nil?
18
+ value = value.to_s.strip
19
+ return nil if value.empty?
20
+ return nil unless number?(value)
21
+ value.to_f
22
+ rescue ArgumentError, TypeError
23
+ nil
16
24
  end
17
25
 
26
+ def number?(value)
27
+ true if Float(value)
28
+ rescue ArgumentError, TypeError
29
+ false
30
+ end
18
31
  end
@@ -1,14 +1,14 @@
1
1
  class Eco::API::Common::People::DefaultParsers::PolicyGroupsParser < Eco::API::Common::Loaders::Parser
2
2
  attribute "policy_group_ids"
3
- parsing_phase :final
3
+ parsing_phase :final
4
4
 
5
- def parser(hash, deps)
5
+ def parser(hash, _deps)
6
6
  policy_group_ids = hash["policy_group_ids"] || []
7
7
  policy_group_ids.map do |name|
8
- policy_groups.to_id(name&.downcase.strip).tap do |known|
8
+ policy_groups.to_id(name&.downcase&.strip).tap do |known|
9
9
  unless !name || known || unknown_pgs.include?(name)
10
10
  unknown_pgs.push(name)
11
- logger.warn("Unknown Policy Group: '#{name}'")
11
+ log(:warn) { "Unknown Policy Group: '#{name}'" }
12
12
  end
13
13
  end
14
14
  end.compact.tap do |pg_names|
@@ -16,8 +16,8 @@ class Eco::API::Common::People::DefaultParsers::PolicyGroupsParser < Eco::API::C
16
16
  end
17
17
  end
18
18
 
19
- def serializer(person, deps)
20
- ids = person&.account&.policy_group_ids || []
19
+ def serializer(person, _deps)
20
+ ids = person&.account&.policy_group_ids || []
21
21
  ids.map do |id|
22
22
  policy_groups.to_name(id)
23
23
  end.compact
@@ -26,11 +26,11 @@ class Eco::API::Common::People::DefaultParsers::PolicyGroupsParser < Eco::API::C
26
26
  private
27
27
 
28
28
  def unknown_pgs
29
- unknown_pgs ||= []
29
+ @unknown_pgs ||= []
30
30
  end
31
31
 
32
32
  def default_id
33
- @default_id ||= policy_groups.to_id(config.people.default_usergroup)
33
+ @default_id ||= policy_groups.to_id(config.people.default_usergroup)
34
34
  end
35
35
 
36
36
  def policy_groups
@@ -1,29 +1,53 @@
1
- module Eco
2
- module API
3
- module Common
4
- module People
5
- class DefaultParsers
6
- class SelectParser < People::BaseParser
7
-
8
- def process
9
- @parsers.define_attribute(:select, dependencies: @options) do |parser|
10
- parser.def_parser do |value, deps|
11
- options_hash = deps[:select_hashes][deps["attr"]]
12
- next value if !options_hash
13
- if value.is_a?(Array)
14
- value.map { |v| options_hash[v&.downcase.strip] }.compact
15
- elsif value
16
- options_hash[value&.downcase.strip]
17
- end
18
- end.def_serializer do |value|
19
- value
20
- end
21
- end
22
- end
23
-
24
- end
25
- end
26
- end
1
+ class Eco::API::Common::People::DefaultParsers::SelectParser < Eco::API::Common::Loaders::Parser
2
+ attribute :select
3
+
4
+ class << self
5
+ def select_tables
6
+ @select_tables ||= {}
7
+ end
8
+ end
9
+
10
+ dependencies select_hashes: (lambda do |person_parser|
11
+ select_tables[person_parser.schema&.id] ||= person_parser.select_tables
12
+ end)
13
+
14
+
15
+ def parser(value, deps)
16
+ return value unless (options_map = options_hash(deps))
17
+ to_select_option(value, options_map, attr: deps['attr'])
18
+ end
19
+
20
+ def serializer(value, _deps)
21
+ value
22
+ end
23
+
24
+ private
25
+
26
+ def to_select_option(value, options_map, attr:)
27
+ if value.is_a?(Array)
28
+ value.map {|val| to_select_option(val, options_map, attr: attr)}.compact
29
+ elsif value
30
+ val = value&.downcase&.strip
31
+ return options_map[val] if options_map.key?(val)
32
+
33
+ unknown!(value, attr: attr)
34
+ nil
27
35
  end
28
36
  end
37
+
38
+ def unknown!(value, attr:)
39
+ return if unknown(attr).key?(value)
40
+ unknown(attr)[value] = value
41
+ log(:warn) { "Unknown select option '#{value}' for '#{attr}'" }
42
+ end
43
+
44
+ def unknown(attr = nil)
45
+ @unknown ||= {}
46
+ return @unknown if attr.nil?
47
+ @unknown[attr] ||= {}
48
+ end
49
+
50
+ def options_hash(deps)
51
+ deps[:select_hashes][deps['attr']]
52
+ end
29
53
  end
@@ -1,20 +1,20 @@
1
1
  class Eco::API::Common::People::DefaultParsers::SendInvitesParser < Eco::API::Common::Loaders::Parser
2
2
  attribute "send_invites"
3
3
 
4
- def parser(hash, deps)
4
+ def parser(hash, _deps)
5
5
  value = hash["send_invites"]
6
6
  value = value.first if value.is_a?(Array)
7
7
  truthy(value)
8
8
  end
9
9
 
10
- def serializer(person, deps)
11
- person.account && person.account.send_invites&.to_s
10
+ def serializer(person, _deps)
11
+ return unless account = person.account
12
+ account.send_invites&.to_s
12
13
  end
13
-
14
+
14
15
  private
15
16
 
16
- def truthy (value)
17
+ def truthy(value)
17
18
  %w[true y yes x].include?(value.to_s&.downcase)
18
19
  end
19
-
20
20
  end
@@ -4,7 +4,7 @@ class Eco::API::Common::People::DefaultParsers::XLSParser < Eco::API::Common::Lo
4
4
  attr_accessor :already_required
5
5
  attr_reader :file
6
6
 
7
- def parser(file, deps)
7
+ def parser(file, _deps)
8
8
  @file = file
9
9
  rows.tap do |rws|
10
10
  @file = nil
@@ -14,7 +14,7 @@ class Eco::API::Common::People::DefaultParsers::XLSParser < Eco::API::Common::Lo
14
14
  end
15
15
  end
16
16
 
17
- def serializer(array_hash, deps)
17
+ def serializer(_array_hash, _deps)
18
18
  raise "Not implemented. TODO: using axlsx or rubyXL gems. See: https://spin.atomicobject.com/2017/03/22/parsing-excel-files-ruby/"
19
19
  end
20
20
 
@@ -28,7 +28,6 @@ class Eco::API::Common::People::DefaultParsers::XLSParser < Eco::API::Common::Lo
28
28
  end
29
29
  end
30
30
 
31
-
32
31
  def headers
33
32
  logger.warn("Headers detection is using your fields_map.json file (native behaviour)")
34
33
  session.fields_mapper.list(:external).uniq
@@ -48,20 +47,18 @@ class Eco::API::Common::People::DefaultParsers::XLSParser < Eco::API::Common::Lo
48
47
  end
49
48
 
50
49
  def rows(target = headers)
51
- begin
52
- spreadheet.parse(header_search: target, clean: true)
53
- rescue Roo::HeaderRowNotFoundError => e
54
- missing = JSON.parse(e.message)
55
- logger.warn("The input file is missing these headers: #{missing}")
56
- present = target - missing
57
- rows(present)
58
- end
50
+ spreadheet.parse(header_search: target, clean: true)
51
+ rescue Roo::HeaderRowNotFoundError => e
52
+ missing = JSON.parse(e.message)
53
+ logger.warn("The input file is missing these headers: #{missing}")
54
+ present = target - missing
55
+ rows(present)
59
56
  end
60
57
 
61
58
  def require_reading_libs!
62
59
  return if already_required
63
60
  require 'roo'
64
61
  require 'roo-xls'
65
- already_required = true
62
+ self.already_required = true
66
63
  end
67
64
  end
@@ -2,7 +2,6 @@ module Eco
2
2
  module API
3
3
  module Common
4
4
  module People
5
-
6
5
  # Class to define a set of default attribute parsers
7
6
  class DefaultParsers < PersonParser
8
7
  autoloads_children_of "Eco::API::Common::Loaders::Parser"
@@ -16,18 +15,8 @@ module Eco
16
15
  private
17
16
 
18
17
  def define_defaults
19
- # Select Options
20
- select_hashes = @schema.fields.map do |fld|
21
- if fld.type == "select"
22
- raise "The schema selection field '#{fld.name}' is missing selection options." unless fld.options && !fld.options.empty?
23
- options_hash = fld.options.map { |v| [v.downcase.strip, v] }.to_h
24
- [fld.alt_id, options_hash]
25
- end
26
- end.compact.to_h
27
-
28
- SelectParser.new(self, select_hashes: select_hashes).process
18
+ # SelectParser.new(self, select_hashes: select_tables).process
29
19
  end
30
-
31
20
  end
32
21
  end
33
22
  end
@@ -4,25 +4,26 @@ module Eco
4
4
  module People
5
5
  # Class meant to offer a _collection_ of entries, normally used to get parsed input data.
6
6
  # @attr_reader entries [Array<Eco::API::Common::PeopleEntry] a pure `Array` object.
7
- class Entries < Eco::Language::Models::Collection
7
+ class Entries < Eco::Language::Models::Collection
8
8
  # Error class that allows to handle cases where multiple entries were found for the same criterion.
9
9
  # @note its main purpose to prevent the false pairing of duplicates or override information between different people.
10
10
  class MultipleSearchResults < StandardError
11
11
  attr_reader :candidates, :property
12
+
12
13
  # @param msg [String] the basic message error.
13
14
  # @param candiates [Array<PersonEntry>] the entries that match the same search criterion.
14
15
  # @param property [String] the property of the entry model that triggered the error (base of the search criterion).
15
16
  def initialize(msg, candidates: [], property: "email")
16
17
  @candidates = candidates
17
18
  @property = property
18
- super(msg + " " + candidates_summary)
19
+ super("#{msg} #{candidates_summary}")
19
20
  end
20
21
 
21
22
  # @param with_index [Boolean] to add an index to each candidate description.
22
23
  # @return [Array<String>] the `candidates` identified
23
24
  def identify_candidates(with_index: false)
24
25
  candidates.map.each_with_index do |entry, i|
25
- index = with_index ? "#{i}. " : ""
26
+ index = with_index ? "#{i}. " : ""
26
27
  "#{index} #{entry.identify}"
27
28
  end
28
29
  end
@@ -38,7 +39,6 @@ module Eco
38
39
  lines = ["The following entries have the same '#{property}':"]
39
40
  lines.concat(identify_candidates(with_index: true)).join("\n ")
40
41
  end
41
-
42
42
  end
43
43
 
44
44
  # build the shortcuts of Collection
@@ -79,11 +79,11 @@ module Eco
79
79
  end
80
80
 
81
81
  def policy_group_ids_any(ids)
82
- attr("policy_group_ids", tags, default_modifier.any.insensitive)
82
+ attr("policy_group_ids", ids, default_modifier.any.insensitive)
83
83
  end
84
84
 
85
85
  def policy_group_ids_all(ids)
86
- attr("policy_group_ids", tags, default_modifier.all.insensitive)
86
+ attr("policy_group_ids", ids, default_modifier.all.insensitive)
87
87
  end
88
88
  # @!endgroup
89
89
 
@@ -105,7 +105,8 @@ module Eco
105
105
  # @param id [String] the `internal id` of the person
106
106
  # @param external_id [String] the `exernal_id` of the person
107
107
  # @param email [String] the `email` of the person
108
- # @param strict [Boolean] if should perform a `:soft` or a `:strict` search. `strict` will avoid repeated email addresses.
108
+ # @param strict [Boolean] if should perform a `:soft` or a `:strict` search. `strict`
109
+ # will avoid repeated email addresses.
109
110
  # @return [Entry, nil] the entry we were searching, or `nil` if not found.
110
111
  def entry(id: nil, external_id: nil, email: nil, strict: false)
111
112
  init_caches
@@ -154,12 +155,12 @@ module Eco
154
155
  # Helper to dump the entries into a CSV
155
156
  # @param filename [String] the destination file
156
157
  def export(filename)
157
- header = each_with_object([]) do |entry, header|
158
- header.push(*entry.internal_entry.keys).uniq!
158
+ header = each_with_object([]) do |entry, hds|
159
+ hds.push(*entry.internal_entry.keys).uniq!
159
160
  end
160
161
  CSV.open(filename, "w") do |csv|
161
162
  csv << header
162
- self.each do |entry|
163
+ each do |entry|
163
164
  csv << entry.internal_entry.values_at(*header)
164
165
  end
165
166
  end
@@ -168,7 +169,7 @@ module Eco
168
169
  # @!group Groupping methods
169
170
 
170
171
  def email_id_maps
171
- email_present.group_by(:email).transform_values { |person| person.id }
172
+ email_present.group_by(:email).transform_values(&:id)
172
173
  end
173
174
 
174
175
  def group_by_supervisor
@@ -191,7 +192,7 @@ module Eco
191
192
  def entry_by_email(email, prevent_multiple_match: false)
192
193
  return nil unless email
193
194
 
194
- candidates = @by_email[email] || []
195
+ candidates = @by_email[email] || []
195
196
  return candidates.first if candidates.length == 1
196
197
 
197
198
  if prevent_multiple_match && !candidates.empty?
@@ -214,7 +215,6 @@ module Eco
214
215
  def no_nil_key(hash)
215
216
  hash.tap {|h| h.delete(nil)}
216
217
  end
217
-
218
218
  end
219
219
  end
220
220
  end