Class: Qa::TermsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/qa/terms_controller.rb

Overview

This controller is used for all requests to all authorities. It will verify params and figure out which class to instantiate based on the “vocab” param. All the authotirty classes inherit from a super class so they implement the same methods.

Instance Method Summary collapse

Instance Method Details

#check_authorityObject



63
64
65
66
67
68
69
# File 'app/controllers/qa/terms_controller.rb', line 63

def check_authority
  begin
    authority_class.constantize
  rescue
    head :bad_request
  end
end

#check_search_paramsObject



57
58
59
60
61
# File 'app/controllers/qa/terms_controller.rb', line 57

def check_search_params
  unless params[:q].present? && params[:vocab].present?
    head :bad_request
  end
end

#check_sub_authorityObject



71
72
73
74
75
# File 'app/controllers/qa/terms_controller.rb', line 71

def check_sub_authority
  unless params[:sub_authority].nil?
    head :bad_request unless authority_class.constantize.authority_valid?(params[:sub_authority])
  end
end

#check_vocab_paramObject



51
52
53
54
55
# File 'app/controllers/qa/terms_controller.rb', line 51

def check_vocab_param
  unless params[:vocab].present?
    head :bad_request
  end
end

#indexObject

search that returns all results



11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/qa/terms_controller.rb', line 11

def index
  #initialize the authority and run the search. if there's a sub-authority and it's valid, include that param
  @authority = authority_class.constantize.new
  @authority.search(params[:q], params[:sub_authority])

  respond_to do |format|
    format.html { render :layout => false, json: @authority.results }
    format.json { render :layout => false, json: @authority.results }
    format.js   { render :layout => false, :text => @authority.results }
  end
end

#searchObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/qa/terms_controller.rb', line 23

def search
  #convert wildcard to be URI encoded
  params[:q].gsub!("*", "%2A")

  #initialize the authority and run the search. if there's a sub-authority and it's valid, include that param
  @authority = authority_class.constantize.new
  @authority.search(params[:q], params[:sub_authority])

  respond_to do |format|
    format.html { render :layout => false, :text => @authority.results.to_json }
    format.json { render :layout => false, :text => @authority.results.to_json }
    format.js   { render :layout => false, :text => @authority.results }
  end

end

#showObject



39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/qa/terms_controller.rb', line 39

def show
  check_sub_authority
  authority = authority_class.constantize.new
  result = authority.get_full_record(params[:id], params[:sub_authority])

  respond_to do |format|
    format.html { render :layout => false, :text => result.to_json }
    format.json { render :layout => false, :text => result.to_json }
    format.js   { render :layout => false, :text => result }
  end
end