Skip to content

Commit

Permalink
Use ReportDownloader for AlmaRenewList
Browse files Browse the repository at this point in the history
Co-authored-by: Beck Davis <[email protected]>
  • Loading branch information
maxkadel and Beck-Davis committed Apr 18, 2024
1 parent 1c35700 commit 7517a55
Showing 1 changed file with 3 additions and 34 deletions.
37 changes: 3 additions & 34 deletions app/models/alma_renew/alma_renew_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ def initialize(input_sftp_base_dir: Rails.application.config.alma_sftp.renew_rep
@input_sftp_base_dir = input_sftp_base_dir
@file_pattern = file_pattern
@sftp = alma_sftp
@renew_item_list = []
@remote_filenames = []
download_renew_items
end

Expand All @@ -29,39 +27,10 @@ def mark_files_as_processed

private

# rubocop:disable Metrics/MethodLength
def download_renew_items
# report_downloader = ReportDownloader.new(sftp: AlmaSftp.new, file_pattern:, process_class: AlmaRenew::AlmaRenewList, input_sftp_base_dir:)
# report_downloader.run
working_file_names = []
sftp.start do |sftp_conn|
sftp_conn.dir.foreach(input_sftp_base_dir) do |entry|
next if /\.processed$/.match?(entry.name)
next unless /#{file_pattern}/.match?(entry.name) && date_in_range?(file_name: entry.name)

Rails.logger.debug { "Found matching pattern in file: #{entry.name}" }
remote_filename = File.join(input_sftp_base_dir, entry.name)
# ascii-8bit required for download! to succeed
temp_file = Tempfile.new(encoding: 'ascii-8bit')
sftp_conn.download!(remote_filename, temp_file)
process(temp_file)
remote_filenames << remote_filename
end
end
working_file_names
end

# rubocop:enable Metrics/MethodLength
def date_in_range?(*)
true
end

def process(temp_file)
CSVValidator.new(csv_filename: temp_file.path).require_headers ['Barcode', 'Patron Group', 'Expiry Date', 'Primary Identifier']
CSV.foreach(temp_file, headers: true, encoding: 'bom|utf-8') do |row|
renew_item_list << Item.new(row.to_h)
end
renew_item_list
report_downloader = ReportDownloader.new(sftp: AlmaSftp.new, file_pattern:, process_class: AlmaRenew::RenewFile, input_sftp_base_dir:)
@renew_item_list = report_downloader.run.flatten
@remote_filenames = report_downloader.remote_filenames
end
end
end

0 comments on commit 7517a55

Please sign in to comment.