lib/echi-converter.rb in echi-converter-0.3.7 vs lib/echi-converter.rb in echi-converter-0.3.8
- old
+ new
@@ -219,14 +219,14 @@
echi_file = $workingdir + "/../files/to_process/" + filename
@binary_file = open(echi_file,"rb")
@log.debug "File size: " + @binary_file.stat.size.to_s
#Read header information first
- filenumber = dump_binary 'int', 4
- @log.debug "File_number " + filenumber.to_s
fileversion = dump_binary 'int', 4
@log.debug "Version " + fileversion.to_s
+ filenumber = dump_binary 'int', 4
+ @log.debug "File_number " + filenumber.to_s
begin
#Perform a transaction for each file, including the log table
#in order to commit as one atomic action upon success
EchiRecord.transaction do
@@ -266,12 +266,14 @@
end
echi_record[field["name"]] = value
end
echi_record.save
- #Scan past the end of line record
- @binary_file.read(1)
+ #Scan past the end of line record if enabled in the configuration file
+ if $config["echi_read_extra_byte"] == "Y"
+ @binary_file.read(1)
+ end
@log.debug '<====================STOP RECORD ' + @record_cnt.to_s + ' ====================>'
@record_cnt += 1
end
@binary_file.close
end
@@ -350,18 +352,18 @@
case tablename
when "echi_acds"
echi_dat_record = EchiAcd.new
when "echi_agents"
echi_dat_record = EchiAgent.new
- when "echi_aux_reasons"
- echi_dat_record = EchiAuxReason.new
+ when "echi_reasons"
+ echi_dat_record = EchiReason.new
when "echi_cwcs"
echi_dat_record = EchiCwc.new
when "echi_splits"
echi_dat_record = EchiSplit.new
- when "echi_trunk_groups"
- echi_dat_record = EchiTrunkGroup.new
+ when "echi_trunks"
+ echi_dat_record = EchiTrunk.new
when "echi_vdns"
echi_dat_record = EchiVdn.new
when "echi_vectors"
echi_dat_record = EchiVector.new
end
@@ -383,19 +385,19 @@
case file["name"]
when "echi_acds"
filename_elements = $config["echi_acd_dat"].split(".")
when "echi_agents"
filename_elements = $config["echi_agent_dat"].split(".")
- when "echi_aux_reasons"
+ when "echi_reasons"
filename_elements = $config["echi_aux_rsn_dat"].split(".")
when "echi_cwcs"
filename_elements = $config["echi_cwc_dat"].split(".")
when "echi_splits"
filename_elements = $config["echi_split_dat"].split(".")
when "echi_vdns"
filename_elements = $config["echi_vdn_dat"].split(".")
- when "echi_trunk_groups"
+ when "echi_trunks"
filename_elements = $config["echi_trunk_group_dat"].split(".")
when "echi_vectors"
filename_elements = $config["echi_vector_dat"].split(".")
end
new_filename = filename_elements[0] + "_" + UUID.timestamp_create.to_s + "." + filename_elements[1]
@@ -418,48 +420,51 @@
process_file = File.open(file["filename"])
process_file.each do |row|
if row != nil
begin
field = row.rstrip.split('|')
- @log.debug '<====================START ' + file["name"] + ' RECORD ' + @record_cnt.to_s + ' ====================>'
- case file["name"]
- when "echi_acds"
- record = EchiAcd.find(:first, :conditions => [ "number = ? AND acd_id = ?", field[1], field[0]])
- when "echi_agents"
- record = EchiAgent.find(:first, :conditions => [ "login_id = ? AND group_id = ?", field[1], field[0]])
- when "echi_aux_reasons"
- record = EchiAuxReason.find(:first, :conditions => [ "aux_reason = ? AND group_id = ?", field[1], field[0]])
- when "echi_cwcs"
- record = EchiCwc.find(:first, :conditions => [ "cwc = ? AND group_id = ?", field[1], field[0]])
- when "echi_splits"
- record = EchiSplit.find(:first, :conditions => [ "number = ? AND acd_number = ?", field[1], field[0]])
- when "echi_trunk_groups"
- record = EchiTrunkGroup.find(:first, :conditions => [ "trunk_group = ? AND acd_number = ?", field[1], field[0]])
- when "echi_vdns"
- record = EchiVdn.find(:first, :conditions => [ "vdn = ? AND group_id = ?", field[1], field[0]])
- when "echi_vectors"
- record = EchiVector.find(:first, :conditions => [ "number = ? AND acd_number = ?", field[1], field[0]])
- end
- if record != nil
- if record.name != field[2]
- record.name = field[2]
- record.update
- @record_cnt += 1
- @log.debug "Updated record - " + field.inspect
+ #Make sure we do not process the extra rows that Avaya nicely throws in the dat files for no good reason that serve as keys
+ if field.length > 1
+ @log.debug '<====================START ' + file["name"] + ' RECORD ' + @record_cnt.to_s + ' ====================>'
+ case file["name"]
+ when "echi_acds"
+ record = EchiAcd.find(:first, :conditions => [ "acd_number = ? AND acd_id = ?", field[1], field[0]])
+ when "echi_agents"
+ record = EchiAgent.find(:first, :conditions => [ "login_id = ? AND group_id = ?", field[1], field[0]])
+ when "echi_reasons"
+ record = EchiReason.find(:first, :conditions => [ "aux_reason = ? AND group_id = ?", field[1], field[0]])
+ when "echi_cwcs"
+ record = EchiCwc.find(:first, :conditions => [ "cwc = ? AND group_id = ?", field[1], field[0]])
+ when "echi_splits"
+ record = EchiSplit.find(:first, :conditions => [ "split_number = ? AND acd_number = ?", field[1], field[0]])
+ when "echi_trunks"
+ record = EchiTrunk.find(:first, :conditions => [ "trunk_group = ? AND acd_number = ?", field[1], field[0]])
+ when "echi_vdns"
+ record = EchiVdn.find(:first, :conditions => [ "vdn = ? AND group_id = ?", field[1], field[0]])
+ when "echi_vectors"
+ record = EchiVector.find(:first, :conditions => [ "vector_number = ? AND acd_number = ?", field[1], field[0]])
+ end
+ if record != nil
+ if record.name != field[2]
+ record.name = field[2]
+ record.update
+ @record_cnt += 1
+ @log.debug "Updated record - " + field.inspect
+ else
+ @log.debug "No update required for - " + field.inspect
+ end
else
- @log.debug "No update required for - " + field.inspect
+ insert_dat_data file["name"], field
+ @record_cnt += 1
+ @log.debug "Inserted new record - " + field.inspect
end
- else
- insert_dat_data file["name"], field
- @record_cnt += 1
- @log.debug "Inserted new record - " + field.inspect
+ @log.debug '<====================STOP ' + file["name"] + ' RECORD ' + @record_cnt.to_s + ' ====================>'
end
rescue => err
@log.info "Error processing ECHI record in process_proper_table_method - " + err
end
end
- @log.debug '<====================STOP ' + file["name"] + ' RECORD ' + @record_cnt.to_s + ' ====================>'
end
process_file.close
archive_file file, @record_cnt
@@ -469,41 +474,41 @@
def process_dat_files
@log.debug "process_dat_files method"
dat_files = Array.new
dat_files[0] = { "name" => "echi_acds", "filename" => $workingdir + "/../files/to_process/" + $config["echi_acd_dat"] }
dat_files[1] = { "name" => "echi_agents", "filename" => $workingdir + "/../files/to_process/" + $config["echi_agent_dat"] }
- dat_files[2] = { "name" => "echi_aux_reasons", "filename" => $workingdir + "/../files/to_process/" + $config["echi_aux_rsn_dat"] }
+ dat_files[2] = { "name" => "echi_reasons", "filename" => $workingdir + "/../files/to_process/" + $config["echi_aux_rsn_dat"] }
dat_files[3] = { "name" => "echi_cwcs", "filename" => $workingdir + "/../files/to_process/" + $config["echi_cwc_dat"] }
dat_files[4] = { "name" => "echi_splits", "filename" => $workingdir + "/../files/to_process/" + $config["echi_split_dat"] }
- dat_files[5] = { "name" => "echi_trunk_groups", "filename" => $workingdir + "/../files/to_process/" + $config["echi_trunk_group_dat"] }
+ dat_files[5] = { "name" => "echi_trunks", "filename" => $workingdir + "/../files/to_process/" + $config["echi_trunk_group_dat"] }
dat_files[6] = { "name" => "echi_vdns", "filename" => $workingdir + "/../files/to_process/" + $config["echi_vdn_dat"] }
dat_files[7] = { "name" => "echi_vectors", "filename" => $workingdir + "/../files/to_process/" + $config["echi_vector_dat"] }
dat_files.each do |file|
- if File.exists?(file["filename"]) && File.size(file["filename"]) > 0
+ if File.exists?(file["filename"]) && File.stat(file["filename"]).size > 0
case file["name"]
when "echi_acds"
EchiAcd.transaction do
process_proper_table file
end
when "echi_agents"
EchiAgent.transaction do
process_proper_table file
end
- when "echi_aux_reasons"
- EchiAuxReason.transaction do
+ when "echi_reasons"
+ EchiReason.transaction do
process_proper_table file
end
when "echi_cwcs"
EchiCwc.transaction do
process_proper_table file
end
when "echi_splits"
EchiSplit.transaction do
process_proper_table file
end
- when "echi_trunk_groups"
- EchiTrunkGroup.transaction do
+ when "echi_trunks"
+ EchiTrunk.transaction do
process_proper_table file
end
when "echi_vdns"
EchiVdn.transaction do
process_proper_table file
\ No newline at end of file