hydra-core 9.1.4 → 9.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69ff56b294572d8de6e686ecb7e4c274fdcaf252
4
- data.tar.gz: fd967b9d4e4fc4b3b10cad811fbd0c347d1f3d0f
3
+ metadata.gz: d6e3435905f64b4bf6e27a51cb61fc02330ca0d3
4
+ data.tar.gz: c7f0cdd9f12a3c861fbcb63dbe3fdae1cd7b3f71
5
5
  SHA512:
6
- metadata.gz: 2289b345f076b1842c84c960886e13b13c2da1cf74484a22dc759bd260363989afc3d9eeb4de308cac7e653a5a54114cc3d8d3c5aa2c80a7f59ff0ef1370946f
7
- data.tar.gz: 36834aa5e956262eaa42975fdacae63a149a01b19644b604fccb5ea296f553d5f3f59b78fcc86f1c0290775db8f4c5900e81c7806b42f6cd3222c70d029d3af0
6
+ metadata.gz: e18e4a744f432ede748ae76b03322dd8c5cfea4b45bd94e71aac04139a2e5f337269e5fad6da231d8d62a57f8ec35ef1418e5eedde85637a97f83cb35f36907b
7
+ data.tar.gz: 28d836045c044883875bc362278a8fdea7f5453503c327cfb0ab30e02e466ee34529135f0415b61b737c72c2b06d7159009ea4b7309ee7b5c5777016461e7dd9
@@ -25,12 +25,12 @@ module Hydra::Controller::ControllerBehavior
25
25
  # Override this method if you wish to customize the way access is denied
26
26
  def deny_access(exception)
27
27
  if exception.action == :edit
28
- redirect_to({ action: 'show' }, alert: exception.message)
28
+ redirect_to(main_app.url_for(action: 'show'), alert: exception.message)
29
29
  elsif current_user and current_user.persisted?
30
- redirect_to root_path, alert: exception.message
30
+ redirect_to main_app.root_path, alert: exception.message
31
31
  else
32
32
  session['user_return_to'.freeze] = request.url
33
- redirect_to new_user_session_path, alert: exception.message
33
+ redirect_to main_app.new_user_session_path, alert: exception.message
34
34
  end
35
35
  end
36
36
 
@@ -0,0 +1,35 @@
1
+ module Hydra
2
+ module ContentNegotiation
3
+ def self.extended(document)
4
+ document.will_export_as(:nt, "application/n-triples")
5
+ document.will_export_as(:jsonld, "application/json")
6
+ document.will_export_as(:ttl, "text/turtle")
7
+ end
8
+
9
+ def export_as_nt
10
+ clean_graph.dump(:ntriples)
11
+ end
12
+
13
+ def export_as_jsonld
14
+ clean_graph.dump(:jsonld, :standard_prefixes => true)
15
+ end
16
+
17
+ def export_as_ttl
18
+ clean_graph.dump(:ttl)
19
+ end
20
+
21
+ private
22
+
23
+ def clean_graph
24
+ @clean_graph ||= clean_graph_repository.find(id)
25
+ end
26
+
27
+ def clean_graph_repository
28
+ CleanGraphRepository.new(connection)
29
+ end
30
+
31
+ def connection
32
+ ActiveFedora.fedora.clean_connection
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ module Hydra::ContentNegotiation
2
+ # CleanGraphRepository has a #find interface which returns a graph for use
3
+ # with content negotiation.
4
+ class CleanGraphRepository
5
+ attr_reader :connection
6
+ def initialize(connection)
7
+ @connection = connection
8
+ end
9
+
10
+ def find(id)
11
+ ReplacingGraphFinder.new(
12
+ GraphFinder.new(connection, id)
13
+ ).graph
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,46 @@
1
+ module Hydra::ContentNegotiation
2
+ # Replaces Fedora URIs in a graph with a Hydra-configured alternative.
3
+ class FedoraUriReplacer
4
+ def initialize(fedora_base_uri, graph)
5
+ @fedora_base_uri = fedora_base_uri
6
+ @graph = graph
7
+ end
8
+
9
+ def run
10
+ RDF::Graph.new.insert(*replaced_objects)
11
+ end
12
+
13
+ private
14
+
15
+ attr_reader :fedora_base_uri, :graph
16
+
17
+ def replace_uri(uri)
18
+ id = ActiveFedora::Base.uri_to_id(uri)
19
+ RDF::URI(Hydra.config.id_to_resource_uri.call(id))
20
+ end
21
+
22
+ def replaced_objects
23
+ replaced_subjects.map do |statement|
24
+ if fedora_uri?(statement.object)
25
+ RDF::Statement.from([statement.subject, statement.predicate, replace_uri(statement.object)])
26
+ else
27
+ statement
28
+ end
29
+ end
30
+ end
31
+
32
+ def fedora_uri?(subject)
33
+ subject.to_s.start_with?(fedora_base_uri.to_s)
34
+ end
35
+
36
+ def replaced_subjects
37
+ graph.each_statement.to_a.map do |s|
38
+ if fedora_uri?(s.subject)
39
+ RDF::Statement.from([replace_uri(s.subject), s.predicate, s.object])
40
+ else
41
+ s
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ module Hydra::ContentNegotiation
2
+ # Finds a graph given a connection and ID.
3
+ class GraphFinder
4
+ attr_reader :connection, :id
5
+ def initialize(connection, id)
6
+ @connection = connection
7
+ @id = id
8
+ end
9
+
10
+ def graph
11
+ connection.get(uri).graph
12
+ end
13
+
14
+ def uri
15
+ ActiveFedora::Base.id_to_uri(id)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ module Hydra::ContentNegotiation
2
+ # Decorator for Finder which replaces Fedora subjects in the graph with a
3
+ # configured URI
4
+ class ReplacingGraphFinder < SimpleDelegator
5
+ def graph
6
+ graph_replacer.run
7
+ end
8
+
9
+ private
10
+
11
+ def graph_replacer
12
+ ::Hydra::ContentNegotiation::FedoraUriReplacer.new(base_uri, __getobj__.graph)
13
+ end
14
+
15
+ def base_uri
16
+ @base_uri ||= uri.gsub(/#{id}$/,'')
17
+ end
18
+ end
19
+ end
data/hydra-core.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency "rails", '~> 4.0'
22
22
  gem.add_dependency 'hydra-access-controls', version
23
23
  gem.add_dependency 'jettywrapper', '>= 2.0.0'
24
+ gem.add_dependency 'active-fedora', '~> 9.1'
24
25
 
25
26
  gem.add_development_dependency 'sqlite3', '~> 1.3'
26
27
  gem.add_development_dependency 'yard', '~> 0.8.7'
@@ -76,6 +76,25 @@ module Hydra
76
76
  copy_file 'config/blacklight.yml', force: true
77
77
  end
78
78
 
79
+ def create_conneg_configuration
80
+ file_path = "config/initializers/mime_types.rb"
81
+ inject_into_file file_path, :before => /\Z/ do
82
+ "\nMime::Type.register \"application/n-triples\", :nt" +
83
+ "\nMime::Type.register \"application/json\", :jsonld" +
84
+ "\nMime::Type.register \"text/turtle\", :ttl"
85
+ end
86
+ end
87
+
88
+ def inject_solr_document_conneg
89
+ file_path = "app/models/solr_document.rb"
90
+ if File.exists?(file_path)
91
+ inject_into_file file_path, :before => /end\Z/ do
92
+ "\n # Do content negotiation for AF models. \n" +
93
+ "\n use_extension( Hydra::ContentNegotiation )\n"
94
+ end
95
+ end
96
+ end
97
+
79
98
  # Add Hydra behaviors to the user model
80
99
  def inject_hydra_user_behavior
81
100
  file_path = "app/models/#{model_name.underscore}.rb"
@@ -1,3 +1,3 @@
1
1
  module HydraHead
2
- VERSION = "9.1.4"
2
+ VERSION = "9.2.0.rc1"
3
3
  end
@@ -55,6 +55,70 @@ describe CatalogController do
55
55
  end
56
56
  end
57
57
 
58
+ describe "content negotiation" do
59
+ describe "show" do
60
+ before do
61
+ allow(controller).to receive(:enforce_show_permissions)
62
+ end
63
+ context "with no asset" do
64
+ it "should return a not found response code" do
65
+ get 'show', :id => "test", :format => :nt
66
+
67
+ expect(response).to be_not_found
68
+ end
69
+ end
70
+ context "with an asset" do
71
+ let(:type) { RDF::URI("http://example.org/example") }
72
+ let(:related_uri) { related.rdf_subject }
73
+ let(:asset) do
74
+ ActiveFedora::Base.create do |g|
75
+ g.resource << [g.rdf_subject, RDF::DC.title, "Test Title"]
76
+ g.resource << [g.rdf_subject, RDF.type, type]
77
+ g.resource << [g.rdf_subject, RDF::DC.isReferencedBy, related_uri]
78
+ end
79
+ end
80
+ let(:related) do
81
+ ActiveFedora::Base.create
82
+ end
83
+ it "should be able to negotiate jsonld" do
84
+ get 'show', :id => asset.id, :format => :jsonld
85
+
86
+ expect(response).to be_success
87
+ graph = RDF::Reader.for(:jsonld).new(response.body)
88
+ expect(graph.statements.to_a.length).to eq 3
89
+ end
90
+ it "should be able to negotiate ttl" do
91
+ get 'show', :id => asset.id, :format => :ttl
92
+
93
+ expect(response).to be_success
94
+ graph = RDF::Reader.for(:ttl).new(response.body)
95
+ expect(graph.statements.to_a.length).to eq 3
96
+ end
97
+ it "should return an n-triples graph with just the content put in" do
98
+ get 'show', :id => asset.id, :format => :nt
99
+
100
+ graph = RDF::Reader.for(:ntriples).new(response.body)
101
+ statements = graph.statements.to_a
102
+ expect(statements.length).to eq 3
103
+ expect(statements.first.subject).to eq asset.rdf_subject
104
+ end
105
+ context "with a configured subject converter" do
106
+ before do
107
+ Hydra.config.id_to_resource_uri = lambda { |id| "http://hydra.box/catalog/#{id}" }
108
+ get 'show', :id => asset.id, :format => :nt
109
+ end
110
+ it "should convert it" do
111
+ graph = RDF::Graph.new << RDF::Reader.for(:ntriples).new(response.body)
112
+ title_statement = graph.query([nil, RDF::DC.title, nil]).first
113
+ related_statement = graph.query([nil, RDF::DC.isReferencedBy, nil]).first
114
+ expect(title_statement.subject).to eq RDF::URI("http://hydra.box/catalog/#{asset.id}")
115
+ expect(related_statement.object).to eq RDF::URI("http://hydra.box/catalog/#{related.id}")
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+
58
122
  describe "filters" do
59
123
  describe "show" do
60
124
  it "should trigger enforce_show_permissions" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.1.4
4
+ version: 9.2.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt, Bess Sadler, Julie Meloni, Naomi Dushay, Jessie Keck, John Scofield,
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-17 00:00:00.000000000 Z
12
+ date: 2015-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - '='
33
33
  - !ruby/object:Gem::Version
34
- version: 9.1.4
34
+ version: 9.2.0.rc1
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - '='
40
40
  - !ruby/object:Gem::Version
41
- version: 9.1.4
41
+ version: 9.2.0.rc1
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: jettywrapper
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: 2.0.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: active-fedora
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '9.1'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '9.1'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: sqlite3
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -127,9 +141,14 @@ files:
127
141
  - app/controllers/concerns/hydra/controller/search_builder.rb
128
142
  - app/helpers/blacklight_helper.rb
129
143
  - app/helpers/hydra/blacklight_helper_behavior.rb
144
+ - app/models/concerns/hydra/content_negotiation.rb
130
145
  - app/models/concerns/hydra/model_methods.rb
131
146
  - app/models/concerns/hydra/models.rb
132
147
  - app/models/concerns/hydra/solr.rb
148
+ - app/models/hydra/content_negotiation/clean_graph_repository.rb
149
+ - app/models/hydra/content_negotiation/fedora_uri_replacer.rb
150
+ - app/models/hydra/content_negotiation/graph_finder.rb
151
+ - app/models/hydra/content_negotiation/replacing_graph_finder.rb
133
152
  - app/models/hydra/datastream/properties.rb
134
153
  - app/search_builders/hydra/search_builder.rb
135
154
  - config/jetty.yml
@@ -189,12 +208,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
208
  version: 1.9.3
190
209
  required_rubygems_version: !ruby/object:Gem::Requirement
191
210
  requirements:
192
- - - ">="
211
+ - - ">"
193
212
  - !ruby/object:Gem::Version
194
- version: '0'
213
+ version: 1.3.1
195
214
  requirements: []
196
215
  rubyforge_project:
197
- rubygems_version: 2.4.5
216
+ rubygems_version: 2.4.8
198
217
  signing_key:
199
218
  specification_version: 4
200
219
  summary: Hydra-Head Rails Engine (requires Rails3)