Class: BaseIndexer::CollectionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/base_indexer/collections_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#remove_prefix, #report_failure, #report_success

Instance Method Details

#updateObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/base_indexer/collections_controller.rb', line 5

def update
  druid = remove_prefix params[:id]

  Rails.logger.debug "Receiving indexing of collection #{druid}"
  targets = params[:subtargets]

  # initial collection item itself
  indexer = BaseIndexer.indexer_class.constantize.new
  indexer.index druid, targets

  # initialize dor-fetcher to get list of druids for this collection
  df = DorFetcher::Client.new(service_url: Rails.application.config.dor_fetcher_url)

  item_druids = df.druid_array(df.get_collection(druid, {}))

  Rails.logger.debug "Found #{item_druids.size} members of the collection #{druid}"

  counter = 0

  item_druids.each do |idruid|
    druid = remove_prefix idruid
    counter += 1
    indexer.index druid, targets
    Rails.logger.debug "#{counter} of #{item_druids.size}: #{druid}"
  end

  @status = report_success
  render nothing: true, status: 200
  Rails.logger.debug "Completing indexing of collection #{druid}"

rescue Exception => e
  @status = report_failure request.method_symbol, params, e
  Rails.logger.error @status
  render nothing: true, status: 202
end