Class: Qa::LinkedDataTermsController

Inherits:
ApplicationController
  • Object
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.



12
13
14
15
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 12

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 19

def search # rubocop:disable Metrics/MethodLength
  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 :service_unavailable
    return
  rescue Qa::ServiceError
    logger.warn "Internal Server Error - Search query #{query} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
    head :internal_server_error
    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 :internal_server_error
    return
  end
  cors_allow_origin_header(response)
  render json: terms
end

#showObject

Return all the information for a given term



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 42

def show # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  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 :service_unavailable
    return
  rescue Qa::ServiceError
    logger.warn "Internal Server Error - Fetch term #{id} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
    head :internal_server_error
    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 :internal_server_error
    return
  end
  cors_allow_origin_header(response)
  render json: term
end