qa 2.0.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +54 -6
- data/app/controllers/qa/application_controller.rb +24 -0
- data/app/controllers/qa/linked_data_terms_controller.rb +116 -51
- data/app/controllers/qa/terms_controller.rb +7 -2
- data/app/models/qa/mesh_tree.rb +5 -9
- data/app/models/qa/subject_mesh_term.rb +2 -7
- data/config/authorities/linked_data/agrovoc.json +8 -1
- data/config/initializers/linked_data_authorities.rb +1 -17
- data/config/routes.rb +11 -0
- data/lib/generators/qa/apidoc/USAGE +11 -0
- data/lib/generators/qa/apidoc/apidoc_generator.rb +22 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/apidoc.json +1322 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/favicon-16x16.png +0 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/favicon-32x32.png +0 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/index.html +61 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/oauth2-redirect.html +67 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-bundle.js +93 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-bundle.js.map +1 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-standalone-preset.js +14 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-standalone-preset.js.map +1 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.css +3 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.css.map +1 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.js +9 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.js.map +1 -0
- data/lib/generators/qa/install/install_generator.rb +11 -0
- data/lib/generators/qa/install/templates/config/initializers/qa.rb +13 -0
- data/lib/generators/qa/local/tables/mysql/mysql_generator.rb +1 -1
- data/lib/generators/qa/local/tables/tables_generator.rb +1 -1
- data/lib/qa.rb +16 -0
- data/lib/qa/authorities/assign_fast_subauthority.rb +3 -3
- data/lib/qa/authorities/getty/aat.rb +13 -6
- data/lib/qa/authorities/getty/tgn.rb +11 -22
- data/lib/qa/authorities/getty/ulan.rb +13 -16
- data/lib/qa/authorities/linked_data.rb +1 -0
- data/lib/qa/authorities/linked_data/authority_service.rb +47 -0
- data/lib/qa/authorities/linked_data/config.rb +9 -3
- data/lib/qa/authorities/linked_data/config/search_config.rb +16 -2
- data/lib/qa/authorities/linked_data/config/term_config.rb +17 -3
- data/lib/qa/authorities/linked_data/find_term.rb +4 -3
- data/lib/qa/authorities/linked_data/generic_authority.rb +8 -1
- data/lib/qa/authorities/linked_data/rdf_helper.rb +15 -0
- data/lib/qa/authorities/linked_data/search_query.rb +19 -3
- data/lib/qa/authorities/loc/generic_authority.rb +2 -2
- data/lib/qa/authorities/loc_subauthority.rb +2 -2
- data/lib/qa/authorities/local.rb +2 -4
- data/lib/qa/authorities/local/file_based_authority.rb +1 -1
- data/lib/qa/authorities/local/mysql_table_based_authority.rb +11 -2
- data/lib/qa/authorities/local/table_based_authority.rb +2 -1
- data/lib/qa/authorities/mesh_tools/mesh_data_parser.rb +1 -1
- data/lib/qa/authorities/mesh_tools/mesh_importer.rb +1 -1
- data/lib/qa/authorities/oclcts/generic_oclc_authority.rb +1 -3
- data/lib/qa/configuration.rb +34 -0
- data/lib/qa/version.rb +1 -1
- data/lib/tasks/mesh.rake +3 -3
- data/spec/controllers/linked_data_terms_controller_spec.rb +247 -18
- data/spec/controllers/terms_controller_spec.rb +87 -12
- data/spec/fixtures/authorities/linked_data/lod_encoding_config.json +91 -0
- data/spec/fixtures/authorities/linked_data/lod_term_id_param_config.json +27 -0
- data/spec/fixtures/authorities/linked_data/lod_term_uri_param_config.json +27 -0
- data/spec/fixtures/{lexvo_snippet.rdf → lexvo_snippet.rdf.xml} +1 -0
- data/spec/lib/authorities/assign_fast_spec.rb +3 -1
- data/spec/lib/authorities/file_based_authority_spec.rb +19 -11
- data/spec/lib/authorities/geonames_spec.rb +3 -3
- data/spec/lib/authorities/getty/aat_spec.rb +14 -8
- data/spec/lib/authorities/getty/tgn_spec.rb +8 -15
- data/spec/lib/authorities/getty/ulan_spec.rb +8 -6
- data/spec/lib/authorities/getty_spec.rb +2 -1
- data/spec/lib/authorities/linked_data/authority_service_spec.rb +47 -0
- data/spec/lib/authorities/linked_data/generic_authority_spec.rb +56 -14
- data/spec/lib/authorities/linked_data/search_config_spec.rb +33 -19
- data/spec/lib/authorities/linked_data/search_query_spec.rb +67 -15
- data/spec/lib/authorities/linked_data/term_config_spec.rb +34 -20
- data/spec/lib/authorities/loc_spec.rb +9 -9
- data/spec/lib/authorities/local_spec.rb +7 -8
- data/spec/lib/authorities/oclcts_spec.rb +27 -20
- data/spec/lib/authorities/table_based_authority_spec.rb +5 -3
- data/spec/lib/authorities_loc_subauthorities.rb +2 -2
- data/spec/lib/configuration_spec.rb +58 -0
- data/spec/lib/mesh_data_parser_spec.rb +2 -0
- data/spec/lib/services/rdf_authority_parser_spec.rb +1 -1
- data/spec/lib/tasks/mesh.rake_spec.rb +13 -12
- data/spec/models/subject_mesh_term_spec.rb +2 -0
- data/spec/requests/cors_headers_spec.rb +118 -0
- data/spec/spec_helper.rb +2 -2
- metadata +167 -137
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: '00029794cefd74912e6ae326330554bb59e3fa0733c5f0b62eae96aaedc397f1'
|
|
4
|
+
data.tar.gz: 325f45dd7d9e188f57da3c2667f677725a48a2b6e439b71839a15503d875fd0e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9784b68a0c26d296de87e9eaa617437fee2daa11789ac70d2212a2c364613073b15fef1f941ba670a56aff1c5400cf45bd0e7e50aad41c736703030b4402a62c
|
|
7
|
+
data.tar.gz: 7b4016ed6d919e1cd1497a0de4465695954fb552916d6d01c0aa833f7eabde71b7dcaa7391e6b076221c0e80285ed308affb7d1e60c064f0f57951415ddf0125
|
data/README.md
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
# Questioning Authority
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Code:
|
|
4
|
+
[](http://badge.fury.io/rb/qa)
|
|
5
|
+
[](https://travis-ci.org/samvera/questioning_authority)
|
|
4
6
|
[](https://coveralls.io/github/samvera/questioning_authority?branch=master)
|
|
5
7
|
|
|
8
|
+
Docs:
|
|
9
|
+
[](./CONTRIBUTING.md)
|
|
10
|
+
[](./LICENSE)
|
|
11
|
+
|
|
12
|
+
Jump In: [](http://slack.samvera.org/)
|
|
13
|
+
|
|
6
14
|
You should question your authorities.
|
|
7
15
|
|
|
8
16
|
----
|
|
@@ -29,10 +37,12 @@ You should question your authorities.
|
|
|
29
37
|
* [Add javascript to support autocomplete](#add-javascript-to-support-autocomplete)
|
|
30
38
|
* [Developer Notes](#developer-notes)
|
|
31
39
|
* [Compatibility](#compatibility)
|
|
40
|
+
* [Product Owner & Maintenance](#product-owner--maintenance)
|
|
41
|
+
* [Product Owner](#product-owner)
|
|
32
42
|
* [Help](#help)
|
|
43
|
+
* [Acknowledgments](#acknowledgments)
|
|
33
44
|
|
|
34
45
|
----
|
|
35
|
-
|
|
36
46
|
## What does this do?
|
|
37
47
|
|
|
38
48
|
Provides a set of uniform RESTful routes to query any controlled vocabulary or set of authority terms.
|
|
@@ -303,7 +313,7 @@ This will create two tables/models Qa::LocalAuthority and Qa::LocalAuthorityEntr
|
|
|
303
313
|
label: 'Uighur',
|
|
304
314
|
uri: 'http://id.loc.gov/vocabulary/languages/uig')
|
|
305
315
|
|
|
306
|
-
Unfortunately, Rails doesn't have a
|
|
316
|
+
Unfortunately, Rails doesn't have a mechanism for adding functional indexes to tables, so if you have a lot of rows, you'll want to add an index:
|
|
307
317
|
|
|
308
318
|
CREATE INDEX "index_qa_local_authority_entries_on_lower_label" ON
|
|
309
319
|
"qa_local_authority_entries" (local_authority_id, lower(label))
|
|
@@ -330,7 +340,7 @@ The entire list (up to the first 1000 terms) can also be returned using:
|
|
|
330
340
|
|
|
331
341
|
#### Loading RDF data into database tables
|
|
332
342
|
|
|
333
|
-
You can use the Qa::Services::RDFAuthorityParser to import rdf files into
|
|
343
|
+
You can use the Qa::Services::RDFAuthorityParser to import rdf files into your database tables. See the class file, lib/qa/services/rdf_authority_parser.rb, for examples and more information.
|
|
334
344
|
To run the class in your local project you must include `gem 'linkeddata'` into your Gemfile and `require 'linkeddata'` into an initializer or your application.rb
|
|
335
345
|
|
|
336
346
|
### Medical Subject Headings (MeSH)
|
|
@@ -348,7 +358,7 @@ Then, create the tables in your database
|
|
|
348
358
|
|
|
349
359
|
rake db:migrate
|
|
350
360
|
|
|
351
|
-
Now that you've setup your application to use MeSH terms, you'll now need to load the
|
|
361
|
+
Now that you've setup your application to use MeSH terms, you'll now need to load the terms into your
|
|
352
362
|
database so you can query them locally.
|
|
353
363
|
|
|
354
364
|
To import the mesh terms into the local database, first download the MeSH descriptor dump in ASCII
|
|
@@ -385,6 +395,8 @@ gem 'rdf-rdfxml'
|
|
|
385
395
|
|
|
386
396
|
#### Configuring a LOD Authority
|
|
387
397
|
|
|
398
|
+
There are a number of authority configurations that are available. See (ld4l-labs/linked_data_authorities)[https://github.com/ld4l-labs/linked_data_authorities] for configurations and instructions on how to use them. These are updated periodically, so check back from time to time to see what's new.
|
|
399
|
+
|
|
388
400
|
Access to LOD authorities can be configured. Currently, a configuration exists in QA for OCLC Fast Linked Data, Library of
|
|
389
401
|
Congress (terms only), and Agrovoc. Look for configuration files in
|
|
390
402
|
[/config/authorities/linked_data](https://github.com/samvera/questioning_authority/tree/master/config/authorities/linked_data).
|
|
@@ -613,7 +625,26 @@ NOTE: All predicates with the URI as the subject will be included under "predica
|
|
|
613
625
|
|
|
614
626
|
See [Using with autocomplete in Sufia](https://github.com/samvera/questioning_authority/wiki/Using-with-autocomplete-in-Sufia) in the wiki documentation for QA.
|
|
615
627
|
|
|
628
|
+
If you are using jQueryUI >= 1.8 you can use the [autocomplete function](http://api.jqueryui.com/autocomplete/), for example:
|
|
616
629
|
|
|
630
|
+
```
|
|
631
|
+
$(function(){
|
|
632
|
+
$('#some_input').autocomplete({
|
|
633
|
+
source: function (request, response) {
|
|
634
|
+
$.ajax({
|
|
635
|
+
url: "/qa/search/loc/subjects?q=" + request.term,
|
|
636
|
+
type: 'GET',
|
|
637
|
+
dataType: 'json',
|
|
638
|
+
complete: function (xhr, status) {
|
|
639
|
+
var results = $.parseJSON(xhr.responseText);
|
|
640
|
+
response(results);
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
},
|
|
644
|
+
autoFocus: true
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
```
|
|
617
648
|
|
|
618
649
|
# Developer Notes
|
|
619
650
|
|
|
@@ -637,9 +668,26 @@ Commit your features into a new branch and submit a pull request.
|
|
|
637
668
|
* Ruby 2.4 or the latest 2.3 version is recommended. Later versions may also work.
|
|
638
669
|
* Rails 5 is required. We recommend the latest Rails 5.0 release.
|
|
639
670
|
|
|
671
|
+
## Product Owner & Maintenance
|
|
672
|
+
|
|
673
|
+
Questioning Authority is a Core Component of the Samvera community. The documentation for
|
|
674
|
+
what this means can be found
|
|
675
|
+
[here](http://samvera.github.io/core_components.html#requirements-for-a-core-component).
|
|
676
|
+
|
|
677
|
+
### Product Owner
|
|
678
|
+
|
|
679
|
+
[elrayle](https://github.com/elrayle)
|
|
680
|
+
|
|
640
681
|
# Help
|
|
641
682
|
|
|
642
|
-
|
|
683
|
+
The Samvera community is here to help. Please see our [support guide](./SUPPORT.md).
|
|
684
|
+
|
|
685
|
+
# Acknowledgments
|
|
686
|
+
|
|
687
|
+
This software has been developed by and is brought to you by the Samvera community. Learn more at the
|
|
688
|
+
[Samvera website](http://samvera.org/).
|
|
689
|
+
|
|
690
|
+

|
|
643
691
|
|
|
644
692
|
### Special thanks to...
|
|
645
693
|
|
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
module Qa
|
|
2
2
|
class ApplicationController < ActionController::Base
|
|
3
|
+
skip_before_action :verify_authenticity_token, only: :options, raise: false
|
|
4
|
+
|
|
5
|
+
# Process the OPTIONS method for all routes
|
|
6
|
+
# @see route definitions in /config/routes.rb
|
|
7
|
+
# @note Reference: https://fetch.spec.whatwg.org/#http-access-control-allow-headers
|
|
8
|
+
def options
|
|
9
|
+
unless Qa.config.cors_headers?
|
|
10
|
+
head :not_implemented
|
|
11
|
+
return
|
|
12
|
+
end
|
|
13
|
+
response.headers['Access-Control-Allow-Origin'] = '*'
|
|
14
|
+
response.headers['Access-Control-Allow-Methods'] = 'GET, OPTIONS'
|
|
15
|
+
head :no_content
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Add cors headers to the passed in http response if cors_headers are enabled. Called by all controller actions
|
|
19
|
+
# to adjust the response.
|
|
20
|
+
# @param http response
|
|
21
|
+
# @see /lib/generators/qa/install/templates/config/initializers/qa.rb
|
|
22
|
+
# @note The qa.rb initializer is copied to /config/initializers/qa.rb and can be modified to enable/disable cors headers.
|
|
23
|
+
# @note Reference: https://fetch.spec.whatwg.org/#http-access-control-allow-headers
|
|
24
|
+
def self.cors_allow_origin_header(response)
|
|
25
|
+
response.headers['Access-Control-Allow-Origin'] = '*' if Qa.config.cors_headers?
|
|
26
|
+
end
|
|
3
27
|
end
|
|
4
28
|
end
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
# This controller is used for all requests to linked data authorities. It will verify params and figure
|
|
2
2
|
# out which linked data authority to query based on the 'vocab' param.
|
|
3
3
|
|
|
4
|
-
class Qa::LinkedDataTermsController < ApplicationController
|
|
5
|
-
before_action :check_authority, :init_authority
|
|
4
|
+
class Qa::LinkedDataTermsController < ::ApplicationController
|
|
5
|
+
before_action :check_authority, :init_authority, except: [:list, :reload]
|
|
6
6
|
before_action :check_search_subauthority, :check_query_param, only: :search
|
|
7
7
|
before_action :check_show_subauthority, :check_id_param, only: :show
|
|
8
|
+
before_action :check_uri_param, only: :fetch
|
|
9
|
+
before_action :validate_auth_reload_token, only: :reload
|
|
10
|
+
|
|
11
|
+
delegate :cors_allow_origin_header, to: Qa::ApplicationController
|
|
8
12
|
|
|
9
13
|
# Provide a warning if there is a request for all terms.
|
|
10
14
|
def index
|
|
@@ -12,56 +16,91 @@ class Qa::LinkedDataTermsController < ApplicationController
|
|
|
12
16
|
head :not_found
|
|
13
17
|
end
|
|
14
18
|
|
|
19
|
+
# Return a list of supported authority names
|
|
20
|
+
# get "/list/linked_data/authorities"
|
|
21
|
+
# @see Qa::Authorities::LinkedData::AuthorityService#authority_names
|
|
22
|
+
def list
|
|
23
|
+
render json: Qa::Authorities::LinkedData::AuthorityService.authority_names.to_json
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Reload authority configurations
|
|
27
|
+
# get "/reload/linked_data/authorities?auth_token=YOUR_AUTH_TOKEN_DEFINED_HERE"
|
|
28
|
+
# @see Qa::Authorities::LinkedData::AuthorityService#load_authorities
|
|
29
|
+
def reload
|
|
30
|
+
Qa::Authorities::LinkedData::AuthorityService.load_authorities
|
|
31
|
+
list
|
|
32
|
+
end
|
|
33
|
+
|
|
15
34
|
# Return a list of terms based on a query
|
|
35
|
+
# get "/search/linked_data/:vocab(/:subauthority)"
|
|
16
36
|
# @see Qa::Authorities::LinkedData::SearchQuery#search
|
|
17
37
|
def search
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
rescue Qa::ServiceUnavailable
|
|
21
|
-
logger.warn "Service Unavailable - Search query #{query} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
|
|
22
|
-
head :service_unavailable
|
|
23
|
-
return
|
|
24
|
-
rescue Qa::ServiceError
|
|
25
|
-
logger.warn "Internal Server Error - Search query #{query} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
|
|
26
|
-
head :internal_server_error
|
|
27
|
-
return
|
|
28
|
-
rescue RDF::FormatError
|
|
29
|
-
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."
|
|
30
|
-
head :internal_server_error
|
|
31
|
-
return
|
|
32
|
-
end
|
|
38
|
+
terms = @authority.search(query, subauth: subauthority, language: language, replacements: replacement_params)
|
|
39
|
+
cors_allow_origin_header(response)
|
|
33
40
|
render json: terms
|
|
41
|
+
rescue Qa::ServiceUnavailable
|
|
42
|
+
logger.warn "Service Unavailable - Search query #{query} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
|
|
43
|
+
head :service_unavailable
|
|
44
|
+
rescue Qa::ServiceError
|
|
45
|
+
logger.warn "Internal Server Error - Search query #{query} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
|
|
46
|
+
head :internal_server_error
|
|
47
|
+
rescue RDF::FormatError
|
|
48
|
+
logger.warn "RDF Format Error - Results from search query #{query} for#{subauth_warn_msg} authority #{vocab_param} " \
|
|
49
|
+
"was not identified as a valid RDF format. You may need to include the linkeddata gem."
|
|
50
|
+
head :internal_server_error
|
|
34
51
|
end
|
|
35
52
|
|
|
36
|
-
# Return all the information for a given term
|
|
53
|
+
# Return all the information for a given term given an id or URI
|
|
54
|
+
# get "/show/linked_data/:vocab/:id"
|
|
55
|
+
# get "/show/linked_data/:vocab/:subauthority/:id
|
|
37
56
|
# @see Qa::Authorities::LinkedData::FindTerm#find
|
|
38
|
-
def show
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
def show # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
58
|
+
term = @authority.find(id, subauth: subauthority, language: language, replacements: replacement_params, jsonld: jsonld?)
|
|
59
|
+
cors_allow_origin_header(response)
|
|
60
|
+
content_type = jsonld? ? 'application/ld+json' : 'application/json'
|
|
61
|
+
render json: term, content_type: content_type
|
|
62
|
+
rescue Qa::TermNotFound
|
|
63
|
+
logger.warn "Term Not Found - Fetch term #{id} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
|
|
64
|
+
head :not_found
|
|
65
|
+
rescue Qa::ServiceUnavailable
|
|
66
|
+
logger.warn "Service Unavailable - Fetch term #{id} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
|
|
67
|
+
head :service_unavailable
|
|
68
|
+
rescue Qa::ServiceError
|
|
69
|
+
logger.warn "Internal Server Error - Fetch term #{id} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
|
|
70
|
+
head :internal_server_error
|
|
71
|
+
rescue RDF::FormatError
|
|
72
|
+
logger.warn "RDF Format Error - Results from fetch term #{id} for#{subauth_warn_msg} authority #{vocab_param} " \
|
|
73
|
+
"was not identified as a valid RDF format. You may need to include the linkeddata gem."
|
|
74
|
+
head :internal_server_error
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Return all the information for a given term given a URI
|
|
78
|
+
# get "/fetch/linked_data/:vocab"
|
|
79
|
+
# @see Qa::Authorities::LinkedData::FindTerm#find
|
|
80
|
+
def fetch # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
81
|
+
term = @authority.find(uri, subauth: subauthority, language: language, replacements: replacement_params, jsonld: jsonld?)
|
|
82
|
+
cors_allow_origin_header(response)
|
|
83
|
+
content_type = jsonld? ? 'application/ld+json' : 'application/json'
|
|
84
|
+
render json: term, content_type: content_type
|
|
85
|
+
rescue Qa::TermNotFound
|
|
86
|
+
logger.warn "Term Not Found - Fetch term #{uri} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
|
|
87
|
+
head :not_found
|
|
88
|
+
rescue Qa::ServiceUnavailable
|
|
89
|
+
logger.warn "Service Unavailable - Fetch term #{uri} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
|
|
90
|
+
head :service_unavailable
|
|
91
|
+
rescue Qa::ServiceError
|
|
92
|
+
logger.warn "Internal Server Error - Fetch term #{uri} unsuccessful for#{subauth_warn_msg} authority #{vocab_param}"
|
|
93
|
+
head :internal_server_error
|
|
94
|
+
rescue RDF::FormatError
|
|
95
|
+
logger.warn "RDF Format Error - Results from fetch term #{uri} for#{subauth_warn_msg} authority #{vocab_param} " \
|
|
96
|
+
"was not identified as a valid RDF format. You may need to include the linkeddata gem."
|
|
97
|
+
head :internal_server_error
|
|
59
98
|
end
|
|
60
99
|
|
|
61
100
|
private
|
|
62
101
|
|
|
63
102
|
def check_authority
|
|
64
|
-
if params[:vocab].nil? || !params[:vocab].size.positive?
|
|
103
|
+
if params[:vocab].nil? || !params[:vocab].size.positive? # rubocop:disable Style/GuardClause
|
|
65
104
|
logger.warn "Required param 'vocab' is missing or empty"
|
|
66
105
|
head :bad_request
|
|
67
106
|
end
|
|
@@ -69,7 +108,7 @@ class Qa::LinkedDataTermsController < ApplicationController
|
|
|
69
108
|
|
|
70
109
|
def check_search_subauthority
|
|
71
110
|
return if subauthority.nil?
|
|
72
|
-
unless @authority.search_subauthority?(subauthority)
|
|
111
|
+
unless @authority.search_subauthority?(subauthority) # rubocop:disable Style/GuardClause
|
|
73
112
|
logger.warn "Unable to initialize linked data search sub-authority '#{subauthority}' for authority '#{vocab_param}'"
|
|
74
113
|
head :bad_request
|
|
75
114
|
end
|
|
@@ -77,7 +116,7 @@ class Qa::LinkedDataTermsController < ApplicationController
|
|
|
77
116
|
|
|
78
117
|
def check_show_subauthority
|
|
79
118
|
return if subauthority.nil?
|
|
80
|
-
unless @authority.term_subauthority?(subauthority)
|
|
119
|
+
unless @authority.term_subauthority?(subauthority) # rubocop:disable Style/GuardClause
|
|
81
120
|
logger.warn "Unable to initialize linked data term sub-authority '#{subauthority}' for authority '#{vocab_param}'"
|
|
82
121
|
head :bad_request
|
|
83
122
|
end
|
|
@@ -95,10 +134,20 @@ class Qa::LinkedDataTermsController < ApplicationController
|
|
|
95
134
|
end
|
|
96
135
|
|
|
97
136
|
def check_query_param
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
137
|
+
missing_required_param('search', 'q') if params[:q].blank?
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def check_id_param
|
|
141
|
+
missing_required_param('show', 'id') if id.blank?
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def check_uri_param
|
|
145
|
+
missing_required_param('fetch', 'uri') if uri.blank?
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def missing_required_param(action_name, param_name)
|
|
149
|
+
logger.warn "Required #{action_name} param '#{param_name}' is missing or empty"
|
|
150
|
+
head :bad_request
|
|
102
151
|
end
|
|
103
152
|
|
|
104
153
|
# converts wildcards into URL-encoded characters
|
|
@@ -106,11 +155,8 @@ class Qa::LinkedDataTermsController < ApplicationController
|
|
|
106
155
|
params[:q].gsub("*", "%2A")
|
|
107
156
|
end
|
|
108
157
|
|
|
109
|
-
def
|
|
110
|
-
|
|
111
|
-
logger.warn "Required show param 'id' is missing or empty"
|
|
112
|
-
head :bad_request
|
|
113
|
-
end
|
|
158
|
+
def uri
|
|
159
|
+
params[:uri]
|
|
114
160
|
end
|
|
115
161
|
|
|
116
162
|
def id
|
|
@@ -132,4 +178,23 @@ class Qa::LinkedDataTermsController < ApplicationController
|
|
|
132
178
|
def subauth_warn_msg
|
|
133
179
|
subauthority.nil? ? "" : " sub-authority #{subauthority} in"
|
|
134
180
|
end
|
|
181
|
+
|
|
182
|
+
def format
|
|
183
|
+
return 'json' unless params.key?(:format)
|
|
184
|
+
return 'json' if params[:format].blank?
|
|
185
|
+
params[:format]
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def jsonld?
|
|
189
|
+
format == 'jsonld'
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def validate_auth_reload_token
|
|
193
|
+
token = params.key?(:auth_token) ? params[:auth_token] : nil
|
|
194
|
+
valid = Qa.config.valid_authority_reload_token?(token)
|
|
195
|
+
return true if valid
|
|
196
|
+
logger.warn "FAIL: unable to reload authorities; error_msg: Invalid token (#{token}) does not match expected token."
|
|
197
|
+
head :unauthorized
|
|
198
|
+
false
|
|
199
|
+
end
|
|
135
200
|
end
|
|
@@ -3,12 +3,15 @@
|
|
|
3
3
|
# All the authority classes inherit from a super class so they implement the
|
|
4
4
|
# same methods.
|
|
5
5
|
|
|
6
|
-
class Qa::TermsController < ApplicationController
|
|
6
|
+
class Qa::TermsController < ::ApplicationController
|
|
7
7
|
before_action :check_vocab_param, :init_authority
|
|
8
8
|
before_action :check_query_param, only: :search
|
|
9
9
|
|
|
10
|
+
delegate :cors_allow_origin_header, to: Qa::ApplicationController
|
|
11
|
+
|
|
10
12
|
# If the subauthority supports it, return a list of all terms in the authority
|
|
11
13
|
def index
|
|
14
|
+
cors_allow_origin_header(response)
|
|
12
15
|
render json: begin
|
|
13
16
|
@authority.all
|
|
14
17
|
rescue NotImplementedError
|
|
@@ -19,12 +22,14 @@ class Qa::TermsController < ApplicationController
|
|
|
19
22
|
# Return a list of terms based on a query
|
|
20
23
|
def search
|
|
21
24
|
terms = @authority.method(:search).arity == 2 ? @authority.search(url_search, self) : @authority.search(url_search)
|
|
25
|
+
cors_allow_origin_header(response)
|
|
22
26
|
render json: terms
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
# If the subauthority supports it, return all the information for a given term
|
|
26
30
|
def show
|
|
27
31
|
term = @authority.find(params[:id])
|
|
32
|
+
cors_allow_origin_header(response)
|
|
28
33
|
render json: term
|
|
29
34
|
end
|
|
30
35
|
|
|
@@ -32,7 +37,7 @@ class Qa::TermsController < ApplicationController
|
|
|
32
37
|
head :not_found unless params[:vocab].present?
|
|
33
38
|
end
|
|
34
39
|
|
|
35
|
-
def init_authority
|
|
40
|
+
def init_authority # rubocop:disable Metrics/MethodLength
|
|
36
41
|
begin
|
|
37
42
|
mod = authority_class.camelize.constantize
|
|
38
43
|
rescue NameError
|
data/app/models/qa/mesh_tree.rb
CHANGED
|
@@ -6,12 +6,8 @@ class Qa::MeshTree < ActiveRecord::Base
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def eval_tree_path
|
|
9
|
-
trees =
|
|
10
|
-
|
|
11
|
-
trees.split("|")
|
|
12
|
-
else
|
|
13
|
-
[]
|
|
14
|
-
end
|
|
9
|
+
trees = self[:eval_tree_path] || (self[:eval_tree_path] = "")
|
|
10
|
+
trees ? trees.split("|") : []
|
|
15
11
|
end
|
|
16
12
|
|
|
17
13
|
def classify_tree
|
|
@@ -20,10 +16,10 @@ class Qa::MeshTree < ActiveRecord::Base
|
|
|
20
16
|
end
|
|
21
17
|
|
|
22
18
|
def classify_tree!
|
|
23
|
-
unless classify_tree.empty?
|
|
19
|
+
unless classify_tree.empty? # rubocop:disable Style/GuardClause
|
|
24
20
|
tree_path = classify_tree.join('|')
|
|
25
|
-
|
|
26
|
-
update_attribute(:eval_tree_path, tree_path)
|
|
21
|
+
Rails.logger.info "After Join #{tree_path.inspect}"
|
|
22
|
+
update_attribute(:eval_tree_path, tree_path) # rubocop:disable Rails/SkipsModelValidations # TODO: Explore how to avoid use of update_attribute.
|
|
27
23
|
end
|
|
28
24
|
end
|
|
29
25
|
|