active-fedora 9.9.0 → 9.10.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 +4 -4
- data/.rubocop.yml +20 -6
- data/.travis.yml +2 -6
- data/History.txt +146 -0
- data/active-fedora.gemspec +11 -8
- data/lib/active_fedora/associations/association.rb +44 -14
- data/lib/active_fedora/associations/association_scope.rb +6 -2
- data/lib/active_fedora/associations/basic_contains_association.rb +2 -3
- data/lib/active_fedora/associations/belongs_to_association.rb +23 -14
- data/lib/active_fedora/associations/builder/association.rb +95 -41
- data/lib/active_fedora/associations/builder/belongs_to.rb +30 -2
- data/lib/active_fedora/associations/builder/collection_association.rb +36 -4
- data/lib/active_fedora/associations/builder/contains.rb +10 -5
- data/lib/active_fedora/associations/builder/directly_contains.rb +6 -8
- data/lib/active_fedora/associations/builder/directly_contains_one.rb +27 -20
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +7 -3
- data/lib/active_fedora/associations/builder/has_many.rb +8 -45
- data/lib/active_fedora/associations/builder/indirectly_contains.rb +6 -8
- data/lib/active_fedora/associations/builder/property.rb +6 -12
- data/lib/active_fedora/associations/builder/singular_association.rb +3 -5
- data/lib/active_fedora/associations/builder/singular_property.rb +5 -4
- data/lib/active_fedora/associations/collection_association.rb +22 -26
- data/lib/active_fedora/associations/collection_proxy.rb +1 -1
- data/lib/active_fedora/associations/contained_finder.rb +1 -2
- data/lib/active_fedora/associations/directly_contains_one_association.rb +2 -3
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
- data/lib/active_fedora/associations/has_many_association.rb +24 -5
- data/lib/active_fedora/associations/rdf.rb +1 -20
- data/lib/active_fedora/associations.rb +1 -1
- data/lib/active_fedora/attached_files.rb +2 -2
- data/lib/active_fedora/attribute_assignment.rb +55 -0
- data/lib/active_fedora/attribute_methods/read.rb +29 -44
- data/lib/active_fedora/attribute_methods/write.rb +16 -19
- data/lib/active_fedora/attribute_methods.rb +149 -29
- data/lib/active_fedora/attributes.rb +6 -18
- data/lib/active_fedora/autosave_association.rb +8 -12
- data/lib/active_fedora/base.rb +2 -2
- data/lib/active_fedora/caching_connection.rb +1 -1
- data/lib/active_fedora/callbacks.rb +9 -9
- data/lib/active_fedora/common.rb +67 -0
- data/lib/active_fedora/core.rb +11 -23
- data/lib/active_fedora/default_model_mapper.rb +24 -0
- data/lib/active_fedora/errors.rb +42 -0
- data/lib/active_fedora/fedora.rb +1 -1
- data/lib/active_fedora/file/attributes.rb +9 -10
- data/lib/active_fedora/file.rb +19 -56
- data/lib/active_fedora/file_persistence.rb +27 -0
- data/lib/active_fedora/indexing.rb +15 -9
- data/lib/active_fedora/indexing_service.rb +4 -4
- data/lib/active_fedora/inheritance.rb +34 -0
- data/lib/active_fedora/ldp_resource.rb +1 -0
- data/lib/active_fedora/model.rb +18 -16
- data/lib/active_fedora/model_classifier.rb +77 -0
- data/lib/active_fedora/nested_attributes.rb +145 -18
- data/lib/active_fedora/persistence.rb +23 -5
- data/lib/active_fedora/predicates.rb +3 -0
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -1
- data/lib/active_fedora/query_result_builder.rb +12 -28
- data/lib/active_fedora/querying.rb +1 -1
- data/lib/active_fedora/rdf/datastream_indexing.rb +1 -1
- data/lib/active_fedora/reflection.rb +212 -80
- data/lib/active_fedora/relation/calculations.rb +1 -5
- data/lib/active_fedora/relation/finder_methods.rb +39 -26
- data/lib/active_fedora/relation.rb +17 -0
- data/lib/active_fedora/scoping/default.rb +117 -0
- data/lib/active_fedora/scoping/named.rb +152 -4
- data/lib/active_fedora/scoping.rb +85 -2
- data/lib/active_fedora/simple_datastream.rb +1 -1
- data/lib/active_fedora/solr_hit.rb +71 -0
- data/lib/active_fedora/solr_instance_loader.rb +12 -36
- data/lib/active_fedora/solr_query_builder.rb +20 -25
- data/lib/active_fedora/solr_service.rb +24 -13
- data/lib/active_fedora/type/boolean.rb +23 -0
- data/lib/active_fedora/type/value.rb +118 -0
- data/lib/active_fedora/type.rb +8 -0
- data/lib/active_fedora/validations.rb +14 -5
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +8 -7
- data/lib/active_fedora/with_metadata/metadata_node.rb +2 -1
- data/lib/active_fedora.rb +35 -15
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +4 -0
- data/lib/generators/active_fedora/config/fedora/templates/.fcrepo_wrapper +3 -0
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +4 -0
- data/lib/generators/active_fedora/config/solr/templates/.solr_wrapper +5 -0
- data/lib/generators/active_fedora/config/solr/templates/solr/config/solrconfig.xml +15 -0
- data/solr/config/solrconfig.xml +15 -0
- data/spec/config_helper.rb +0 -5
- data/spec/integration/associations_spec.rb +5 -5
- data/spec/integration/attached_files_spec.rb +4 -4
- data/spec/integration/base_spec.rb +4 -4
- data/spec/integration/bug_spec.rb +0 -1
- data/spec/integration/collection_association_spec.rb +34 -3
- data/spec/integration/file_spec.rb +2 -2
- data/spec/integration/full_featured_model_spec.rb +4 -4
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +1 -1
- data/spec/integration/has_many_associations_spec.rb +30 -1
- data/spec/integration/indirect_container_spec.rb +1 -1
- data/spec/integration/nested_attribute_spec.rb +6 -0
- data/spec/integration/ntriples_datastream_spec.rb +4 -4
- data/spec/integration/om_datastream_spec.rb +7 -7
- data/spec/integration/persistence_spec.rb +1 -1
- data/spec/integration/relation_delegation_spec.rb +1 -1
- data/spec/integration/scoped_query_spec.rb +13 -13
- data/spec/integration/solr_hit_spec.rb +52 -0
- data/spec/samples/hydra-mods_article_datastream.rb +2 -2
- data/spec/spec_helper.rb +5 -9
- data/spec/unit/active_fedora_spec.rb +0 -26
- data/spec/unit/attributes_spec.rb +13 -7
- data/spec/unit/base_spec.rb +20 -0
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -3
- data/spec/unit/callback_spec.rb +3 -8
- data/spec/unit/collection_proxy_spec.rb +1 -1
- data/spec/unit/default_model_mapper_spec.rb +39 -0
- data/spec/unit/file_spec.rb +21 -2
- data/spec/unit/finder_methods_spec.rb +30 -6
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +4 -4
- data/spec/unit/has_many_association_spec.rb +25 -3
- data/spec/unit/indexing_spec.rb +17 -3
- data/spec/unit/model_classifier_spec.rb +49 -0
- data/spec/unit/model_spec.rb +0 -9
- data/spec/unit/ntriples_datastream_spec.rb +16 -16
- data/spec/unit/om_datastream_spec.rb +7 -7
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -1
- data/spec/unit/query_result_builder_spec.rb +4 -10
- data/spec/unit/query_spec.rb +28 -28
- data/spec/unit/rdf/indexing_service_spec.rb +16 -16
- data/spec/unit/reflection_spec.rb +2 -2
- data/spec/unit/scoping_spec.rb +67 -0
- data/spec/unit/simple_datastream_spec.rb +2 -2
- data/spec/unit/solr_config_options_spec.rb +29 -32
- data/spec/unit/solr_hit_spec.rb +58 -0
- data/spec/unit/solr_query_builder_spec.rb +9 -1
- data/spec/unit/solr_service_spec.rb +19 -3
- data/spec/unit/validations_spec.rb +1 -1
- metadata +82 -20
- data/spec/support/freeze_mocks.rb +0 -12
|
@@ -60,9 +60,9 @@ module ActiveFedora
|
|
|
60
60
|
options[:reject_if] = REJECT_ALL_BLANK_PROC if options[:reject_if] == :all_blank
|
|
61
61
|
|
|
62
62
|
attr_names.each do |association_name|
|
|
63
|
-
if reflection =
|
|
64
|
-
reflection.
|
|
65
|
-
|
|
63
|
+
if reflection = _reflect_on_association(association_name)
|
|
64
|
+
reflection.autosave = true
|
|
65
|
+
define_autosave_association_callbacks(reflection)
|
|
66
66
|
## TODO this ought to work, but doesn't seem to do the class inheritance right
|
|
67
67
|
|
|
68
68
|
nested_attributes_options = self.nested_attributes_options.dup
|
|
@@ -70,10 +70,8 @@ module ActiveFedora
|
|
|
70
70
|
self.nested_attributes_options = nested_attributes_options
|
|
71
71
|
|
|
72
72
|
type = (reflection.collection? ? :collection : :one_to_one)
|
|
73
|
+
generate_association_writer(association_name, type)
|
|
73
74
|
|
|
74
|
-
# def pirate_attributes=(attributes)
|
|
75
|
-
# assign_nested_attributes_for_one_to_one_association(:pirate, attributes)
|
|
76
|
-
# end
|
|
77
75
|
class_eval <<-eoruby, __FILE__, __LINE__ + 1
|
|
78
76
|
remove_possible_method(:#{association_name}_attributes=)
|
|
79
77
|
|
|
@@ -83,6 +81,7 @@ module ActiveFedora
|
|
|
83
81
|
eoruby
|
|
84
82
|
elsif reflect_on_property(association_name)
|
|
85
83
|
resource_class.accepts_nested_attributes_for(association_name, options)
|
|
84
|
+
generate_property_writer(association_name, type)
|
|
86
85
|
|
|
87
86
|
# Delegate the setter to the resource.
|
|
88
87
|
class_eval <<-eoruby, __FILE__, __LINE__ + 1
|
|
@@ -98,6 +97,53 @@ module ActiveFedora
|
|
|
98
97
|
end
|
|
99
98
|
end
|
|
100
99
|
end
|
|
100
|
+
|
|
101
|
+
private
|
|
102
|
+
|
|
103
|
+
# Generates a writer method for this association. Serves as a point for
|
|
104
|
+
# accessing the objects in the association. For example, this method
|
|
105
|
+
# could generate the following:
|
|
106
|
+
#
|
|
107
|
+
# def pirate_attributes=(attributes)
|
|
108
|
+
# assign_nested_attributes_for_one_to_one_association(:pirate, attributes)
|
|
109
|
+
# end
|
|
110
|
+
#
|
|
111
|
+
# This redirects the attempts to write objects in an association through
|
|
112
|
+
# the helper methods defined below. Makes it seem like the nested
|
|
113
|
+
# associations are just regular associations.
|
|
114
|
+
def generate_association_writer(association_name, type)
|
|
115
|
+
generated_association_methods.module_eval <<-eoruby, __FILE__, __LINE__ + 1
|
|
116
|
+
if method_defined?(:#{association_name}_attributes=)
|
|
117
|
+
remove_method(:#{association_name}_attributes=)
|
|
118
|
+
end
|
|
119
|
+
def #{association_name}_attributes=(attributes)
|
|
120
|
+
assign_nested_attributes_for_#{type}_association(:#{association_name}, attributes)
|
|
121
|
+
end
|
|
122
|
+
eoruby
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Generates a writer method for this association. Serves as a point for
|
|
126
|
+
# accessing the objects in the association. For example, this method
|
|
127
|
+
# could generate the following:
|
|
128
|
+
#
|
|
129
|
+
# def pirate_attributes=(attributes)
|
|
130
|
+
# assign_nested_attributes_for_one_to_one_association(:pirate, attributes)
|
|
131
|
+
# end
|
|
132
|
+
#
|
|
133
|
+
# This redirects the attempts to write objects in an association through
|
|
134
|
+
# the helper methods defined below. Makes it seem like the nested
|
|
135
|
+
# associations are just regular associations.
|
|
136
|
+
def generate_property_writer(association_name, _type)
|
|
137
|
+
generated_association_methods.module_eval <<-eoruby, __FILE__, __LINE__ + 1
|
|
138
|
+
if method_defined?(:#{association_name}_attributes=)
|
|
139
|
+
remove_method(:#{association_name}_attributes=)
|
|
140
|
+
end
|
|
141
|
+
def #{association_name}_attributes=(attributes)
|
|
142
|
+
attribute_will_change!(:#{association_name})
|
|
143
|
+
resource.#{association_name}_attributes=(attributes)
|
|
144
|
+
end
|
|
145
|
+
eoruby
|
|
146
|
+
end
|
|
101
147
|
end
|
|
102
148
|
|
|
103
149
|
# Returns ActiveFedora::Base#marked_for_destruction? It's
|
|
@@ -115,13 +161,63 @@ module ActiveFedora
|
|
|
115
161
|
# These hash keys are nested attributes implementation details.
|
|
116
162
|
UNASSIGNABLE_KEYS = %w( id _destroy ).freeze
|
|
117
163
|
|
|
164
|
+
# Assigns the given attributes to the association.
|
|
165
|
+
#
|
|
166
|
+
# If an associated record does not yet exist, one will be instantiated. If
|
|
167
|
+
# an associated record already exists, the method's behavior depends on
|
|
168
|
+
# the value of the update_only option. If update_only is +false+ and the
|
|
169
|
+
# given attributes include an <tt>:id</tt> that matches the existing record's
|
|
170
|
+
# id, then the existing record will be modified. If no <tt>:id</tt> is provided
|
|
171
|
+
# it will be replaced with a new record. If update_only is +true+ the existing
|
|
172
|
+
# record will be modified regardless of whether an <tt>:id</tt> is provided.
|
|
173
|
+
#
|
|
174
|
+
# If the given attributes include a matching <tt>:id</tt> attribute, or
|
|
175
|
+
# update_only is true, and a <tt>:_destroy</tt> key set to a truthy value,
|
|
176
|
+
# then the existing record will be marked for destruction.
|
|
177
|
+
def assign_nested_attributes_for_one_to_one_association(association_name, attributes)
|
|
178
|
+
options = nested_attributes_options[association_name]
|
|
179
|
+
|
|
180
|
+
attributes = attributes.to_h if attributes.respond_to?(:permitted?)
|
|
181
|
+
attributes = attributes.with_indifferent_access
|
|
182
|
+
existing_record = send(association_name)
|
|
183
|
+
|
|
184
|
+
if (options[:update_only] || !attributes['id'].blank?) && existing_record &&
|
|
185
|
+
(options[:update_only] || existing_record.id.to_s == attributes['id'].to_s)
|
|
186
|
+
assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy]) unless call_reject_if(association_name, attributes)
|
|
187
|
+
|
|
188
|
+
elsif attributes['id'].present?
|
|
189
|
+
raise_nested_attributes_record_not_found!(association_name, attributes['id'])
|
|
190
|
+
|
|
191
|
+
elsif !reject_new_record?(association_name, attributes)
|
|
192
|
+
assignable_attributes = attributes.except(*UNASSIGNABLE_KEYS)
|
|
193
|
+
|
|
194
|
+
if existing_record && existing_record.new_record?
|
|
195
|
+
existing_record.assign_attributes(assignable_attributes)
|
|
196
|
+
association(association_name).initialize_attributes(existing_record)
|
|
197
|
+
else
|
|
198
|
+
method = "build_#{association_name}"
|
|
199
|
+
if respond_to?(method)
|
|
200
|
+
send(method, assignable_attributes)
|
|
201
|
+
else
|
|
202
|
+
raise ArgumentError, "Cannot build association `#{association_name}'. Are you trying to build a polymorphic one-to-one association?"
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
118
208
|
def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
|
|
119
209
|
options = nested_attributes_options[association_name]
|
|
120
210
|
|
|
121
|
-
if
|
|
122
|
-
|
|
211
|
+
if attributes_collection.respond_to?(:permitted?)
|
|
212
|
+
attributes_collection = attributes_collection.to_h
|
|
123
213
|
end
|
|
124
214
|
|
|
215
|
+
unless attributes_collection.is_a?(Hash) || attributes_collection.is_a?(Array)
|
|
216
|
+
raise ArgumentError, "Hash or Array expected, got #{attributes_collection.class.name} (#{attributes_collection.inspect})"
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
check_record_limit!(options[:limit], attributes_collection)
|
|
220
|
+
|
|
125
221
|
if attributes_collection.is_a? Hash
|
|
126
222
|
keys = attributes_collection.keys
|
|
127
223
|
attributes_collection = if keys.include?('id') || keys.include?(:id)
|
|
@@ -134,13 +230,14 @@ module ActiveFedora
|
|
|
134
230
|
association = send(association_name)
|
|
135
231
|
|
|
136
232
|
existing_records = if association.loaded?
|
|
137
|
-
association.
|
|
233
|
+
association.target
|
|
138
234
|
else
|
|
139
235
|
attribute_ids = attributes_collection.map { |a| a['id'] || a[:id] }.compact
|
|
140
236
|
attribute_ids.present? ? association.to_a.select { |x| attribute_ids.include?(x.id) } : []
|
|
141
237
|
end
|
|
142
238
|
|
|
143
239
|
attributes_collection.each do |attributes|
|
|
240
|
+
attributes = attributes.to_h if attributes.respond_to?(:permitted)
|
|
144
241
|
attributes = attributes.with_indifferent_access
|
|
145
242
|
|
|
146
243
|
if attributes['id'].blank?
|
|
@@ -156,11 +253,31 @@ module ActiveFedora
|
|
|
156
253
|
end
|
|
157
254
|
|
|
158
255
|
else
|
|
159
|
-
raise_nested_attributes_record_not_found(association_name, attributes['id'])
|
|
256
|
+
raise_nested_attributes_record_not_found!(association_name, attributes['id'])
|
|
160
257
|
end
|
|
161
258
|
end
|
|
162
259
|
end
|
|
163
260
|
|
|
261
|
+
# Takes in a limit and checks if the attributes_collection has too many
|
|
262
|
+
# records. It accepts limit in the form of symbol, proc, or
|
|
263
|
+
# number-like object (anything that can be compared with an integer).
|
|
264
|
+
#
|
|
265
|
+
# Raises TooManyRecords error if the attributes_collection is
|
|
266
|
+
# larger than the limit.
|
|
267
|
+
def check_record_limit!(limit, attributes_collection)
|
|
268
|
+
return unless limit
|
|
269
|
+
limit = case limit
|
|
270
|
+
when Symbol
|
|
271
|
+
send(limit)
|
|
272
|
+
when Proc
|
|
273
|
+
limit.call
|
|
274
|
+
else
|
|
275
|
+
limit
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
raise TooManyRecords, "Maximum #{limit} records are allowed. Got #{attributes_collection.size} records instead." if limit && attributes_collection.size > limit
|
|
279
|
+
end
|
|
280
|
+
|
|
164
281
|
# Updates a record with the +attributes+ or marks it for destruction if
|
|
165
282
|
# +allow_destroy+ is +true+ and has_destroy_flag? returns +true+.
|
|
166
283
|
def assign_to_or_mark_for_destruction(record, attributes, allow_destroy)
|
|
@@ -170,19 +287,14 @@ module ActiveFedora
|
|
|
170
287
|
|
|
171
288
|
# Determines if a hash contains a truthy _destroy key.
|
|
172
289
|
def has_destroy_flag?(hash)
|
|
173
|
-
|
|
290
|
+
Type::Boolean.new.cast(hash['_destroy'])
|
|
174
291
|
end
|
|
175
292
|
|
|
176
293
|
# Determines if a new record should be rejected by checking
|
|
177
294
|
# has_destroy_flag? or if a <tt>:reject_if</tt> proc exists for this
|
|
178
295
|
# association and evaluates to +true+.
|
|
179
296
|
def reject_new_record?(association_name, attributes)
|
|
180
|
-
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
def raise_nested_attributes_record_not_found(association_name, record_id)
|
|
184
|
-
reflection = self.class.reflect_on_association(association_name)
|
|
185
|
-
raise ObjectNotFoundError, "Couldn't find #{reflection.klass.name} with ID=#{record_id} for #{self.class.name} with ID=#{id}"
|
|
297
|
+
will_be_destroyed?(association_name, attributes) || call_reject_if(association_name, attributes)
|
|
186
298
|
end
|
|
187
299
|
|
|
188
300
|
# Determines if a record with the particular +attributes+ should be
|
|
@@ -191,8 +303,9 @@ module ActiveFedora
|
|
|
191
303
|
#
|
|
192
304
|
# Returns false if there is a +destroy_flag+ on the attributes.
|
|
193
305
|
def call_reject_if(association_name, attributes)
|
|
306
|
+
return false if will_be_destroyed?(association_name, attributes)
|
|
307
|
+
|
|
194
308
|
opts = nested_attributes_options[association_name]
|
|
195
|
-
return false if has_destroy_flag?(attributes) && opts[:allow_destroy]
|
|
196
309
|
case callback = opts[:reject_if]
|
|
197
310
|
when Symbol
|
|
198
311
|
method(callback).arity == 0 ? send(callback) : send(callback, attributes)
|
|
@@ -200,5 +313,19 @@ module ActiveFedora
|
|
|
200
313
|
callback.call(attributes)
|
|
201
314
|
end
|
|
202
315
|
end
|
|
316
|
+
|
|
317
|
+
# Only take into account the destroy flag if <tt>:allow_destroy</tt> is true
|
|
318
|
+
def will_be_destroyed?(association_name, attributes)
|
|
319
|
+
allow_destroy?(association_name) && has_destroy_flag?(attributes)
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def allow_destroy?(association_name)
|
|
323
|
+
nested_attributes_options[association_name][:allow_destroy]
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
def raise_nested_attributes_record_not_found!(association_name, record_id)
|
|
327
|
+
reflection = self.class._reflect_on_association(association_name).klass.name
|
|
328
|
+
raise ObjectNotFoundError, "Couldn't find #{reflection.klass.name} with ID=#{record_id} for #{self.class.name} with ID=#{id}"
|
|
329
|
+
end
|
|
203
330
|
end
|
|
204
331
|
end
|
|
@@ -33,7 +33,7 @@ module ActiveFedora
|
|
|
33
33
|
|
|
34
34
|
# Pushes the object and all of its new or dirty attached files into Fedora
|
|
35
35
|
def update(attributes)
|
|
36
|
-
|
|
36
|
+
assign_attributes(attributes)
|
|
37
37
|
save
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -57,7 +57,7 @@ module ActiveFedora
|
|
|
57
57
|
raise ObjectNotFoundError, "Unable to find #{id} in the repository"
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
ActiveFedora::SolrService.delete(id) if
|
|
60
|
+
ActiveFedora::SolrService.delete(id) if ActiveFedora.enable_solr_updates?
|
|
61
61
|
self.class.eradicate(id) if opts[:eradicate]
|
|
62
62
|
freeze
|
|
63
63
|
end
|
|
@@ -70,6 +70,17 @@ module ActiveFedora
|
|
|
70
70
|
delete(*opts)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
+
# Deletes the record in the database and freezes this instance to reflect
|
|
74
|
+
# that no changes should be made (since they can't be persisted).
|
|
75
|
+
#
|
|
76
|
+
# There's a series of callbacks associated with #destroy!. If the
|
|
77
|
+
# <tt>before_destroy</tt> callback throws +:abort+ the action is cancelled
|
|
78
|
+
# and #destroy! raises ActiveFedora::RecordNotDestroyed.
|
|
79
|
+
# See ActiveFedora::Callbacks for further details.
|
|
80
|
+
def destroy!
|
|
81
|
+
destroy || _raise_record_not_destroyed
|
|
82
|
+
end
|
|
83
|
+
|
|
73
84
|
def eradicate
|
|
74
85
|
self.class.eradicate(id)
|
|
75
86
|
end
|
|
@@ -138,12 +149,12 @@ module ActiveFedora
|
|
|
138
149
|
|
|
139
150
|
def create_or_update(*args)
|
|
140
151
|
raise ReadOnlyRecord if readonly?
|
|
141
|
-
result = new_record? ?
|
|
152
|
+
result = new_record? ? _create_record(*args) : _update_record(*args)
|
|
142
153
|
result != false
|
|
143
154
|
end
|
|
144
155
|
|
|
145
156
|
# Deals with preparing new object to be saved to Fedora, then pushes it and its attached files into Fedora.
|
|
146
|
-
def
|
|
157
|
+
def _create_record(_options = {})
|
|
147
158
|
assign_rdf_subject
|
|
148
159
|
serialize_attached_files
|
|
149
160
|
@ldp_source = @ldp_source.create
|
|
@@ -152,13 +163,20 @@ module ActiveFedora
|
|
|
152
163
|
refresh
|
|
153
164
|
end
|
|
154
165
|
|
|
155
|
-
def
|
|
166
|
+
def _update_record(_options = {})
|
|
156
167
|
serialize_attached_files
|
|
157
168
|
execute_sparql_update
|
|
158
169
|
save_contained_resources
|
|
159
170
|
refresh
|
|
160
171
|
end
|
|
161
172
|
|
|
173
|
+
def _raise_record_not_destroyed
|
|
174
|
+
@_association_destroy_exception ||= nil
|
|
175
|
+
raise @_association_destroy_exception || RecordNotDestroyed.new("Failed to destroy the record", self)
|
|
176
|
+
ensure
|
|
177
|
+
@_association_destroy_exception = nil
|
|
178
|
+
end
|
|
179
|
+
|
|
162
180
|
def refresh
|
|
163
181
|
@ldp_source = build_ldp_resource(id)
|
|
164
182
|
@resource = nil
|
|
@@ -14,6 +14,7 @@ module ActiveFedora
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def self.find_graph_predicate(predicate)
|
|
17
|
+
Deprecation.warn("find_graph_predicate has been deprecated and will be removed in ActiveFedora 10.0")
|
|
17
18
|
# TODO, these could be cached
|
|
18
19
|
case predicate
|
|
19
20
|
when :has_model, "hasModel", :hasModel
|
|
@@ -42,6 +43,7 @@ module ActiveFedora
|
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
def self.vocabularies(vocabs = {})
|
|
46
|
+
Deprecation.warn("vocabularies has been deprecated and will be removed in ActiveFedora 10.0")
|
|
45
47
|
@vocabularies ||= vocabs
|
|
46
48
|
predicate_mappings.keys.each do |ns|
|
|
47
49
|
@vocabularies[ns] = ::RDF::Vocabulary.new(ns) unless @vocabularies.key? ns
|
|
@@ -75,6 +77,7 @@ module ActiveFedora
|
|
|
75
77
|
end
|
|
76
78
|
|
|
77
79
|
def self.predicate_namespaces
|
|
80
|
+
Deprecation.warn("predicate_namespaces has been deprecated and will be removed in ActiveFedora 10.0")
|
|
78
81
|
predicate_config[:predicate_namespaces] ||= {}
|
|
79
82
|
end
|
|
80
83
|
|
|
@@ -147,7 +147,7 @@ module ActiveFedora
|
|
|
147
147
|
@fields.each do |field_key, field_info|
|
|
148
148
|
things = send(field_key)
|
|
149
149
|
next unless things
|
|
150
|
-
field_symbol = ActiveFedora
|
|
150
|
+
field_symbol = ActiveFedora.index_field_mapper.solr_name(field_key, type: field_info[:type])
|
|
151
151
|
things.val.each do |val|
|
|
152
152
|
::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val)
|
|
153
153
|
end
|
|
@@ -1,50 +1,34 @@
|
|
|
1
1
|
module ActiveFedora
|
|
2
2
|
module QueryResultBuilder
|
|
3
3
|
def self.lazy_reify_solr_results(solr_results, opts = {})
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
return to_enum(:lazy_reify_solr_results, solr_results, opts) unless block_given?
|
|
5
|
+
|
|
6
|
+
solr_results.each do |hit|
|
|
7
|
+
yield ActiveFedora::SolrHit.for(hit).reify(opts)
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def self.reify_solr_results(solr_results, opts = {})
|
|
12
|
-
solr_results
|
|
12
|
+
lazy_reify_solr_results(solr_results, opts).to_a
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def self.reify_solr_result(hit, _opts = {})
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
Deprecation.warn(ActiveFedora::Base, 'ActiveFedora::QueryResultBuilder.reify_solr_result is deprecated and will be removed in ActiveFedora 10.0; call #reify on the SolrHit instead.')
|
|
17
|
+
ActiveFedora::SolrHit.for(hit).reify
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
# Returns all possible classes for the solr object
|
|
21
21
|
def self.classes_from_solr_document(hit, _opts = {})
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
hit[HAS_MODEL_SOLR_FIELD].each { |value| classes << Model.from_class_uri(value) }
|
|
25
|
-
|
|
26
|
-
classes.compact
|
|
22
|
+
Deprecation.warn(ActiveFedora::Base, 'ActiveFedora::QueryResultBuilder.classes_from_solr_document is deprecated and will be removed in ActiveFedora 10.0; call #models on the SolrHit instead.')
|
|
23
|
+
ActiveFedora::SolrHit.for(hit).models
|
|
27
24
|
end
|
|
28
25
|
|
|
29
26
|
# Returns the best singular class for the solr object
|
|
30
27
|
def self.class_from_solr_document(hit, opts = {})
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Array(hit[HAS_MODEL_SOLR_FIELD]).each do |value|
|
|
34
|
-
model_value = Model.from_class_uri(value)
|
|
35
|
-
next unless model_value
|
|
36
|
-
|
|
37
|
-
# Set as the first model in case opts[:class] was nil
|
|
38
|
-
best_model_match ||= model_value
|
|
39
|
-
|
|
40
|
-
# If there is an inheritance structure, use the most specific case.
|
|
41
|
-
best_model_match = model_value if best_model_match > model_value
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
ActiveFedora::Base.logger.warn "Could not find a model for #{hit['id']}, defaulting to ActiveFedora::Base" if ActiveFedora::Base.logger && !best_model_match
|
|
45
|
-
best_model_match || ActiveFedora::Base
|
|
28
|
+
Deprecation.warn(ActiveFedora::Base, 'ActiveFedora::QueryResultBuilder.class_from_solr_document is deprecated and will be removed in ActiveFedora 10.0; call #model on the SolrHit instead.')
|
|
29
|
+
ActiveFedora::SolrHit.for(hit).model(opts)
|
|
46
30
|
end
|
|
47
31
|
|
|
48
|
-
HAS_MODEL_SOLR_FIELD =
|
|
32
|
+
HAS_MODEL_SOLR_FIELD = ActiveFedora.index_field_mapper.solr_name("has_model", :symbol).freeze
|
|
49
33
|
end
|
|
50
34
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module ActiveFedora
|
|
2
2
|
module Querying
|
|
3
3
|
delegate :find, :first, :exists?, :where, :limit, :offset, :order, :delete_all,
|
|
4
|
-
:destroy_all, :count, :last, :find_with_conditions, :find_in_batches, :find_each, to: :all
|
|
4
|
+
:destroy_all, :count, :last, :find_with_conditions, :find_in_batches, :search_with_conditions, :search_in_batches, :search_by_id, :find_each, to: :all
|
|
5
5
|
|
|
6
6
|
def self.extended(base)
|
|
7
7
|
base.class_attribute :solr_query_handler
|
|
@@ -13,7 +13,7 @@ module ActiveFedora::RDF
|
|
|
13
13
|
config = self.class.config_for_term_or_uri(field)
|
|
14
14
|
return nil unless config && config.behaviors # punt on index names for deep nodes!
|
|
15
15
|
config.behaviors.each do |behavior|
|
|
16
|
-
result = ActiveFedora
|
|
16
|
+
result = ActiveFedora.index_field_mapper.solr_name(apply_prefix(field, file_path), behavior, type: config.type)
|
|
17
17
|
return result if Solrizer::DefaultDescriptors.send(behavior).evaluate_suffix(:text).stored?
|
|
18
18
|
end
|
|
19
19
|
raise RuntimeError "no stored fields were found"
|