eco-helpers 1.4.0 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +150 -2
  3. data/LICENSE +21 -0
  4. data/eco-helpers.gemspec +11 -10
  5. data/lib/eco/api.rb +3 -0
  6. data/lib/eco/api/common.rb +5 -1
  7. data/lib/eco/api/common/base_loader.rb +54 -0
  8. data/lib/eco/api/common/class_auto_loader.rb +109 -0
  9. data/lib/eco/api/common/class_helpers.rb +33 -0
  10. data/lib/eco/api/common/class_hierarchy.rb +1 -1
  11. data/lib/eco/api/common/class_meta_basics.rb +16 -0
  12. data/lib/eco/api/common/loaders.rb +13 -0
  13. data/lib/eco/api/common/loaders/error_handler.rb +41 -0
  14. data/lib/eco/api/common/loaders/parser.rb +127 -0
  15. data/lib/eco/api/common/loaders/policy.rb +25 -0
  16. data/lib/eco/api/common/loaders/use_case.rb +40 -0
  17. data/lib/eco/api/common/people/default_parsers.rb +5 -10
  18. data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +13 -23
  19. data/lib/eco/api/common/people/default_parsers/csv_parser.rb +20 -35
  20. data/lib/eco/api/common/people/default_parsers/date_parser.rb +15 -26
  21. data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +20 -0
  22. data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +26 -0
  23. data/lib/eco/api/common/people/default_parsers/multi_parser.rb +15 -27
  24. data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +14 -19
  25. data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +31 -0
  26. data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +15 -24
  27. data/lib/eco/api/common/people/entries.rb +54 -24
  28. data/lib/eco/api/common/people/entry_factory.rb +18 -15
  29. data/lib/eco/api/common/people/person_attribute_parser.rb +29 -12
  30. data/lib/eco/api/common/people/person_entry.rb +308 -216
  31. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +5 -2
  32. data/lib/eco/api/common/people/person_parser.rb +52 -19
  33. data/lib/eco/api/common/session/base_session.rb +3 -6
  34. data/lib/eco/api/common/session/environment.rb +2 -23
  35. data/lib/eco/api/common/session/logger.rb +4 -0
  36. data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +2 -0
  37. data/lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb +9 -1
  38. data/lib/eco/api/common/version_patches/exception.rb +24 -2
  39. data/lib/eco/api/custom.rb +13 -0
  40. data/lib/eco/api/custom/error_handler.rb +20 -0
  41. data/lib/eco/api/custom/namespace.rb +7 -0
  42. data/lib/eco/api/custom/parser.rb +50 -0
  43. data/lib/eco/api/custom/policy.rb +28 -0
  44. data/lib/eco/api/custom/use_case.rb +16 -0
  45. data/lib/eco/api/error.rb +1 -0
  46. data/lib/eco/api/error/handlers.rb +10 -3
  47. data/lib/eco/api/microcases.rb +35 -0
  48. data/lib/eco/api/microcases/account_excluded.rb +24 -0
  49. data/lib/eco/api/microcases/append_usergroups.rb +19 -0
  50. data/lib/eco/api/microcases/core_excluded.rb +20 -0
  51. data/lib/eco/api/microcases/fix_default_group.rb +34 -0
  52. data/lib/eco/api/microcases/fix_filter_tags.rb +42 -0
  53. data/lib/eco/api/microcases/people_cache.rb +17 -0
  54. data/lib/eco/api/microcases/people_load.rb +59 -0
  55. data/lib/eco/api/microcases/people_refresh.rb +31 -0
  56. data/lib/eco/api/microcases/people_search.rb +65 -0
  57. data/lib/eco/api/microcases/refresh_abilities.rb +19 -0
  58. data/lib/eco/api/microcases/refresh_default_tag.rb +27 -0
  59. data/lib/eco/api/microcases/s3upload_targets.rb +39 -0
  60. data/lib/eco/api/microcases/set_account.rb +20 -0
  61. data/lib/eco/api/microcases/set_core.rb +18 -0
  62. data/lib/eco/api/microcases/set_core_with_supervisor.rb +23 -0
  63. data/lib/eco/api/microcases/set_supervisor.rb +30 -0
  64. data/lib/eco/api/microcases/strict_search.rb +19 -0
  65. data/lib/eco/api/microcases/with_each.rb +27 -0
  66. data/lib/eco/api/microcases/with_each_leaver.rb +24 -0
  67. data/lib/eco/api/microcases/with_each_present.rb +30 -0
  68. data/lib/eco/api/microcases/with_each_starter.rb +30 -0
  69. data/lib/eco/api/microcases/with_each_subordinate.rb +34 -0
  70. data/lib/eco/api/microcases/with_supervisor.rb +36 -0
  71. data/lib/eco/api/organization/people.rb +72 -35
  72. data/lib/eco/api/organization/presets_factory.rb +13 -4
  73. data/lib/eco/api/organization/presets_reference.json +9 -1
  74. data/lib/eco/api/organization/presets_values.json +4 -1
  75. data/lib/eco/api/policies.rb +11 -7
  76. data/lib/eco/api/session.rb +62 -29
  77. data/lib/eco/api/session/batch.rb +2 -45
  78. data/lib/eco/api/session/batch/base_policy.rb +7 -6
  79. data/lib/eco/api/session/batch/errors.rb +28 -4
  80. data/lib/eco/api/session/batch/feedback.rb +7 -1
  81. data/lib/eco/api/session/batch/job.rb +40 -23
  82. data/lib/eco/api/session/batch/jobs.rb +9 -4
  83. data/lib/eco/api/session/batch/jobs_groups.rb +1 -1
  84. data/lib/eco/api/session/batch/request_stats.rb +91 -58
  85. data/lib/eco/api/session/batch/status.rb +35 -31
  86. data/lib/eco/api/session/config.rb +106 -44
  87. data/lib/eco/api/session/config/api.rb +132 -7
  88. data/lib/eco/api/session/config/apis.rb +24 -25
  89. data/lib/eco/api/session/config/logger.rb +2 -2
  90. data/lib/eco/api/session/config/post_launch.rb +1 -1
  91. data/lib/eco/api/session/config/workflow.rb +8 -7
  92. data/lib/eco/api/usecases.rb +47 -33
  93. data/lib/eco/api/usecases/backup/append_usergroups_case.rb +36 -0
  94. data/lib/eco/api/usecases/backup/create_case.rb +104 -0
  95. data/lib/eco/api/usecases/backup/create_details_case.rb +31 -0
  96. data/lib/eco/api/usecases/backup/create_details_with_supervisor_case.rb +48 -0
  97. data/lib/eco/api/usecases/backup/hris_case.rb +124 -0
  98. data/lib/eco/api/usecases/backup/set_default_tag_case.rb +49 -0
  99. data/lib/eco/api/usecases/backup/set_supervisor_case.rb +41 -0
  100. data/lib/eco/api/usecases/backup/transfer_account_case.rb +90 -0
  101. data/lib/eco/api/usecases/backup/update_case.rb +112 -0
  102. data/lib/eco/api/usecases/backup/update_details_case.rb +64 -0
  103. data/lib/eco/api/usecases/backup/upsert_case.rb +114 -0
  104. data/lib/eco/api/usecases/base_case.rb +2 -0
  105. data/lib/eco/api/usecases/base_io.rb +3 -3
  106. data/lib/eco/api/usecases/default_cases.rb +23 -53
  107. data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +10 -31
  108. data/lib/eco/api/usecases/default_cases/change_email_case.rb +23 -47
  109. data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +56 -43
  110. data/lib/eco/api/usecases/default_cases/create_case.rb +15 -101
  111. data/lib/eco/api/usecases/default_cases/create_details_case.rb +11 -26
  112. data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +12 -43
  113. data/lib/eco/api/usecases/default_cases/delete_sync_case.rb +11 -0
  114. data/lib/eco/api/usecases/default_cases/delete_trans_case.rb +14 -0
  115. data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +10 -21
  116. data/lib/eco/api/usecases/default_cases/hris_case.rb +23 -120
  117. data/lib/eco/api/usecases/default_cases/new_email_case.rb +10 -23
  118. data/lib/eco/api/usecases/default_cases/new_id_case.rb +11 -25
  119. data/lib/eco/api/usecases/default_cases/new_id_case0.rb +14 -0
  120. data/lib/eco/api/usecases/default_cases/org_data_convert_case.rb +83 -0
  121. data/lib/eco/api/usecases/default_cases/refresh_abilities_case.rb +30 -0
  122. data/lib/eco/api/usecases/default_cases/refresh_case.rb +7 -20
  123. data/lib/eco/api/usecases/default_cases/reinvite_sync_case.rb +11 -0
  124. data/lib/eco/api/usecases/default_cases/reinvite_trans_case.rb +17 -0
  125. data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +11 -0
  126. data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +17 -0
  127. data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +9 -19
  128. data/lib/eco/api/usecases/default_cases/restore_db_case.rb +92 -0
  129. data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +32 -40
  130. data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +15 -33
  131. data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +66 -57
  132. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +36 -44
  133. data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +40 -55
  134. data/lib/eco/api/usecases/default_cases/transfer_account_case.rb +264 -84
  135. data/lib/eco/api/usecases/default_cases/update_case.rb +15 -109
  136. data/lib/eco/api/usecases/default_cases/update_details_case.rb +14 -61
  137. data/lib/eco/api/usecases/default_cases/upsert_case.rb +16 -111
  138. data/lib/eco/api/usecases/use_case_io.rb +9 -9
  139. data/lib/eco/cli/config.rb +10 -2
  140. data/lib/eco/cli/config/default.rb +2 -1
  141. data/lib/eco/cli/config/default/input_filters.rb +58 -0
  142. data/lib/eco/cli/config/default/options.rb +60 -25
  143. data/lib/eco/cli/config/default/people.rb +4 -4
  144. data/lib/eco/cli/config/default/people_filters.rb +108 -0
  145. data/lib/eco/cli/config/default/usecases.rb +69 -32
  146. data/lib/eco/cli/config/default/workflow.rb +37 -27
  147. data/lib/eco/cli/config/filters.rb +50 -0
  148. data/lib/eco/cli/config/filters/input_filters.rb +29 -0
  149. data/lib/eco/cli/config/filters/people_filters.rb +29 -0
  150. data/lib/eco/cli/config/help.rb +49 -0
  151. data/lib/eco/cli/config/options_set.rb +17 -1
  152. data/lib/eco/cli/config/use_cases.rb +79 -53
  153. data/lib/eco/cli/scripting.rb +10 -2
  154. data/lib/eco/cli/scripting/args_helpers.rb +25 -15
  155. data/lib/eco/cli/scripting/argument.rb +1 -0
  156. data/lib/eco/cli/scripting/arguments.rb +1 -1
  157. data/lib/eco/csv.rb +8 -3
  158. data/lib/eco/csv/table.rb +1 -1
  159. data/lib/eco/data/crypto/encryption.rb +3 -0
  160. data/lib/eco/data/files/helpers.rb +6 -1
  161. data/lib/eco/language/match.rb +19 -9
  162. data/lib/eco/language/match_modifier.rb +13 -5
  163. data/lib/eco/language/models/collection.rb +77 -56
  164. data/lib/eco/language/models/parser_serializer.rb +39 -15
  165. data/lib/eco/version.rb +1 -1
  166. metadata +149 -63
  167. data/lib/eco/api/session/task.rb +0 -175
  168. data/lib/eco/api/usecases/default_case.rb +0 -19
  169. data/lib/eco/api/usecases/default_cases/delete_case.rb +0 -32
  170. data/lib/eco/api/usecases/default_cases/recover_db_case.rb +0 -98
  171. data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +0 -26
  172. data/lib/eco/api/usecases/default_cases/reinvite_case.rb +0 -41
  173. data/lib/eco/api/usecases/default_cases/remove_account_case.rb +0 -38
  174. data/lib/eco/cli/config/default/filters.rb +0 -70
  175. data/lib/eco/cli/config/people_filters.rb +0 -38
@@ -1,112 +1,18 @@
1
- module Eco
2
- module API
3
- class UseCases
4
- class DefaultCases
5
- class UpdateCase < DefaultCase
6
-
7
- def process
8
- @cases.define("update", type: :sync) do |entries, people, session, options, usecase|
9
- update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
10
- supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
11
-
12
- strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
13
- pgs = session.policy_groups
14
-
15
- if session.config.people.default_usergroup?
16
- def_id = pgs.to_id(session.config.people.default_usergroup)
17
- end
18
-
19
- entries.each.with_index do |entry, i|
20
- if person = people.find(entry, strict: strict_search)
21
-
22
- unless options.dig(:exclude, :core)
23
- ini_tags = person.filter_tags || []
24
-
25
- core_attrs = ["name", "external_id", "email", "filter_tags"]
26
- core_excluded = core_attrs.map.select {|attr| options.dig(:exclude, attr.to_sym)}
27
- core_excluded.push("supervisor_id")
28
-
29
- entry.set_core(person, exclude: core_excluded)
30
-
31
- if session.tagtree && !options.dig(:exclude, :filter_tags)
32
- person.filter_tags = session.tagtree.user_tags(
33
- initial: ini_tags,
34
- final: person.filter_tags,
35
- preserve_custom: true,
36
- add_custom: true
37
- )
38
- end
39
- end
40
-
41
- entry.set_details(person) unless options.dig(:exclude, :details)
42
-
43
- unless options.dig(:exclude, :account)
44
- add_account = !person.account
45
- ini_pg_ids = person.account&.policy_group_ids || []
46
-
47
- account_excluded = []
48
- account_excluded.push("policy_group_ids") if options.dig(:exclude, :policy_groups)
49
-
50
- entry.set_account(person, exclude: account_excluded)
51
-
52
- person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
53
-
54
- unless options.dig(:exclude, :policy_groups) && !create
55
- end_pg_ids = person.account.policy_group_ids || []
56
-
57
- if add_account && def_id && !entry.policy_group_ids?
58
- # on account creation, if missing policy_group_ids column in the input
59
- # use default_usergroup, if it's defined
60
- end_pg_ids = [def_id]
61
- end
62
-
63
- # avoid false updates by preserving the original order
64
- person.account.policy_group_ids = pgs.user_pg_ids(
65
- initial: ini_pg_ids,
66
- final: end_pg_ids
67
- )
68
- end
69
-
70
- person.account.permissions_custom = session.new_preset(person) unless options.dig(:exclude, :abilities)
71
-
72
- unless options.dig(:exclude, :filter_tags) || entry.default_tag?
73
- if session.tagtree
74
- person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
75
- else
76
- tags = person.filter_tags || []
77
- person.account.default_tag = tags.first unless tags.length > 1
78
- end
79
- end
80
-
81
- end
82
- update.add(person)
83
-
84
- # set supervisor
85
- unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
86
- if !(sup_id = entry.supervisor_id)
87
- person.supervisor_id = nil
88
- else
89
- if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
90
- person.supervisor_id = supervisor.id
91
- else
92
- # delay setting supervisor if does not exit
93
- supers.add(person) do |person|
94
- person.supervisor_id = sup_id
95
- end
96
- end
97
- end
98
- end
99
-
100
- else
101
- session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
102
- end
103
- end
104
- end
105
-
106
- end
107
-
108
- end
109
- end
1
+ class Eco::API::UseCases::DefaultCases::UpdateCase < Eco::API::Common::Loaders::UseCase
2
+ name "update"
3
+ type :sync
4
+
5
+ def main(entries, people, session, options, usecase)
6
+ micro = session.micro
7
+ update = session.new_job("main", "update", :update, usecase)
8
+ supers = session.new_job("post", "supers", :update, usecase, :core)
9
+
10
+ micro.with_each_present(entries, people, options, log_starter: true) do |entry, person|
11
+ update.add(person)
12
+ micro.set_core_with_supervisor(entry, person, people, supers, options)
13
+ entry.set_details(person) unless options.dig(:exclude, :details)
14
+ micro.set_account(entry, person, options)
110
15
  end
111
16
  end
17
+
112
18
  end
@@ -1,64 +1,17 @@
1
- module Eco
2
- module API
3
- class UseCases
4
- class DefaultCases
5
- class UpdateDetailsCase < DefaultCase
6
-
7
- def process
8
- @cases.define("update-details", type: :sync) do |entries, people, session, options, usecase|
9
- job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details])
10
- supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
11
-
12
- strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
13
-
14
- entries.each.with_index do |entry, i|
15
- if person = people.find(entry, strict: strict_search)
16
- unless options.dig(:exclude, :core)
17
- core_attrs = ["name", "external_id", "email", "filter_tags"]
18
- core_excluded = core_attrs.map.select {|attr| options.dig(:exclude, attr.to_sym)}
19
- core_excluded.push("supervisor_id")
20
-
21
- entry.set_core(person, exclude: core_excluded) unless options.dig(:exclude, :core)
22
-
23
- if session.tagtree && !options.dig(:exclude, :filter_tags)
24
- person.filter_tags = session.tagtree.user_tags(
25
- initial: ini_tags,
26
- final: person.filter_tags,
27
- preserve_custom: true,
28
- add_custom: true
29
- )
30
- end
31
- end
32
-
33
- entry.set_details(person)
34
-
35
- job.add(person)
36
-
37
- # set supervisor
38
- unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
39
- if !(sup_id = entry.supervisor_id)
40
- person.supervisor_id = nil
41
- else
42
- if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
43
- person.supervisor_id = supervisor.id
44
- else
45
- # delay setting supervisor if does not exit
46
- supers.add(person) do |person|
47
- person.supervisor_id = sup_id
48
- end
49
- end
50
- end
51
- end
52
-
53
- else
54
- session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
55
- end
56
- end
57
- end
58
- end
59
-
60
- end
61
- end
1
+ class Eco::API::UseCases::DefaultCases::UpdateDetailsCase < Eco::API::Common::Loaders::UseCase
2
+ name "update-details"
3
+ type :sync
4
+
5
+ def main(entries, people, session, options, usecase)
6
+ micro = session.micro
7
+ update = session.new_job("main", "update", :update, usecase)
8
+ supers = session.new_job("post", "supers", :update, usecase, :core)
9
+
10
+ micro.with_each_present(entries, people, options, log_starter: true) do |entry, person|
11
+ update.add(person)
12
+ micro.set_core_with_supervisor(entry, person, people, supers, options)
13
+ entry.set_details(person) unless options.dig(:exclude, :details)
62
14
  end
63
15
  end
16
+
64
17
  end
@@ -1,114 +1,19 @@
1
- module Eco
2
- module API
3
- class UseCases
4
- class DefaultCases
5
- class UpsertCase < DefaultCase
6
-
7
- def process
8
- @cases.define("upsert", type: :sync) do |entries, people, session, options, usecase|
9
- creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account])
10
- update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
11
- supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
12
-
13
- strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
14
- pgs = session.policy_groups
15
-
16
- if session.config.people.default_usergroup?
17
- def_id = pgs.to_id(session.config.people.default_usergroup)
18
- end
19
-
20
- entries.each_with_index do |entry, i|
21
- person = people.find(entry, strict: strict_search)
22
- person = session.new_person if create = !person
23
-
24
- unless options.dig(:exclude, :core) && !create
25
- ini_tags = person.filter_tags || []
26
-
27
- core_excluded = ["supervisor_id"]
28
-
29
- unless create
30
- core_attrs = ["name", "external_id", "email", "filter_tags"]
31
- core_excluded += core_attrs.map.select {|attr| options.dig(:exclude, attr.to_sym)}
32
- end
33
-
34
- entry.set_core(person, exclude: core_excluded)
35
- if session.tagtree && !options.dig(:exclude, :filter_tags)
36
- person.filter_tags = session.tagtree.user_tags(
37
- initial: ini_tags,
38
- final: person.filter_tags,
39
- preserve_custom: true,
40
- add_custom: true
41
- )
42
- end
43
- end
44
-
45
- entry.set_details(person) unless options.dig(:exclude, :details)
46
-
47
- unless options.dig(:exclude, :account)
48
- add_account = !person.account
49
- ini_pg_ids = person.account&.policy_group_ids || []
50
-
51
- account_excluded = []
52
- account_excluded.push("policy_group_ids") if options.dig(:exclude, :policy_groups) && !create
53
-
54
- entry.set_account(person, exclude: account_excluded)
55
-
56
- person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
57
-
58
- unless options.dig(:exclude, :policy_groups) && !create
59
- end_pg_ids = person.account.policy_group_ids || []
60
-
61
- if add_account && def_id && !entry.policy_group_ids?
62
- # on account creation, if missing policy_group_ids column in the input
63
- # use default_usergroup, if it's defined
64
- end_pg_ids = [def_id]
65
- end
66
-
67
- # avoid false updates by preserving the original order
68
- person.account.policy_group_ids = pgs.user_pg_ids(
69
- initial: ini_pg_ids,
70
- final: end_pg_ids
71
- )
72
- end
73
-
74
- person.account.permissions_custom = session.new_preset(person) unless !create && options.dig(:exclude, :abilities)
75
-
76
- unless options.dig(:exclude, :filter_tags) || entry.default_tag?
77
- if session.tagtree
78
- person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
79
- else
80
- tags = person.filter_tags || []
81
- person.account.default_tag = tags.first unless tags.length > 1
82
- end
83
- end
84
-
85
- end
86
-
87
- creation.add(person) if create
88
- update.add(person) unless create
89
-
90
- # set supervisor
91
- unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
92
- if !(sup_id = entry.supervisor_id)
93
- person.supervisor_id = nil
94
- else
95
- if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
96
- person.supervisor_id = supervisor.id
97
- else
98
- # delay setting supervisor if does not exit
99
- supers.add(person) do |person|
100
- person.supervisor_id = sup_id
101
- end
102
- end
103
- end
104
- end
105
-
106
- end
107
- end
108
- end
109
-
110
- end
111
- end
1
+ class Eco::API::UseCases::DefaultCases::UpsertCase < Eco::API::Common::Loaders::UseCase
2
+ name "upsert"
3
+ type :sync
4
+
5
+ def main(entries, people, session, options, usecase)
6
+ micro = session.micro
7
+ creation = session.new_job("main", "create", :create, usecase)
8
+ update = session.new_job("main", "update", :update, usecase)
9
+ supers = session.new_job("post", "supers", :update, usecase, :core)
10
+
11
+ micro.with_each(entries, people, options) do |entry, person|
12
+ person.new? ? creation.add(person) : update.add(person)
13
+ micro.set_core_with_supervisor(entry, person, people, supers, options)
14
+ entry.set_details(person) unless options.dig(:exclude, :details)
15
+ micro.set_account(entry, person, options)
112
16
  end
113
17
  end
18
+
114
19
  end
@@ -30,7 +30,6 @@ module Eco
30
30
  super(**default.merge(kargs))
31
31
  end
32
32
 
33
-
34
33
  # @param value [Eco::API::UseCases::UseCase] the usecase this InputOuput should be linked to
35
34
  def usecase=(value)
36
35
  raise "It should be a Eco::API::UseCases::UseCase. Given: #{value}" if !value.is_a?(Eco::API::UseCases::UseCase)
@@ -47,9 +46,9 @@ module Eco
47
46
  end
48
47
 
49
48
  # @see Eco::API::UseCases::BaseIO#params
50
- # Same as its superclass but adding `usecase` parameter
51
- def params(keyed: false)
52
- super(keyed: keyed).tap do |res|
49
+ # Same as its superclass but adding `usecase` and `job` parameters
50
+ def params(keyed: false, all: false)
51
+ super(keyed: keyed, all: all).tap do |res|
53
52
  if keyed
54
53
  res.merge!(usecase: usecase)
55
54
  res.merge!(job: @job) if @job
@@ -62,19 +61,20 @@ module Eco
62
61
 
63
62
  def chain(usecase:)
64
63
  raise "It should be a UseCase. Given: #{usecase}" if !usecase.is_a?(UseCase)
65
-
66
- aux_io = self.class.new(input: input, people: people, session: session, options: options, usecase: usecase)
67
- kargs = aux_io.params(keyed: true)
64
+ #aux_io = self.class.new(input: input, people: people, session: session, options: options, usecase: usecase)
65
+ #kargs = aux_io.params(keyed: true)
66
+ kargs = params(keyed: true, all: true).merge(usecase: usecase)
67
+ kargs.delete(:job)
68
68
 
69
69
  case self.type
70
70
  when :import
71
71
  kargs[:input] = output
72
72
  when :filter
73
73
  kargs[:people] = output
74
- when :transform, :sync, :export, :error_handler
74
+ when :transform, :sync, :export, :error_handler, :other
75
75
  # no redirections => should it redirect the input?
76
76
  end
77
- self.class.new(kargs)
77
+ self.class.new(**kargs)
78
78
  end
79
79
  end
80
80
 
@@ -49,12 +49,19 @@ module Eco
49
49
  end
50
50
 
51
51
  def people_filters
52
- @people_filters ||= Eco::CLI::Config::PeopleFilters.new(core_config: self)
52
+ @people_filters ||= Eco::CLI::Config::Filters::PeopleFilters.new(core_config: self)
53
53
  @people_filters.tap do |filters|
54
54
  yield(filters) if block_given?
55
55
  end
56
56
  end
57
57
 
58
+ def input_filters
59
+ @input_filters ||= Eco::CLI::Config::Filters::InputFilters.new(core_config: self)
60
+ @input_filters.tap do |filters|
61
+ yield(filters) if block_given?
62
+ end
63
+ end
64
+
58
65
  def usecases
59
66
  @usecases ||= Eco::CLI::Config::UseCases.new(core_config: self)
60
67
  @usecases.tap do |cases|
@@ -66,7 +73,8 @@ module Eco
66
73
  end
67
74
  end
68
75
 
76
+ require_relative 'config/help'
69
77
  require_relative 'config/options_set'
70
78
  require_relative 'config/input'
71
- require_relative 'config/people_filters'
79
+ require_relative 'config/filters'
72
80
  require_relative 'config/use_cases'
@@ -9,7 +9,8 @@ end
9
9
 
10
10
  require_relative 'default/options'
11
11
  require_relative 'default/input'
12
+ require_relative 'default/input_filters'
12
13
  require_relative 'default/people'
13
- require_relative 'default/filters'
14
+ require_relative 'default/people_filters'
14
15
  require_relative 'default/usecases'
15
16
  require_relative 'default/workflow'
@@ -0,0 +1,58 @@
1
+ ASSETS.cli.config do |cnf|
2
+ cnf.input_filters do |filters|
3
+
4
+ filters.add("-input-filter-tags-all", "only those that have ALL the specified tags separated by '|'") do |input, session, options|
5
+ tags = SCR.get_arg("-input-filter-tags-all", with_param: true).upcase.split("|")
6
+ options.deep_merge!(input: {filter: {filter_tags: {all: tags}}})
7
+ input.filter_tags_all(tags).tap do |filtered|
8
+ msg = "Filtered #{filtered.count} entries (out of #{input.count}) with 'all' filter_tags #{tags}"
9
+ session.logger.info(msg)
10
+ end
11
+ end
12
+
13
+ filters.add("-input-filter-tags-any", "only those that have ANY the specified tags separated by '|'") do |input, session, options|
14
+ tags = SCR.get_arg("-input-filter-tags-any", with_param: true).upcase.split("|")
15
+ options.deep_merge!(input: {filter: {filter_tags: {any: tags}}})
16
+ input.filter_tags_any(tags).tap do |filtered|
17
+ msg = "Filtered #{filtered.count} entries (out of #{input.count}) with 'any' filter_tags #{tags}"
18
+ session.logger.info(msg)
19
+ end
20
+ end
21
+
22
+ filters.add("-input-filter-tags-tree", "only those that have ANY tag in the specified subtrees separated by '|'") do |input, session, options|
23
+ top_tags = SCR.get_arg("-input-filter-tags-tree", with_param: true).upcase.split("|")
24
+ tags = top_tags.each_with_object([]) do |top, tags|
25
+ tags.concat(session.tagtree.node(top).tags)
26
+ end.uniq
27
+ options.deep_merge!(input: {filter: {filter_tags: {tree: top_tags, any: tags}}})
28
+ input.filter_tags_any(tags).tap do |filtered|
29
+ msg = "Filtered #{filtered.count} entries (out of #{input.count}) with 'any' filter_tags in subtrees #{top_tags}"
30
+ session.logger.info(msg)
31
+ end
32
+ end
33
+
34
+ filters.add("-input-no-id", "only those that do not have 'id' or 'external_id' specified") do |input, session, options|
35
+ options.deep_merge!(input: {filter: {external_id: nil}})
36
+ input.select do |entry|
37
+ !!(entry.id || entry.external_id)
38
+ end.yield_self do |filtered|
39
+ input.newFrom filtered
40
+ end
41
+ end
42
+
43
+ #filters.add("-input-supervisors") do |people, session, options|
44
+ # options.deep_merge!(input: {filter: {subordinates: true}})
45
+ # people.newFrom people.to_a.select {|person| person.subordinates > 0}
46
+ #end
47
+
48
+ filters.add("-input-supervisor-id", "only those with certain supervisor id or external_id") do |input, session, options|
49
+ id = SCR.get_arg("-input-supervisor-id", with_param: true)
50
+ options.deep_merge!(input: {filter: {supervisor_id: id}})
51
+ #unless sup = entries.find({"id" => id, "external_id" => id})
52
+ # raise "Could not find anyone in the input with that id '#{id}'"
53
+ #end
54
+ input.supervisor_id(id)
55
+ end
56
+
57
+ end
58
+ end