class Eco::API::UseCases::DefaultCases::HrisCase

Attributes

creation[R]
leavers[R]
options[R]
people[R]
session[R]
supers[R]
update[R]

Public Instance Methods

main(entries, people, session, options, usecase) click to toggle source
# File lib/eco/api/usecases/default_cases/hris_case.rb, line 8
def main(entries, people, session, options, usecase)
  @session = session; @options = options; @people = people
  require_only_one_schema!
  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, options) do |person|
    leavers.add(person, &method(:leavers_callback))
  end

  micro.with_each(entries, people, options, append_created: append_created) do |entry, person|
    person.new? ? creation.add(person) : update.add(person)
    micro.set_core_with_supervisor(entry, person, people, supers, options)
    entry.set_details(person) unless options.dig(:exclude, :details)
    micro.set_account(entry, person, options)
  end
end

Private Instance Methods

append_created() click to toggle source
# File lib/eco/api/usecases/default_cases/hris_case.rb, line 31
def append_created
  options.dig(:people, :append_created)
end
leavers_callback(person) click to toggle source
# File lib/eco/api/usecases/default_cases/hris_case.rb, line 35
def leavers_callback(person)
  person.supervisor_id = nil
  person.account       = nil if person.account
end
require_only_one_schema!() click to toggle source
# File lib/eco/api/usecases/default_cases/hris_case.rb, line 40
def require_only_one_schema!
  unless schema_id = options.dig(:people, :filter, :details, :schema_id)
    active_schema = session.schema
    other_schemas = session.schemas.map(&:id) - [active_schema.id]
    other_people  = people.group_by_schema.values_at(*other_schemas).map(&:to_a).flatten
    if other_people.length > 3
      msg  = "There are #{other_people.length} people in schemas other than #{active_schema.name}."
      msg << " Please, use the filter option '-schema_id SchemaName' for the 'hris' case to only include those of that schema"
      msg << " in the current update. The HRIS case identifies people that are not in the file as leavers"
      msg << " (as it will remove the account of all the people of other schemas if they are not in the input file)."
      msg << "\n For example: -schema-id '#{active_schema.name.downcase}'"
      logger.error(msg)
      raise msg
    end
  end
end