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

pulibrary / pdc_discovery / 5af13607-7741-41ac-b110-c94c8a3ee0f0

pending completion
5af13607-7741-41ac-b110-c94c8a3ee0f0

Pull #441

circleci

hectorcorrea
Better error handling
Pull Request #441: Indexing to a new collection

99 of 99 new or added lines in 3 files covered. (100.0%)

1816 of 2220 relevant lines covered (81.8%)

95.45 hits per line

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

91.3
/app/lib/dspace_indexer.rb
1
# frozen_string_literal: true
2

3
require 'faraday_middleware'
1✔
4
require 'traject'
1✔
5

6
##
7
# Index DSpace objects to solr
8
class DspaceIndexer
1✔
9
  REST_LIMIT = 100
1✔
10

11
  ##
12
  # @param [String] XML from DSpace rest interface
13
  def initialize(dspace_xml)
1✔
14
    @dspace_xml = dspace_xml
75✔
15
  end
16

17
  ##
18
  # Index XML as received from DSpace
19
  def index
1✔
20
    traject_indexer.process(@dspace_xml)
74✔
21
    traject_indexer.complete
×
22
  end
23

24
  def research_data_config_path
1✔
25
    pathname = ::Rails.root.join('lib', 'traject', "dataspace_research_data_config.rb")
75✔
26
    pathname.to_s
75✔
27
  end
28

29
  ##
30
  # Load the traject indexing config for DataSpace research data objects
31
  def traject_indexer
1✔
32
    @traject_indexer ||= Traject::Indexer::NokogiriIndexer.new.tap do |i|
75✔
33
      i.load_config_file(research_data_config_path)
75✔
34
    end
35
  end
36

37
  ##
38
  # TODO: Pass in indexing options from the command line
39
  # Convenience method for kicking off indexing
40
  # @example DspaceIndexer.index(collection_handle: '88435/dsp015m60qr913')
41
  def self.index(_options)
1✔
42
    server = "#{Rails.configuration.pdc_discovery.dataspace_url}/rest"
1✔
43
    collection_id = '261'
1✔
44
    url = "#{server}/collections/#{collection_id}/items?limit=#{REST_LIMIT}&offset=0&expand=all"
1✔
45

46
    resp = Faraday.get(url, {}, { 'Accept': 'application/xml' })
1✔
47
    i = DspaceIndexer.new(resp.body)
1✔
48
    i.index
1✔
49
    i
×
50
  end
51
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