qa 4.2.0 → 4.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.
Files changed (28) hide show
  1. checksums.yaml +5 -5
  2. data/app/controllers/qa/linked_data_terms_controller.rb +17 -39
  3. data/app/controllers/qa/terms_controller.rb +26 -2
  4. data/app/services/qa/linked_data/authority_url_service.rb +35 -21
  5. data/app/services/qa/linked_data/graph_service.rb +2 -4
  6. data/app/services/qa/linked_data/request_header_service.rb +97 -0
  7. data/lib/qa/authorities/discogs/discogs_instance_builder.rb +17 -19
  8. data/lib/qa/authorities/discogs/discogs_translation.rb +26 -22
  9. data/lib/qa/authorities/discogs/discogs_utils.rb +32 -20
  10. data/lib/qa/authorities/discogs/discogs_works_builder.rb +26 -47
  11. data/lib/qa/authorities/discogs/generic_authority.rb +64 -33
  12. data/lib/qa/authorities/getty/tgn.rb +1 -1
  13. data/lib/qa/authorities/linked_data/find_term.rb +60 -18
  14. data/lib/qa/authorities/linked_data/search_query.rb +43 -15
  15. data/lib/qa/authorities/loc/generic_authority.rb +2 -2
  16. data/lib/qa/version.rb +1 -1
  17. data/spec/controllers/linked_data_terms_controller_spec.rb +36 -0
  18. data/spec/controllers/terms_controller_spec.rb +26 -2
  19. data/spec/fixtures/discogs-find-response-json.json +1 -1
  20. data/spec/lib/authorities/discogs/generic_authority_spec.rb +103 -9
  21. data/spec/lib/authorities/getty/tgn_spec.rb +2 -2
  22. data/spec/lib/authorities/linked_data/find_term_spec.rb +11 -11
  23. data/spec/lib/authorities/linked_data/search_query_spec.rb +9 -9
  24. data/spec/lib/authorities/loc_spec.rb +9 -9
  25. data/spec/services/linked_data/authority_url_service_spec.rb +14 -8
  26. data/spec/services/linked_data/graph_service_spec.rb +2 -1
  27. data/spec/services/linked_data/request_header_service_spec.rb +124 -0
  28. metadata +9 -7
@@ -28,7 +28,7 @@ module Qa::Authorities
28
28
  end
29
29
  %(SELECT DISTINCT ?s ?name ?par {
30
30
  ?s a skos:Concept; luc:term "#{search}";
31
- skos:inScheme <http://vocab.getty.edu/ulan/> ;
31
+ skos:inScheme <http://vocab.getty.edu/tgn/> ;
32
32
  gvp:prefLabelGVP [skosxl:literalForm ?name] ;
33
33
  gvp:parentString ?par .
34
34
  FILTER #{ex} .
@@ -15,17 +15,21 @@ module Qa::Authorities
15
15
  @term_config = term_config
16
16
  end
17
17
 
18
- attr_reader :term_config, :full_graph, :filtered_graph, :language, :id, :uri, :access_time_s, :normalize_time_s, :fetched_size, :normalized_size
19
- private :full_graph, :filtered_graph, :language, :id, :uri, :access_time_s, :normalize_time_s, :fetched_size, :normalized_size
18
+ attr_reader :term_config, :full_graph, :filtered_graph, :language, :id, :uri, :access_time_s, :normalize_time_s, :fetched_size, :normalized_size, :subauthority
19
+ private :full_graph, :filtered_graph, :language, :id, :uri, :access_time_s, :normalize_time_s, :fetched_size, :normalized_size, :subauthority
20
20
 
21
21
  delegate :term_subauthority?, :prefixes, :authority_name, to: :term_config
22
22
 
23
23
  # Find a single term in a linked data authority
24
24
  # @param [String] the id of the term to fetch
25
- # @param [Symbol] (optional) language: language used to select literals when multi-language is supported (e.g. :en, :fr, etc.)
26
- # @param [Hash] (optional) replacements: replacement values with { pattern_name (defined in YAML config) => value }
27
- # @param [String] subauth: the subauthority from which to fetch the term
28
- # @return [Hash] json results
25
+ # @param request_header [Hash] optional attributes that can be appended to the generated URL
26
+ # @option language [Symbol] language used to select literals when multi-language is supported (e.g. :en, :fr, etc.)
27
+ # @option replacements [Hash] replacement values with { pattern_name (defined in YAML config) => value }
28
+ # @option subauthority [String] the subauthority from which to fetch the term
29
+ # @option format [String] return data in this format
30
+ # @option performance_data [Boolean] true if include_performance_data should be returned with the results; otherwise, false (default: false)
31
+ # @note All parameters after request_header are deprecated and will be removed in the next major release.
32
+ # @return [Hash, String] normalized json results when format='json'; otherwise, serialized RDF in the requested format
29
33
  # @example Json Results for Linked Data Term
30
34
  # { "uri":"http://id.worldcat.org/fast/530369",
31
35
  # "id":"530369","label":"Cornell University",
@@ -39,13 +43,12 @@ module Qa::Authorities
39
43
  # "http://schema.org/name":["Cornell University","Ithaca (N.Y.). Cornell University"],
40
44
  # "http://www.w3.org/2004/02/skos/core#altLabel":["Ithaca (N.Y.). Cornell University"],
41
45
  # "http://schema.org/sameAs":["http://id.loc.gov/authorities/names/n79021621","https://viaf.org/viaf/126293486"] } }
42
- def find(id, language: nil, replacements: {}, subauth: nil, jsonld: false, performance_data: false) # rubocop:disable Metrics/ParameterLists
43
- raise Qa::InvalidLinkedDataAuthority, "Unable to initialize linked data term sub-authority #{subauth}" unless subauth.nil? || term_subauthority?(subauth)
44
- @language = language_service.preferred_language(user_language: language, authority_language: term_config.term_language)
46
+ def find(id, request_header: {}, language: nil, replacements: {}, subauth: nil, format: 'json', performance_data: false) # rubocop:disable Metrics/ParameterLists
47
+ request_header = build_request_header(language: language, replacements: replacements, subauth: subauth, format: format, performance_data: performance_data) if request_header.empty?
48
+ unpack_request_header(request_header)
49
+ raise Qa::InvalidLinkedDataAuthority, "Unable to initialize linked data term sub-authority #{subauthority}" unless subauthority.nil? || term_subauthority?(subauthority)
45
50
  @id = id
46
- @performance_data = performance_data
47
- @jsonld = jsonld
48
- url = authority_service.build_url(action_config: term_config, action: :term, action_request: normalize_id, substitutions: replacements, subauthority: subauth, language: @language)
51
+ url = authority_service.build_url(action_config: term_config, action: :term, action_request: normalize_id, request_header: request_header)
49
52
  Rails.logger.info "QA Linked Data term url: #{url}"
50
53
  load_graph(url: url)
51
54
  normalize_results
@@ -66,20 +69,22 @@ module Qa::Authorities
66
69
 
67
70
  def normalize_results
68
71
  normalize_start_dt = Time.now.utc
69
- normalize_end_dt = Time.now.utc
70
72
 
71
- json = perform_normalization
73
+ results = perform_normalization
72
74
 
75
+ normalize_end_dt = Time.now.utc
73
76
  @normalize_time_s = normalize_end_dt - normalize_start_dt
74
- @normalized_size = json.to_s.size if performance_data?
75
- Rails.logger.info("Time to convert data to json: #{normalize_time_s}s")
76
- json = append_performance_data(json) if performance_data?
77
- json
77
+ @normalized_size = results.to_s.size if performance_data?
78
+ Rails.logger.info("Time to normalize data: #{normalize_time_s}s")
79
+ results = append_performance_data(results) if performance_data?
80
+ results
78
81
  end
79
82
 
80
83
  def perform_normalization
81
84
  return "{}" unless full_graph.size.positive?
82
85
  return full_graph.dump(:jsonld, standard_prefixes: true) if jsonld?
86
+ return full_graph.dump(:n3, standard_prefixes: true) if n3?
87
+ return full_graph.dump(:ntriples, standard_prefixes: true) if ntriples?
83
88
 
84
89
  filter_graph
85
90
  extract_uri
@@ -87,6 +92,15 @@ module Qa::Authorities
87
92
  convert_results_to_json(results)
88
93
  end
89
94
 
95
+ def unpack_request_header(request_header)
96
+ @subauthority = request_header.fetch(:subauthority, nil)
97
+ @format = request_header.fetch(:format, 'json')
98
+ @performance_data = request_header.fetch(:performance_data, false)
99
+ @language = language_service.preferred_language(user_language: request_header.fetch(:user_language, nil),
100
+ authority_language: term_config.term_language)
101
+ request_header[:language] = Array(@language)
102
+ end
103
+
90
104
  def filter_graph
91
105
  @filtered_graph = graph_service.deep_copy(graph: @full_graph)
92
106
  @filtered_graph = graph_service.filter(graph: @filtered_graph, language: language) unless language.blank?
@@ -182,10 +196,20 @@ module Qa::Authorities
182
196
  opt_ldpaths.delete_if { |_k, v| v.blank? }
183
197
  end
184
198
 
199
+ # Give precedent to format parameter over jsonld parameter. NOTE: jsonld parameter for find method is deprecated.
185
200
  def jsonld?
201
+ return @format.casecmp?('jsonld') if @format
186
202
  @jsonld == true
187
203
  end
188
204
 
205
+ def n3?
206
+ @format && @format.casecmp?('n3')
207
+ end
208
+
209
+ def ntriples?
210
+ @format && @format.casecmp?('ntriples')
211
+ end
212
+
189
213
  def performance_data?
190
214
  @performance_data == true && !jsonld?
191
215
  end
@@ -270,6 +294,24 @@ module Qa::Authorities
270
294
  total_time_s: (access_time_s + normalize_time_s) }
271
295
  { performance: performance, results: results }
272
296
  end
297
+
298
+ # This is providing support for calling build_url with individual parameters instead of the request_header.
299
+ # This is deprecated and will be removed in the next major release.
300
+ def build_request_header(language:, replacements:, subauth:, format:, performance_data:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
301
+ unless language.blank? && replacements.blank? && subauth.blank? && format == 'json' && !performance_data
302
+ Qa.deprecation_warning(
303
+ in_msg: 'Qa::Authorities::LinkedData::FindTerm',
304
+ msg: "individual attributes for options (e.g. replacements, subauth, language) are deprecated; use request_header instead"
305
+ )
306
+ end
307
+ request_header = {}
308
+ request_header[:replacements] = replacements || {}
309
+ request_header[:subauthority] = subauth || nil
310
+ request_header[:language] = language || nil
311
+ request_header[:format] = format || 'json'
312
+ request_header[:performance_data] = performance_data
313
+ request_header
314
+ end
273
315
  end
274
316
  end
275
317
  end
@@ -15,29 +15,30 @@ module Qa::Authorities
15
15
  @search_config = search_config
16
16
  end
17
17
 
18
- attr_reader :search_config, :full_graph, :filtered_graph, :language, :access_time_s, :normalize_time_s, :fetched_size, :normalized_size
19
- private :full_graph, :filtered_graph, :language, :access_time_s, :normalize_time_s, :fetched_size, :normalized_size
18
+ attr_reader :search_config, :full_graph, :filtered_graph, :language, :access_time_s, :normalize_time_s, :fetched_size, :normalized_size, :subauthority
19
+ private :full_graph, :filtered_graph, :language, :access_time_s, :normalize_time_s, :fetched_size, :normalized_size, :subauthority
20
20
 
21
21
  delegate :subauthority?, :supports_sort?, :prefixes, :authority_name, to: :search_config
22
22
 
23
23
  # Search a linked data authority
24
24
  # @praram [String] the query
25
- # @param language [Symbol] (optional) language used to select literals when multi-language is supported (e.g. :en, :fr, etc.)
26
- # @param replacements [Hash] (optional) replacement values with { pattern_name (defined in YAML config) => value }
27
- # @param subauth [String] (optional) the subauthority to query
28
- # @param context [Boolean] (optional) true if context should be returned with the results; otherwise, false (default: false)
29
- # @param performance_data [Boolean] (optional) true if include_performance_data should be returned with the results; otherwise, false (default: false)
25
+ # @param request_header [Hash] optional attributes that can be appended to the generated URL
26
+ # @option language [Symbol] language used to select literals when multi-language is supported (e.g. :en, :fr, etc.)
27
+ # @option replacements [Hash] replacement values with { pattern_name (defined in YAML config) => value }
28
+ # @option subauthority [String] the subauthority to query
29
+ # @option context [Boolean] true if context should be returned with the results; otherwise, false (default: false)
30
+ # @option performance_data [Boolean] true if include_performance_data should be returned with the results; otherwise, false (default: false)
30
31
  # @return [String] json results
32
+ # @note All parameters after request_header are deprecated and will be removed in the next major release.
31
33
  # @example Json Results for Linked Data Search
32
34
  # [ {"uri":"http://id.worldcat.org/fast/5140","id":"5140","label":"Cornell, Joseph"},
33
35
  # {"uri":"http://id.worldcat.org/fast/72456","id":"72456","label":"Cornell, Sarah Maria, 1802-1832"},
34
36
  # {"uri":"http://id.worldcat.org/fast/409667","id":"409667","label":"Cornell, Ezra, 1807-1874"} ]
35
- def search(query, language: nil, replacements: {}, subauth: nil, context: false, performance_data: false) # rubocop:disable Metrics/ParameterLists
36
- raise Qa::InvalidLinkedDataAuthority, "Unable to initialize linked data search sub-authority #{subauth}" unless subauth.nil? || subauthority?(subauth)
37
- @context = context
38
- @performance_data = performance_data
39
- @language = language_service.preferred_language(user_language: language, authority_language: search_config.language)
40
- url = authority_service.build_url(action_config: search_config, action: :search, action_request: query, substitutions: replacements, subauthority: subauth, language: @language)
37
+ def search(query, request_header: {}, language: nil, replacements: {}, subauth: nil, context: false, performance_data: false) # rubocop:disable Metrics/ParameterLists
38
+ request_header = build_request_header(language: language, replacements: replacements, subauth: subauth, context: context, performance_data: performance_data) if request_header.empty?
39
+ unpack_request_header(request_header)
40
+ raise Qa::InvalidLinkedDataAuthority, "Unable to initialize linked data search sub-authority #{subauthority}" unless subauthority.nil? || subauthority?(subauthority)
41
+ url = authority_service.build_url(action_config: search_config, action: :search, action_request: query, request_header: request_header)
41
42
  Rails.logger.info "QA Linked Data search url: #{url}"
42
43
  load_graph(url: url)
43
44
  normalize_results
@@ -66,7 +67,7 @@ module Qa::Authorities
66
67
  normalize_end_dt = Time.now.utc
67
68
  @normalize_time_s = normalize_end_dt - normalize_start_dt
68
69
  @normalized_size = json.to_s.size if performance_data?
69
- Rails.logger.info("Time to convert data to json: #{normalize_time_s}s")
70
+ Rails.logger.info("Time to normalize data: #{normalize_time_s}s")
70
71
  json = append_performance_data(json) if performance_data?
71
72
  json
72
73
  end
@@ -87,7 +88,16 @@ module Qa::Authorities
87
88
 
88
89
  results_mapper_service.map_values(graph: filtered_graph, prefixes: prefixes, ldpath_map: ldpath_map,
89
90
  predicate_map: predicate_map, sort_key: :sort,
90
- preferred_language: @language, context_map: context_map)
91
+ preferred_language: language, context_map: context_map)
92
+ end
93
+
94
+ def unpack_request_header(request_header)
95
+ @subauthority = request_header.fetch(:subauthority, nil)
96
+ @context = request_header.fetch(:context, false)
97
+ @performance_data = request_header.fetch(:performance_data, false)
98
+ @language = language_service.preferred_language(user_language: request_header.fetch(:user_language, nil),
99
+ authority_language: search_config.language)
100
+ request_header[:language] = Array(@language)
91
101
  end
92
102
 
93
103
  def context_map
@@ -180,6 +190,24 @@ module Qa::Authorities
180
190
  total_time_s: (access_time_s + normalize_time_s) }
181
191
  { performance: performance, results: results }
182
192
  end
193
+
194
+ # This is providing support for calling build_url with individual parameters instead of the request_header.
195
+ # This is deprecated and will be removed in the next major release.
196
+ def build_request_header(language:, replacements:, subauth:, context:, performance_data:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
197
+ unless language.blank? && replacements.blank? && subauth.blank? && !context && !performance_data
198
+ Qa.deprecation_warning(
199
+ in_msg: 'Qa::Authorities::LinkedData::SearchQuery',
200
+ msg: "individual attributes for options (e.g. replacements, subauth, language) are deprecated; use request_header instead"
201
+ )
202
+ end
203
+ request_header = {}
204
+ request_header[:replacements] = replacements || {}
205
+ request_header[:subauthority] = subauth || nil
206
+ request_header[:language] = language || nil
207
+ request_header[:context] = context
208
+ request_header[:performance_data] = performance_data
209
+ request_header
210
+ end
183
211
  end
184
212
  end
185
213
  end
@@ -26,7 +26,7 @@ module Qa::Authorities
26
26
  def build_query_url(q)
27
27
  escaped_query = ERB::Util.url_encode(q)
28
28
  authority_fragment = Loc.get_url_for_authority(subauthority) + ERB::Util.url_encode(subauthority)
29
- "http://id.loc.gov/search/?q=#{escaped_query}&q=#{authority_fragment}&format=json"
29
+ "https://id.loc.gov/search/?q=#{escaped_query}&q=#{authority_fragment}&format=json"
30
30
  end
31
31
 
32
32
  def find(id)
@@ -34,7 +34,7 @@ module Qa::Authorities
34
34
  end
35
35
 
36
36
  def find_url(id)
37
- "http://id.loc.gov/authorities/#{@subauthority}/#{id}.json"
37
+ "https://id.loc.gov/authorities/#{@subauthority}/#{id}.json"
38
38
  end
39
39
 
40
40
  private
@@ -1,3 +1,3 @@
1
1
  module Qa
2
- VERSION = "4.2.0".freeze
2
+ VERSION = "4.3.0".freeze
3
3
  end
@@ -425,6 +425,24 @@ describe Qa::LinkedDataTermsController, type: :controller do
425
425
  expect(JSON.parse(response.body).keys).to match_array ["@context", "@graph"]
426
426
  end
427
427
  end
428
+
429
+ context 'and it was requested as n3' do
430
+ it 'succeeds and returns term data as n3 content type' do
431
+ get :show, params: { id: '530369', vocab: 'OCLC_FAST', format: 'n3' }
432
+ expect(response).to be_successful
433
+ expect(response.content_type).to eq 'text/n3'
434
+ expect(response.body).to start_with "@prefix"
435
+ end
436
+ end
437
+
438
+ context 'and it was requested as ntriples' do
439
+ it 'succeeds and returns term data as ntriples content type' do
440
+ get :show, params: { id: '530369', vocab: 'OCLC_FAST', format: 'ntriples' }
441
+ expect(response).to be_successful
442
+ expect(response.content_type).to eq 'application/n-triples'
443
+ expect(response.body).to include('<http://id.worldcat.org/fast/530369> <http://www.w3.org/2004/02/skos/core#prefLabel> "Cornell University"')
444
+ end
445
+ end
428
446
  end
429
447
 
430
448
  context 'when cors headers are enabled' do
@@ -587,6 +605,24 @@ describe Qa::LinkedDataTermsController, type: :controller do
587
605
  end
588
606
  end
589
607
 
608
+ context 'and it was requested as n3' do
609
+ it 'succeeds and returns term data as n3 content type' do
610
+ get :fetch, params: { uri: 'http://id.worldcat.org/fast/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG', format: 'n3' }
611
+ expect(response).to be_successful
612
+ expect(response.content_type).to eq 'text/n3'
613
+ expect(response.body).to start_with "@prefix"
614
+ end
615
+ end
616
+
617
+ context 'and it was requested as ntriples' do
618
+ it 'succeeds and returns term data as ntriples content type' do
619
+ get :fetch, params: { uri: 'http://id.worldcat.org/fast/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG', format: 'ntriples' }
620
+ expect(response).to be_successful
621
+ expect(response.content_type).to eq 'application/n-triples'
622
+ expect(response.body).to include('<http://id.worldcat.org/fast/530369> <http://www.w3.org/2004/02/skos/core#prefLabel> "Cornell University"')
623
+ end
624
+ end
625
+
590
626
  context 'blank nodes not included in predicates list' do
591
627
  before do
592
628
  stub_request(:get, 'http://localhost/test_default/term?uri=http://id.worldcat.org/fast/530369wbn')
@@ -82,7 +82,7 @@ describe Qa::TermsController, type: :controller do
82
82
 
83
83
  context "loc" do
84
84
  before do
85
- stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
85
+ stub_request(:get, "https://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
86
86
  .with(headers: { 'Accept' => 'application/json' })
87
87
  .to_return(body: webmock_fixture("loc-names-response.txt"), status: 200)
88
88
  end
@@ -188,7 +188,7 @@ describe Qa::TermsController, type: :controller do
188
188
  describe "#show" do
189
189
  context "with supported authorities" do
190
190
  before do
191
- stub_request(:get, "http://id.loc.gov/authorities/subjects/sh85077565.json")
191
+ stub_request(:get, "https://id.loc.gov/authorities/subjects/sh85077565.json")
192
192
  .with(headers: { 'Accept' => 'application/json' })
193
193
  .to_return(status: 200, body: webmock_fixture("loc-names-response.txt"), headers: {})
194
194
  end
@@ -228,5 +228,29 @@ describe Qa::TermsController, type: :controller do
228
228
  end
229
229
  end
230
230
  end
231
+ context "with request for n3" do
232
+ before do
233
+ stub_request(:get, "https://api.discogs.com/releases/3380671")
234
+ .to_return(status: 200, body: webmock_fixture("discogs-find-response-json.json"))
235
+ end
236
+ it 'Access-Control-Allow-Origin is not present' do
237
+ get :show, params: { vocab: "discogs", subauthority: "release", id: "3380671", format: 'n3' }
238
+ expect(response).to be_successful
239
+ expect(response.content_type).to eq 'text/n3'
240
+ expect(response.body).to start_with "@prefix"
241
+ end
242
+ end
243
+ context "with request for ntriples" do
244
+ before do
245
+ stub_request(:get, "https://api.discogs.com/releases/3380671")
246
+ .to_return(status: 200, body: webmock_fixture("discogs-find-response-json.json"))
247
+ end
248
+ it 'Access-Control-Allow-Origin is not present' do
249
+ get :show, params: { vocab: "discogs", subauthority: "release", id: "3380671", format: 'ntriples' }
250
+ expect(response).to be_successful
251
+ expect(response.content_type).to eq 'application/n-triples'
252
+ expect(response.body).to include('_:agentn1 <http://www.w3.org/2000/01/rdf-schema#label> "Dexter Gordon"')
253
+ end
254
+ end
231
255
  end
232
256
  end
@@ -1 +1 @@
1
- {"status":"Accepted","series":[],"labels":[{"name":"Blue Note"}],"year":1962,"artists":[{"name":"Dexter Gordon"}],"id":3380671,"genres":["Jazz"],"title":"A Swingin' Affair","styles":["Hard Bop"],"formats":[{"qty":"1","descriptions":["LP","Album","Mono"],"name":"Vinyl"}]}
1
+ {"status":"Accepted","series":[],"labels":[{"name":"Blue Note"}],"year":1962,"artists":[{"name":"Dexter Gordon"}],"id":3380671,"genres":["Jazz"],"title":"A Swingin' Affair","styles":["Hard Bop"],"formats":[{"qty":"1","descriptions":["LP","Album","Mono"],"name":"Vinyl"}],"uri":"https://www.discogs.com/Dexter-Gordon-A-Swingin-Affair/release/3380671","resource_url":"https://api.discogs.com/releases/3380671"}
@@ -136,6 +136,50 @@ describe Qa::Authorities::Discogs::GenericAuthority do
136
136
  end
137
137
  end
138
138
 
139
+ context "n3 format and subauthority master" do
140
+ let(:tc) { instance_double(Qa::TermsController) }
141
+ let :results do
142
+ authority.find("950011", tc)
143
+ end
144
+ before do
145
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
146
+ allow(tc).to receive(:params).and_return('format' => "n3", 'subauthority' => "master")
147
+ end
148
+
149
+ it "returns the Discogs data converted to n3 for a given id" do
150
+ expect(results).to start_with "@prefix"
151
+ expect(results).to include("Blue Moon / You Go To My Head")
152
+ expect(results).to include("Billie Holiday And Her Orchestra")
153
+ expect(results).to include("Haven Gillespie")
154
+ expect(results).to include("1952")
155
+ expect(results).to include("Jazz")
156
+ expect(results).to include("Barney Kessel")
157
+ expect(results).to include("Guitar")
158
+ end
159
+ end
160
+
161
+ context "ntriples format and subauthority master" do
162
+ let(:tc) { instance_double(Qa::TermsController) }
163
+ let :results do
164
+ authority.find("950011", tc)
165
+ end
166
+ before do
167
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
168
+ allow(tc).to receive(:params).and_return('format' => "ntriples", 'subauthority' => "master")
169
+ end
170
+
171
+ it "returns the Discogs data converted to ntriples for a given id" do
172
+ expect(results).to include("https://www.discogs.com/Billie-Holiday-And-Her-Orchestra-Blue-Moon-You-Go-To-My-Head/master/950011")
173
+ expect(results).to include("Blue Moon / You Go To My Head")
174
+ expect(results).to include("Billie Holiday And Her Orchestra")
175
+ expect(results).to include("Haven Gillespie")
176
+ expect(results).to include("1952")
177
+ expect(results).to include("Jazz")
178
+ expect(results).to include("Barney Kessel")
179
+ expect(results).to include("Guitar")
180
+ end
181
+ end
182
+
139
183
  context "json-ld format and subauthority all" do
140
184
  let(:tc) { instance_double(Qa::TermsController) }
141
185
  let :results do
@@ -161,6 +205,56 @@ describe Qa::Authorities::Discogs::GenericAuthority do
161
205
  expect(results).to include("1952")
162
206
  end
163
207
  end
208
+
209
+ context "n3 format and subauthority all" do
210
+ let(:tc) { instance_double(Qa::TermsController) }
211
+ let :results do
212
+ authority.find("7143179", tc)
213
+ end
214
+ before do
215
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
216
+ allow(tc).to receive(:params).and_return('format' => "n3", 'subauthority' => "all")
217
+ end
218
+
219
+ it "returns the Discogs data converted to n3 for a given id" do
220
+ expect(results).to start_with "@prefix"
221
+ expect(results).to include("You Go To My Head")
222
+ expect(results).to include("Rodgers & Hart")
223
+ expect(results).to include("Ray Brown")
224
+ expect(results).to include("1952")
225
+ expect(results).to include("Single")
226
+ expect(results).to include("mono")
227
+ expect(results).to include("45 RPM")
228
+ expect(results).to include("Vinyl")
229
+ expect(results).to include("http://id.loc.gov/vocabulary/carriers/sd")
230
+ expect(results).to include("1952")
231
+ end
232
+ end
233
+
234
+ context "ntriples format and subauthority all" do
235
+ let(:tc) { instance_double(Qa::TermsController) }
236
+ let :results do
237
+ authority.find("7143179", tc)
238
+ end
239
+ before do
240
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
241
+ allow(tc).to receive(:params).and_return('format' => "ntriples", 'subauthority' => "all")
242
+ end
243
+
244
+ it "returns the Discogs data converted to ntriples for a given id" do
245
+ expect(results).to include("https://www.discogs.com/Billie-Holiday-And-Her-Orchestra-Blue-Moon-You-Go-To-My-Head/release/7143179")
246
+ expect(results).to include("You Go To My Head")
247
+ expect(results).to include("Rodgers & Hart")
248
+ expect(results).to include("Ray Brown")
249
+ expect(results).to include("1952")
250
+ expect(results).to include("Single")
251
+ expect(results).to include("mono")
252
+ expect(results).to include("45 RPM")
253
+ expect(results).to include("Vinyl")
254
+ expect(results).to include("http://id.loc.gov/vocabulary/carriers/sd")
255
+ expect(results).to include("1952")
256
+ end
257
+ end
164
258
  end
165
259
  end
166
260
 
@@ -179,13 +273,13 @@ describe Qa::Authorities::Discogs::GenericAuthority do
179
273
  end
180
274
 
181
275
  it "has id and label keys" do
182
- expect(results.first["uri"]).to eq("https://api.discogs.com/releases/1750352")
276
+ expect(results.first["uri"]).to eq("https://www.discogs.com/Melody-Gardot-Who-Will-Comfort-Me-Over-The-Rainbow/release/1750352")
183
277
  expect(results.first["id"]).to eq "1750352"
184
278
  expect(results.first["label"]).to eq "Melody Gardot - Who Will Comfort Me / Over The Rainbow"
185
- expect(results.first["context"]["Year"]).to eq ['2009']
186
- expect(results.first["context"]["Formats"][0]).to eq "Vinyl"
187
- expect(results.first["context"]["Record Labels"][1]).to eq "Universal Music Classics & Jazz"
188
- expect(results.first["context"]["Type"][0]).to eq "release"
279
+ expect(results.first["context"][1]["values"]).to eq ["2009"]
280
+ expect(results.first["context"][3]["values"][0]).to eq "Vinyl"
281
+ expect(results.first["context"][2]["values"][1]).to eq "Universal Music Classics & Jazz"
282
+ expect(results.first["context"][4]["values"][0]).to eq "release"
189
283
  end
190
284
  end
191
285
 
@@ -202,12 +296,12 @@ describe Qa::Authorities::Discogs::GenericAuthority do
202
296
  end
203
297
 
204
298
  it "has id and label keys" do
205
- expect(results.first['uri']).to eq "https://api.discogs.com/masters/606116"
299
+ expect(results.first['uri']).to eq "https://www.discogs.com/Wes-Montgomery-Bumpin-On-Sunset-Tequila/master/606116"
206
300
  expect(results.first['id']).to eq "606116"
207
301
  expect(results.first['label']).to eq "Wes Montgomery - Bumpin' On Sunset / Tequila"
208
- expect(results.first['context']["Year"]).to eq ['1966']
209
- expect(results.first['context']["Formats"][2]).to eq "45 RPM"
210
- expect(results.first["context"]["Type"][0]).to eq "master"
302
+ expect(results.first['context'][1]["values"]).to eq ['1966']
303
+ expect(results.first['context'][3]["values"][2]).to eq "45 RPM"
304
+ expect(results.first["context"][4]["values"][0]).to eq "master"
211
305
  end
212
306
  end
213
307