active-fedora 4.1.0 → 4.2.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.
- data/.rvmrc +1 -1
- data/Gemfile +10 -2
- data/Gemfile.lock +53 -27
- data/History.txt +22 -1
- data/README.textile +2 -2
- data/active-fedora.gemspec +3 -3
- data/config/predicate_mappings.yml +2 -0
- data/lib/active_fedora/associations/belongs_to_association.rb +2 -6
- data/lib/active_fedora/base.rb +44 -7
- data/lib/active_fedora/datastreams.rb +15 -13
- data/lib/active_fedora/model.rb +76 -51
- data/lib/active_fedora/rdf_datastream.rb +56 -26
- data/lib/active_fedora/semantic_node.rb +9 -0
- data/lib/active_fedora/unsaved_digital_object.rb +6 -0
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora_dev.rake +11 -2
- data/spec/integration/associations_spec.rb +17 -0
- data/spec/integration/base_spec.rb +87 -36
- data/spec/integration/datastream_spec.rb +29 -0
- data/spec/integration/ntriples_datastream_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/mock_fedora.rb +6 -2
- data/spec/unit/base_spec.rb +55 -40
- data/spec/unit/datastreams_spec.rb +6 -2
- data/spec/unit/model_spec.rb +106 -60
- data/spec/unit/ntriples_datastream_spec.rb +85 -7
- data/spec/unit/semantic_node_spec.rb +17 -3
- data/spec/unit/unsaved_digital_object_spec.rb +9 -0
- metadata +272 -173
data/.rvmrc
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
4
|
# development environment upon cd'ing into the directory
|
5
5
|
|
6
|
-
ruby_string="1.9.3-
|
6
|
+
ruby_string="1.9.3-p194"
|
7
7
|
gemset_name="active_fedora_4.0"
|
8
8
|
|
9
9
|
# Install rubies when used instead of only displaying a warning and exiting
|
data/Gemfile
CHANGED
@@ -4,5 +4,13 @@ source "http://rubygems.org"
|
|
4
4
|
|
5
5
|
gemspec
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
group :development, :test do
|
8
|
+
gem 'ruby-debug', :platform => :ruby_18
|
9
|
+
# gem 'debugger', :platform => :ruby_19
|
10
|
+
|
11
|
+
gem 'rcov', :platform => :mri_18
|
12
|
+
gem 'simplecov', :platform => :mri_19
|
13
|
+
gem 'simplecov-rcov', :platform => :mri_19
|
14
|
+
end
|
15
|
+
|
16
|
+
gem 'jruby-openssl', :platform=> :jruby
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active-fedora (4.
|
4
|
+
active-fedora (4.2.0)
|
5
5
|
activeresource (>= 3.0.0)
|
6
6
|
activesupport (>= 3.0.0)
|
7
7
|
equivalent-xml
|
@@ -11,9 +11,9 @@ PATH
|
|
11
11
|
nokogiri
|
12
12
|
om (~> 1.6.0)
|
13
13
|
rdf
|
14
|
-
rdf-rdfxml (
|
14
|
+
rdf-rdfxml (~> 0.3.8)
|
15
15
|
rsolr
|
16
|
-
rubydora (~> 0.5.
|
16
|
+
rubydora (~> 0.5.9)
|
17
17
|
solrizer (~> 1.2.0)
|
18
18
|
xml-simple (>= 1.0.12)
|
19
19
|
|
@@ -21,28 +21,30 @@ GEM
|
|
21
21
|
remote: http://rubygems.org/
|
22
22
|
specs:
|
23
23
|
RedCloth (4.2.9)
|
24
|
-
activemodel (3.2.
|
25
|
-
activesupport (= 3.2.
|
24
|
+
activemodel (3.2.3)
|
25
|
+
activesupport (= 3.2.3)
|
26
26
|
builder (~> 3.0.0)
|
27
|
-
activeresource (3.2.
|
28
|
-
activemodel (= 3.2.
|
29
|
-
activesupport (= 3.2.
|
30
|
-
activesupport (3.2.
|
27
|
+
activeresource (3.2.3)
|
28
|
+
activemodel (= 3.2.3)
|
29
|
+
activesupport (= 3.2.3)
|
30
|
+
activesupport (3.2.3)
|
31
31
|
i18n (~> 0.6)
|
32
32
|
multi_json (~> 1.0)
|
33
33
|
addressable (2.2.8)
|
34
34
|
akami (1.0.0)
|
35
35
|
gyoku (>= 0.4.0)
|
36
|
+
backports (2.5.3)
|
36
37
|
builder (3.0.0)
|
37
|
-
childprocess (0.3.
|
38
|
+
childprocess (0.3.2)
|
38
39
|
ffi (~> 1.0.6)
|
40
|
+
columnize (0.3.6)
|
39
41
|
daemons (1.1.8)
|
40
42
|
diff-lcs (1.1.3)
|
41
43
|
equivalent-xml (0.2.9)
|
42
44
|
nokogiri (>= 1.4.3)
|
43
|
-
fastercsv (1.5.
|
45
|
+
fastercsv (1.5.5)
|
44
46
|
ffi (1.0.11)
|
45
|
-
gyoku (0.4.
|
47
|
+
gyoku (0.4.5)
|
46
48
|
builder (>= 2.1.2)
|
47
49
|
httpi (0.9.7)
|
48
50
|
rack
|
@@ -53,13 +55,15 @@ GEM
|
|
53
55
|
i18n
|
54
56
|
logger
|
55
57
|
mediashelf-loggable
|
58
|
+
linecache (0.46)
|
59
|
+
rbx-require-relative (> 0.0.4)
|
56
60
|
logger (1.2.8)
|
57
61
|
mediashelf-loggable (0.4.9)
|
58
62
|
metaclass (0.0.1)
|
59
63
|
mime-types (1.18)
|
60
64
|
mocha (0.10.5)
|
61
65
|
metaclass (~> 0.0.1)
|
62
|
-
multi_json (1.
|
66
|
+
multi_json (1.3.5)
|
63
67
|
multipart-post (1.1.2)
|
64
68
|
nokogiri (1.5.2)
|
65
69
|
nori (1.1.0)
|
@@ -68,24 +72,35 @@ GEM
|
|
68
72
|
nokogiri (>= 1.4.2)
|
69
73
|
rack (1.4.1)
|
70
74
|
rake (0.9.2.2)
|
75
|
+
rbx-require-relative (0.0.9)
|
76
|
+
rcov (1.0.0)
|
71
77
|
rdf (0.3.5.2)
|
72
78
|
addressable (>= 2.2.6)
|
73
|
-
rdf-rdfxml (0.3.
|
74
|
-
|
79
|
+
rdf-rdfxml (0.3.8)
|
80
|
+
rdf (>= 0.3.4)
|
81
|
+
rdf-xsd (>= 0.3.5)
|
82
|
+
rdf-xsd (0.3.7)
|
83
|
+
backports
|
84
|
+
nokogiri (>= 1.5.0)
|
75
85
|
rdf (>= 0.3.4)
|
76
86
|
rest-client (1.6.7)
|
77
87
|
mime-types (>= 1.16)
|
78
88
|
rsolr (1.0.8)
|
79
89
|
builder (>= 2.1.2)
|
80
|
-
rspec (2.
|
81
|
-
rspec-core (~> 2.
|
82
|
-
rspec-expectations (~> 2.
|
83
|
-
rspec-mocks (~> 2.
|
84
|
-
rspec-core (2.
|
85
|
-
rspec-expectations (2.
|
90
|
+
rspec (2.10.0)
|
91
|
+
rspec-core (~> 2.10.0)
|
92
|
+
rspec-expectations (~> 2.10.0)
|
93
|
+
rspec-mocks (~> 2.10.0)
|
94
|
+
rspec-core (2.10.1)
|
95
|
+
rspec-expectations (2.10.0)
|
86
96
|
diff-lcs (~> 1.1.3)
|
87
|
-
rspec-mocks (2.
|
88
|
-
|
97
|
+
rspec-mocks (2.10.1)
|
98
|
+
ruby-debug (0.10.4)
|
99
|
+
columnize (>= 0.1)
|
100
|
+
ruby-debug-base (~> 0.10.4.0)
|
101
|
+
ruby-debug-base (0.10.4)
|
102
|
+
linecache (>= 0.3)
|
103
|
+
rubydora (0.5.9)
|
89
104
|
activemodel
|
90
105
|
activesupport
|
91
106
|
fastercsv
|
@@ -101,7 +116,13 @@ GEM
|
|
101
116
|
nokogiri (>= 1.4.0)
|
102
117
|
nori (~> 1.1)
|
103
118
|
wasabi (~> 2.1)
|
104
|
-
|
119
|
+
simplecov (0.6.4)
|
120
|
+
multi_json (~> 1.0)
|
121
|
+
simplecov-html (~> 0.5.3)
|
122
|
+
simplecov-html (0.5.3)
|
123
|
+
simplecov-rcov (0.2.3)
|
124
|
+
simplecov (>= 0.4.1)
|
125
|
+
solrizer (1.2.1)
|
105
126
|
daemons
|
106
127
|
mediashelf-loggable (~> 0.4.7)
|
107
128
|
nokogiri
|
@@ -109,10 +130,10 @@ GEM
|
|
109
130
|
stomp
|
110
131
|
xml-simple
|
111
132
|
stomp (1.2.2)
|
112
|
-
wasabi (2.1.
|
133
|
+
wasabi (2.1.1)
|
113
134
|
nokogiri (>= 1.4.0)
|
114
135
|
xml-simple (1.1.1)
|
115
|
-
yard (0.
|
136
|
+
yard (0.8.1)
|
116
137
|
|
117
138
|
PLATFORMS
|
118
139
|
ruby
|
@@ -121,7 +142,12 @@ DEPENDENCIES
|
|
121
142
|
RedCloth
|
122
143
|
active-fedora!
|
123
144
|
jettywrapper (>= 1.2.0)
|
124
|
-
|
145
|
+
jruby-openssl
|
146
|
+
mocha (= 0.10.5)
|
125
147
|
rake
|
148
|
+
rcov
|
126
149
|
rspec (>= 2.9.0)
|
150
|
+
ruby-debug
|
151
|
+
simplecov
|
152
|
+
simplecov-rcov
|
127
153
|
yard
|
data/History.txt
CHANGED
@@ -1,4 +1,25 @@
|
|
1
|
-
4.
|
1
|
+
4.2.0
|
2
|
+
Added Base.find_each which allows yielding of each result
|
3
|
+
Added Base.find_in_batches which allows yielding of a chunk of solr results
|
4
|
+
Added ActiveFedora::NtriplesRDFDatastream
|
5
|
+
Rubydora to 0.5.9
|
6
|
+
HYDRA-726 integration tests verify versionable attribute of datastreams
|
7
|
+
HYDRA-811 allow setting a pid after object is initialized, but before it is saved
|
8
|
+
find(:all) must use solr paramater qt=standard
|
9
|
+
HYDRA-812 belongs_to should replace assertions, even if the asserted object is not found.
|
10
|
+
HYDRA-814 add clone()
|
11
|
+
HYDRA-815 give :type a default value (ActiveFedora::Datastream) for has_file_datastream
|
12
|
+
HYDRA-816 Sharding works automatically if multiple connections are specified in fedora.yml
|
13
|
+
HYDRA-818 Assign_pid should work correctly when the config is not sharded.
|
14
|
+
|
15
|
+
4.1.0
|
16
|
+
ActiveFedora::Base.find() now supports filtering by solr fields (boolean AND).
|
17
|
+
* example: ModsAsset.find('title_t' => 'Song of Fire and Ice','author_t'=>['Agatha Christie', 'Dr. Seuss']
|
18
|
+
ActiveFedora::Base.find_with_conditions which is the replacement for ActiveFedora::Base.find_by_fields_by_solr (previously deprecated)
|
19
|
+
YAML configurations are loaded through ERB, allowing reference to evaluated Ruby or environment variables
|
20
|
+
When setting ng_xml= with a Nokogiri node, cast it to a new Nokogiri document
|
21
|
+
|
22
|
+
4.0.0
|
2
23
|
Removed deprecations
|
3
24
|
* allowing :fedora level in fedora.yml
|
4
25
|
* automatic includes of Relationships and FileMethods is removed
|
data/README.textile
CHANGED
@@ -51,14 +51,14 @@ Then open a new terminal, go to your ActiveFedora source directory, and import f
|
|
51
51
|
|
52
52
|
<pre>
|
53
53
|
export FEDORA_HOME=/path/to/hydra/jetty/fedora/default
|
54
|
-
rake active_fedora:load_fixtures
|
54
|
+
rake active_fedora:load_fixtures environment=test
|
55
55
|
</pre>
|
56
56
|
|
57
57
|
This does the equivalent of:
|
58
58
|
|
59
59
|
<pre>
|
60
60
|
$FEDORA_HOME/client/bin/fedora-ingest-demos.sh localhost 8983 fedoraAdmin fedoraAdmin http
|
61
|
-
rake af:import_fixture pid=hydrangea:fixture_mods_article1
|
61
|
+
rake af:import_fixture pid=hydrangea:fixture_mods_article1 environment=test
|
62
62
|
</pre>
|
63
63
|
|
64
64
|
Now you're ready to run the tests. In the directory where active_fedora is installed, run
|
data/active-fedora.gemspec
CHANGED
@@ -26,15 +26,15 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_dependency("activesupport", '>= 3.0.0')
|
27
27
|
s.add_dependency("mediashelf-loggable")
|
28
28
|
s.add_dependency("equivalent-xml")
|
29
|
-
s.add_dependency("rubydora", '~>0.5.
|
29
|
+
s.add_dependency("rubydora", '~>0.5.9')
|
30
30
|
s.add_dependency("rdf")
|
31
|
-
s.add_dependency("rdf-rdfxml", '0.3.
|
31
|
+
s.add_dependency("rdf-rdfxml", '~>0.3.8')
|
32
32
|
s.add_development_dependency("yard")
|
33
33
|
s.add_development_dependency("RedCloth") # for RDoc formatting
|
34
34
|
s.add_development_dependency("rake")
|
35
35
|
s.add_development_dependency("jettywrapper", ">=1.2.0")
|
36
36
|
s.add_development_dependency("rspec", ">= 2.9.0")
|
37
|
-
s.add_development_dependency("mocha", "
|
37
|
+
s.add_development_dependency("mocha", "0.10.5")
|
38
38
|
|
39
39
|
s.files = `git ls-files`.split("\n")
|
40
40
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -4,15 +4,11 @@ module ActiveFedora
|
|
4
4
|
|
5
5
|
def replace(record)
|
6
6
|
if record.nil?
|
7
|
-
|
8
|
-
old_record = find_target
|
9
|
-
@owner.remove_relationship(@reflection.options[:property], old_record) unless old_record.nil?
|
7
|
+
@owner.clear_relationship(@reflection.options[:property])
|
10
8
|
else
|
11
9
|
raise_on_type_mismatch(record)
|
12
10
|
|
13
|
-
|
14
|
-
old_record = find_target
|
15
|
-
@owner.remove_relationship(@reflection.options[:property], old_record) unless old_record.nil?
|
11
|
+
@owner.clear_relationship(@reflection.options[:property])
|
16
12
|
|
17
13
|
@target = (AssociationProxy === record ? record.target : record)
|
18
14
|
@owner.add_relationship(@reflection.options[:property], record) unless record.new_record?
|
data/lib/active_fedora/base.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
SOLR_DOCUMENT_ID = "id" unless (defined?(SOLR_DOCUMENT_ID) && !SOLR_DOCUMENT_ID.nil?)
|
2
2
|
ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES)
|
3
|
+
require "digest"
|
3
4
|
|
4
5
|
module ActiveFedora
|
5
6
|
|
@@ -132,10 +133,19 @@ module ActiveFedora
|
|
132
133
|
fedora_connection[idx].connection
|
133
134
|
end
|
134
135
|
|
135
|
-
#
|
136
|
+
# This is where your sharding strategy is implemented -- it's how we figure out which shard an object will be (or was) written to.
|
137
|
+
# Given a pid, it decides which shard that pid will be written to (and thus retrieved from).
|
138
|
+
# For a given pid, as long as your shard configuration remains the same it will always return the same value.
|
139
|
+
# If you're not using sharding, this will always return 0, meaning use the first/only Fedora Repository in your configuration.
|
140
|
+
# Default strategy runs a modulo of the md5 of the pid against the number of shards.
|
141
|
+
# If you want to use a different sharding strategy, override this method. Make sure that it will always return the same value for a given pid and shard configuration.
|
136
142
|
#@return [Integer] the index of the shard this object is stored in
|
137
143
|
def self.shard_index(pid)
|
138
|
-
|
144
|
+
if ActiveFedora.config.sharded?
|
145
|
+
Digest::MD5.hexdigest(pid).hex % ActiveFedora.config.credentials.length
|
146
|
+
else
|
147
|
+
0
|
148
|
+
end
|
139
149
|
end
|
140
150
|
|
141
151
|
|
@@ -149,15 +159,42 @@ module ActiveFedora
|
|
149
159
|
obj
|
150
160
|
end
|
151
161
|
|
162
|
+
def clone
|
163
|
+
new_object = self.class.create
|
164
|
+
clone_into(new_object)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Clone the datastreams from this object into the provided object, while preserving the pid of the provided object
|
168
|
+
# @param [Base] new_object clone into this object
|
169
|
+
def clone_into(new_object)
|
170
|
+
rels = Nokogiri::XML( rels_ext.content)
|
171
|
+
rels.xpath("//rdf:Description/@rdf:about").first.value = new_object.internal_uri
|
172
|
+
new_object.rels_ext.content = rels.to_xml
|
173
|
+
new_object.rels_ext.dirty = false
|
174
|
+
|
175
|
+
datastreams.each do |k, v|
|
176
|
+
next if k == 'RELS-EXT'
|
177
|
+
new_object.datastreams[k].content = v.content
|
178
|
+
end
|
179
|
+
new_object if new_object.save
|
180
|
+
end
|
152
181
|
|
153
182
|
### if you are doing sharding, override this method to do something other than use a sequence
|
154
183
|
# @return [String] the unique pid for a new object
|
155
184
|
def self.assign_pid(obj)
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
185
|
+
args = {}
|
186
|
+
args[:namespace] = obj.namespace if obj.namespace
|
187
|
+
# TODO: This juggling of Fedora credentials & establishing connections should be handled by
|
188
|
+
# an establish_fedora_connection method,possibly wrap it all into a fedora_connection method - MZ 06-05-2012
|
189
|
+
if ActiveFedora.config.sharded?
|
190
|
+
credentials = ActiveFedora.config.credentials[0]
|
191
|
+
else
|
192
|
+
credentials = ActiveFedora.config.credentials
|
193
|
+
end
|
194
|
+
fedora_connection[0] ||= ActiveFedora::RubydoraConnection.new(credentials)
|
195
|
+
d = REXML::Document.new( fedora_connection[0].connection.next_pid(args))
|
196
|
+
pid =d.elements['//pid'].text
|
197
|
+
pid
|
161
198
|
end
|
162
199
|
|
163
200
|
def inner_object # :nodoc
|
@@ -21,8 +21,10 @@ module ActiveFedora
|
|
21
21
|
|
22
22
|
def serialize_datastreams
|
23
23
|
datastreams.each {|k, ds| ds.serialize! }
|
24
|
-
self.metadata_is_dirty = datastreams.any?
|
25
|
-
|
24
|
+
self.metadata_is_dirty = datastreams.any? do |k,ds|
|
25
|
+
ds.changed? && (ds.class.included_modules.include?(ActiveFedora::MetadataDatastreamHelper) || ds.instance_of?(ActiveFedora::RelsExtDatastream) || ds.kind_of?(ActiveFedora::RDFDatastream))
|
26
|
+
end
|
27
|
+
true
|
26
28
|
end
|
27
29
|
|
28
30
|
# Adds the disseminator location to the datastream after the pid has been established
|
@@ -259,17 +261,17 @@ module ActiveFedora
|
|
259
261
|
|
260
262
|
# Specify the attributes of a file bearing datastream
|
261
263
|
#
|
262
|
-
#
|
263
|
-
#
|
264
|
-
#
|
265
|
-
#
|
266
|
-
#
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
264
|
+
# @param [Hash] args
|
265
|
+
# @option args :name ("content") The dsid of the datastream
|
266
|
+
# @option args :type (ActiveFedora::Datastream) The class the datastream should have
|
267
|
+
# @option args :label ("File Datastream") The default value to put in the dsLabel field
|
268
|
+
# @option args :control_group ("M") The type of controlGroup to store the datastream as. Defaults to M
|
269
|
+
def has_file_datastream(args = {})
|
270
|
+
ds_specs[args.fetch(:name, "content")]= {
|
271
|
+
:type => args.fetch(:type,ActiveFedora::Datastream),
|
272
|
+
:label => args.fetch(:label,"File Datastream"),
|
273
|
+
:control_group => args.fetch(:control_group,"M")
|
274
|
+
}
|
273
275
|
end
|
274
276
|
end
|
275
277
|
|
data/lib/active_fedora/model.rb
CHANGED
@@ -102,23 +102,60 @@ module ActiveFedora
|
|
102
102
|
# @option opts [Integer] :rows when :all is passed, the maximum number of rows to load from solr
|
103
103
|
# @option opts [Boolean] :cast when true, examine the model and cast it to the first known cModel
|
104
104
|
def find(args, opts={})
|
105
|
-
opts
|
106
|
-
if args == :all
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
105
|
+
return find_one(args, opts[:cast]) if args.class == String
|
106
|
+
args = {} if args == :all
|
107
|
+
results = []
|
108
|
+
find_each(args, opts) do |obj|
|
109
|
+
results << obj
|
110
|
+
end
|
111
|
+
results
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
# Yields each batch of solr records that was found by the find +options+ as
|
116
|
+
# an array. The size of each batch is set by the <tt>:batch_size</tt>
|
117
|
+
# option; the default is 1000.
|
118
|
+
#
|
119
|
+
# Returns a solr result matching the supplied conditions
|
120
|
+
# @param[Hash] conditions solr conditions to match
|
121
|
+
# @param[Hash] options
|
122
|
+
# @option opts [Array] :sort a list of fields to sort by
|
123
|
+
# @option opts [Array] :rows number of rows to return
|
124
|
+
#
|
125
|
+
# @example
|
126
|
+
# Person.find_in_batches('age_t'=>'21', {:batch_size=>50}) do |group|
|
127
|
+
# group.each { |person| puts person['name_t'] }
|
128
|
+
# end
|
129
|
+
|
130
|
+
def find_in_batches conditions, opts={}
|
131
|
+
opts[:q] = create_query(conditions)
|
132
|
+
opts[:qt] = 'standard'
|
133
|
+
#set default sort to created date ascending
|
134
|
+
unless opts.include?(:sort)
|
135
|
+
opts[:sort]=[ActiveFedora::SolrService.solr_name(:system_create,:date)+' asc']
|
136
|
+
end
|
137
|
+
|
138
|
+
batch_size = opts.delete(:batch_size) || 1000
|
139
|
+
|
140
|
+
counter = 0
|
141
|
+
begin
|
142
|
+
counter += 1
|
143
|
+
response = ActiveFedora::SolrService.instance.conn.paginate counter, batch_size, "select", :params => opts
|
144
|
+
docs = response["response"]["docs"]
|
145
|
+
yield docs
|
146
|
+
end while docs.has_next?
|
147
|
+
end
|
148
|
+
|
149
|
+
# Yields the found ActiveFedora::Base object to the passed block
|
150
|
+
#
|
151
|
+
# @param [Hash] conditions the conditions for the solr search to match
|
152
|
+
# @param [Hash] opts
|
153
|
+
# @option opts [Boolean] :cast when true, examine the model and cast it to the first known cModel
|
154
|
+
def find_each( conditions={}, opts={})
|
155
|
+
find_in_batches(conditions, opts.merge({:fl=>SOLR_DOCUMENT_ID})) do |group|
|
156
|
+
group.each do |hit|
|
157
|
+
yield(find_one(hit[SOLR_DOCUMENT_ID], opts[:cast]))
|
119
158
|
end
|
120
|
-
elsif args.class == String
|
121
|
-
return find_one(args, opts[:cast])
|
122
159
|
end
|
123
160
|
end
|
124
161
|
|
@@ -131,6 +168,7 @@ module ActiveFedora
|
|
131
168
|
!inner.new?
|
132
169
|
end
|
133
170
|
|
171
|
+
#@deprecated
|
134
172
|
def find_model(pid)
|
135
173
|
ActiveSupport::Deprecation.warn("find_model is deprecated. Use find instead")
|
136
174
|
find(pid)
|
@@ -146,8 +184,10 @@ module ActiveFedora
|
|
146
184
|
SolrService.query(q, :raw=>true, :rows=>0)['response']['numFound']
|
147
185
|
end
|
148
186
|
|
187
|
+
#@deprecated
|
149
188
|
#Sends a query directly to SolrService
|
150
189
|
def solr_search(query, args={})
|
190
|
+
ActiveSupport::Deprecation.warn("solr_search is deprecated and will be removed in the next release. Use SolrService.query instead")
|
151
191
|
SolrService.instance.conn.query(query, args)
|
152
192
|
end
|
153
193
|
|
@@ -172,6 +212,7 @@ module ActiveFedora
|
|
172
212
|
end
|
173
213
|
end
|
174
214
|
|
215
|
+
# @deprecated
|
175
216
|
# Find all ActiveFedora objects for this model that match arguments
|
176
217
|
# passed in by querying Solr. Like find_by_solr this returns a solr result.
|
177
218
|
#
|
@@ -258,8 +299,24 @@ module ActiveFedora
|
|
258
299
|
SolrService.query(query, query_opts)
|
259
300
|
end
|
260
301
|
|
261
|
-
#
|
302
|
+
# Returns a solr result matching the supplied conditions
|
303
|
+
# @param[Hash] conditions solr conditions to match
|
304
|
+
# @param[Hash] options
|
305
|
+
# @option opts [Array] :sort a list of fields to sort by
|
306
|
+
# @option opts [Array] :rows number of rows to return
|
262
307
|
def find_with_conditions(conditions, opts={})
|
308
|
+
query = create_query(conditions)
|
309
|
+
#set default sort to created date ascending
|
310
|
+
unless opts.include?(:sort)
|
311
|
+
opts[:sort]=[ActiveFedora::SolrService.solr_name(:system_create,:date)+' asc']
|
312
|
+
end
|
313
|
+
SolrService.query(query, opts)
|
314
|
+
end
|
315
|
+
|
316
|
+
|
317
|
+
# Returns a solr query for the supplied conditions
|
318
|
+
# @param[Hash] conditions solr conditions to match
|
319
|
+
def create_query(conditions)
|
263
320
|
escaped_class_uri = SolrService.escape_uri_for_query(self.to_class_uri)
|
264
321
|
clauses = ["#{ActiveFedora::SolrService.solr_name(:has_model, :symbol)}:#{escaped_class_uri}"]
|
265
322
|
conditions.each_pair do |key,value|
|
@@ -276,13 +333,7 @@ module ActiveFedora
|
|
276
333
|
end
|
277
334
|
end
|
278
335
|
|
279
|
-
|
280
|
-
|
281
|
-
#set default sort to created date ascending
|
282
|
-
unless opts.include?(:sort)
|
283
|
-
opts[:sort]=[ActiveFedora::SolrService.solr_name(:system_create,:date)+' asc']
|
284
|
-
end
|
285
|
-
SolrService.query(query, opts)
|
336
|
+
clauses.join(" AND ")
|
286
337
|
end
|
287
338
|
|
288
339
|
def quote_for_solr(value)
|
@@ -299,18 +350,8 @@ module ActiveFedora
|
|
299
350
|
return fields
|
300
351
|
end
|
301
352
|
|
302
|
-
#wrapper around instance_variable_set, sets @name to value
|
303
|
-
def attribute_set(name, value)
|
304
|
-
instance_variable_set("@#{name}", value)
|
305
|
-
end
|
306
|
-
|
307
|
-
#wrapper around instance_variable_get, returns current value of @name
|
308
|
-
def attribute_get(name)
|
309
|
-
instance_variable_get("@#{name}")
|
310
|
-
end
|
311
|
-
|
312
353
|
private
|
313
|
-
# Retrieve the Fedora object with
|
354
|
+
# Retrieve the Fedora object with the given pid, explore the returned object, determine its model
|
314
355
|
# using #{ActiveFedora::ContentModel.known_models_for} and cast to that class.
|
315
356
|
# Raises a ObjectNotFoundError if the object is not found.
|
316
357
|
# @param [String] pid of the object to load
|
@@ -326,22 +367,6 @@ module ActiveFedora
|
|
326
367
|
end
|
327
368
|
|
328
369
|
end
|
329
|
-
def create_property_getter(property) # :nodoc:
|
330
|
-
|
331
|
-
class_eval <<-END, __FILE__, __LINE__
|
332
|
-
def #{property.name}
|
333
|
-
attribute_get("#{property.name}")
|
334
|
-
end
|
335
|
-
END
|
336
|
-
end
|
337
|
-
|
338
|
-
def create_property_setter(property)# :nodoc:
|
339
|
-
class_eval <<-END, __FILE__, __LINE__
|
340
|
-
def #{property.name}=(value)
|
341
|
-
attribute_set("#{property.name}", value)
|
342
|
-
end
|
343
|
-
END
|
344
|
-
end
|
345
370
|
|
346
371
|
private
|
347
372
|
|