active-fedora 6.0.0.rc6 → 6.0.0.rc7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/active-fedora.gemspec +1 -1
- data/lib/active_fedora.rb +1 -0
- data/lib/active_fedora/digital_object.rb +4 -7
- data/lib/active_fedora/indexing.rb +11 -42
- data/lib/active_fedora/solr_instance_loader.rb +93 -0
- data/lib/active_fedora/version.rb +1 -1
- data/spec/integration/rels_ext_datastream_spec.rb +3 -1
- data/spec/integration/solr_instance_loader_spec.rb +62 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 443c8f93ef41704da2c34752bb28a811ac9684ac
|
4
|
+
data.tar.gz: 925b1f309a57f0584e0fae33cb7a2785dde7166f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 573ea265ed95d54c703227de1622f6e037e5a42aa95bbedf253f703cdc927dca0efe888000c951c5aaf714dea9985e0adcaabc6477d3adb61bc0998ec5c03969
|
7
|
+
data.tar.gz: cd0df254f2b44148e9d9bf5656fb9e941c7c5d142b3f00ebcdd9f42ad3629af980907d83ccde2b7a9a6ccfb8e4942b805f860cd7d7713c097fc73222cfdc5f54
|
data/active-fedora.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_dependency("activesupport", '>= 3.0.0')
|
24
24
|
s.add_dependency("builder", '~> 3.0.0')
|
25
25
|
s.add_dependency("mediashelf-loggable")
|
26
|
-
s.add_dependency("rubydora", '~>1.
|
26
|
+
s.add_dependency("rubydora", '~>1.5')
|
27
27
|
s.add_dependency("rdf")
|
28
28
|
s.add_dependency("rdf-rdfxml", '~>1.0.0')
|
29
29
|
s.add_dependency("deprecation")
|
data/lib/active_fedora.rb
CHANGED
@@ -32,13 +32,10 @@ module ActiveFedora
|
|
32
32
|
|
33
33
|
def self.find(original_class, pid)
|
34
34
|
conn = original_class.connection_for_pid(pid)
|
35
|
-
obj =
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
# PID is nil
|
40
|
-
raise ActiveFedora::ObjectNotFoundError, "Unable to find '#{pid}' in fedora. See logger for details."
|
41
|
-
end
|
35
|
+
obj = begin
|
36
|
+
super(pid, conn)
|
37
|
+
rescue Rubydora::RecordNotFound
|
38
|
+
raise ActiveFedora::ObjectNotFoundError, "Unable to find '#{pid}' in fedora. See logger for details."
|
42
39
|
end
|
43
40
|
obj.original_class = original_class
|
44
41
|
# PID is not found, but was "well-formed" for its Fedora request. So
|
@@ -4,8 +4,8 @@ module ActiveFedora
|
|
4
4
|
|
5
5
|
# Return a Hash representation of this object where keys in the hash are appropriate Solr field names.
|
6
6
|
# @param [Hash] solr_doc (optional) Hash to insert the fields into
|
7
|
-
# @param [Hash] opts (optional)
|
8
|
-
# If opts[:model_only] == true, the base object metadata and the RELS-EXT datastream will be omitted. This is mainly to support shelver, which calls .to_solr for each model an object subscribes to.
|
7
|
+
# @param [Hash] opts (optional)
|
8
|
+
# If opts[:model_only] == true, the base object metadata and the RELS-EXT datastream will be omitted. This is mainly to support shelver, which calls .to_solr for each model an object subscribes to.
|
9
9
|
def to_solr(solr_doc = Hash.new, opts={})
|
10
10
|
unless opts[:model_only]
|
11
11
|
c_time = create_date
|
@@ -43,7 +43,7 @@ module ActiveFedora
|
|
43
43
|
self.datastreams.each_pair { |dsid,ds| profile_hash['datastreams'][dsid] = ds.solrize_profile }
|
44
44
|
solr_doc[self.class.profile_solr_name] = profile_hash.to_json
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
# Serialize the datastream's RDF relationships to solr
|
48
48
|
# @param [Hash] solr_doc @deafult an empty Hash
|
49
49
|
def solrize_relationships(solr_doc = Hash.new)
|
@@ -58,7 +58,7 @@ module ActiveFedora
|
|
58
58
|
|
59
59
|
# Updates Solr index with self.
|
60
60
|
def update_index
|
61
|
-
if defined?( Solrizer::Fedora::Solrizer )
|
61
|
+
if defined?( Solrizer::Fedora::Solrizer )
|
62
62
|
#logger.info("Trying to solrize pid: #{pid}")
|
63
63
|
solrizer = Solrizer::Fedora::Solrizer.new
|
64
64
|
solrizer.solrize( self )
|
@@ -70,63 +70,32 @@ module ActiveFedora
|
|
70
70
|
|
71
71
|
|
72
72
|
module ClassMethods
|
73
|
-
# This method can be used instead of ActiveFedora::Model::ClassMethods.find.
|
73
|
+
# This method can be used instead of ActiveFedora::Model::ClassMethods.find.
|
74
74
|
# It works similarly except it populates an object from Solr instead of Fedora.
|
75
75
|
# It is most useful for objects used in read-only displays in order to speed up loading time. If only
|
76
76
|
# a pid is passed in it will query solr for a corresponding solr document and then use it
|
77
77
|
# to populate this object.
|
78
|
-
#
|
78
|
+
#
|
79
79
|
# If a value is passed in for optional parameter solr_doc it will not query solr again and just use the
|
80
80
|
# one passed to populate the object.
|
81
81
|
#
|
82
82
|
# It will anything stored within solr such as metadata and relationships. Non-metadata datastreams will not
|
83
83
|
# be loaded and if needed you should use find instead.
|
84
84
|
def load_instance_from_solr(pid,solr_doc=nil)
|
85
|
-
|
86
|
-
result = find_with_conditions(:id=>pid)
|
87
|
-
raise ActiveFedora::ObjectNotFoundError, "Object #{pid} not found in solr" if result.empty?
|
88
|
-
solr_doc = result.first
|
89
|
-
#double check pid and id in record match
|
90
|
-
raise ActiveFedora::ObjectNotFoundError, "Object #{pid} not found in Solr" unless !result.nil? && !solr_doc.nil? && pid == solr_doc[SOLR_DOCUMENT_ID]
|
91
|
-
else
|
92
|
-
raise "Solr document record id and pid do not match" unless pid == solr_doc[SOLR_DOCUMENT_ID]
|
93
|
-
end
|
94
|
-
klass = if class_str = solr_doc[ActiveFedora::SolrService.solr_name('has_model', :symbol)]
|
95
|
-
ActiveFedora::SolrService.class_from_solr_document(solr_doc)
|
96
|
-
else
|
97
|
-
ActiveFedora::Base
|
98
|
-
end
|
99
|
-
|
100
|
-
profile_json = Array(solr_doc[ActiveFedora::Base.profile_solr_name]).first
|
101
|
-
unless profile_json.present?
|
102
|
-
raise ActiveFedora::ObjectNotFoundError, "Object #{pid} does not contain a solrized profile"
|
103
|
-
end
|
104
|
-
profile_hash = ActiveSupport::JSON.decode(profile_json)
|
105
|
-
obj = klass.allocate.init_with(SolrDigitalObject.new(solr_doc, profile_hash, klass))
|
106
|
-
#set by default to load any dependent relationship objects from solr as well
|
107
|
-
#need to call rels_ext once so it exists when iterating over datastreams
|
108
|
-
obj.rels_ext
|
109
|
-
obj.datastreams.each_value do |ds|
|
110
|
-
if ds.respond_to?(:profile_from_hash) and (ds_prof = profile_hash['datastreams'][ds.dsid])
|
111
|
-
ds.profile_from_hash(ds_prof)
|
112
|
-
end
|
113
|
-
ds.from_solr(solr_doc) if ds.respond_to?(:from_solr)
|
114
|
-
end
|
115
|
-
obj.inner_object.freeze
|
116
|
-
obj
|
85
|
+
SolrInstanceLoader.new(self, pid, solr_doc).object
|
117
86
|
end
|
118
|
-
|
119
|
-
# Using the fedora search (not solr), get every object and reindex it.
|
87
|
+
|
88
|
+
# Using the fedora search (not solr), get every object and reindex it.
|
120
89
|
def reindex_everything
|
121
90
|
connections.each do |conn|
|
122
91
|
conn.search(nil) do |object|
|
123
92
|
ActiveFedora::Base.find(object.pid, :cast=>true).update_index
|
124
93
|
end
|
125
94
|
end
|
126
|
-
end
|
95
|
+
end
|
127
96
|
|
128
97
|
private
|
129
|
-
|
98
|
+
|
130
99
|
def connections
|
131
100
|
if ActiveFedora.config.sharded?
|
132
101
|
return ActiveFedora.config.credentials.map { |cred| ActiveFedora::RubydoraConnection.new(cred).connection}
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module ActiveFedora
|
2
|
+
class FedoraSolrMismatchError < ActiveFedora::ObjectNotFoundError
|
3
|
+
def initialize(pid, solr_document_id)
|
4
|
+
super("Solr record id and pid do not match; Solr ID=#{solr_document_id}, PID=#{pid}")
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
# Responsible for loading an ActiveFedora::Base proxy from a Solr document.
|
9
|
+
class SolrInstanceLoader
|
10
|
+
attr_reader :context, :pid
|
11
|
+
private :context, :pid
|
12
|
+
def initialize(context, pid, solr_doc = nil)
|
13
|
+
@context = context
|
14
|
+
@pid = pid
|
15
|
+
@solr_doc = solr_doc
|
16
|
+
validate_solr_doc_and_pid!(@solr_doc)
|
17
|
+
end
|
18
|
+
|
19
|
+
def object
|
20
|
+
return @object if @object
|
21
|
+
@object = allocate_object
|
22
|
+
@object.rels_ext
|
23
|
+
load_object_datastreams(@object)
|
24
|
+
@object.inner_object.freeze
|
25
|
+
@object
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def allocate_object
|
31
|
+
active_fedora_class.allocate.init_with(solr_digital_object)
|
32
|
+
end
|
33
|
+
|
34
|
+
def solr_digital_object
|
35
|
+
SolrDigitalObject.new(solr_doc, profile_hash, active_fedora_class)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def load_object_datastreams(obj)
|
40
|
+
obj.datastreams.each_value do |ds|
|
41
|
+
if ds.respond_to?(:profile_from_hash) and (ds_prof = profile_hash['datastreams'][ds.dsid])
|
42
|
+
ds.profile_from_hash(ds_prof)
|
43
|
+
end
|
44
|
+
ds.from_solr(solr_doc) if ds.respond_to?(:from_solr)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def solr_doc
|
49
|
+
@solr_doc ||= begin
|
50
|
+
result = context.find_with_conditions(:id=>pid)
|
51
|
+
if result.empty?
|
52
|
+
raise ActiveFedora::ObjectNotFoundError, "Object #{pid} not found in solr"
|
53
|
+
end
|
54
|
+
@solr_doc = result.first
|
55
|
+
validate_solr_doc_and_pid!(@solr_doc)
|
56
|
+
@solr_doc
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_solr_doc_and_pid!(document)
|
61
|
+
return true if document.nil?
|
62
|
+
solr_id = document[SOLR_DOCUMENT_ID]
|
63
|
+
if pid != solr_id
|
64
|
+
raise ActiveFedora::FedoraSolrMismatchError.new(pid, solr_id)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def active_fedora_class
|
69
|
+
@active_fedora_class ||= begin
|
70
|
+
if solr_doc[ActiveFedora::SolrService.solr_name('has_model', :symbol)]
|
71
|
+
ActiveFedora::SolrService.class_from_solr_document(solr_doc)
|
72
|
+
else
|
73
|
+
ActiveFedora::Base
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def profile_json
|
79
|
+
@profile_json ||= begin
|
80
|
+
profile_json = Array(solr_doc[ActiveFedora::Base.profile_solr_name]).first
|
81
|
+
unless profile_json.present?
|
82
|
+
raise ActiveFedora::ObjectNotFoundError, "Object #{pid} does not contain a solrized profile"
|
83
|
+
end
|
84
|
+
profile_json
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def profile_hash
|
89
|
+
@profile_hash ||= ActiveSupport::JSON.decode(profile_json)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -74,7 +74,9 @@ describe ActiveFedora::RelsExtDatastream do
|
|
74
74
|
# make sure that _something_ was actually added to the object's relationships hash
|
75
75
|
@test_object.ids_for_outbound(:is_member_of).size.should == 1
|
76
76
|
new_rels = ActiveFedora::Base.find(@test_object.pid).relationships
|
77
|
-
|
77
|
+
# This stopped working, need to push an issue into the rdf library. (when dumping ntriples, the order of assertions changed)
|
78
|
+
#new_rels.should == @test_object.relationships
|
79
|
+
new_rels.dump(:rdfxml).should == @test_object.relationships.dump(:rdfxml)
|
78
80
|
end
|
79
81
|
|
80
82
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'active_fedora'
|
4
|
+
|
5
|
+
describe ActiveFedora::SolrInstanceLoader do
|
6
|
+
let(:context) { ActiveFedora::Base }
|
7
|
+
let(:pid) { nil }
|
8
|
+
let(:solr_doc) { nil }
|
9
|
+
let(:active_fedora_object) { ActiveFedora::Base.find(pid, :cast => true) }
|
10
|
+
subject { ActiveFedora::SolrInstanceLoader.new(context, pid, solr_doc) }
|
11
|
+
|
12
|
+
describe 'existing pid' do
|
13
|
+
let(:pid) { 'hydrangea:fixture_mods_article1' }
|
14
|
+
describe 'without a solr document' do
|
15
|
+
it 'it finds the SOLR document and casts into an AF::Base object' do
|
16
|
+
expect(subject.object).to eq(active_fedora_object)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
describe 'with matching solr document' do
|
20
|
+
let(:solr_doc) { ActiveFedora::Base.find_with_conditions(:id=>pid).first }
|
21
|
+
it 'it casts the SOLR document and casts into an AF::Base object' do
|
22
|
+
expect(subject.object).to eq(active_fedora_object)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
describe 'with a mismatching solr document' do
|
26
|
+
let(:mismatching_pid) { 'hydrangea:fixture_mods_article2' }
|
27
|
+
let(:solr_doc) { ActiveFedora::Base.find_with_conditions(:id=>mismatching_pid).first }
|
28
|
+
it 'it raise ObjectNotFoundError' do
|
29
|
+
expect {
|
30
|
+
subject
|
31
|
+
}.to raise_error(ActiveFedora::ObjectNotFoundError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
describe 'missing pid' do
|
36
|
+
let(:pid) { 'hydrangea:fixture_mods_article8675309' }
|
37
|
+
describe 'without a solr document' do
|
38
|
+
it 'it raise ObjectNotFoundError' do
|
39
|
+
expect {
|
40
|
+
subject.object
|
41
|
+
}.to raise_error(ActiveFedora::ObjectNotFoundError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
describe 'with matching solr document' do
|
45
|
+
let(:solr_doc) { ActiveFedora::Base.find_with_conditions(:id=>pid).first }
|
46
|
+
it 'it raise ObjectNotFoundError' do
|
47
|
+
expect {
|
48
|
+
subject.object
|
49
|
+
}.to raise_error(ActiveFedora::ObjectNotFoundError)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
describe 'with a mismatching solr document' do
|
53
|
+
let(:mismatching_pid) { 'hydrangea:fixture_mods_article2' }
|
54
|
+
let(:solr_doc) { ActiveFedora::Base.find_with_conditions(:id=>mismatching_pid).first }
|
55
|
+
it 'it raise ObjectNotFoundError' do
|
56
|
+
expect {
|
57
|
+
subject
|
58
|
+
}.to raise_error(ActiveFedora::ObjectNotFoundError)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-fedora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.0.
|
4
|
+
version: 6.0.0.rc7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Zumwalt
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-03-
|
13
|
+
date: 2013-03-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rsolr
|
@@ -130,14 +130,14 @@ dependencies:
|
|
130
130
|
requirements:
|
131
131
|
- - ~>
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: '1.
|
133
|
+
version: '1.5'
|
134
134
|
type: :runtime
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
137
|
requirements:
|
138
138
|
- - ~>
|
139
139
|
- !ruby/object:Gem::Version
|
140
|
-
version: '1.
|
140
|
+
version: '1.5'
|
141
141
|
- !ruby/object:Gem::Dependency
|
142
142
|
name: rdf
|
143
143
|
requirement: !ruby/object:Gem::Requirement
|
@@ -392,6 +392,7 @@ files:
|
|
392
392
|
- lib/active_fedora/service_definitions.rb
|
393
393
|
- lib/active_fedora/simple_datastream.rb
|
394
394
|
- lib/active_fedora/solr_digital_object.rb
|
395
|
+
- lib/active_fedora/solr_instance_loader.rb
|
395
396
|
- lib/active_fedora/solr_service.rb
|
396
397
|
- lib/active_fedora/test_support.rb
|
397
398
|
- lib/active_fedora/unsaved_digital_object.rb
|
@@ -459,6 +460,7 @@ files:
|
|
459
460
|
- spec/integration/persistence_spec.rb
|
460
461
|
- spec/integration/rels_ext_datastream_spec.rb
|
461
462
|
- spec/integration/scoped_query_spec.rb
|
463
|
+
- spec/integration/solr_instance_loader_spec.rb
|
462
464
|
- spec/integration/solr_service_spec.rb
|
463
465
|
- spec/rails3_test_app/.gitignore
|
464
466
|
- spec/rails3_test_app/.rspec
|
@@ -619,6 +621,7 @@ test_files:
|
|
619
621
|
- spec/integration/persistence_spec.rb
|
620
622
|
- spec/integration/rels_ext_datastream_spec.rb
|
621
623
|
- spec/integration/scoped_query_spec.rb
|
624
|
+
- spec/integration/solr_instance_loader_spec.rb
|
622
625
|
- spec/integration/solr_service_spec.rb
|
623
626
|
- spec/rails3_test_app/.gitignore
|
624
627
|
- spec/rails3_test_app/.rspec
|