Class: Qa::LinkedDataTermsController

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

Overview

This controller is used for all requests to linked data authorities. It will verify params and figure out which linked data authority to query based on the ‘vocab’ param.

Instance Method Summary collapse

Instance Method Details

#indexObject

Provide a warning if there is a request for all terms.



10
11
12
13
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 10

def index
  logger.warn 'Linked data authorities do not support retrieving all terms.'
  head :not_found
end

#searchObject

Return a list of terms based on a query



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 17

def search
  begin
    terms = @authority.search(query, subauth: subauthority, language: language, replacements: replacement_params)
  rescue Qa::ServiceUnavailable
    logger.warn "Service Unavailable - Search query #{query} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
    head :not_found
    return
  rescue RDF::FormatError
    logger.warn "RDF Format Error - Results from search query #{query} for#{subauth_warn_msg} authority #{vocab_param} was not identified as a valid RDF format.  You may need to include the linkeddata gem."
    head :not_found
    return
  end
  render json: terms
end

#showObject

Return all the information for a given term



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 34

def show
  begin
    term = @authority.find(id, subauth: subauthority, language: language, replacements: replacement_params)
  rescue Qa::TermNotFound
    logger.warn "Term Not Found - Fetch term #{id} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
    head :not_found
    return
  rescue Qa::ServiceUnavailable
    logger.warn "Service Unavailable - Fetch term #{id} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
    head :not_found
    return
  rescue RDF::FormatError
    logger.warn "RDF Format Error - Results from fetch term #{id} for#{subauth_warn_msg} authority #{vocab_param} was not identified as a valid RDF format.  You may need to include the linkeddata gem."
    head :not_found
    return
  end
  render json: term
end