class Ucert::CmbrunNYTracker

Class to handle CMBRUN NY user entitlement report

Attributes

crny_2_ad_user[R]
crny_position[R]
crny_user_entitlement[R]
crny_user_status_report[RW]

Class constant variables

file_crny_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/cmbrun_ny_tracker.rb, line 20
def initialize (params ={})
  @verbose=params.fetch(:verbose, false)
  # CMBRun NY user entitlement report generation:
              # Logon to the CMBRun NY platform from the production environment, Navigating to 'User Management', select "198:New York Branch", then click
              # on "Search(5)" button; you will see the user record in the current window; right click one of the record, select "Export All to Excel"
              # Open the Excel workbook and "Save as" the .xlsx format
  @crny_user_entitlement_report = File.dirname(__FILE__)+"/../../data/cmbrun_ny/CMBRUN_USER_RPT.xlsx"
              # Follow the similiar procedure above to download the Position report from the "Position Management" menu
              @crny_position_report = File.dirname(__FILE__)+"/../../data/cmbrun_ny/CMBNY_Position_Rpt.xlsx"
  # CMBRun NY to AD user map file
  @file_crny_user_map =  File.dirname(__FILE__)+"/../../data/cmbrun_ny/crny_access_user_map.txt"
              # Load user map from the local cacsh file
              @crny_2_ad_user=load_known_user_map_from_file(@file_crny_user_map)
              # Load the user entitlement instance variable from the user report
              @crny_user_entitlement=parse_crny_user_report(@crny_user_entitlement_report)
              # Procedure to add DN foreign key to the @crny_user_entitlement, by performing the AD search
              insert_dn
              # Load the position instance variable from the positon report
              @crny_position=parse_crny_position_report(@crny_position_report)
              # Save the user map to local cache file
              save!
      end

Public Instance Methods

crny_search_by_dn(dn) click to toggle source

Search user entitlement record by AD DN

# File lib/ucert/cmbrun_ny_tracker.rb, line 229
    def crny_search_by_dn (dn)
            begin
  puts "Perform search on the user entitlement records by AD DN: #{dn}" if @verbose
  @crny_user_entitlement.each do |key, val|
      return val if @crny_user_entitlement[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 @crny_user_entitlement data structure

# File lib/ucert/cmbrun_ny_tracker.rb, line 136
def dn_2_index (dn)
                begin
(1..@crny_user_entitlement.count).map do |index|
  return index if @crny_user_entitlement[index]["DN"]==dn
end
                rescue => ee
                        puts "Exception on method #{__method__}: #{ee}"
                end
end
print_position()
Alias for: print_user_position
print_user()
print_user_position() click to toggle source

Print out the user position table in plain text, to be imported into database

Also aliased as: print_position
save!(file=@file_crny_user_map)
Alias for: save_crny_user_map!
search_by_dn(dn)
Alias for: crny_search_by_dn

Private Instance Methods

insert_dn() click to toggle source

Procedures to add additonal field 'dn' into the @crny_user_entitlement data structure, by person the AD search

# File lib/ucert/cmbrun_ny_tracker.rb, line 147
def insert_dn
                begin
                        tracker = Ucert::AdTracker.new(:verbose=>false)
                         @crny_user_entitlement.each do |index, record|
                                puts "\n\nPerform DN lookup for record: #{record}" if @verbose
                                key1 = record['User Name']
                                my_key = record['User ID'].upcase + ":" + record['User Name'].upcase
                                puts "Perform 1st order search from the local cache: #{my_key}" if @verbose
                                if @crny_2_ad_user.key?(my_key)
                                        dn=@crny_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")
                                        end
                                end
                                @crny_user_entitlement[index]['DN'] = dn
                        end
                        tracker=nil
                rescue => ee
                        puts "Exception on method #{__method__}: #{ee}"
                end
end
parse_crny_position_report(file) click to toggle source

Parsing the CMBRun NY position report in Excel workbook format

# File lib/ucert/cmbrun_ny_tracker.rb, line 90
  def parse_crny_position_report (file)
begin
                          puts "Start parsing Excel workbook file: #{file}" if @verbose
                          crny_position=Hash.new
                          workbook = RubyXL::Parser.parse(file)
  worksheet = workbook[0]
                          row_cnt=0
                          pos_index=String.new        # position index
                          header=Array.new
  worksheet.count.times  do |row|
                                  row_cnt+=1
                                  puts "Parsing workbook row: #{row_cnt}" if @verbose
                                  entry=Array.new
                                  # Processing Header Row
                                  if row_cnt==1
                                          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)
                                                  end
                                          end
                                  end
    record = header.zip(entry).to_h.reject {|k,v| k.nil?}
                                  puts "Position record: #{record}" if @verbose
                                  next if record["Position Number"].empty?
                                  pos_index = record["Position Number"]
    crny_position[pos_index] = record unless crny_position.key?(pos_index)
  end
  workbook=nil
  return crny_position
rescue => ee
                          puts "Exception on method #{__method__}: #{ee}"
                  end
  end
parse_crny_user_report(file) click to toggle source

Parsing the CMBRun NY user report in text format

# File lib/ucert/cmbrun_ny_tracker.rb, line 44
  def parse_crny_user_report (file)
begin
                          puts "Start parsing Excel workbook file: #{file}" if @verbose
                          crny_user_entitlement=Hash.new
                          workbook = RubyXL::Parser.parse(file)
  worksheet = workbook[0]
                          row_cnt=0
                          user_index=0        # user record index
                          header=Array.new
  worksheet.count.times  do |row|
                                  row_cnt+=1
                                  puts "Parsing workbook row: #{row_cnt}" if @verbose
                                  entry=Array.new
                                  # Processing Header Row
                                  if row_cnt==1
                                          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)
                                                  end
                                          end
                                          user_index += 1
                                  end
    record = header.zip(entry).to_h.reject {|k,v| k.nil?}
                                  puts "User record: #{record}" if @verbose
                                  next if record["User ID"].empty?
    crny_user_entitlement[user_index] = record unless crny_user_entitlement.key?(user_index)
  end
  workbook=nil
  return crny_user_entitlement
rescue => ee
                          puts "Exception on method #{__method__}: #{ee}"
                  end
  end
print_user_entitlement() click to toggle source

Print out the user entitlement table in plain text, to be imported into database

Also aliased as: print_user
save_crny_user_map!(file=@file_crny_user_map) click to toggle source

Save the Prime to AD user mapping relation into the cache file

# File lib/ucert/cmbrun_ny_tracker.rb, line 209
def save_crny_user_map!(file=@file_crny_user_map)
        puts "Saving the known Prime to AD user mapping relationship to file: #{file} ..." if @verbose
        begin
                timestamp=Time.now
                f=File.open(file, 'w')
                f.write "# local CMBRun NY to AD user map file created by the #{self.class} class #{__method__} method at: #{timestamp}"
                @crny_user_entitlement.values.map do |record|
                        key = record['User ID'].upcase + ":" + record['User Name'].upcase
                        value = record['DN']
                        f.write "\n#{key}|#{value}"
                end
                f.close
                puts "CMBRun NY 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!