• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / bibdata / f04bc944-f9b4-4a42-8b26-dcacd0e3e688

11 Mar 2025 10:27PM UTC coverage: 34.017% (-58.1%) from 92.162%
f04bc944-f9b4-4a42-8b26-dcacd0e3e688

Pull #2653

circleci

christinach
Add new lc_subject_facet field.
Helps with the vocabulary work https://github.com/pulibrary/orangelight/pull/3386
In this new field we index only the lc subject heading and the subdivisions
So that when the user searches using the Details section, they can query solr for
all the subject headings and their divisions.

This is needed for the Subject browse Vocabulary work.
example: "lc_subject_facet": [
             "Booksellers and bookselling—Italy—Directories",
             "Booksellers and bookselling-Italy",
             "Booksellers and bookselling"
              ]
Pull Request #2653: Add new lc_subject_facet field.

1 of 3 new or added lines in 1 file covered. (33.33%)

2215 existing lines in 93 files now uncovered.

1294 of 3804 relevant lines covered (34.02%)

0.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

41.54
/app/jobs/import/alma.rb
1
require 'net/sftp'
1✔
2

3
module Import
1✔
4
  class Alma
1✔
5
    # Downloads the files from the sftp server and attaches them to Event, Dump,
6
    # DumpFile objects. Kicks off further processing if necessary
7
    include Sidekiq::Job
1✔
8
    queue_as :default
1✔
9
    attr_reader :dump_file_type
1✔
10

11
    def perform(dump_id, job_id)
1✔
UNCOV
12
      dump = Dump.find(dump_id)
×
UNCOV
13
      @dump_file_type = find_dump_file_type(dump)
×
UNCOV
14
      AlmaDownloader.files_for(job_id:, dump_file_type:).each do |file|
×
UNCOV
15
        dump.dump_files << file
×
16
      end
17

UNCOV
18
      dump.save
×
19

UNCOV
20
      IndexManager.for(Rails.application.config.solr['url']).index_remaining! if incremental_dump?
×
21
    end
22

23
    def incremental_dump?
1✔
UNCOV
24
      dump_file_type == :updated_records
×
25
    end
26

27
    def find_dump_file_type(dump)
1✔
UNCOV
28
      job_config = find_job_configuration(dump:)
×
UNCOV
29
      job_config['dump_file_type'].downcase.to_sym
×
30
    end
31

32
    class AlmaDownloader
1✔
33
      def self.files_for(job_id:, dump_file_type:)
1✔
UNCOV
34
        new(job_id:, dump_file_type:).files_for
×
35
      end
36

37
      attr_reader :job_id, :dump_file_type
1✔
38

39
      def initialize(job_id:, dump_file_type:)
1✔
UNCOV
40
        @job_id = job_id
×
UNCOV
41
        @dump_file_type = dump_file_type
×
42
      end
43

44
      def files_for
1✔
UNCOV
45
        dump_files = []
×
UNCOV
46
        Net::SFTP.start(sftp_host, sftp_username, password: sftp_password) do |sftp|
×
UNCOV
47
          downloads = []
×
UNCOV
48
          remote_paths(sftp_session: sftp).each do |remote_path|
×
UNCOV
49
            df = DumpFile.create(dump_file_type:, path: dump_file_path(remote_path))
×
UNCOV
50
            dump_files << df
×
UNCOV
51
            download = transfer_file(sftp_session: sftp, remote_path:, local_path: df.path)
×
UNCOV
52
            downloads << download
×
53
          end
54

55
          # wait for all asynchronous downloads to complete before closing sftp
56
          # session
UNCOV
57
          downloads.each(&:wait)
×
58
        end
59

UNCOV
60
        dump_files
×
61
      end
62

63
      # look to sftp server and identify the desired files using job_id
64
      def remote_paths(sftp_session:)
1✔
UNCOV
65
        sftp_session.dir.entries(remote_base_path).select { |entry| parse_job_id(entry.name) == job_id }.map { |entry| File.join(remote_base_path, entry.name) }
×
66
      end
67

68
      def remote_base_path
1✔
UNCOV
69
        Rails.configuration.alma['sftp_alma_base_path']
×
70
      end
71

72
      def dump_file_path(remote_path)
1✔
UNCOV
73
        File.join(MARC_LIBERATION_CONFIG['data_dir'], File.basename(remote_path))
×
74
      end
75

76
      # By default alma puts the timestamp before the job_id in filenames, and the
77
      #   default timestamp used differed from the documented timestamp
78
      #
79
      # So we configured the job_id to come before the timestamp to
80
      # protect against future variation in the timestamp format.
81
      # configured form is:
82
      # fulldump_<job ID>_<time stamp>_<new or update or delete>_<counter>.xml.tar.gz
83
      #
84
      # documentation is at
85
      # https://knowledge.exlibrisgroup.com/Alma/Product_Documentation/010Alma_Online_Help_(English)/090Integrations_with_External_Systems/030Resource_Management/080Publishing_and_Inventory_Enrichment#File_name
86
      def parse_job_id(name)
1✔
UNCOV
87
        name.split('_')[1]
×
88
      end
89

90
      # Do the actual download from the sftp server
91
      def transfer_file(sftp_session:, remote_path:, local_path:)
1✔
UNCOV
92
        File.truncate(local_path, 0) if File.exist?(local_path)
×
UNCOV
93
        sftp_session.download(remote_path, local_path)
×
94
      end
95

96
      def sftp_options
1✔
97
        {
98
          username: sftp_username,
×
99
          password: sftp_password,
100
          passive: true,
101
          ssl: true
102
        }
103
      end
104

105
      def sftp_username
1✔
UNCOV
106
        Rails.configuration.alma['sftp_username']
×
107
      end
108

109
      def sftp_password
1✔
UNCOV
110
        Rails.configuration.alma['sftp_password']
×
111
      end
112

113
      def sftp_host
1✔
UNCOV
114
        Rails.configuration.alma['sftp_host']
×
115
      end
116
    end
117

118
    private
1✔
119

120
      def event_message(dump:)
1✔
UNCOV
121
        event = dump.event
×
UNCOV
122
        return {} if event.nil?
×
123

UNCOV
124
        JSON.parse(event.message_body)
×
125
      end
126

127
      def jobs_configuration
1✔
UNCOV
128
        Rails.configuration.alma[:jobs] || {}
×
129
      end
130

131
      def find_job_configuration(dump:)
1✔
UNCOV
132
        job_name = event_message(dump:).dig('job_instance', 'name')
×
133

UNCOV
134
        jobs_configuration[job_name] || {}
×
135
      end
136
  end
137
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc