• 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

19.05
/app/models/scsb/partner_updates/update.rb
1
require 'marc_cleanup'
1✔
2

3
module Scsb
1✔
4
  class PartnerUpdates
1✔
5
    class Update
1✔
6
      attr_accessor :dump
1✔
7

8
      def initialize(dump:, dump_file_type:, timestamp:)
1✔
UNCOV
9
        @last_dump = timestamp
×
UNCOV
10
        @dump = dump
×
UNCOV
11
        @dump_file_type = dump_file_type
×
UNCOV
12
        @s3_bucket = Scsb::S3Bucket.partner_transfer_client
×
UNCOV
13
        @scsb_file_dir = ENV['SCSB_FILE_DIR']
×
UNCOV
14
        @update_directory = ENV['SCSB_PARTNER_UPDATE_DIRECTORY'] || '/tmp/updates'
×
15
      end
16

17
      def attach_dump_file(filepath, dump_file_type: nil)
1✔
UNCOV
18
        dump_file_type ||= @dump_file_type
×
UNCOV
19
        df = DumpFile.create(dump_file_type:, path: filepath)
×
UNCOV
20
        df.zip
×
UNCOV
21
        df.save
×
UNCOV
22
        @dump.dump_files << df
×
UNCOV
23
        @dump.save
×
24
      end
25

26
      def process_partner_updates(files:, file_prefix: 'scsb_update_')
1✔
UNCOV
27
        xml_files = []
×
UNCOV
28
        files.each do |file|
×
UNCOV
29
          filename = File.basename(file, '.zip')
×
UNCOV
30
          filename.gsub!(/^[^_]+_([0-9]+)_([0-9]+).*$/, '\1_\2')
×
UNCOV
31
          file_increment = 1
×
UNCOV
32
          Zip::File.open(file) do |zip_file|
×
UNCOV
33
            zip_file.each do |entry|
×
UNCOV
34
              target = "#{@update_directory}/#{filename}_#{file_increment}.xml"
×
UNCOV
35
              xml_files << target
×
UNCOV
36
              entry.extract(target)
×
UNCOV
37
              file_increment += 1
×
38
            end
39
          end
UNCOV
40
          File.unlink(file)
×
41
        end
UNCOV
42
        xml_files.each do |file|
×
UNCOV
43
          filename = File.basename(file)
×
UNCOV
44
          reader = MARC::XMLReader.new(file.to_s, parser: :nokogiri)
×
UNCOV
45
          filepath = "#{@scsb_file_dir}/#{file_prefix}#{filename}"
×
UNCOV
46
          writer = MARC::XMLWriter.new(filepath)
×
UNCOV
47
          reader.each { |record| writer.write(Scsb::PartnerUpdates::Update.process_record(record)) }
×
UNCOV
48
          writer.close
×
UNCOV
49
          File.unlink(file)
×
UNCOV
50
          attach_dump_file(filepath)
×
51
        end
52
      end
53

54
      def self.process_record(record)
1✔
UNCOV
55
        record = field_delete(['856', '959'], record)
×
UNCOV
56
        record.leader[5] = 'c' if record.leader[5].eql?('d')
×
UNCOV
57
        record = bad_utf8_fix(record) if bad_utf8?(record)
×
UNCOV
58
        record = invalid_xml_fix(record) if invalid_xml_chars?(record)
×
UNCOV
59
        record = tab_newline_fix(record) if tab_newline_char?(record)
×
UNCOV
60
        record = leaderfix(record) if leader_errors?(record)
×
UNCOV
61
        record = composed_chars_normalize(record) if composed_chars_errors?(record)
×
UNCOV
62
        record = extra_space_fix(record)
×
UNCOV
63
        empty_subfield_fix(record)
×
64
      end
65

66
      def add_error(message:)
1✔
67
        error = Array.wrap(@dump.event.error)
×
68
        error << message
×
69
        @dump.event.error = error.join('; ')
×
70
        @dump.event.save
×
71
      end
72

73
      def date_strings
1✔
74
        @dump.dump_files.map do |df|
×
75
          if df.dump_file_type == 'recap_records_full_metadata'
×
76
            File.basename(df.path).split('_')[3]
×
77
          else
78
            File.basename(df.path).split('_')[2]
×
79
          end
80
        end
81
      end
82

83
      def prepare_directory
1✔
UNCOV
84
        FileUtils.mkdir_p(@update_directory)
×
85
      end
86
    end
87
  end
88
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