active-fedora 3.2.0.pre1 → 3.2.0.pre2
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/Gemfile.lock +1 -1
- data/History.txt +3 -1
- data/lib/active_fedora.rb +3 -3
- data/lib/active_fedora/associations.rb +0 -2
- data/lib/active_fedora/associations/association_collection.rb +15 -1
- data/lib/active_fedora/associations/belongs_to_association.rb +5 -1
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +5 -1
- data/lib/active_fedora/base.rb +36 -92
- data/lib/active_fedora/datastream.rb +1 -2
- data/lib/active_fedora/file_management.rb +73 -0
- data/lib/active_fedora/metadata_datastream_helper.rb +3 -1
- data/lib/active_fedora/model.rb +6 -18
- data/lib/active_fedora/relationships.rb +634 -0
- data/lib/active_fedora/samples/special_thing.rb +4 -4
- data/lib/active_fedora/semantic_node.rb +97 -236
- data/lib/active_fedora/version.rb +1 -1
- data/spec/integration/base_file_management_spec.rb +1 -0
- data/spec/integration/base_spec.rb +114 -68
- data/spec/integration/full_featured_model_spec.rb +0 -1
- data/spec/integration/mods_article_integration_spec.rb +0 -1
- data/spec/integration/nokogiri_datastream_spec.rb +0 -1
- data/spec/integration/rels_ext_datastream_spec.rb +10 -7
- data/spec/integration/semantic_node_spec.rb +10 -16
- data/spec/samples/models/hydrangea_article.rb +1 -2
- data/spec/samples/oral_history_sample_model.rb +1 -1
- data/spec/unit/base_spec.rb +26 -16
- data/spec/unit/metadata_datastream_spec.rb +1 -0
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -0
- data/spec/unit/relationship_spec.rb +1 -0
- data/spec/unit/relationships_spec.rb +846 -0
- data/spec/unit/semantic_node_spec.rb +2 -338
- metadata +8 -7
- data/lib/active_fedora/relationships_helper.rb +0 -881
- data/spec/unit/relationships_helper_spec.rb +0 -800
@@ -39,9 +39,9 @@ class SpecialThing < ActiveFedora::Base
|
|
39
39
|
#
|
40
40
|
|
41
41
|
# This is an example of how you can add a custom relationship to a model
|
42
|
-
# This will allow you to call .
|
43
|
-
|
42
|
+
# This will allow you to call .derivation on instances of the model to get the _outbound_ "hasDerivation" relationship in the RELS-EXT datastream
|
43
|
+
belongs_to :derivation, :property=>:has_derivation
|
44
44
|
|
45
45
|
# This will allow you to call .inspirations on instances of the model to get a list of all of the objects that assert "hasDerivation" relationships pointing at this object
|
46
|
-
|
47
|
-
end
|
46
|
+
has_many :inspirations, :property=>:has_derivation
|
47
|
+
end
|
@@ -4,6 +4,7 @@ module ActiveFedora
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
included do
|
6
6
|
class_attribute :class_relationships, :internal_uri
|
7
|
+
class_attribute :class_relationships_desc
|
7
8
|
self.class_relationships = {}
|
8
9
|
end
|
9
10
|
attr_accessor :relationships_loaded, :load_from_solr, :subject
|
@@ -32,6 +33,34 @@ module ActiveFedora
|
|
32
33
|
rels_ext.dirty = true
|
33
34
|
end
|
34
35
|
|
36
|
+
# Checks that this object is matches the model class passed in.
|
37
|
+
# It requires two steps to pass to return true
|
38
|
+
# 1. It has a hasModel relationship of the same model
|
39
|
+
# 2. kind_of? returns true for the model passed in
|
40
|
+
# This method can most often be used to detect if an object from Fedora that was created
|
41
|
+
# with a different model was then used to populate this object.
|
42
|
+
# @param [Class] the model class name to check if an object conforms_to that model
|
43
|
+
# @return [Boolean] true if this object conforms to the given model name
|
44
|
+
def conforms_to?(model_class)
|
45
|
+
if self.kind_of?(model_class)
|
46
|
+
#check has model and class match
|
47
|
+
mod = relationships.first(:predicate=>Predicates.find_graph_predicate(:has_model))
|
48
|
+
if mod
|
49
|
+
expected = ActiveFedora::ContentModel.pid_from_ruby_class(self.class)
|
50
|
+
if mod.object.to_s == expected
|
51
|
+
return true
|
52
|
+
else
|
53
|
+
raise "has_model relationship check failed for model #{model_class} raising exception, expected: '#{expected}' actual: '#{mod.object.to_s}'"
|
54
|
+
end
|
55
|
+
else
|
56
|
+
raise "has_model relationship does not exist for model #{model_class} check raising exception"
|
57
|
+
end
|
58
|
+
else
|
59
|
+
raise "kind_of? check failed for model #{model_class}, actual #{self.class} raising exception"
|
60
|
+
end
|
61
|
+
return false
|
62
|
+
end
|
63
|
+
|
35
64
|
# Create an RDF statement
|
36
65
|
# @param uri a string represending the subject
|
37
66
|
# @param predicate a predicate symbol
|
@@ -120,40 +149,6 @@ module ActiveFedora
|
|
120
149
|
return unless content.present?
|
121
150
|
RelsExtDatastream.from_xml content, rels_ext
|
122
151
|
end
|
123
|
-
|
124
|
-
def relationships_from_class
|
125
|
-
rels = {}
|
126
|
-
self.class.relationships.each_pair do |subj, pred|
|
127
|
-
rels[subj] = {}
|
128
|
-
pred.each_key do |pred_key|
|
129
|
-
rels[subj][pred_key] = []
|
130
|
-
end
|
131
|
-
end
|
132
|
-
return rels
|
133
|
-
end
|
134
|
-
|
135
|
-
def load_inbound_relationship(name, predicate, opts={})
|
136
|
-
opts = {:rows=>25}.merge(opts)
|
137
|
-
query = self.class.inbound_relationship_query(self.pid,"#{name}")
|
138
|
-
return [] if query.empty?
|
139
|
-
solr_result = SolrService.instance.conn.query(query, :rows=>opts[:rows])
|
140
|
-
if opts[:response_format] == :solr
|
141
|
-
return solr_result
|
142
|
-
else
|
143
|
-
if opts[:response_format] == :id_array
|
144
|
-
id_array = []
|
145
|
-
solr_result.hits.each do |hit|
|
146
|
-
id_array << hit[SOLR_DOCUMENT_ID]
|
147
|
-
end
|
148
|
-
return id_array
|
149
|
-
elsif opts[:response_format] == :load_from_solr || self.load_from_solr
|
150
|
-
return ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
151
|
-
else
|
152
|
-
return ActiveFedora::SolrService.reify_solr_results(solr_result)
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
152
|
|
158
153
|
def ids_for_outbound(predicate)
|
159
154
|
(object_relations[predicate] || []).map do |o|
|
@@ -162,220 +157,86 @@ module ActiveFedora
|
|
162
157
|
end
|
163
158
|
end
|
164
159
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
elsif opts[:response_format] == :load_from_solr || self.load_from_solr
|
176
|
-
return ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
177
|
-
else
|
178
|
-
return ActiveFedora::SolrService.reify_solr_results(solr_result)
|
179
|
-
end
|
180
|
-
else
|
181
|
-
ary = send(inbound_method_name,opts) + send(outbound_method_name, opts)
|
182
|
-
return ary.uniq
|
183
|
-
end
|
160
|
+
# Return hash that persists relationship metadata defined by has_relationship calls
|
161
|
+
# @return [Hash] Hash of relationship subject (:self or :inbound) mapped to nested hashs of each relationship name mapped to another hash relationship options
|
162
|
+
# @example For the following relationship
|
163
|
+
#
|
164
|
+
# has_relationship "audio_records", :has_part, :type=>AudioRecord
|
165
|
+
#
|
166
|
+
# Results in the following returned by relationships_desc
|
167
|
+
# {:self=>{"audio_records"=>{:type=>AudioRecord, :singular=>nil, :predicate=>:has_part, :inbound=>false}}}
|
168
|
+
def relationships_desc
|
169
|
+
@relationships_desc ||= self.class.relationships_desc
|
184
170
|
end
|
185
171
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
id_array = []
|
197
|
-
solr_result.hits.each do |hit|
|
198
|
-
id_array << hit[SOLR_DOCUMENT_ID]
|
199
|
-
end
|
200
|
-
return id_array
|
201
|
-
elsif opts[:response_format] == :load_from_solr || self.load_from_solr
|
202
|
-
return ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
203
|
-
else
|
204
|
-
return ActiveFedora::SolrService.reify_solr_results(solr_result)
|
172
|
+
# Return hash of relationship names and predicate pairs (inbound and outbound).
|
173
|
+
# It retrieves this information via the relationships_desc hash in the class.
|
174
|
+
# @return [Hash] A hash of relationship names (inbound and outbound) mapped to predicates used
|
175
|
+
def relationship_predicates
|
176
|
+
return @relationship_predicates if @relationship_predicates
|
177
|
+
@relationship_predicates = {}
|
178
|
+
relationships_desc.each_pair do |subj, names|
|
179
|
+
@relationship_predicates[subj] = {}
|
180
|
+
names.each_pair do |name, args|
|
181
|
+
@relationship_predicates[subj][name] = args[:predicate]
|
205
182
|
end
|
206
183
|
end
|
184
|
+
@relationship_predicates
|
207
185
|
end
|
208
|
-
|
209
|
-
module ClassMethods
|
210
|
-
# Allows for a relationship to be treated like any other attribute of a model class. You define
|
211
|
-
# relationships in your model class using this method. You then have access to several
|
212
|
-
# helper methods to list, append, and remove objects from the list of relationships.
|
213
|
-
# ====Examples to define two relationships
|
214
|
-
# class AudioRecord < ActiveFedora::Base
|
215
|
-
#
|
216
|
-
# has_relationship "oral_history", :has_part, :inbound=>true, :type=>OralHistory
|
217
|
-
# # returns all similar audio
|
218
|
-
# has_relationship "similar_audio", :has_part, :type=>AudioRecord
|
219
|
-
# #returns only similar audio with format wav
|
220
|
-
# has_relationship "similar_audio_wav", :has_part, :solr_fq=>"format_t:wav"
|
221
|
-
#
|
222
|
-
# The first two parameters are required:
|
223
|
-
# name: relationship name
|
224
|
-
# predicate: predicate for the relationship
|
225
|
-
# opts:
|
226
|
-
# possible parameters
|
227
|
-
# :inbound => if true loads an external relationship via Solr (defaults to false)
|
228
|
-
# :type => The type of model to use when instantiated an object from the pid in this relationship (defaults to ActiveFedora::Base)
|
229
|
-
# :solr_fq => Define a solr query here if you want to filter out some objects in your relationship (must be a properly formatted solr query)
|
230
|
-
#
|
231
|
-
# If inbound is true it expects the relationship to be defined by another object's RELS-EXT
|
232
|
-
# and to load that relationship from Solr. Otherwise, if inbound is true the relationship is stored in
|
233
|
-
# this object's RELS-EXT datastream
|
234
|
-
#
|
235
|
-
# Word of caution - The same predicate may not be used twice for two inbound or two outbound relationships. However, it may be used twice if one is inbound
|
236
|
-
# and one is outbound as shown in the example above. A full list of possible predicates are defined by predicate_mappings
|
237
|
-
#
|
238
|
-
# For the oral_history relationship in the example above the following helper methods are created:
|
239
|
-
# oral_history: returns array of OralHistory objects that have this AudioRecord with predicate :has_part
|
240
|
-
# oral_history_ids: Return array of pids for OralHistory objects that have this AudioRecord with predicate :has_part
|
241
|
-
# oral_history_query: Return solr query that can be used to retrieve related objects as solr documents
|
242
|
-
#
|
243
|
-
# For the outbound relationship "similar_audio" there are two additional methods to append and remove objects from that relationship
|
244
|
-
# since it is managed internally:
|
245
|
-
# similar_audio: Return array of AudioRecord objects that have been added to similar_audio relationship
|
246
|
-
# similar_audio_ids: Return array of AudioRecord object pids that have been added to similar_audio relationship
|
247
|
-
# similar_audio_query: Return solr query that can be used to retrieve related objects as solr documents
|
248
|
-
# similar_audio_append: Add an AudioRecord object to the similar_audio relationship
|
249
|
-
# similar_audio_remove: Remove an AudioRecord from the similar_audio relationship
|
250
|
-
def has_relationship(name, predicate, opts = {})
|
251
|
-
opts = {:singular => nil, :inbound => false}.merge(opts)
|
252
|
-
if opts[:inbound] == true
|
253
|
-
#raise "Duplicate use of predicate for inbound relationship name not allowed" if predicate_exists_with_different_relationship_name?(:inbound,name,predicate)
|
254
|
-
register_relationship_desc(:inbound, name, predicate, opts)
|
255
|
-
register_predicate(:inbound, predicate)
|
256
|
-
create_inbound_relationship_finders(name, predicate, opts)
|
257
|
-
else
|
258
|
-
#raise "Duplicate use of predicate for named outbound relationship \"#{predicate.inspect}\" not allowed" if named_predicate_exists_with_different_name?(:self,name,predicate)
|
259
|
-
register_relationship_desc(:self, name, predicate, opts)
|
260
|
-
register_predicate(:self, predicate)
|
261
|
-
create_relationship_name_methods(name)
|
262
|
-
create_outbound_relationship_finders(name, predicate, opts)
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
# Generates relationship finders for predicates that point in both directions
|
267
|
-
#
|
268
|
-
# @param [String] name of the relationship method(s) to create
|
269
|
-
# @param [Symbol] outbound_predicate Predicate used in outbound relationships
|
270
|
-
# @param [Symbol] inbound_predicate Predicate used in inbound relationships
|
271
|
-
# @param [Hash] opts
|
272
|
-
#
|
273
|
-
# Example:
|
274
|
-
# has_bidirectional_relationship("parts", :has_part, :is_part_of)
|
275
|
-
#
|
276
|
-
# will create three instance methods: parts_outbound, and parts_inbound and parts
|
277
|
-
# the inbound and outbound methods are the same that would result from calling
|
278
|
-
# create_inbound_relationship_finders and create_outbound_relationship_finders
|
279
|
-
# The third method combines the results of both and handles generating appropriate
|
280
|
-
# solr queries where necessary.
|
281
|
-
def has_bidirectional_relationship(name, outbound_predicate, inbound_predicate, opts={})
|
282
|
-
create_bidirectional_relationship_finders(name, outbound_predicate, inbound_predicate, opts)
|
283
|
-
end
|
284
|
-
|
285
|
-
|
286
|
-
# relationships are tracked as a hash of structure
|
287
|
-
# @example
|
288
|
-
# ds.relationships # => {:self=>{:has_model=>["afmodel:SimpleThing"],:has_part=>["demo:20"]},:inbound=>{:is_part_of=>["demo:6"]}
|
289
|
-
def relationships
|
290
|
-
@class_relationships ||= Hash[:self => {}]
|
291
|
-
end
|
292
|
-
|
293
|
-
|
294
|
-
def register_subject(subject)
|
295
|
-
if !relationships.has_key?(subject)
|
296
|
-
relationships[subject] = {}
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
def register_predicate(subject, predicate)
|
301
|
-
register_subject(subject)
|
302
|
-
if !relationships[subject].has_key?(predicate)
|
303
|
-
relationships[subject][predicate] = []
|
304
|
-
end
|
305
|
-
end
|
306
186
|
|
187
|
+
# Return hash of outbound relationship names and predicate pairs
|
188
|
+
# @return [Hash] A hash of outbound relationship names mapped to predicates used
|
189
|
+
def outbound_relationship_predicates
|
190
|
+
relationship_predicates.has_key?(:self) ? relationship_predicates[:self] : {}
|
191
|
+
end
|
307
192
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
def #{name}_ids
|
314
|
-
#{name}(:response_format => :id_array)
|
315
|
-
end
|
316
|
-
def #{name}_from_solr
|
317
|
-
#{name}(:response_format => :load_from_solr)
|
318
|
-
end
|
319
|
-
def #{name}_query
|
320
|
-
relationship_query("#{name}")
|
321
|
-
end
|
322
|
-
END
|
323
|
-
end
|
324
|
-
|
325
|
-
def create_outbound_relationship_finders(name, predicate, opts = {})
|
326
|
-
class_eval <<-END, __FILE__, __LINE__
|
327
|
-
def #{name}(opts={})
|
328
|
-
load_outbound_relationship(#{name.inspect}, #{predicate.inspect}, opts)
|
329
|
-
end
|
330
|
-
def #{name}_ids
|
331
|
-
#{name}(:response_format => :id_array)
|
332
|
-
end
|
333
|
-
def #{name}_from_solr
|
334
|
-
#{name}(:response_format => :load_from_solr)
|
335
|
-
end
|
336
|
-
def #{name}_query
|
337
|
-
relationship_query("#{name}")
|
338
|
-
end
|
339
|
-
END
|
340
|
-
end
|
341
|
-
|
193
|
+
# Return hash of inbound relationship names and predicate pairs
|
194
|
+
# @return [Hash] A hash of inbound relationship names mapped to predicates used
|
195
|
+
def inbound_relationship_predicates
|
196
|
+
relationship_predicates.has_key?(:inbound) ? relationship_predicates[:inbound] : {}
|
197
|
+
end
|
342
198
|
|
343
199
|
|
344
|
-
|
345
|
-
#
|
200
|
+
module ClassMethods
|
201
|
+
# Return hash that persists relationship metadata defined by has_relationship calls. If you implement a child class of ActiveFedora::Base it will inherit
|
202
|
+
# the relationship descriptions defined there by merging in the class
|
203
|
+
# instance variable values. It will also do this for any level of
|
204
|
+
# ancestors.
|
205
|
+
# @return [Hash] Hash of relationship subject (:self or :inbound) mapped to nested hashs of each relationship name mapped to another hash relationship options
|
206
|
+
# @example
|
207
|
+
# For the following relationship
|
346
208
|
#
|
347
|
-
#
|
348
|
-
#
|
349
|
-
#
|
350
|
-
#
|
351
|
-
def
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
209
|
+
# has_relationship "audio_records", :has_part, :type=>AudioRecord
|
210
|
+
#
|
211
|
+
# Results in the following returned by relationships_desc
|
212
|
+
# {:self=>{"audio_records"=>{:type=>AudioRecord, :singular=>nil, :predicate=>:has_part, :inbound=>false}}}
|
213
|
+
def relationships_desc
|
214
|
+
#get any relationship descriptions from superclasses
|
215
|
+
if @class_relationships_desc.nil?
|
216
|
+
@class_relationships_desc ||= Hash[:self => {}]
|
217
|
+
|
218
|
+
#get super classes
|
219
|
+
super_klasses = []
|
220
|
+
#insert in reverse order so the child overwrites anything in parent
|
221
|
+
super_klass = self.superclass
|
222
|
+
while !super_klass.nil?
|
223
|
+
super_klasses.insert(0,super_klass)
|
224
|
+
super_klass = super_klass.superclass
|
225
|
+
end
|
226
|
+
|
227
|
+
super_klasses.each do |super_klass|
|
228
|
+
if super_klass.respond_to?(:relationships_desc)
|
229
|
+
super_rels = super_klass.relationships_desc
|
230
|
+
super_rels.each_pair do |subject,rels|
|
231
|
+
@class_relationships_desc[subject] = {} unless @class_relationships_desc.has_key?(subject)
|
232
|
+
@class_relationships_desc[subject].merge!(rels)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
372
236
|
end
|
373
|
-
|
237
|
+
@class_relationships_desc
|
374
238
|
end
|
375
|
-
|
376
|
-
|
239
|
+
|
377
240
|
end
|
378
241
|
end
|
379
|
-
|
380
|
-
|
381
242
|
end
|
@@ -13,6 +13,7 @@ describe ActiveFedora::Base do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should persist and re-load collection members" do
|
16
|
+
ActiveSupport::Deprecation.stubs(:warn)
|
16
17
|
container_copy = ActiveFedora::Base.load_instance(@test_container.pid)
|
17
18
|
container_copy.collection_members(:response_format=>:id_array).should == ["foo:2"]
|
18
19
|
end
|
@@ -1,35 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class MockAFBaseRelationship < ActiveFedora::Base
|
4
|
-
has_relationship "testing", :has_part, :type=>MockAFBaseRelationship
|
5
|
-
has_relationship "testing2", :has_member, :type=>MockAFBaseRelationship
|
6
|
-
has_relationship "testing_inbound", :has_part, :type=>MockAFBaseRelationship, :inbound=>true
|
7
|
-
has_relationship "testing_inbound2", :has_member, :type=>MockAFBaseRelationship, :inbound=>true
|
8
|
-
has_bidirectional_relationship "testing_bidirectional", :has_collection_member, :is_member_of_collection
|
9
|
-
#next 2 used to test objects on opposite end of bidirectional relationship
|
10
|
-
has_relationship "testing_inbound3", :has_collection_member, :inbound=>true
|
11
|
-
has_relationship "testing3", :is_member_of_collection
|
12
|
-
end
|
13
|
-
|
14
|
-
class MockAFBaseFromSolr < ActiveFedora::Base
|
15
|
-
has_relationship "testing", :has_part, :type=>MockAFBaseFromSolr
|
16
|
-
has_relationship "testing2", :has_member, :type=>MockAFBaseFromSolr
|
17
|
-
has_relationship "testing_inbound", :has_part, :type=>MockAFBaseFromSolr, :inbound=>true
|
18
|
-
has_relationship "testing_inbound2", :has_member, :type=>MockAFBaseFromSolr, :inbound=>true
|
19
|
-
|
20
|
-
has_metadata :name => "properties", :type => ActiveFedora::MetadataDatastream do |m|
|
21
|
-
m.field "holding_id", :string
|
22
|
-
end
|
23
|
-
|
24
|
-
has_metadata :name => "descMetadata", :type => ActiveFedora::QualifiedDublinCoreDatastream do |m|
|
25
|
-
m.field "created", :date, :xml_node => "created"
|
26
|
-
m.field "language", :string, :xml_node => "language"
|
27
|
-
m.field "creator", :string, :xml_node => "creator"
|
28
|
-
# Created remaining fields
|
29
|
-
m.field "geography", :string, :xml_node => "geography"
|
30
|
-
m.field "title", :string, :xml_node => "title"
|
31
|
-
end
|
32
|
-
end
|
33
3
|
|
34
4
|
describe "Datastreams synched together" do
|
35
5
|
before do
|
@@ -57,6 +27,40 @@ end
|
|
57
27
|
|
58
28
|
|
59
29
|
describe ActiveFedora::Base do
|
30
|
+
before :all do
|
31
|
+
ActiveSupport::Deprecation.stubs(:warn).with("Deprecation: Relationships will not be included by default in the next version. To use has_relationship add 'include ActiveFedora::Relationships' to your model")
|
32
|
+
class MockAFBaseRelationship < ActiveFedora::Base
|
33
|
+
include ActiveFedora::FileManagement
|
34
|
+
has_relationship "testing", :has_part, :type=>MockAFBaseRelationship
|
35
|
+
has_relationship "testing2", :has_member, :type=>MockAFBaseRelationship
|
36
|
+
has_relationship "testing_inbound", :has_part, :type=>MockAFBaseRelationship, :inbound=>true
|
37
|
+
has_relationship "testing_inbound2", :has_member, :type=>MockAFBaseRelationship, :inbound=>true
|
38
|
+
has_bidirectional_relationship "testing_bidirectional", :has_collection_member, :is_member_of_collection
|
39
|
+
#next 2 used to test objects on opposite end of bidirectional relationship
|
40
|
+
has_relationship "testing_inbound3", :has_collection_member, :inbound=>true
|
41
|
+
has_relationship "testing3", :is_member_of_collection
|
42
|
+
end
|
43
|
+
|
44
|
+
class MockAFBaseFromSolr < ActiveFedora::Base
|
45
|
+
has_relationship "testing", :has_part, :type=>MockAFBaseFromSolr
|
46
|
+
has_relationship "testing2", :has_member, :type=>MockAFBaseFromSolr
|
47
|
+
has_relationship "testing_inbound", :has_part, :type=>MockAFBaseFromSolr, :inbound=>true
|
48
|
+
has_relationship "testing_inbound2", :has_member, :type=>MockAFBaseFromSolr, :inbound=>true
|
49
|
+
|
50
|
+
has_metadata :name => "properties", :type => ActiveFedora::MetadataDatastream do |m|
|
51
|
+
m.field "holding_id", :string
|
52
|
+
end
|
53
|
+
|
54
|
+
has_metadata :name => "descMetadata", :type => ActiveFedora::QualifiedDublinCoreDatastream do |m|
|
55
|
+
m.field "created", :date, :xml_node => "created"
|
56
|
+
m.field "language", :string, :xml_node => "language"
|
57
|
+
m.field "creator", :string, :xml_node => "creator"
|
58
|
+
# Created remaining fields
|
59
|
+
m.field "geography", :string, :xml_node => "geography"
|
60
|
+
m.field "title", :string, :xml_node => "title"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
60
64
|
|
61
65
|
before(:all) do
|
62
66
|
ActiveFedora::SolrService.register(ActiveFedora.solr_config[:url])
|
@@ -324,37 +328,40 @@ describe ActiveFedora::Base do
|
|
324
328
|
describe '#delete' do
|
325
329
|
it 'if inbound relationships exist should remove relationships from those inbound targets as well when deleting this object' do
|
326
330
|
@test_object2 = MockAFBaseRelationship.new
|
327
|
-
# @test_object2.new_object = true
|
328
331
|
@test_object2.save
|
329
332
|
@test_object3 = MockAFBaseRelationship.new
|
330
|
-
# @test_object3.new_object = true
|
331
333
|
@test_object3.save
|
332
334
|
@test_object4 = MockAFBaseRelationship.new
|
333
|
-
# @test_object4.new_object = true
|
334
335
|
@test_object4.save
|
335
336
|
@test_object5 = MockAFBaseRelationship.new
|
336
|
-
# @test_object5.new_object = true
|
337
337
|
@test_object5.save
|
338
338
|
#append to relationship by 'testing'
|
339
339
|
@test_object2.add_relationship_by_name("testing",@test_object3)
|
340
340
|
@test_object2.add_relationship_by_name("testing2",@test_object4)
|
341
341
|
@test_object5.add_relationship_by_name("testing",@test_object2)
|
342
|
-
|
342
|
+
#@test_object5.add_relationship_by_name("testing2",@test_object3)
|
343
343
|
@test_object2.save
|
344
344
|
@test_object5.save
|
345
|
-
#check
|
346
|
-
|
347
|
-
@
|
348
|
-
@
|
349
|
-
@
|
345
|
+
#check that the inbound relationships on test_object3 and test_object4 were eliminated
|
346
|
+
#testing goes to :has_part and testing2 goes to :has_member
|
347
|
+
@test_object2.relationships_by_name(false)[:inbound]["testing_inbound"].should == [@test_object5.internal_uri]
|
348
|
+
@test_object2.relationships_by_name(false)[:self]["parts_outbound"].should == [@test_object3.internal_uri]
|
349
|
+
@test_object2.relationships_by_name(false)[:self]["testing"].should == [@test_object3.internal_uri]
|
350
|
+
|
351
|
+
@test_object3.relationships_by_name(false)[:inbound]["testing_inbound"].should == [@test_object2.internal_uri]
|
352
|
+
@test_object4.relationships_by_name(false)[:inbound]["testing_inbound2"].should == [@test_object2.internal_uri]
|
353
|
+
|
354
|
+
@test_object5.relationships_by_name(false)[:self]["testing"].should == [@test_object2.internal_uri]
|
355
|
+
|
350
356
|
@test_object2.delete
|
351
357
|
#need to reload since removed from rels_ext in memory
|
352
358
|
@test_object5 = MockAFBaseRelationship.load_instance(@test_object5.pid)
|
353
359
|
|
354
360
|
#check any test_object2 inbound rels gone from source
|
355
|
-
@test_object3.relationships_by_name(false)
|
356
|
-
|
357
|
-
@
|
361
|
+
@test_object3.relationships_by_name(false)[:inbound]["testing_inbound"].should == []
|
362
|
+
|
363
|
+
@test_object4.relationships_by_name(false)[:inbound]["testing_inbound2"].should == []
|
364
|
+
@test_object5.relationships_by_name(false)[:self]["testing"].should == []
|
358
365
|
end
|
359
366
|
end
|
360
367
|
|
@@ -496,15 +503,38 @@ describe ActiveFedora::Base do
|
|
496
503
|
@test_object2.save
|
497
504
|
@test_object5.save
|
498
505
|
#check inbound correct, testing goes to :has_part and testing2 goes to :has_member
|
499
|
-
@test_object2.relationships_by_name(false)
|
500
|
-
@
|
501
|
-
@
|
502
|
-
@
|
506
|
+
@test_object2.relationships_by_name(false)[:self]["testing"].should == [@test_object3.internal_uri]
|
507
|
+
@test_object2.relationships_by_name(false)[:self]["testing2"].should == [@test_object4.internal_uri]
|
508
|
+
@test_object2.relationships_by_name(false)[:self]["parts_outbound"].should == [@test_object3.internal_uri]
|
509
|
+
@test_object2.relationships_by_name(false)[:inbound]["testing_inbound"].should == [@test_object5.internal_uri]
|
510
|
+
|
511
|
+
@test_object3.relationships_by_name(false)[:inbound]["testing_inbound"].should == [@test_object2.internal_uri]
|
512
|
+
@test_object3.relationships_by_name(false)[:inbound]["testing_inbound2"].should == [@test_object5.internal_uri]
|
513
|
+
|
514
|
+
@test_object4.relationships_by_name(false)[:inbound]["testing_inbound2"].should == [@test_object2.internal_uri]
|
515
|
+
|
516
|
+
@test_object5.relationships_by_name(false)[:self]["testing"].should == [@test_object2.internal_uri]
|
517
|
+
@test_object5.relationships_by_name(false)[:self]["testing2"].should == [@test_object3.internal_uri]
|
518
|
+
@test_object5.relationships_by_name(false)[:self]["parts_outbound"].should == [@test_object2.internal_uri]
|
519
|
+
|
503
520
|
#all inbound should now be empty if no parameter supplied to relationships
|
504
|
-
@test_object2.relationships_by_name
|
505
|
-
@
|
506
|
-
@
|
507
|
-
@
|
521
|
+
@test_object2.relationships_by_name[:self]["testing"].should == [@test_object3.internal_uri]
|
522
|
+
@test_object2.relationships_by_name[:self]["testing2"].should == [@test_object4.internal_uri]
|
523
|
+
@test_object2.relationships_by_name[:self]["parts_outbound"].should == [@test_object3.internal_uri]
|
524
|
+
@test_object2.relationships_by_name.should_not have_key :inbound
|
525
|
+
|
526
|
+
@test_object3.relationships_by_name.should_not have_key :inbound
|
527
|
+
@test_object4.relationships_by_name.should_not have_key :inbound
|
528
|
+
|
529
|
+
|
530
|
+
@test_object5.relationships_by_name[:self]["testing"].should == [@test_object2.internal_uri]
|
531
|
+
@test_object5.relationships_by_name[:self]["testing2"].should == [@test_object3.internal_uri]
|
532
|
+
@test_object5.relationships_by_name[:self]["parts_outbound"].should == [@test_object2.internal_uri]
|
533
|
+
@test_object5.relationships_by_name.should_not have_key :inbound
|
534
|
+
# @test_object2.relationships_by_name.should == {:self=>{"testing2"=>[@test_object4.internal_uri], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[@test_object3.internal_uri], "parts_outbound"=>[@test_object3.internal_uri], "testing_bidirectional_outbound"=>[]}}
|
535
|
+
# @test_object3.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
|
536
|
+
# @test_object4.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
|
537
|
+
# @test_object5.relationships_by_name.should == {:self=>{"testing2"=>[@test_object3.internal_uri], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[@test_object2.internal_uri], "parts_outbound"=>[@test_object2.internal_uri], "testing_bidirectional_outbound"=>[]}}
|
508
538
|
end
|
509
539
|
end
|
510
540
|
|
@@ -530,10 +560,19 @@ describe ActiveFedora::Base do
|
|
530
560
|
@test_object2.save
|
531
561
|
@test_object5.save
|
532
562
|
#check inbound correct, testing goes to :has_part and testing2 goes to :has_member
|
533
|
-
@test_object2.relationships_by_name(false)
|
534
|
-
@
|
535
|
-
@
|
536
|
-
@
|
563
|
+
@test_object2.relationships_by_name(false)[:self]["testing"].should == [@test_object3.internal_uri]
|
564
|
+
@test_object2.relationships_by_name(false)[:self]["testing2"].should == [@test_object4.internal_uri]
|
565
|
+
@test_object2.relationships_by_name(false)[:self]["parts_outbound"].should == [@test_object3.internal_uri]
|
566
|
+
@test_object2.relationships_by_name(false)[:inbound]["testing_inbound"].should == [@test_object5.internal_uri]
|
567
|
+
|
568
|
+
@test_object3.relationships_by_name(false)[:inbound]["testing_inbound"].should == [@test_object2.internal_uri]
|
569
|
+
@test_object3.relationships_by_name(false)[:inbound]["testing_inbound2"].should == [@test_object5.internal_uri]
|
570
|
+
|
571
|
+
@test_object4.relationships_by_name(false)[:inbound]["testing_inbound2"].should == [@test_object2.internal_uri]
|
572
|
+
|
573
|
+
@test_object5.relationships_by_name(false)[:self]["testing"].should == [@test_object2.internal_uri]
|
574
|
+
@test_object5.relationships_by_name(false)[:self]["testing2"].should == [@test_object3.internal_uri]
|
575
|
+
@test_object5.relationships_by_name(false)[:self]["parts_outbound"].should == [@test_object2.internal_uri]
|
537
576
|
end
|
538
577
|
end
|
539
578
|
|
@@ -559,23 +598,30 @@ describe ActiveFedora::Base do
|
|
559
598
|
@test_object2.save
|
560
599
|
@test_object5.save
|
561
600
|
#check inbound correct, testing goes to :has_part and testing2 goes to :has_member
|
562
|
-
@test_object2.relationships_by_name(false).should ==
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
@test_object3.relationships_by_name(false)
|
569
|
-
|
570
|
-
@
|
601
|
+
@test_object2.relationships_by_name(false)[:self]["testing"].should == [@test_object3.internal_uri]
|
602
|
+
@test_object2.relationships_by_name(false)[:self]["testing2"].should == [@test_object4.internal_uri]
|
603
|
+
@test_object2.relationships_by_name(false)[:self]["parts_outbound"].should == [@test_object3.internal_uri]
|
604
|
+
@test_object2.relationships_by_name(false)[:inbound]["testing_inbound"].should == [@test_object5.internal_uri]
|
605
|
+
|
606
|
+
@test_object3.relationships_by_name(false)[:inbound]["testing_inbound"].should == [@test_object2.internal_uri]
|
607
|
+
@test_object3.relationships_by_name(false)[:inbound]["testing_inbound2"].should == [@test_object5.internal_uri]
|
608
|
+
|
609
|
+
@test_object4.relationships_by_name(false)[:inbound]["testing_inbound2"].should == [@test_object2.internal_uri]
|
610
|
+
|
611
|
+
@test_object5.relationships_by_name(false)[:self]["testing"].should == [@test_object2.internal_uri]
|
612
|
+
@test_object5.relationships_by_name(false)[:self]["testing2"].should == [@test_object3.internal_uri]
|
613
|
+
@test_object5.relationships_by_name(false)[:self]["parts_outbound"].should == [@test_object2.internal_uri]
|
614
|
+
|
571
615
|
@test_object2.remove_relationship_by_name("testing",@test_object3.internal_uri)
|
572
616
|
@test_object2.save
|
573
617
|
#check now removed for both outbound and inbound
|
574
|
-
@test_object2.relationships_by_name(false)
|
618
|
+
@test_object2.relationships_by_name(false)[:self]["testing"].should == []
|
619
|
+
@test_object2.relationships_by_name(false)[:self]["testing2"].should == [@test_object4.internal_uri]
|
620
|
+
@test_object2.relationships_by_name(false)[:self]["parts_outbound"].should == []
|
621
|
+
@test_object2.relationships_by_name(false)[:inbound]["testing_inbound"].should == [@test_object5.internal_uri]
|
575
622
|
|
576
|
-
@test_object3.
|
577
|
-
|
578
|
-
@test_object3.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[@test_object5.internal_uri]}, :self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
|
623
|
+
@test_object3.relationships_by_name(false)[:inbound]["testing_inbound"].should == []
|
624
|
+
@test_object3.relationships_by_name(false)[:inbound]["testing_inbound2"].should == [@test_object5.internal_uri]
|
579
625
|
end
|
580
626
|
end
|
581
627
|
|