Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves HELIO-4065 Update Heliotropium to use new SFTP host
- Loading branch information
1 parent
e06cd16
commit e295a69
Showing
103 changed files
with
1,373 additions
and
1,932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.