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

pulibrary / bibdata / b3c4a532-5da0-46f8-9c20-20018605a028

21 Mar 2025 08:11PM UTC coverage: 42.257% (-49.9%) from 92.185%
b3c4a532-5da0-46f8-9c20-20018605a028

push

circleci

sandbergja
Move various gems from the default Gemfile group to a more appropriate group

1599 of 3784 relevant lines covered (42.26%)

2.56 hits per line

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

27.66
/app/services/location_data_service.rb
1
class LocationDataService
1✔
2
  # Delete existing locations data repopulate tables with data from Alma
3
  def self.delete_existing_and_repopulate
1✔
4
    new.delete_existing_and_repopulate
×
5
  end
6

7
  def delete_existing_and_repopulate
1✔
8
    DeliveryLocation.delete_all
×
9
    HoldingLocation.delete_all
×
10
    Library.delete_all
×
11
    populate_libraries
×
12
    populate_delivery_locations
×
13
    populate_holding_locations
×
14
  end
15

16
  def populate_libraries
1✔
17
    # Populate Library model using the libraries.json file
18
    libraries_array.each do |library|
×
19
      Library.create(
×
20
        label: library['label'],
21
        code: library['code'],
22
        order: library['order']
23
      )
24
    end
25
  end
26

27
  def populate_holding_locations
1✔
28
    holding_locations_array.each do |holding_location|
×
29
      holding_location_record = HoldingLocation.create(
×
30
        label: holding_location['label'],
31
        code: holding_location['code'],
32
        aeon_location: holding_location['aeon_location'],
33
        recap_electronic_delivery_location: holding_location['recap_electronic_delivery_location'],
34
        open: holding_location['open'],
35
        requestable: holding_location['requestable'],
36
        always_requestable: holding_location['always_requestable'],
37
        circulates: holding_location['circulates'],
38
        remote_storage: holding_location['remote_storage'],
39
        fulfillment_unit: holding_location['fulfillment_unit'],
40
        locations_library_id: holding_location['library'] ? library_id(holding_location['library']['code']) : {},
×
41
        holding_library_id: holding_location['holding_library'] ? library_id(holding_location['holding_library']['code']) : {} # Library.where(label: holding_location["holding_library"]).first.id
×
42
      )
43
      holding_location_record.delivery_location_ids = delivery_library_ids(holding_location['delivery_locations'])
×
44
    end
45
  end
46

47
  # Populate delivery locations based on the delivery_locations.json
48
  # @note Do NOT remove values from here without updating Figgy appropriately.
49
  # The URIs are referenced in Figgy and removing them will break manifests.
50
  # These values will not change when we move to alma.
51
  def populate_delivery_locations
1✔
52
    highest_id = delivery_locations_array.sort_by { |x| x['id'] }.last['id']
×
53
    # Reset the auto-increment column so it starts above the highest count.
54
    DeliveryLocation.connection.execute("ALTER SEQUENCE locations_delivery_locations_id_seq RESTART WITH #{highest_id + 1}")
×
55
    delivery_locations_array.each do |delivery_location|
×
56
      library_record_id = find_library_by_code(delivery_location['library']['code']).id
×
57
      DeliveryLocation.create(
×
58
        id: delivery_location['id'],
59
        label: delivery_location['label'],
60
        address: delivery_location['address'],
61
        phone_number: delivery_location['phone_number'],
62
        contact_email: delivery_location['contact_email'],
63
        staff_only: delivery_location['staff_only'],
64
        locations_library_id: library_record_id,
65
        gfa_pickup: delivery_location['gfa_pickup'],
66
        pickup_location: delivery_location['pickup_location'],
67
        digital_location: delivery_location['digital_location']
68
      )
69
    end
70
  end
71

72
  private
1✔
73

74
    def library_id(holding_library_code)
1✔
75
      return {} unless holding_library_code
×
76

77
      library = find_library_by_code(holding_library_code)
×
78
      library.id if library.present?
×
79
    end
80

81
    # Find the delivery library using the gfa_pickup value
82
    # example: gfa_pickup = ["QT", "QA", "PA", "QC"] for anxbnc
83
    def delivery_library_ids(gfa_pickup)
1✔
84
      ids = []
×
85
      gfa_pickup.each do |d|
×
86
        delivery_location = DeliveryLocation.all.find { |m| m['gfa_pickup'] == d }
×
87
        ids << delivery_location.id if delivery_location.present?
×
88
      end
89
      ids
×
90
    end
91

92
    # Find the library using the library code
93
    def find_library_by_code(code)
1✔
94
      Library.find_by(code:)
×
95
    end
96

97
    # Parses holding_locations.json file
98
    # Creates an array of holding_location hashes
99
    def holding_locations_array
1✔
100
      file = File.read(File.join(MARC_LIBERATION_CONFIG['location_files_dir'], 'holding_locations.json'))
×
101
      JSON.parse(file)
×
102
    end
103

104
    # Parses delivery_locations.json file
105
    # Creates an array of delivery_locations hashes
106
    def delivery_locations_array
1✔
107
      file = File.read(File.join(MARC_LIBERATION_CONFIG['location_files_dir'], 'delivery_locations.json'))
×
108
      JSON.parse(file)
×
109
    end
110

111
    # Parses libraries.json file
112
    # Creates an array of libraries hashes
113
    def libraries_array
1✔
114
      file = File.read(File.join(MARC_LIBERATION_CONFIG['location_files_dir'], 'libraries.json'))
×
115
      JSON.parse(file)
×
116
    end
117
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