class Ucert::AdpPayrollTracker
Class to handle Active Employee list within the ADP Payroll report
Attributes
adp_2_ad_user[R]
employee[R]
employee_report[RW]
Class constant variables
file_adp_user_map[RW]
Class constant variables
verbose[RW]
Class constant variables
Public Class Methods
new(params ={})
click to toggle source
Instance default variables
# File lib/ucert/adp_payroll_tracker.rb, line 20 def initialize (params ={}) @verbose=params.fetch(:verbose, false) # ADP Payroll report generation: # Contact CMBNY HR Manager to obtain the report monthly in Excel Workbook @employee_report = File.dirname(__FILE__)+"/../../data/adp/Active Employee Report.xlsx" # ADP Payroll to AD user map file @file_adp_user_map = File.dirname(__FILE__)+"/../../data/adp/adp_user_map.txt" @employee = Hash.new # Load user map from the local cacsh file @adp_2_ad_user=load_known_user_map_from_file(@file_adp_user_map) # Read the active employee report @employee=parse_adp_payroll_report(@employee_report) # Procedure to add DN foreign key to the @employee, by performing the AD search insert_dn # Save the user map to local cache file save! end
Public Instance Methods
adp_search_by_dn(dn)
click to toggle source
Search user entitlement record by AD DN
# File lib/ucert/adp_payroll_tracker.rb, line 174 def adp_search_by_dn (dn) begin puts "Perform search on the user entitlement records by AD DN: #{dn}" if @verbose @employee.each do |key, val| return val if @employee[key]['DN'].eql? dn end return nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Also aliased as: search_by_dn
dn_2_index(dn)
click to toggle source
Retrieve the user index from the @employee data structure
# File lib/ucert/adp_payroll_tracker.rb, line 85 def dn_2_index (dn) begin (1..@employee.count).map do |index| return index if @employee[index]["DN"]==dn end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Private Instance Methods
insert_dn()
click to toggle source
Procedures to add additonal field 'dn' into the @employee data structure, by person the AD search
# File lib/ucert/adp_payroll_tracker.rb, line 96 def insert_dn #begin tracker = Ucert::AdTracker.new(:verbose=>false) @employee.each do |index, record| puts "\n\nPerform DN lookup for record: #{record}" if @verbose key1 = record['Work Contact: Work Email'] key2 = record['First Name'].split(/\s+/)[1] + " " + record['Last Name'] if record['First Name'].split(/\s+/)[1] and record['Last Name'] key3 = record['First Name'].gsub(/\s+/,"").split(/\(|\)/)[1] + " " + record['Last Name'] if record['First Name'].gsub(/\s+/,"").split(/\(|\)/)[1] and record['Last Name'] my_key = record['First Name'] + ':' + record['Last Name'] + ':' + record['Work Contact: Work Email'].strip puts "Perform 1st order search from the local cache: #{my_key}" if @verbose if @adp_2_ad_user.key?(my_key) dn=@adp_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 #=begin if dn.nil? and !key1.nil? puts "Perform 2nd order search only if the last fail, by using: #{key1}" if @verbose dn = tracker.ad_search_by_text(key1, "person") end if dn.nil? and !key2.nil? puts "Perform 3rd order search only if the last fail, by using: #{key2}" if @verbose dn = tracker.ad_search_by_text(key2, "person") end if dn.nil? and !key3.nil? puts "Perform 4th order search only if the last fail, by using: #{key3}" if @verbose dn = tracker.ad_search_by_text(key3, "person") end #=end end @employee[index]['DN'] = dn end tracker=nil #rescue => ee # puts "Exception on method #{__method__}: #{ee}" #end end
parse_adp_payroll_report(file)
click to toggle source
Parsing the ADP Employee user entitlement report from HR department
# File lib/ucert/adp_payroll_tracker.rb, line 39 def parse_adp_payroll_report (file) begin puts "Start parsing Excel workbook file: #{file}" if @verbose adp_payroll=Hash.new workbook = RubyXL::Parser.parse(file) worksheet=workbook.worksheets.first row_cnt=0 header=Array.new user_index=0 worksheet.count.times do |row| row_cnt+=1 puts "Parsing workbook row: #{row_cnt}" if @verbose next if row_cnt == 1 # skip the 1st row - report timestamp information only entry=Array.new # Processing Header Row if row_cnt==2 0.upto(worksheet[row].size) do |col| if worksheet[row][col].nil? header.push(nil) else header.push(worksheet[row][col].value.to_s) end end next else 0.upto(worksheet[row].size) do |col| if worksheet[row][col].nil? entry.push(nil) else entry.push(worksheet[row][col].value.to_s.strip) end end user_index += 1 end record = header.zip(entry).to_h.reject {|k,v| k.nil?} puts "User record: #{record}" if @verbose adp_payroll[user_index] = record unless adp_payroll.key?(user_index) end workbook=nil return adp_payroll rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
print_user_access()
click to toggle source
Print out the user entitlement table in plain text, to be imported into database
# File lib/ucert/adp_payroll_tracker.rb, line 138 def print_user_access begin puts "User Entitlement Report in Plain-text Format" if @verbose @employee[1].each {|k,v| print k,"|"} if @verbose puts if @verbose @employee.values.map do |rec| rec.each {|k,v| print v,"|"} puts end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Also aliased as: print_user
save_adp_user_map!(file=@file_adp_user_map)
click to toggle source
Save the AdpEmployee to AD user mapping relation into the cache file
# File lib/ucert/adp_payroll_tracker.rb, line 154 def save_adp_user_map!(file=@file_adp_user_map) puts "Saving the known AdpEmployee to AD user mapping relationship to file: #{file} ..." if @verbose begin timestamp=Time.now f=File.open(file, 'w') f.write "# AdpEmployee to AD user map file created by the #{self.class} class #{__method__} method at: #{timestamp}" @employee.values.map do |record| key = record['First Name'] + ':' + record['Last Name'] + ':' + record['Work Contact: Work Email'].strip value = record['DN'] f.write "\n#{key}|#{value}" end f.close puts "ADP Payroll to AD user map file is successfully saved to: #{file}" if @verbose rescue => ee puts "Exception on method #{__method__}: #{ee}" if @verbose end end
Also aliased as: save!