Class: Eco::API::UseCases::DefaultCases::HrisCase
- Inherits:
-
Common::Loaders::UseCase
- Object
- Common::BaseLoader
- Common::Loaders::UseCase
- Eco::API::UseCases::DefaultCases::HrisCase
- Defined in:
- lib/eco/api/usecases/backup/hris_case.rb,
lib/eco/api/usecases/default_cases/hris_case.rb
Instance Method Summary collapse
Methods inherited from Common::Loaders::UseCase
Methods inherited from Common::BaseLoader
<=>, created_at, #initialize, #name, name_only_once!, set_created_at!
Methods included from Common::ClassHelpers
#class_resolver, #descendants, #descendants?, #new_class, #resolve_class, #to_constant
Constructor Details
This class inherits a constructor from Eco::API::Common::Loaders::UseCase
Instance Method Details
#main(entries, people, session, options, usecase) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/eco/api/usecases/default_cases/hris_case.rb', line 5 def main(entries, people, session, , usecase) micro = session.micro creation = session.new_job("main", "create", :create, usecase) update = session.new_job("main", "update", :update, usecase) supers = session.new_job("post", "supers", :update, usecase, :core) leavers = session.new_job("post", "leavers", :update, usecase, :account) micro.with_each_leaver(entries, people, ) do |person| leavers.add(person) do |person| person.supervisor_id = nil person.account = nil if person.account end end micro.with_each(entries, people, ) do |entry, person| person.new? ? creation.add(person) : update.add(person) micro.set_core_with_supervisor(entry, person, people, supers, ) entry.set_details(person) unless .dig(:exclude, :details) micro.set_account(entry, person, ) end end |
#process ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/eco/api/usecases/backup/hris_case.rb', line 7 def process @cases.define("hris", type: :sync) do |entries, people, session, , usecase| creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account]) update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account]) supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core) leavers = session.job_group("post").new("leavers", usecase: usecase, type: :update, sets: :account) strict_search = session.config.people.strict_search? && (![:search]&.key?(:strict) || .dig(:search, :strict)) pgs = session.policy_groups people.each_with_index do |person, i| if !entries.find(person, strict: strict_search) leavers.add(person) do |person| person.supervisor_id = nil person.account = nil if person.account end end end if session.config.people.default_usergroup? def_id = pgs.to_id(session.config.people.default_usergroup) end entries.each_with_index do |entry, i| person = people.find(entry, strict: strict_search) person = session.new_person if create = !person unless .dig(:exclude, :core) && !create = person. || [] core_attrs = ["name", "external_id", "email", "filter_tags"] core_excluded = core_attrs.map.select {|attr| .dig(:exclude, attr.to_sym)} core_excluded.push("supervisor_id") entry.set_core(person, exclude: core_excluded) if session.tagtree && !.dig(:exclude, :filter_tags) person. = session.tagtree.( initial: , final: person., preserve_custom: true, add_custom: true ) end end entry.set_details(person) unless .dig(:exclude, :details) unless .dig(:exclude, :account) add_account = !person.account ini_pg_ids = person.account&.policy_group_ids || [] account_excluded = [] account_excluded.push("policy_group_ids") if .dig(:exclude, :policy_groups) && !create entry.set_account(person, exclude: account_excluded) person.account.send_invites = [:send_invites] if .key?(:send_invites) unless .dig(:exclude, :policy_groups) && !create end_pg_ids = person.account.policy_group_ids || [] if add_account && def_id && !entry.policy_group_ids? # on account creation, if missing policy_group_ids column in the input # use default_usergroup, if it's defined end_pg_ids = [def_id] end # avoid false updates by preserving the original order person.account.policy_group_ids = pgs.user_pg_ids( initial: ini_pg_ids, final: end_pg_ids ) end person.account. = session.new_preset(person) unless !create && .dig(:exclude, :abilities) unless .dig(:exclude, :filter_tags) || entry.default_tag? if session.tagtree person.account.default_tag = session.tagtree.default_tag(*person.) else = person. || [] person.account.default_tag = .first unless .length > 1 end end end creation.add(person) if create update.add(person) unless create # set supervisor unless .dig(:exclude, :core) || .dig(:exclude, :supervisor) if !(sup_id = entry.supervisor_id) person.supervisor_id = nil else if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id) person.supervisor_id = supervisor.id else # delay setting supervisor if does not exit supers.add(person) do |person| person.supervisor_id = sup_id end end end end end end end |