Module: Eco::API::MicroCases::People::Manage::Search

Included in:
Eco::API::MicroCases::People::Manage
Defined in:
lib/eco/api/microcases/people/manage/search.rb

Instance Method Summary collapse

Instance Method Details

#people_search(data, options: {}, silent: false) ⇒ Eco::API::Organization::People

Note:
  • this helper is normally used to get partial part of the people manager.
  • therefore, normally used with delta input files (files with only the differences).

Helper to search/obtain people from data against the server (People Manager).

Parameters:

  • data (Eco::API::Organization::People, Enumerable<Person>, Enumerable<Hash>)

    People to search against the server.

  • options (Hash) (defaults to: {})

    the options.

  • silent (Boolean) (defaults to: false)

    false if low level search messages should be shown.

Returns:



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
# File 'lib/eco/api/microcases/people/manage/search.rb', line 16

def people_search(data, options: {}, silent: false) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength

  log(:info) { "Going to api get #{data.length} entries..." }

  silent &&= data.count <= 500

  start = Time.now
  people = session.batch.search(data, silent: silent).then do |status|
    secs = (Time.now - start).round(3)

    Eco::API::Organization::People.new(status.people).tap do |ppl|
      cnt     = ppl.count
      per_sec = (cnt.to_f / secs).round(2)

      msg     = "... could get #{cnt} people "
      msg    << "(out of #{data.length} entries) in #{secs} seconds (#{per_sec} people/sec)"

      log(:info) { msg }
    end
  end

  # get the supervisors of found people (current supervisors)

  supers = people_search_prepare_supers_request(people)
  if supers.length.positive?
    log(:info) {
      "  Going to api get #{supers.length} current supervisors..."
    }

    start = Time.now
    people = session.batch.search(supers, silent: silent).then do |status|
      secs    = (Time.now - start).round(3)
      found   = status.people
      cnt     = found.count
      per_sec = (cnt.to_f / secs).round(2)

      msg     = "... could find #{cnt} current supers "
      msg    << "(out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)"
      log(:info) { msg }

      people.merge(found, strict: micro.strict_search?(options))
    end
  end

  # get the supervisors referred in the input data (future supervisors)

  supers = people_search_prepare_supers_request(data, people)
  if supers.length.positive?
    log(:info) {
      "  Going to api get #{supers.length} supervisors as per input entries..."
    }

    start = Time.now
    people = session.batch.search(supers, silent: silent).then do |status|
      secs    = (Time.now - start).round(3)
      found   = status.people
      cnt     = found.count
      per_sec = (cnt.to_f / secs).round(2)

      msg     = "... could find #{cnt} input supers "
      msg    << "(out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)"
      log(:info) { msg }

      people.merge(found, strict: micro.strict_search?(options))
    end
  end

  log(:info) {
    "Finally got #{people.length} people (out of #{data.length} entries)"
  }

  people
end