@@ -200,7 +200,7 @@ def self.import_training_documents
200200 valid_csv_rows = filter_rows_with_existing_topics ( csv_data , import_stats )
201201 azure_files = fetch_azure_files
202202 importable_rows = match_csv_with_azure_files ( valid_csv_rows , azure_files )
203- unmatched_files = collect_unmatched_files ( csv_data , azure_files , importable_rows )
203+ unmatched_files = collect_unmatched_files ( csv_data , azure_files , importable_rows , report )
204204
205205 report . update! (
206206 summary_stats : build_summary_stats ( import_stats , csv_data , azure_files ) ,
@@ -239,7 +239,7 @@ def self.initialize_import_stats
239239 }
240240 end
241241
242- def self . filter_rows_with_existing_topics ( csv_data , stats )
242+ def self . filter_rows_with_existing_topics ( csv_data , stats , report )
243243 csv_data . filter_map do |row |
244244 topic_id = row [ "Topic_ID" ] . to_i
245245 if Topic . find_by ( id : topic_id )
@@ -306,6 +306,7 @@ def self.handle_attachment_error(topic, filename, error, stats, report)
306306 import_report_id : report . id ,
307307 topic_id : topic . id ,
308308 file_name : filename ,
309+ error_type : error . class . to_s ,
309310 error_message : error . message
310311 )
311312
@@ -317,16 +318,38 @@ def self.handle_attachment_error(topic, filename, error, stats, report)
317318 puts "Error with file: #{ filename } for topic #{ topic . title } - #{ error . message } "
318319 end
319320
320- def self . collect_unmatched_files ( csv_data , azure_files , importable_rows )
321+ def self . collect_unmatched_files ( csv_data , azure_files , importable_rows , report )
321322 csv_file_names = csv_data . map { |row | row [ "File_Name" ] }
322323 azure_file_names = azure_files . map { |file | file [ :name ] }
323324 matched_file_names = importable_rows . map { |row | row [ "File_Name" ] }
324325
325- {
326- csv_without_azure : csv_file_names - azure_file_names ,
327- azure_without_csv : azure_file_names - csv_file_names ,
326+ r = {
327+ csv_without_azure_files : csv_file_names - azure_file_names ,
328+ azure_files_without_csv : azure_file_names - csv_file_names ,
328329 total_unmatched : ( csv_file_names + azure_file_names - matched_file_names ) . uniq ,
329330 }
331+
332+ r [ :csv_without_azure_files ] . each do |csv_row_name |
333+ ImportError . create! (
334+ import_report_id : report . id ,
335+ file_name : csv_row_name ,
336+ error_type : "CSV::Row::File not found in Azure" ,
337+ error_message : "CSV Row File not found in Azure" ,
338+ topic_id : csv_row_name . split ( "_" ) . first
339+ )
340+ end
341+
342+ r [ :azure_files_without_csv ] . each do |azure_file_name |
343+ ImportError . create! (
344+ import_report_id : report . id ,
345+ file_name : azure_file_name ,
346+ error_type : "Azure::File not found in CSV" ,
347+ error_message : "Azure::File not found in CSV" ,
348+ topic_id : azure_file_name . split ( "_" ) . first
349+ )
350+ end
351+
352+ r
330353 end
331354
332355 def self . build_summary_stats ( import_stats , csv_data , azure_files )
0 commit comments