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

#fetchObject

Return all the information for a given term given a URI get “/fetch/linked_data/:vocab”



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 91

def fetch # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  term = @authority.find(uri, subauth: subauthority, language: language, replacements: replacement_params, format: format, performance_data: performance_data?)
  cors_allow_origin_header(response)
  render json: term, content_type: content_type_for_format
rescue Qa::TermNotFound
  msg = "Term Not Found - Fetch term #{uri} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  logger.warn msg
  render json: { errors: msg }, status: :not_found
rescue Qa::ServiceUnavailable
  msg = "Service Unavailable - Fetch term #{uri} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  logger.warn msg
  render json: { errors: msg }, status: :service_unavailable
rescue Qa::ServiceError
  msg = "Internal Server Error - Fetch term #{uri} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  logger.warn msg
  render json: { errors: msg }, status: :internal_server_error
rescue RDF::FormatError
  msg = "RDF Format Error - Results from fetch term #{uri} for#{subauth_warn_msg} authority #{vocab_param} " \
              "was not identified as a valid RDF format.  You may need to include the linkeddata gem."
  logger.warn msg
  render json: { errors: msg }, status: :internal_server_error
end

#indexObject

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



14
15
16
17
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 14

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

#listObject

Return a list of supported authority names optionally with details about the authority get “/list/linked_data/authorities?details=true|false” (default details=false)

See Also:

  • Qa::LinkedData::AuthorityService#authority_names
  • Qa::LinkedData::AuthorityService#authority_details


23
24
25
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 23

def list
  details? ? render_detail_list : render_simple_list
end

#reloadObject

Reload authority configurations get “/reload/linked_data/authorities?auth_token=YOUR_AUTH_TOKEN_DEFINED_HERE”

See Also:

  • Qa::LinkedData::AuthorityService#load_authorities


30
31
32
33
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 30

def reload
  Qa::LinkedData::AuthorityService.load_authorities
  list
end

#searchObject

Return a list of terms based on a query get “/search/linked_data/:vocab(/:subauthority)”



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 38

def search # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  terms = @authority.search(query, subauth: subauthority, language: language, replacements: replacement_params, context: context?, performance_data: performance_data?)
  cors_allow_origin_header(response)
  render json: terms
rescue Qa::ServiceUnavailable
  msg = "Service Unavailable - Search query #{query} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  logger.warn msg
  render json: { errors: msg }, status: :service_unavailable
rescue Qa::ServiceError
  msg = "Internal Server Error - Search query #{query} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  logger.warn msg
  render json: { errors: msg }, status: :internal_server_error
rescue RDF::FormatError
  msg = "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."
  logger.warn msg
  render json: { errors: msg }, status: :internal_server_error
end

#showObject

Return all the information for a given term given an id or URI get “/show/linked_data/:vocab/:id” get “/show/linked_data/:vocab/:subauthority/:id



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 61

def show # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  term = @authority.find(id, subauth: subauthority, language: language, replacements: replacement_params, format: format, performance_data: performance_data?)
  cors_allow_origin_header(response)
  render json: term, content_type: content_type_for_format
rescue Qa::TermNotFound
  msg = "Term Not Found - Fetch term #{id} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  logger.warn msg
  render json: { errors: msg }, status: :not_found
rescue Qa::ServiceUnavailable
  msg = "Service Unavailable - Fetch term #{id} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  logger.warn msg
  render json: { errors: msg }, status: :service_unavailable
rescue Qa::ServiceError
  msg = "Internal Server Error - Fetch term #{id} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  logger.warn msg
  render json: { errors: msg }, status: :internal_server_error
rescue RDF::FormatError
  msg = "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."
  logger.warn msg
  render json: { errors: msg }, status: :internal_server_error
rescue Qa::DataNormalizationError => e
  msg = "Data Normalization Error - #{e.message}"
  logger.warn msg
  render json: { errors: msg }, status: :internal_server_error
end