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 Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#request_header_serviceObject (readonly)

Returns the value of attribute request_header_service.



17
18
19
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 17

def request_header_service
  @request_header_service
end

Instance Method Details

#fetchObject

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



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 97

def fetch # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  term = @authority.find(uri)
  cors_allow_origin_header(response)
  render json: term, content_type: request_header_service.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.



20
21
22
23
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 20

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


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

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


36
37
38
39
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 36

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)”



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

def search # rubocop:disable Metrics/MethodLength
  terms = @authority.search(query)
  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



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 67

def show # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  term = @authority.find(id)
  cors_allow_origin_header(response)
  render json: term, content_type: request_header_service.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