Skip to content

Commit

Permalink
Resolves HELIO-4065 Update Heliotropium to use new SFTP host
Browse files Browse the repository at this point in the history
  • Loading branch information
gkostin1966 committed Nov 5, 2021
1 parent e06cd16 commit e0f187c
Show file tree
Hide file tree
Showing 102 changed files with 1,376 additions and 1,932 deletions.
7 changes: 3 additions & 4 deletions Gemfile
Expand Up @@ -61,10 +61,6 @@ gem 'ettin', '~> 1.2'
# https://github.com/jmettraux/rufus-scheduler
gem 'rufus-scheduler', '~> 3.6'

# Wrapper around Box REST API
# https://github.com/cburnette/boxr
gem 'boxr', '~> 1.4'

# A Ruby library to parse, create and manage MARC records
# https://github.com/ruby-marc/ruby-marc
gem 'marc', '~>1.0'
Expand All @@ -88,6 +84,9 @@ gem 'jquery-rails', '~> 4.3'
gem 'nio4r', '= 2.5.1'
gem 'puma', '4.3.9'

# Needed to connect to DreamHost FTP Server
gem 'net-sftp', '~> 2.1', '>= 2.1.2'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: %i[mri mingw x64_mingw]
Expand Down
33 changes: 15 additions & 18 deletions Gemfile.lock
Expand Up @@ -55,15 +55,11 @@ GEM
autoprefixer-rails (>= 9.1.0)
popper_js (>= 1.14.3, < 2)
sassc-rails (>= 2.0.0)
boxr (1.18.0)
addressable (~> 2.3)
hashie (~> 3.5)
httpclient (~> 2.8)
jwt (>= 1.4)
builder (3.2.4)
byebug (11.1.3)
capybara (3.35.3)
capybara (3.36.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
Expand All @@ -90,7 +86,7 @@ GEM
diff-lcs (1.4.4)
docile (1.4.0)
erubi (1.10.0)
et-orbi (1.2.4)
et-orbi (1.2.5)
tzinfo
ettin (1.3.0)
deep_merge
Expand All @@ -101,13 +97,11 @@ GEM
factory_bot (~> 5.2.0)
railties (>= 4.2.0)
ffi (1.15.4)
fugit (1.5.1)
fugit (1.5.2)
et-orbi (~> 1.1, >= 1.1.8)
raabro (~> 1.4)
globalid (0.5.2)
activesupport (>= 5.0)
hashie (3.6.0)
httpclient (2.8.3)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
jbuilder (2.11.2)
Expand All @@ -116,8 +110,7 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.5.1)
jwt (2.2.3)
json (2.6.1)
kaminari (1.2.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1)
Expand All @@ -143,12 +136,16 @@ GEM
rexml
scrub_rb (>= 1.0.1, < 2)
unf
marcel (1.0.1)
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.1)
mini_mime (1.1.2)
minitest (5.14.4)
msgpack (1.4.2)
mysql2 (0.4.10)
net-sftp (2.1.2)
net-ssh (>= 2.6.5)
net-ssh (6.1.0)
nio4r (2.5.1)
nokogiri (1.12.5-x86_64-darwin)
racc (~> 1.4)
Expand All @@ -162,7 +159,7 @@ GEM
puma (4.3.9)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.5.2)
racc (1.6.0)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
Expand Down Expand Up @@ -223,7 +220,7 @@ GEM
rubocop-ast (>= 0.6.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.11.0)
rubocop-ast (1.12.0)
parser (>= 3.0.1.1)
rubocop-performance (1.10.2)
rubocop (>= 0.90.0, < 2.0)
Expand Down Expand Up @@ -293,7 +290,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.8)
unicode-display_width (1.7.0)
unicode-display_width (1.8.0)
web-console (3.7.0)
actionview (>= 5.0)
activemodel (>= 5.0)
Expand All @@ -317,7 +314,6 @@ PLATFORMS
DEPENDENCIES
bootsnap (~> 1.4.6)
bootstrap (~> 4.3)
boxr (~> 1.4)
byebug
capybara (~> 3.29)
coffee-rails (~> 4.2)
Expand All @@ -330,6 +326,7 @@ DEPENDENCIES
listen (>= 3.0.5, < 3.2)
marc (~> 1.0)
mysql2 (~> 0.4.10)
net-sftp (~> 2.1, >= 2.1.2)
nio4r (= 2.5.1)
puma (= 4.3.9)
rails (~> 5.2.6)
Expand Down
36 changes: 18 additions & 18 deletions app/mailers/notifier_mailer.rb
Expand Up @@ -7,30 +7,30 @@ def administrators(subject, text)
subject: subject)
end

def marc_file_updates(collection, text)
@collection = collection
def marc_file_updates(publisher, text)
@publisher = publisher
@text = text
mail(to: collection.mailers.marc_file_updates.to,
from: collection.mailers.marc_file_updates.from,
bcc: collection.mailers.marc_file_updates.bcc,
subject: collection.mailers.marc_file_updates.subject)
mail(to: publisher.mailers.marc_file_updates.to,
from: publisher.mailers.marc_file_updates.from,
bcc: publisher.mailers.marc_file_updates.bcc,
subject: publisher.mailers.marc_file_updates.subject)
end

def encoding_error(collection, text)
@collection = collection
def encoding_error(publisher, text)
@publisher = publisher
@text = text
mail(to: collection.mailers.encoding_error.to,
from: collection.mailers.encoding_error.from,
bcc: collection.mailers.encoding_error.bcc,
subject: collection.mailers.encoding_error.subject)
mail(to: publisher.mailers.encoding_error.to,
from: publisher.mailers.encoding_error.from,
bcc: publisher.mailers.encoding_error.bcc,
subject: publisher.mailers.encoding_error.subject)
end

def missing_record(collection, text)
@collection = collection
def missing_record(publisher, text)
@publisher = publisher
@text = text
mail(to: collection.mailers.missing_record.to,
from: collection.mailers.missing_record.from,
bcc: collection.mailers.missing_record.bcc,
subject: collection.mailers.missing_record.subject)
mail(to: publisher.mailers.missing_record.to,
from: publisher.mailers.missing_record.from,
bcc: publisher.mailers.missing_record.bcc,
subject: publisher.mailers.missing_record.subject)
end
end
21 changes: 21 additions & 0 deletions app/modules/ftp_fulcrum_org.rb
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require_relative 'ftp_fulcrum_org/marc'
require_relative 'ftp_fulcrum_org/marc_file'
require_relative 'ftp_fulcrum_org/catalog'
require_relative 'ftp_fulcrum_org/kbart'
require_relative 'ftp_fulcrum_org/kbart_file'
require_relative 'ftp_fulcrum_org/work'
require_relative 'ftp_fulcrum_org/collection'
require_relative 'ftp_fulcrum_org/publisher'
require_relative 'ftp_fulcrum_org/ftp_fulcrum_org'

module FtpFulcrumOrg
def self.chdir_ftp_fulcrum_org_dir
tmp_dir = Rails.root.join('tmp')
Dir.mkdir(tmp_dir) unless Dir.exist?(tmp_dir)
Dir.chdir(tmp_dir)
Dir.mkdir('ftp_fulcrum_org') unless Dir.exist?('ftp_fulcrum_org')
Dir.chdir('ftp_fulcrum_org')
end
end
51 changes: 51 additions & 0 deletions app/modules/ftp_fulcrum_org/catalog.rb
@@ -0,0 +1,51 @@
# frozen_string_literal: true

module FtpFulcrumOrg
class Catalog
def initialize(publisher, sftp, pathname)
@publisher = publisher
@sftp = sftp
@pathname = pathname
end

def marc_files
@marc_files ||= begin
files = []
@sftp.dir.entries(@pathname).each do |entry|
next unless /(mrc|xml)/i.match?(File.extname(entry.name))

files << MarcFile.new(@sftp, File.join(@pathname, entry.name))
end
files
end
end

def marc(doi)
marcs.each do |marc|
next unless /#{doi}/i.match?(marc.doi)

return marc
end
nil
end

def marcs # rubocop:disable Metrics/MethodLength
@marcs ||= begin
marcs = []
::MarcRecord.where(folder: @publisher.key).each do |db_marc_record|
next unless db_marc_record.parsed

begin
marc = MARC::Reader.decode(db_marc_record.mrc, external_encoding: "UTF-8", validate_encoding: true)
marcs << Marc.new(marc)
rescue Encoding::InvalidByteSequenceError => e
msg = "FtpFulcrumOrg::Catalog#marcs(id #{db_marc_record.id}, doi #{db_marc_record.doi}) #{e}"
Rails.logger.error msg
NotifierMailer.administrators("StandardError", msg).deliver_now
end
end
marcs
end
end
end
end
26 changes: 26 additions & 0 deletions app/modules/ftp_fulcrum_org/collection.rb
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module FtpFulcrumOrg
class Collection
attr_reader :publisher
attr_reader :name
attr_reader :updated

def initialize(publisher, sftp, pathname)
@publisher = publisher
@sftp = sftp
@pathname = pathname
match = /(^.+)_(\d{4}-\d{2}-\d{2})\.(.+$)/.match(File.basename(@pathname))
@name = match[1]
@updated = Date.parse(match[2])
@ext = match[3]
end

def works
@works ||= begin
kbart_file = KbartFile.new(@sftp, @pathname)
kbart_file.kbarts.map { |kbart| Work.new(self, kbart) }
end
end
end
end

0 comments on commit e0f187c

Please sign in to comment.