Module: Cul::Hydra::Resolver

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/cul/hydra/resolver.rb

Instance Method Summary collapse

Instance Method Details

#blacklight_solrObject



62
63
64
# File 'app/controllers/concerns/cul/hydra/resolver.rb', line 62

def blacklight_solr
  @solr ||=  RSolr.connect(blacklight_solr_config)
end

#blacklight_solr_configObject



66
67
68
# File 'app/controllers/concerns/cul/hydra/resolver.rb', line 66

def blacklight_solr_config
  Blacklight.solr_config
end

#getObject



27
28
29
30
31
32
33
34
# File 'app/controllers/concerns/cul/hydra/resolver.rb', line 27

def get
  get_solr_response_for_app_id
  action = params.delete(:action)
  action.sub!(/s$/,'')
  method_name = action + '_url'
  url = send method_name.to_sym, @document[:id]
  redirect_to url
end

#get_solr_response_for_app_id(id = nil, extra_controller_params = {}) ⇒ Object

Raises:

  • (Blacklight::Exceptions::InvalidSolrID)


17
18
19
20
21
22
23
24
25
# File 'app/controllers/concerns/cul/hydra/resolver.rb', line 17

def get_solr_response_for_app_id(id=nil, extra_controller_params={})
  id ||= params[:id]
  solr_params = blacklight_config.default_document_solr_params.merge!(extra_controller_params)
  solr_params[:fq] = "identifier_ssim:#{(id)}"
  solr_response = find((blacklight_config.document_solr_request_handler || blacklight_config.qt), solr_params)
  raise Blacklight::Exceptions::InvalidSolrID.new if solr_response.docs.empty?
  document = SolrDocument.new(solr_response.docs.first, solr_response)
  @response, @document = [solr_response, document]
end

#invalid_solr_id_errorObject

when a request for /resolve/:action/BAD_SOLR_ID is made, this method is executed…



56
57
58
59
60
# File 'app/controllers/concerns/cul/hydra/resolver.rb', line 56

def invalid_solr_id_error
  id = params.delete(:id)
  flash[:notice] = I18n.t('blacklight.search.errors.invalid_solr_id') + " (#{id})"
	redirect_to(root_path)
end

#rsolr_request_error(exception) ⇒ Object

when solr (RSolr) throws an error (RSolr::RequestError), this method is executed.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/concerns/cul/hydra/resolver.rb', line 37

def rsolr_request_error(exception)
  if Rails.env == "development"
    raise exception # Rails own code will catch and give usual Rails error page with stack trace
  else
    flash_notice = I18n.t('blacklight.search.errors.request_error')
    # Set the notice flag if the flash[:notice] is already set to the error that we are setting.
    # This is intended to stop the redirect loop error
    notice = flash[:notice] if flash[:notice] == flash_notice
    logger.error exception
    unless notice
      flash[:notice] = flash_notice
      redirect_to root_path, :status => 500
    else
      render :file => "#{Rails.root}/public/500.html", :status => 500
    end
  end
end