Class: Ucert::GoTracker

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/ucert/go_contact_tracker.rb

Constant Summary collapse

@@column_name =
['department', 'title', 'en_name', 'cn_name_pinyin', 'cn_name', 'wk_phone','wk_phone_ext', 'cell_phone', 'email']

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#file_2_list, #is_fqdn?, #is_ip?, #is_url?, #list_2_file, #load_known_user_map_from_file, #nslookup, #search_ad, #update_dn

Constructor Details

#initialize(params = {}) ⇒ GoTracker

Instance default variables



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ucert/go_contact_tracker.rb', line 21

def initialize (params ={})
  @cmbny_contact_sheet = File.dirname(__FILE__) + '/../../data/go_contact/go_contact.xlsx'
  @verbose = params.fetch(:verbose, false)
  # Go to AD user map file

  @file_go_user_map = File.dirname(__FILE__) + '/../../data/go_contact/go_user_map.txt'
  @dn_title_level_map = File.dirname(__FILE__) + '/../../data/go_contact/title_level_map.txt'
  # Load user map from the local cache file

  @go_2_ad_user = load_known_user_map_from_file(@file_go_user_map)
  @go_contact = parse_go_contact(@cmbny_contact_sheet)
  # Procedure to add DN foreign key to the @go_contact, by performing the AD search

  insert_dn(@go_contact)
  insert_title_and_level(@go_contact)
  @go_contact_0 = @go_contact[0]
  @go_contact_1 = @go_contact[1]
  org_chart
  @go_dptm = go_dptm_list
  # Save the user map to local cache file

  save!
  #save_title_level_map

end

Instance Attribute Details

#go_2_ad_userObject (readonly)

Returns the value of attribute go_2_ad_user.



18
19
20
# File 'lib/ucert/go_contact_tracker.rb', line 18

def go_2_ad_user
  @go_2_ad_user
end

#go_contactObject

Returns the value of attribute go_contact.



17
18
19
# File 'lib/ucert/go_contact_tracker.rb', line 17

def go_contact
  @go_contact
end

#go_contact_0Object

Returns the value of attribute go_contact_0.



17
18
19
# File 'lib/ucert/go_contact_tracker.rb', line 17

def go_contact_0
  @go_contact_0
end

#go_contact_1Object

Returns the value of attribute go_contact_1.



17
18
19
# File 'lib/ucert/go_contact_tracker.rb', line 17

def go_contact_1
  @go_contact_1
end

#go_dptmObject (readonly)

Returns the value of attribute go_dptm.



18
19
20
# File 'lib/ucert/go_contact_tracker.rb', line 18

def go_dptm
  @go_dptm
end

#org_chartObject

Returns the value of attribute org_chart.



17
18
19
# File 'lib/ucert/go_contact_tracker.rb', line 17

def org_chart
  @org_chart
end

#verboseObject

Returns the value of attribute verbose.



17
18
19
# File 'lib/ucert/go_contact_tracker.rb', line 17

def verbose
  @verbose
end

Instance Method Details

#export_go_contact_sheet(output_full_time, output_non_fte) ⇒ Object



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/ucert/go_contact_tracker.rb', line 284

def export_go_contact_sheet(output_full_time, output_non_fte)
  workbook = RubyXL::Workbook.new
  workbook.worksheets[0].sheet_name = 'FTE'
  workbook.add_worksheet('Non_FTE')
  workbook.worksheets.each_with_index do |worksheet, index|
    if index==0
      @full_time = output_full_time
    else
      @full_time = output_non_fte
    end
    record=0
    begin0=2
    worksheet.merge_cells(0, 0, 0, 8)
    worksheet.add_cell(0, 0, "China Merchants Bank New York Branch Contact Sheet #{Time.now.year}")
    worksheet.change_row_height(0,40.5)
    worksheet.sheet_data[0][0].change_font_size(font_size = 28)
    worksheet.sheet_data[0][0].change_font_name(font_name = 'Arial')
    worksheet.sheet_data[0][0].change_font_bold(true)
    worksheet.sheet_data[0][0].change_horizontal_alignment('center')
    worksheet.sheet_data[0][0].change_vertical_alignment('center')
    worksheet.change_column_width(0, 34.29)
    worksheet.change_column_width(1, 3.14)
    worksheet.change_column_width(2, 25.86)
    worksheet.change_column_width(3, 19.71)
    worksheet.change_column_width(4, 15.71)
    worksheet.change_column_width(5, 16.29)
    worksheet.change_column_width(6, 7.57)
    worksheet.change_column_width(7, 15.57)
    worksheet.change_column_width(8, 38.29)
    worksheet.add_cell(1, 0, 'Department')
    worksheet.add_cell(1, 1, 'Title')
    worksheet.add_cell(1, 2, 'English Name')
    worksheet.add_cell(1, 3, 'Chinese Name')
    worksheet.add_cell(1, 4, 'Chinese Name')
    worksheet.add_cell(1, 5, 'Work Phone')
    worksheet.add_cell(1, 6, 'Ext.')
    worksheet.add_cell(1, 7, 'Cell Number')
    worksheet.add_cell(1, 8, 'E-mail Address')
    for i in 0..8
      worksheet.sheet_data[1][i].change_font_bold(true)
      worksheet.sheet_data[1][i].change_horizontal_alignment('center')
      worksheet.sheet_data[1][i].change_font_size(font_size = 11)
      worksheet.sheet_data[1][i].change_font_name('Arial')
    end
    while @full_time[record] do
      if record % 2 != 0
        worksheet.change_row_fill(record, 'D7E4BC')
      end
      worksheet.change_row_border(record, :top, 'thin')
      worksheet.change_row_border(record, :bottom, 'thin')
      worksheet.change_row_border(record, :left, 'thin')
      worksheet.change_row_border(record, :right, 'thin')
      for i in 0..8
        worksheet.add_cell(begin0, i, @full_time[record][@@column_name[i]])
        #worksheet.sheet_data[begin0][i].change_font_bold(true) if (1...7) === @full_time[record]['level'].to_i

        worksheet.sheet_data[begin0][i].change_horizontal_alignment('center')
        worksheet.sheet_data[begin0][i].change_font_size(font_size = 11)
        worksheet.sheet_data[begin0][i].change_font_name('Arial')
      end
      record += 1
      begin0 += 1
    end
    worksheet.change_row_fill(record, 'D7E4BC')
    worksheet.change_row_border(record, :top, 'thin')
    worksheet.change_row_border(record, :bottom, 'thin')
    worksheet.change_row_border(record, :left, 'thin')
    worksheet.change_row_border(record, :right, 'thin')
    worksheet.change_row_border(record + 1, :top, 'thin')
    worksheet.change_row_border(record + 1, :bottom, 'thin')
    worksheet.change_row_border(record + 1, :left, 'thin')
    worksheet.change_row_border(record + 1, :right, 'thin')

    worksheet.merge_cells(record + 2, 0, record + 7, 0)
    worksheet.add_cell(record + 2, 0, 'CMBNY IT Dept. Disaster Recovery Lines')
    worksheet.sheet_data[record + 2][0].change_vertical_alignment('center')
    worksheet.add_cell(record + 8, 0, 'CMBNY IT Help Desk Line:')
    worksheet.add_cell(record + 9, 0, 'Human Resources Office Fax:')
    worksheet.add_cell(record + 3, 0, '')
    worksheet.add_cell(record + 4, 0, '')
    worksheet.add_cell(record + 5, 0, '')
    worksheet.add_cell(record + 6, 0, '')
    worksheet.add_cell(record + 7, 0, '')
    worksheet.add_cell(record + 2, 1, '')
    worksheet.add_cell(record + 3, 1, '')
    worksheet.add_cell(record + 4, 1, '')
    worksheet.add_cell(record + 5, 1, '')
    worksheet.add_cell(record + 6, 1, '')
    worksheet.add_cell(record + 7, 1, '')
    worksheet.add_cell(record + 8, 1, '')
    worksheet.add_cell(record + 9, 1, '')
    worksheet.sheet_data[record + 2][0].change_font_bold(true)
    worksheet.sheet_data[record + 2][0].change_font_name('Arial')
    worksheet.sheet_data[record + 2][0].change_font_size(font_size = 11)
    worksheet.sheet_data[record + 8][0].change_font_bold(true)
    worksheet.sheet_data[record + 8][0].change_font_name('Arial')
    worksheet.sheet_data[record + 8][0].change_font_size(font_size = 11)
    worksheet.sheet_data[record + 9][0].change_font_bold(true)
    worksheet.sheet_data[record + 9][0].change_font_name('Arial')
    worksheet.sheet_data[record + 9][0].change_font_size(font_size = 11)
    worksheet.merge_cells(record + 2, 1, record + 7, 1)
    worksheet.add_cell(record + 2, 2, '646 843-6811')
    worksheet.add_cell(record + 3, 2, '646 843-6812')
    worksheet.add_cell(record + 4, 2, '646 843-6813')
    worksheet.add_cell(record + 5, 2, '646 843-6814')
    worksheet.add_cell(record + 6, 2, '646 843-6815')
    worksheet.add_cell(record + 7, 2, '646 843-6816')
    worksheet.add_cell(record + 8, 2, '6999')
    worksheet.add_cell(record + 9, 2, '212 355-5147')
    for i in 2..9
      worksheet.sheet_data[record + i][2].change_horizontal_alignment('center')
      worksheet.sheet_data[record + i][2].change_font_name('Arial')
      worksheet.sheet_data[record + i][2].change_font_size(font_size = 11)
      for j in 0..2
        worksheet.sheet_data[record + i][j].change_border(:top, 'thin')
        worksheet.sheet_data[record + i][j].change_border(:bottom, 'thin')
        worksheet.sheet_data[record + i][j].change_border(:left, 'thin')
        worksheet.sheet_data[record + i][j].change_border(:right, 'thin')
      end
    end
    worksheet.merge_cells(record + 2, 4, record + 13, 4)
    worksheet.add_cell(record + 2, 4, 'Main Office Lines')
    for i in 3..13
      worksheet.add_cell(record + i, 4, '')
    end
    worksheet.sheet_data[record + 2][4].change_font_bold(true)
    worksheet.sheet_data[record + 2][4].change_font_name('Arial')
    worksheet.sheet_data[record + 2][4].change_horizontal_alignment('center')
    worksheet.sheet_data[record + 2][4].change_vertical_alignment('center')
    worksheet.sheet_data[record + 2][4].change_font_size(font_size = 11)
    for i in 2..13
      worksheet.merge_cells(record + i, 5, record + i, 8)
    end
    worksheet.add_cell(record + 2, 5, '18 Fl Main number: 212 750-4810')
    worksheet.add_cell(record + 3, 5, '18 Fl Large Conference Room: 646 843-6801 ')
    worksheet.add_cell(record + 4, 5, '18 FL Small Conference Room: 646 843-6858')
    worksheet.add_cell(record + 5, 5, '18 Fl Copier Room: 646 843-6874                      18th FL FAX: 212 753-1319')
    worksheet.add_cell(record + 6, 5, '27 Fl Large Conference Room: 212 980-7141   ')
    worksheet.add_cell(record + 7, 5, '23 FI Main number: 212 753-1801       ')
    worksheet.add_cell(record + 8, 5, '23 FL Large Conference Room: 212 355-5930   23rd FL FAX: 212-355-3934')
    worksheet.add_cell(record + 9, 5, '17 FL Main number: 212 758-3273                      17th FL FAX: 212 223-0219')
    worksheet.add_cell(record + 10, 5, 'Building Lobby: 212 308-4177                              Mail Room: 212 888-1146')
    worksheet.add_cell(record + 11, 5, 'Calling Card (new): Access # 800 858-9414     Pin Number:1477320752')
    worksheet.add_cell(record + 12, 5, 'Calling Card (new): Access # 800 858-9414     Pin Number: 8337314307')
    worksheet.add_cell(record + 13, 5, 'Calling Card (new): Access # 800 858-9414     Pin Number: 3056429452')
    for j in 6..8
      for i in 2..13
        worksheet.add_cell(record + i, j, '')
      end
    end
    for i in 2..13
      worksheet.sheet_data[record + i][5].change_font_name('Arial')
      worksheet.sheet_data[record + i][5].change_font_size(font_size = 11)
      worksheet.sheet_data[record + i][4].change_border(:top, 'thin')
      worksheet.sheet_data[record + i][4].change_border(:bottom, 'thin')
      worksheet.sheet_data[record + i][4].change_border(:left, 'thin')
      worksheet.sheet_data[record + i][4].change_border(:right, 'thin')
      for j in 5..8
        worksheet.sheet_data[record + i][j].change_border(:top, 'thin')
        worksheet.sheet_data[record + i][j].change_border(:bottom, 'thin')
        worksheet.sheet_data[record + i][j].change_border(:left, 'thin')
        worksheet.sheet_data[record + i][j].change_border(:right, 'thin')
      end
    end
    worksheet.cols[1].hidden = true     # hiding the 'Title' column

    # refer to source: https://github.com/weshatheleopard/rubyXL/blob/master/lib/rubyXL/objects/worksheet.rb

    # legal size paper, refer to http://xlsxwriter.readthedocs.io/page_setup.html

    # worksheet.page_setup(fitToWidth: 1, fitToHeight: 1, paperSize: 4)

  end
  return workbook
end

#find_lower_level_from_hash(dn) ⇒ Object



725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
# File 'lib/ucert/go_contact_tracker.rb', line 725

def find_lower_level_from_hash(dn)
  list = Array.new()
  if dn == @org_chart["GM"]["DGM"]["CBI"]["DN"]
    @dept = "Corporate Banking China Group"
  elsif dn == @org_chart["GM"]["DGM"]["CBII"]["DN"]
    @dept = "Corporate Banking US Group"
  elsif dn == @org_chart["GM"]["DGM"]["CPG"]["DN"]
    @dept = "Credit Product Group"
  elsif dn == @org_chart["GM"]["DGM"]["IB"]["DN"]
    @dept = "Investment Banking"
  elsif dn == @org_chart["GM"]["FI"]["DN"]
    @dept = "Financial Institution"
  elsif dn == @org_chart["GM"]["PB"]["DN"]
    @dept = "Private Banking"
  elsif dn == @org_chart["GM"]["AGM2"]["TB"]["DN"]
    @dept = "Transaction Banking"
  elsif dn == @org_chart["GM"]["AGM1"]["FA"]["DN"]
    @dept = "Finance & Accounting"
  elsif dn == @org_chart["GM"]["HRGO"]["DN"]
    @dept = "General Office"
  elsif dn == @org_chart["GM"]["HRGO"]["DN"]
    @dept = "Human Resources"
  elsif dn == @org_chart["GM"]["AGM2"]["IT"]["DN"]
    @dept = "Information Technology"
  elsif dn == @org_chart["GM"]["AGM1"]["LC"]["DN"]
    @dept = "Legal & Compliance"
  elsif dn == @org_chart["GM"]["AGM2"]["OPS"]["DN"]
    @dept = "Operations"
  elsif dn == @org_chart["GM"]["AGM1"]["Risk"]["DN"]
    @dept = "Risk Management"
  elsif dn == @org_chart["GM"]["SBD"]["DN"]
    @dept = "Strategy & Business Development"
  elsif dn == @org_chart["GM"]["TRE"]["DN"]
    @dept = "Treasury"
  else
    return nil
  end
    @go_contact_0.values.map do |entry|
      entry.values.map do |every|
        if every == @dept
          if entry["en_name"] != @org_chart["GM"]["DGM"]["CBI"]["Name"] && entry["en_name"] != @org_chart["GM"]["DGM"]["CBII"]["Name"] && entry["en_name"] != @org_chart["GM"]["DGM"]["CPG"]["Name"] &&
            entry["en_name"] != @org_chart["GM"]["DGM"]["IB"]["Name"] && entry["en_name"] != @org_chart["GM"]["FI"]["Name"] && entry["en_name"] != @org_chart["GM"]["PB"]["Name"] &&
            entry["en_name"] != @org_chart["GM"]["AGM2"]["TB"]["Name"] && entry["en_name"] != @org_chart["GM"]["AGM1"]["FA"]["Name"] && entry["en_name"] != @org_chart["GM"]["HRGO"]["Name"] &&
            entry["en_name"] != @org_chart["GM"]["AGM2"]["IT"]["Name"] && entry["en_name"] != @org_chart["GM"]["AGM1"]["LC"]["Name"] && entry["en_name"] != @org_chart["GM"]["AGM2"]["OPS"]["Name"] &&
            entry["en_name"] != @org_chart["GM"]["AGM1"]["Risk"]["Name"] && entry["en_name"] != @org_chart["GM"]["SBD"]["Name"] && entry["en_name"] != @org_chart["GM"]["TRE"]["Name"]
            list.push(entry["en_name"])
          end
        end
      end
    end
    return list
    list.clear
end

#find_lower_level_from_org(hash, dn, list, flag) ⇒ Object



698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
# File 'lib/ucert/go_contact_tracker.rb', line 698

def find_lower_level_from_org(hash, dn, list, flag)
  hash.each do |key, value|
    if value.is_a? String
      if value == dn
        @flag = true
        break
      end
    else
      temp = Array.new
      value.each do |key1, value1|
        if key1 != "Name" && key1 != "DN"
          value1.each do |entry, every|
            if entry == "Name"
              temp.push(every)
            end
          end
        end
      end
      @list = temp
      find_lower_level_from_org(value, dn, list, flag)
      if @flag == true
        return @list
      end
    end
  end
end

#find_upper_level_from_hash(dn) ⇒ Object



600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# File 'lib/ucert/go_contact_tracker.rb', line 600

def find_upper_level_from_hash(dn)
  @go_contact_0.values.map do |entry|
    entry.values.map do |every|
      if every == dn
        @dept = entry["department"]
      end
    end
  end

  if @dept == "Corporate Banking China Group"
    return @org_chart["GM"]["DGM"]["CBI"]["Name"]
  elsif @dept == "Corporate Banking US Group"
    return @org_chart["GM"]["DGM"]["CBII"]["Name"]
  elsif @dept == "Credit Product Group"
    return @org_chart["GM"]["DGM"]["CPG"]["Name"]
  elsif @dept == "Investment Banking"
    return @org_chart["GM"]["DGM"]["IB"]["Name"]
  elsif @dept == "Financial Institution"
    return @org_chart["GM"]["FI"]["Name"]
  elsif @dept == "Private Banking"
    return @org_chart["GM"]["PB"]["Name"]
  elsif @dept == "Transaction Banking"
    return @org_chart["GM"]["AGM2"]["TB"]["Name"]
  elsif @dept == "Finance & Accounting"
    return @org_chart["GM"]["AGM1"]["FA"]["Name"]
  elsif @dept == "General Office"
    return @org_chart["GM"]["HRGO"]["Name"]
  elsif @dept == "Human Resources"
    return @org_chart["GM"]["HRGO"]["Name"]
  elsif @dept == "Information Technology"
    return @org_chart["GM"]["AGM2"]["IT"]["Name"]
  elsif @dept == "Legal & Compliance"
    return @org_chart["GM"]["AGM1"]["LC"]["Name"]
  elsif @dept == "Operations"
    return @org_chart["GM"]["AGM2"]["OPS"]["Name"]
  elsif @dept == "Risk Management"
    return @org_chart["GM"]["AGM1"]["Risk"]["Name"]
  elsif @dept == "Strategy & Business Development"
    return @org_chart["GM"]["SBD"]["Name"]
  elsif @dept == "Treasury"
    return @org_chart["GM"]["TRE"]["Name"]
  end

  return nil
end

#find_upper_level_from_org(hash, dn, firstLevelName, secondLevelName, nextLevelName, flag) ⇒ Object



646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
# File 'lib/ucert/go_contact_tracker.rb', line 646

def find_upper_level_from_org(hash, dn, firstLevelName, secondLevelName, nextLevelName, flag)
  hash.each do |key1, temp|
    if temp.is_a? String
      if temp == dn
        @flag = true
        break
      end
    else
      if key1 == "GM"
        temp.each do |tt, yy|
          if tt == "Name"
            @firstLevelName = yy
            @nextLevelName = @firstLevelName
            break
          end
        end
      elsif key1 == "DGM" || key1 == "AGM1" || key1 == "AGM2"
        @nextLevelName = @firstLevelName
        temp.each do |tt, yy|
          if tt == "Name"
            @secondLevelName = yy
            break
          end
        end
      elsif key1 == "TRE" || key1 == "FI" || key1 == "PB" || key1 == "SBD" || key1 == "HRGO"
        @nextLevelName = @firstLevelName
      else
        @nextLevelName = @secondLevelName
      end
      find_upper_level_from_org(temp, dn, @firstLevelName, @secondLevelName, @nextLevelName, @flag)
      if @flag == true
        return @nextLevelName
      end
    end
  end
end

#go_dptm_listObject

Dump out list of departments



251
252
253
254
255
256
257
258
# File 'lib/ucert/go_contact_tracker.rb', line 251

def go_dptm_list
  @go_dptm = Hash.new unless @go_dptm
  @go_contact_0.values.map do |entry|
    my_dptm = entry['department']
    @go_dptm[my_dptm] = true unless @go_dptm.key?(my_dptm)
  end
  return @go_dptm
end

#go_printObject



235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/ucert/go_contact_tracker.rb', line 235

def go_print
  begin
    @go_contact.each do |index, table|
      table.values.map do |entry|
        entry.values.map do |every|
          print every, "|"
        end
        puts
      end
    end
  rescue => ee
    puts "Exception on method #{__method__}: #{ee}"
  end
end

#go_search_by_dn(dn) ⇒ Object Also known as: search_by_dn



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/ucert/go_contact_tracker.rb', line 215

def go_search_by_dn (dn)
  begin
    puts "Begin searches on the cache for: #{dn}" if @verbose
    go_contact_0_result = @go_contact_0.select{|key, hash| hash['DN'] == dn}
    #@go_contact_0.key({'dn' => dn})

    if go_contact_0_result.empty?
       go_contact_1_result = @go_contact_1.select{|key, hash| hash['DN'] == dn}
       go_contact_1_result.each do |key, value|
         return value
       end
    end
    go_contact_0_result.each do |key, value|
      return value
    end
  rescue => ee
    puts "Exception on method #{__method__}: #{ee}"
 end
end

#go_search_lower_level(dn) ⇒ Object



683
684
685
686
687
688
689
690
691
692
693
694
695
696
# File 'lib/ucert/go_contact_tracker.rb', line 683

def go_search_lower_level(dn)
  step1 = find_lower_level_from_org(@org_chart, dn, nil, false)
  if step1 == @org_chart || step1.empty?
    step2 = find_lower_level_from_hash(dn)
    if step2 == nil
      return nil
    else
      return step2
    end
  else
    return step1
  end

end

#go_search_upper_level(dn) ⇒ Object



585
586
587
588
589
590
591
592
593
594
595
596
597
598
# File 'lib/ucert/go_contact_tracker.rb', line 585

def go_search_upper_level(dn)
  step1 = find_upper_level_from_org(@org_chart, dn, "", "", "", false)
  if step1 == @org_chart
     step2 = find_upper_level_from_hash(dn)
     if step2 == nil
       return nil
     else
       return step2
     end
  else
    return step1
  end

end

#go_searches_by_text(txt, max = 10) ⇒ Object Also known as: searches

Primary keywords search method used to search related employee records



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/ucert/go_contact_tracker.rb', line 179

def go_searches_by_text (txt,max=10)
  begin
    puts "Begin searches on the cache for: #{txt}" if @verbose
    # Additional logic to deal with special characters in the user input string; and allow

    # first/last name input bi-direction

    keywords = txt.downcase.gsub(/\s+/," ").split(/(\,|\s|\;|\&|\!|\@|\#|\$|\%|\^|\*|\(|\)|\-|\=|\+|\=|\{|\}|\[|\]|\:|\~)/) \
      - ["", nil, ",", ";", "&", "!", "@", "#", "$", "%", "^", "*", "(", ")", "-", "+", "=", "{", "}", "[", "]", ":" "~"]
    puts "Search by structured keywords: #{keywords}" if @verbose
    search_result_dn = Array.new
    cnt=0
    @go_contact.each do |index, table|
      table.each do |key, val|
        break if cnt >= max
        puts "Searching person cache data." if @verbose
        val.map do |entry|
          every = entry.to_s.downcase
          puts "Inspecting record: #{entry}" if @verbose
          #if every.downcase.include?(txt)

          success=keywords.inject(true) {|found,word| break unless found; every.include?(word) && found; }
          if success
            puts "Match found: #{entry}" if @verbose
            search_result_dn.push(val['DN'])
            cnt+=1
            break
            next
          end
        end
      end
    end
    return search_result_dn
  rescue => ee
    puts "Exception on method #{__method__}: #{ee}"
  end
end

#insert_dn(go_contact) ⇒ Object

Procedures to add additonal field ‘DN’ into the data structure, by perform the AD search



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/ucert/go_contact_tracker.rb', line 82

def insert_dn (go_contact)
    begin
      tracker = Ucert::AdTracker.new(:verbose=>false)
       go_contact.each do |num, table|
       table.each do |index, record|
        puts "\n\nPerform DN lookup for record: #{record}" if @verbose
        key1 = record["email"]
         key2 = record["en_name"]
        my_key = record["email"].upcase
        puts "Perform 1st order search from the local cache: #{my_key}" if @verbose
          if @go_2_ad_user.key?(my_key)
            dn=@go_2_ad_user[my_key]
            # additional logic to update the existing DN record

            unless tracker.ad_person_records.key?(dn)
              dn = update_dn(tracker, dn)
            end
            puts "Found in the local cache file: #{dn}" if @verbose
          else
            if dn.nil? and !key1.nil?
              puts "Perform 2nd order search only if the 1st one fail, by using: #{key1}" if @verbose
              dn = tracker.ad_search_by_text(key1, "person")
              puts "Found: #{dn}" unless dn.nil? if @verbose
            end
             if dn.nil? and !key2.nil?
              puts "Perform 3nd order search only if the 1st one fail, by using: #{key2}" if @verbose
              dn = tracker.ad_search_by_text(key2, "person")
              puts "Found: #{dn}" unless dn.nil? if @verbobe
            end
          end
        table[index]['DN'] = dn
         end
      end
      tracker=nil
    rescue => ee
      puts "Exception on method #{__method__}: #{ee}"
    end
end

#insert_title_and_level(go_contact) ⇒ Object

method to retrieve additional employee information beyond the contact workbook, which is stored in ‘title_level_map.txt’ title is employee title, level is the weighting factor when sorting the employee record in the workbook



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/ucert/go_contact_tracker.rb', line 122

def insert_title_and_level(go_contact)
  dn_title_table = parse_title_level(@dn_title_level_map)
  go_contact.each do |_, contact|
    contact.each do |_, employee|
       if dn_title_table[employee['DN']].nil?
        employee['level'] = 110
        employee['title'] = nil
        employee['employment_status'] = nil
       else
        employee['level'] = dn_title_table[employee['DN']]['level'].to_i
        employee['title'] = dn_title_table[employee['DN']]['title']
        unless dn_title_table[employee['DN']]['employment_status'].nil?
          employee['employment_status'] = dn_title_table[employee['DN']]['employment_status'].strip
        end
       end
    end
  end
end

#parse_go_contact(file) ⇒ Object



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
# File 'lib/ucert/go_contact_tracker.rb', line 42

def parse_go_contact(file)
  begin
    workbook = RubyXL::Parser.parse(file)
    go_contact = {}
    for i in 0..1
      worksheet = workbook[i]
      worksheet.cols[1].hidden = false # unlock the 'title' column

      go_contact[i] = Hash.new
      record = 0
      worksheet.each do |row|
        puts "Start parsing on record number: #{record}" if @verbose
        index = row[0].value.to_s.strip.downcase
        next if index.include?"china merchants bank new york branch contact sheet" or index.empty?
        index = row[0].value.to_s.strip.downcase or index.empty?
        next if index == "department" or index.empty?
        break if index == "cmbny it dept. disaster recovery lines" or index.empty?
        go_contact[i][record] = Hash.new unless go_contact[i].key?(row)
        @@column_name.each_with_index do |name, index|
          #if name == 'employment_status'

            # if i==0

            #  go_contact[i][record]['title'].downcase.include?("temp") ? go_contact[i][record][name] = "temp" : go_contact[i][record][name] = "full time"

            # else

            #  go_contact[i][record][name] = "intern"

            # end

          #else

            puts "name: #{name}, index: #{index}" if @verbose
            go_contact[i][record][name] = row[index.to_i].value.to_s.strip
          #end

        end
          record += 1
      end
    end
    workbook = nil
    return go_contact
  rescue => ee
    puts "Exception on method #{__method__}: #{ee}"
  end
end

#parse_title_level(file) ⇒ Object

method to parse the ‘title_level_map’ file



142
143
144
145
146
147
148
149
150
151
# File 'lib/ucert/go_contact_tracker.rb', line 142

def parse_title_level(file)
  table = {}
  f = File.open(file, 'r')
  f.each_with_index do |line, index|
    next if index.zero?
    arr = line.split('|')
    table[arr[0]] = { 'title' => arr[1], 'level' => arr[2], 'employment_status' => arr[3]} unless arr.empty?
  end
  table
end

#save_go_user_map!(file = @file_go_user_map, employee_contact = @go_contact) ⇒ Object Also known as: save!

Save the GO contact to AD user mapping relation into the cache file



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/ucert/go_contact_tracker.rb', line 261

def save_go_user_map!(file=@file_go_user_map, employee_contact=@go_contact)
  puts "Saving the known Go Contact to AD user mapping relationship to file: #{file} ..." if @verbose
  begin
    timestamp=Time.now
    f=File.open(file, 'w')
    f.write "# local Go Contact to AD user map file created by the #{self.class} class #{__method__} method at: #{timestamp}"
     employee_contact.each do |index, table|
       table.each do |key, record|
         my_key = record['email'].upcase
         value = record['DN']
         next if my_key.nil?
         next if my_key.empty?
        f.write "\n#{my_key}|#{value}"
      end
     end
    f.close
    puts "GO to AD user map file is successfully saved to: #{file}" if @verbose
  rescue => ee
    puts "Exception on method #{__method__}: #{ee}" if @verbose
  end
end

#save_title_level_map(file = @dn_title_level_map, employee_contact = @go_contact) ⇒ Object

Method to write the cache back to the title_level_map. Note this method’s usage should be limited, as the cyber_idm web app has a similar procedure ‘sync_go_level_map’ to write database record back to title_level_map now



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/ucert/go_contact_tracker.rb', line 155

def save_title_level_map(file=@dn_title_level_map, employee_contact=@go_contact)
  puts "Saving the known Go Contact to Title Level mapping relationship to file: #{file} ..." if @verbose
timestamp = Time.now
f = File.open(file, 'w')
f.write "# local Go Contact to Title Level map file created by the #{self.class} class #{__method__} method at: #{timestamp}"
  employee_contact.each do |_, table|
    table.each do |_, record|
      puts record
      level = record['level']
      title = record['title']
      employment_status = record['employment_status']
      value = record['dn']
      next if value.nil?
      next if value.empty?
      f.write "\n#{value}|#{title}|#{level}|#{employment_status}"
    end
  end
f.close
puts "Title Level user map file is successfully saved to: #{file}" if @verbose
rescue => ee
  puts "Exception on method #{__method__}: #{ee}" if @verbose
end

#write_wookbook(workbook, file = @cmbny_contact_sheet) ⇒ Object



455
456
457
# File 'lib/ucert/go_contact_tracker.rb', line 455

def write_wookbook(workbook,file=@cmbny_contact_sheet)
  workbook.write(file)
end