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”



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 80

def fetch # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  term = @authority.find(uri, subauth: subauthority, language: language, replacements: replacement_params, jsonld: jsonld?)
  cors_allow_origin_header(response)
  content_type = jsonld? ? 'application/ld+json' : 'application/json'
  render json: term, content_type: content_type
rescue Qa::TermNotFound
  logger.warn "Term Not Found - Fetch term #{uri} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  head :not_found
rescue Qa::ServiceUnavailable
  logger.warn "Service Unavailable - Fetch term #{uri} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  head :service_unavailable
rescue Qa::ServiceError
  logger.warn "Internal Server Error - Fetch term #{uri} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  head :internal_server_error
rescue RDF::FormatError
  logger.warn "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."
  head :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 get “/list/linked_data/authorities”

See Also:

  • Authorities::LinkedData::AuthorityService#authority_names


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

def list
  render json: Qa::Authorities::LinkedData::AuthorityService.authority_names.to_json
end

#reloadObject

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

See Also:

  • Authorities::LinkedData::AuthorityService#load_authorities


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

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

#searchObject

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



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 37

def search
  terms = @authority.search(query, subauth: subauthority, language: language, replacements: replacement_params)
  cors_allow_origin_header(response)
  render json: terms
rescue Qa::ServiceUnavailable
  logger.warn "Service Unavailable - Search query #{query} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  head :service_unavailable
rescue Qa::ServiceError
  logger.warn "Internal Server Error - Search query #{query} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  head :internal_server_error
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
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



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/qa/linked_data_terms_controller.rb', line 57

def show # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  term = @authority.find(id, subauth: subauthority, language: language, replacements: replacement_params, jsonld: jsonld?)
  cors_allow_origin_header(response)
  content_type = jsonld? ? 'application/ld+json' : 'application/json'
  render json: term, content_type: content_type
rescue Qa::TermNotFound
  logger.warn "Term Not Found - Fetch term #{id} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  head :not_found
rescue Qa::ServiceUnavailable
  logger.warn "Service Unavailable - Fetch term #{id} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  head :service_unavailable
rescue Qa::ServiceError
  logger.warn "Internal Server Error - Fetch term #{id} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
  head :internal_server_error
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
end