active-fedora 3.1.6 → 3.2.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +22 -22
- data/History.txt +9 -3
- data/active-fedora.gemspec +3 -3
- data/config/predicate_mappings.yml +1 -0
- data/config/service_mappings.yml +9 -0
- data/lib/active_fedora.rb +7 -1
- data/lib/active_fedora/base.rb +84 -30
- data/lib/active_fedora/datastream.rb +4 -1
- data/lib/active_fedora/datastream_collections.rb +304 -293
- data/lib/active_fedora/metadata_datastream.rb +2 -24
- data/lib/active_fedora/metadata_datastream_helper.rb +32 -5
- data/lib/active_fedora/named_relationships.rb +95 -0
- data/lib/active_fedora/nested_attributes.rb +1 -1
- data/lib/active_fedora/predicates.rb +76 -0
- data/lib/active_fedora/reflection.rb +9 -1
- data/lib/active_fedora/relationship.rb +1 -0
- data/lib/active_fedora/relationship_graph.rb +152 -0
- data/lib/active_fedora/relationships_helper.rb +32 -41
- data/lib/active_fedora/rels_ext_datastream.rb +3 -10
- data/lib/active_fedora/semantic_node.rb +47 -203
- data/lib/active_fedora/service_definitions.rb +89 -0
- data/lib/active_fedora/unsaved_digital_object.rb +40 -0
- data/lib/active_fedora/version.rb +1 -1
- data/spec/integration/base_spec.rb +106 -309
- data/spec/integration/datastream_collections_spec.rb +135 -0
- data/spec/integration/rels_ext_datastream_spec.rb +14 -35
- data/spec/integration/semantic_node_spec.rb +6 -10
- data/spec/unit/base_datastream_management_spec.rb +0 -3
- data/spec/unit/base_extra_spec.rb +5 -9
- data/spec/unit/base_spec.rb +103 -57
- data/spec/unit/{base_named_datastream_spec.rb → datastream_collections_spec.rb} +107 -150
- data/spec/unit/metadata_datastream_spec.rb +0 -1
- data/spec/unit/nokogiri_datastream_spec.rb +0 -1
- data/spec/unit/predicates_spec.rb +64 -0
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -7
- data/spec/unit/relationship_graph_spec.rb +95 -0
- data/spec/unit/relationship_spec.rb +4 -4
- data/spec/unit/relationships_helper_spec.rb +43 -104
- data/spec/unit/rels_ext_datastream_spec.rb +6 -6
- data/spec/unit/semantic_node_spec.rb +27 -116
- data/spec/unit/service_definitions_spec.rb +52 -0
- data/spec/unit/solr_config_options_spec.rb +1 -1
- metadata +35 -17
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'active_support/core_ext/class/inheritable_attributes'
|
2
1
|
module ActiveFedora
|
3
2
|
# This module is meant to extend semantic node to add functionality based on a relationship's name
|
4
3
|
# It is meant to turn a relationship into just another attribute in a model.
|
@@ -25,16 +24,10 @@ module ActiveFedora
|
|
25
24
|
module RelationshipsHelper
|
26
25
|
extend ActiveSupport::Concern
|
27
26
|
|
28
|
-
# ms_inheritable_attributes :class_relationships_desc
|
29
27
|
included do
|
30
|
-
|
31
|
-
# self.class_relationships_desc = {}
|
28
|
+
class_attribute :class_relationships_desc
|
32
29
|
end
|
33
30
|
|
34
|
-
# def self.included(klass)
|
35
|
-
# klass.extend(ClassMethods)
|
36
|
-
# end
|
37
|
-
|
38
31
|
|
39
32
|
# ** EXPERIMENTAL **
|
40
33
|
#
|
@@ -103,7 +96,7 @@ module ActiveFedora
|
|
103
96
|
rels[:self] = {}
|
104
97
|
names.each_pair do |name, predicate|
|
105
98
|
set = []
|
106
|
-
res = relationships.query(:predicate => find_graph_predicate(predicate))
|
99
|
+
res = relationships.query(:predicate => Predicates.find_graph_predicate(predicate))
|
107
100
|
res.each_object do |o|
|
108
101
|
set << o.to_s
|
109
102
|
end
|
@@ -285,8 +278,6 @@ module ActiveFedora
|
|
285
278
|
(assert_conforms_to 'object', object, klass)
|
286
279
|
end
|
287
280
|
end
|
288
|
-
#r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>outbound_relationship_predicates[name],:object=>object})
|
289
|
-
#add_relationship(r)
|
290
281
|
add_relationship(outbound_relationship_predicates[name],object)
|
291
282
|
else
|
292
283
|
false
|
@@ -330,7 +321,7 @@ module ActiveFedora
|
|
330
321
|
def conforms_to?(model_class)
|
331
322
|
if self.kind_of?(model_class)
|
332
323
|
#check has model and class match
|
333
|
-
mod = relationships.first(:predicate=>find_graph_predicate(:has_model))
|
324
|
+
mod = relationships.first(:predicate=>Predicates.find_graph_predicate(:has_model))
|
334
325
|
if mod
|
335
326
|
expected = ActiveFedora::ContentModel.pid_from_ruby_class(self.class)
|
336
327
|
if mod.object.to_s == expected
|
@@ -429,121 +420,121 @@ module ActiveFedora
|
|
429
420
|
|
430
421
|
# @deprecated Please use {#find_relationship_by_name} instead.
|
431
422
|
def named_relationship(name)
|
432
|
-
|
423
|
+
ActiveSupport::Deprecation.warn("Deprecation: named_relationship has been deprecated. Please call find_relationship_by_name instead.")
|
433
424
|
find_relationship_by_name(name)
|
434
425
|
end
|
435
426
|
|
436
427
|
# @deprecated Please use {#register_relationship_desc_subject} instead.
|
437
428
|
def register_named_subject(subject)
|
438
|
-
|
429
|
+
ActiveSupport::Deprecation.warn("Deprecation: register_named_subject has been deprecated. Please call register_relationship_desc_subject instead.")
|
439
430
|
register_relationship_desc_subject(subject)
|
440
431
|
end
|
441
432
|
|
442
433
|
# @deprecated Please use {#register_relationship_desc} instead.
|
443
434
|
def register_named_relationship(subject, name, predicate, opts)
|
444
|
-
|
435
|
+
ActiveSupport::Deprecation.warn("Deprecation: register_named_relationship has been deprecated. Please call register_relationship_desc instead.")
|
445
436
|
register_relationship_desc(subject, name, predicate, opts)
|
446
437
|
end
|
447
438
|
|
448
439
|
# @deprecated Please use {#relationships_by_name} instead.
|
449
440
|
def named_relationships(outbound_only=true)
|
450
|
-
|
441
|
+
ActiveSupport::Deprecation.warn("Deprecation: named_relationships has been deprecated. Please call relationships_by_name instead.")
|
451
442
|
relationships_by_name(outbound_only)
|
452
443
|
end
|
453
444
|
|
454
445
|
# @deprecated Please use {#relationships_by_name_from_class} instead.
|
455
446
|
def named_relationships_from_class
|
456
|
-
|
447
|
+
ActiveSupport::Deprecation.warn("Deprecation: named_relationships_from_class has been deprecated. Please call relationships_by_name_from_class instead.")
|
457
448
|
relationships_by_name_from_class
|
458
449
|
end
|
459
450
|
|
460
451
|
# @deprecated Please use {#inbound_relationships_by_name} instead.
|
461
452
|
def named_inbound_relationships
|
462
|
-
|
453
|
+
ActiveSupport::Deprecation.warn("Deprecation: named_inbound_relationships has been deprecated. Please call inbound_relationships_by_name instead.")
|
463
454
|
inbound_relationships_by_name
|
464
455
|
end
|
465
456
|
|
466
457
|
# @deprecated Please use {#outbound_relationships_by_name} instead.
|
467
458
|
def named_outbound_relationships
|
468
|
-
|
459
|
+
ActiveSupport::Deprecation.warn("Deprecation: named_outbound_relationships has been deprecated. Please call outbound_relationships_by_name instead.")
|
469
460
|
outbound_relationships_by_name
|
470
461
|
end
|
471
462
|
|
472
463
|
# @deprecated Please use {#outbound_relationship_predicates} instead.
|
473
464
|
def outbound_named_relationship_predicates
|
474
|
-
|
465
|
+
ActiveSupport::Deprecation.warn("Deprecation: outbound_named_relationship_predicates has been deprecated. Please call outbound_relationship_predicates instead.")
|
475
466
|
outbound_relationship_predicates
|
476
467
|
end
|
477
468
|
|
478
469
|
# @deprecated Please use {#inbound_relationship_predicates} instead.
|
479
470
|
def inbound_named_relationship_predicates
|
480
|
-
|
471
|
+
ActiveSupport::Deprecation.warn("Deprecation: inbound_named_relationship_predicates has been deprecated. Please call inbound_relationship_predicates instead.")
|
481
472
|
inbound_relationship_predicates
|
482
473
|
end
|
483
474
|
|
484
475
|
# @deprecated Please use {#relationship_predicates} instead.
|
485
476
|
def named_relationship_predicates
|
486
|
-
|
477
|
+
ActiveSupport::Deprecation.warn("Deprecation: named_relationship_predicates has been deprecated. Please call relationship_predicates instead.")
|
487
478
|
relationship_predicates
|
488
479
|
end
|
489
480
|
|
490
481
|
# @deprecated Please use {#relationship_predicates_from_class} instead.
|
491
482
|
def named_relationship_predicates_from_class
|
492
|
-
|
483
|
+
ActiveSupport::Deprecation.warn("Deprecation: named_relationship_predicates_from_class has been deprecated. Please call relationship_predicates_from_class instead.")
|
493
484
|
relationship_predicates_from_class
|
494
485
|
end
|
495
486
|
|
496
487
|
# @deprecated Please use {#is_relationship_name?} instead.
|
497
488
|
def is_named_relationship?(name, outbound_only=true)
|
498
|
-
|
489
|
+
ActiveSupport::Deprecation.warn("Deprecation: is_named_relationship? has been deprecated. Please call is_relationship_name? instead.")
|
499
490
|
is_relationship_name?(name,outbound_only)
|
500
491
|
end
|
501
492
|
|
502
493
|
# @deprecated Please use {#relationships_desc} instead.
|
503
494
|
def named_relationships_desc
|
504
|
-
|
495
|
+
ActiveSupport::Deprecation.warn("Deprecation: named_relationships_desc has been deprecated. Please call relationships_desc instead.")
|
505
496
|
relationships_desc
|
506
497
|
end
|
507
498
|
|
508
499
|
# @deprecated Please use {#relationships_desc_from_class} instead.
|
509
500
|
def named_relationships_desc_from_class
|
510
|
-
|
501
|
+
ActiveSupport::Deprecation.warn("Deprecation: named_relationships_desc_from_class has been deprecated. Please call relationships_desc_from_class instead.")
|
511
502
|
relationships_desc_from_class
|
512
503
|
end
|
513
504
|
|
514
505
|
# @deprecated Please use {#relationship_model_type} instead.
|
515
506
|
def named_relationship_type(name)
|
516
|
-
|
507
|
+
ActiveSupport::Deprecation.warn("Deprecation: named_relationship_type has been deprecated. Please call relationship_model_type instead.")
|
517
508
|
relationship_model_type(name)
|
518
509
|
end
|
519
510
|
|
520
511
|
# @deprecated Please use {#add_relationship_by_name} instead.
|
521
512
|
def add_named_relationship(name,object)
|
522
|
-
|
513
|
+
ActiveSupport::Deprecation.warn("Deprecation: add_named_relationship has been deprecated. Please call add_relationship_by_name instead.")
|
523
514
|
add_relationship_by_name(name,object)
|
524
515
|
end
|
525
516
|
|
526
517
|
# @deprecated Please use {#remove_relationship_by_name} instead.
|
527
518
|
def remove_named_relationship(name,object)
|
528
|
-
|
519
|
+
ActiveSupport::Deprecation.warn("Deprecation: remove_named_relationship has been deprecated. Please call remove_relationship_by_name instead.")
|
529
520
|
remove_relationship_by_name(name,object)
|
530
521
|
end
|
531
522
|
|
532
523
|
# @deprecated Please use {#assert_conforms_to} instead.
|
533
524
|
def assert_kind_of_model(name,object,model_class)
|
534
|
-
|
525
|
+
ActiveSupport::Deprecation.warn("Deprecation: assert_kind_of_model has been deprecated. Please call assert_conforms_to instead.")
|
535
526
|
assert_conforms_to(name,object,model_class)
|
536
527
|
end
|
537
528
|
|
538
529
|
# @deprecated Please use {#conforms_to?} instead.
|
539
530
|
def kind_of_model?(model_class)
|
540
|
-
|
531
|
+
ActiveSupport::Deprecation.warn("Deprecation: kind_of_model? has been deprecated. Please call conforms_to? instead.")
|
541
532
|
conforms_to?(model_class)
|
542
533
|
end
|
543
534
|
|
544
535
|
# @deprecated Please use {#relationship_query} instead.
|
545
536
|
def named_relationship_query(relationship_name)
|
546
|
-
|
537
|
+
ActiveSupport::Deprecation.warn("Deprecation: named_relationship_query has been deprecated. Please call relationship_query instead.")
|
547
538
|
relationship_query(relationship_name)
|
548
539
|
end
|
549
540
|
|
@@ -834,55 +825,55 @@ module ActiveFedora
|
|
834
825
|
|
835
826
|
# @deprecated Please use {#relationships_desc} instead.
|
836
827
|
def named_relationships_desc
|
837
|
-
|
828
|
+
ActiveSupport::Deprecation.warn("Deprecation: named_relationships_desc has been deprecated. Please call relationships_desc instead.")
|
838
829
|
relationships_desc
|
839
830
|
end
|
840
831
|
|
841
832
|
# @deprecated Please use {#register_relationship_desc_subject} instead.
|
842
833
|
def register_named_subject(subject)
|
843
|
-
|
834
|
+
ActiveSupport::Deprecation.warn("Deprecation: register_named_subject has been deprecated. Please call register_relationship_desc_subject instead.")
|
844
835
|
register_relationship_desc_subject(subject)
|
845
836
|
end
|
846
837
|
|
847
838
|
# @deprecated Please use {#register_relationship_desc} instead.
|
848
839
|
def register_named_relationship(subject, name, predicate, opts)
|
849
|
-
|
840
|
+
ActiveSupport::Deprecation.warn("Deprecation: register_named_relationship has been deprecated. Please call register_relationship_desc instead.")
|
850
841
|
register_relationship_desc(subject, name, predicate, opts)
|
851
842
|
end
|
852
843
|
|
853
844
|
# @deprecated Please use {#create_relationship_name_methods} instead.
|
854
845
|
def create_named_relationship_methods(name)
|
855
|
-
|
846
|
+
ActiveSupport::Deprecation.warn("Deprecation: create_named_relationship_methods has been deprecated. Please call create_relationship_name_methods instead.")
|
856
847
|
create_relationship_name_methods(name)
|
857
848
|
end
|
858
849
|
|
859
850
|
# @deprecated Please use {#create_bidirectional_relationship_name_methods} instead.
|
860
851
|
def create_bidirectional_named_relationship_methods(name,outbound_name)
|
861
|
-
|
852
|
+
ActiveSupport::Deprecation.warn("Deprecation: create_bidirectional_named_relationship_methods has been deprecated. Please call create_bidirectional_relationship_name_methods instead.")
|
862
853
|
create_bidirectional_relationship_name_methods(name,outbound_name)
|
863
854
|
end
|
864
855
|
|
865
856
|
# @deprecated Please use {#outbound_relationship_query} instead.
|
866
857
|
def outbound_named_relationship_query(relationship_name,outbound_pids)
|
867
|
-
|
858
|
+
ActiveSupport::Deprecation.warn("Deprecation: outbound_named_relationship_query has been deprecated. Please call outbound_relationship_query instead.")
|
868
859
|
outbound_relationship_query(relationship_name,outbound_pids)
|
869
860
|
end
|
870
861
|
|
871
862
|
# @deprecated Please use {#inbound_relationship_query} instead.
|
872
863
|
def inbound_named_relationship_query(pid,relationship_name)
|
873
|
-
|
864
|
+
ActiveSupport::Deprecation.warn("Deprecation: inbound_named_relationship_query has been deprecated. Please call inbound_relationship_query instead.")
|
874
865
|
inbound_relationship_query(pid,relationship_name)
|
875
866
|
end
|
876
867
|
|
877
868
|
# @deprecated Please use {#bidirectional_relationship_query} instead.
|
878
869
|
def bidirectional_named_relationship_query(pid,relationship_name,outbound_pids)
|
879
|
-
|
870
|
+
ActiveSupport::Deprecation.warn("Deprecation: bidirectional_named_relationship_query has been deprecated. Please call bidirectional_relationship_query instead.")
|
880
871
|
bidirectional_relationship_query(pid,relationship_name,outbound_pids)
|
881
872
|
end
|
882
873
|
|
883
874
|
# @deprecated Please use {#predicate_exists_with_different_relationship_name?} instead.
|
884
875
|
def named_predicate_exists_with_different_name?(subject,name,predicate)
|
885
|
-
|
876
|
+
ActiveSupport::Deprecation.warn("Deprecation: named_predicate_exists_with_different_name? has been deprecated. Please call predicate_exists_with_different_relationship_name? instead.")
|
886
877
|
predicate_exists_with_different_relationship_name?(subject,name,predicate)
|
887
878
|
end
|
888
879
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'active_support/core_ext/class/inheritable_attributes'
|
2
1
|
require 'solrizer/field_name_mapper'
|
3
2
|
require 'uri'
|
4
3
|
require 'rdf/rdfxml'
|
@@ -61,10 +60,10 @@ module ActiveFedora
|
|
61
60
|
end
|
62
61
|
|
63
62
|
def self.short_predicate(predicate)
|
64
|
-
if match = /^(#{
|
63
|
+
if match = /^(#{Predicates.predicate_mappings.keys.join('|')})(.+)$/.match(predicate.to_str)
|
65
64
|
namespace = match[1]
|
66
65
|
predicate = match[2]
|
67
|
-
pred =
|
66
|
+
pred = Predicates.predicate_mappings[namespace].invert[predicate]
|
68
67
|
pred
|
69
68
|
else
|
70
69
|
raise "Unable to parse predicate: #{predicate}"
|
@@ -84,21 +83,15 @@ module ActiveFedora
|
|
84
83
|
def from_solr(solr_doc)
|
85
84
|
#cycle through all possible predicates
|
86
85
|
model.relationships_loaded = true
|
87
|
-
|
86
|
+
Predicates.predicate_mappings[Predicates.default_predicate_namespace].keys.each do |predicate|
|
88
87
|
predicate_symbol = ActiveFedora::SolrService.solr_name(predicate, :symbol)
|
89
88
|
value = (solr_doc[predicate_symbol].nil? ? solr_doc[predicate_symbol.to_s]: solr_doc[predicate_symbol])
|
90
89
|
unless value.nil?
|
91
90
|
if value.is_a? Array
|
92
91
|
value.each do |obj|
|
93
|
-
#o_uri = URI.parse(obj)
|
94
|
-
#literal = o_uri.scheme.nil?
|
95
|
-
#r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>obj, :is_literal=>literal)
|
96
92
|
model.add_relationship(predicate, obj)
|
97
93
|
end
|
98
94
|
else
|
99
|
-
#o_uri = URI.parse(value)
|
100
|
-
#literal = o_uri.scheme.nil?
|
101
|
-
#r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>value, :is_literal=>literal)
|
102
95
|
model.add_relationship(predicate, value)
|
103
96
|
end
|
104
97
|
end
|
@@ -1,31 +1,35 @@
|
|
1
1
|
require 'rdf'
|
2
|
-
require 'active_support/core_ext/class/inheritable_attributes'
|
3
2
|
module ActiveFedora
|
4
3
|
module SemanticNode
|
5
4
|
extend ActiveSupport::Concern
|
6
5
|
included do
|
7
|
-
|
6
|
+
class_attribute :class_relationships, :internal_uri
|
8
7
|
self.class_relationships = {}
|
9
|
-
self.class_named_relationships_desc = {}
|
10
8
|
end
|
11
|
-
attr_accessor :
|
12
|
-
|
13
|
-
#TODO I think we can remove named_relationship_desc from attr_accessor - jcoyne
|
9
|
+
attr_accessor :relationships_loaded, :load_from_solr, :subject
|
14
10
|
|
15
11
|
def assert_kind_of(n, o,t)
|
16
12
|
raise "Assertion failure: #{n}: #{o} is not of type #{t}" unless o.kind_of?(t)
|
17
13
|
end
|
14
|
+
|
15
|
+
def object_relations
|
16
|
+
load_relationships if !relationships_loaded
|
17
|
+
@object_relations ||= RelationshipGraph.new
|
18
|
+
end
|
18
19
|
|
20
|
+
def relationships_are_dirty
|
21
|
+
object_relations.dirty
|
22
|
+
end
|
23
|
+
def relationships_are_dirty=(val)
|
24
|
+
object_relations.dirty = val
|
25
|
+
end
|
26
|
+
|
19
27
|
# Add a relationship to the Object.
|
20
28
|
# @param predicate
|
21
29
|
# @param object Either a string URI or an object that is a kind of ActiveFedora::Base
|
22
30
|
def add_relationship(predicate, target, literal=false)
|
23
|
-
|
24
|
-
|
25
|
-
relationships.insert stmt
|
26
|
-
@relationships_are_dirty = true
|
27
|
-
rels_ext.dirty = true
|
28
|
-
end
|
31
|
+
object_relations.add(predicate, target, literal)
|
32
|
+
rels_ext.dirty = true
|
29
33
|
end
|
30
34
|
|
31
35
|
# Create an RDF statement
|
@@ -33,6 +37,7 @@ module ActiveFedora
|
|
33
37
|
# @param predicate a predicate symbol
|
34
38
|
# @param target an object to store
|
35
39
|
def build_statement(uri, predicate, target, literal=false)
|
40
|
+
ActiveSupport::Deprecation.warn("ActiveFedora::Base#build_statement has been deprecated.")
|
36
41
|
raise "Not allowed anymore" if uri == :self
|
37
42
|
target = target.internal_uri if target.respond_to? :internal_uri
|
38
43
|
subject = RDF::URI.new(uri) #TODO cache
|
@@ -60,42 +65,15 @@ module ActiveFedora
|
|
60
65
|
|
61
66
|
end
|
62
67
|
|
63
|
-
def find_graph_predicate(predicate)
|
64
|
-
#TODO, these could be cached
|
65
|
-
case predicate
|
66
|
-
when :has_model, "hasModel", :hasModel
|
67
|
-
xmlns="info:fedora/fedora-system:def/model#"
|
68
|
-
begin
|
69
|
-
rel_predicate = ActiveFedora::Base.predicate_lookup(predicate,xmlns)
|
70
|
-
rescue UnregisteredPredicateError
|
71
|
-
xmlns = nil
|
72
|
-
rel_predicate = nil
|
73
|
-
end
|
74
|
-
else
|
75
|
-
xmlns="info:fedora/fedora-system:def/relations-external#"
|
76
|
-
begin
|
77
|
-
rel_predicate = ActiveFedora::Base.predicate_lookup(predicate,xmlns)
|
78
|
-
rescue UnregisteredPredicateError
|
79
|
-
xmlns = nil
|
80
|
-
rel_predicate = nil
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
unless xmlns && rel_predicate
|
85
|
-
rel_predicate, xmlns = ActiveFedora::Base.find_predicate(predicate)
|
86
|
-
end
|
87
|
-
self.class.vocabularies[xmlns][rel_predicate]
|
88
|
-
end
|
89
68
|
|
90
69
|
|
91
|
-
# ** EXPERIMENTAL **
|
92
70
|
#
|
93
71
|
# Remove a Rels-Ext relationship from the Object.
|
94
72
|
# @param predicate
|
95
73
|
# @param object Either a string URI or an object that responds to .pid
|
96
74
|
def remove_relationship(predicate, obj, literal=false)
|
97
|
-
|
98
|
-
|
75
|
+
object_relations.delete(predicate, obj)
|
76
|
+
self.relationships_are_dirty = true
|
99
77
|
rels_ext.dirty = true
|
100
78
|
end
|
101
79
|
|
@@ -106,10 +84,8 @@ module ActiveFedora
|
|
106
84
|
items = []
|
107
85
|
objects.each do |object|
|
108
86
|
if (response_format == :uri)
|
109
|
-
#create a Relationship object so that it generates the appropriate uri
|
110
87
|
#inbound relationships are always object properties
|
111
|
-
|
112
|
-
items.push(r.object)
|
88
|
+
items.push(object.internal_uri)
|
113
89
|
else
|
114
90
|
items.push(object)
|
115
91
|
end
|
@@ -128,19 +104,14 @@ module ActiveFedora
|
|
128
104
|
# If no arguments are supplied, return the whole RDF::Graph.
|
129
105
|
# if a predicate is supplied as a parameter, then it returns the result of quering the graph with that predicate
|
130
106
|
def relationships(*args)
|
131
|
-
unless @subject
|
132
|
-
raise "Must have internal_uri" unless internal_uri
|
133
|
-
@subject = RDF::URI.new(internal_uri)
|
134
|
-
end
|
135
|
-
@relationships ||= RDF::Graph.new
|
136
107
|
load_relationships if !relationships_loaded
|
137
108
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
109
|
+
if args.empty?
|
110
|
+
raise "Must have internal_uri" unless internal_uri
|
111
|
+
return object_relations.to_graph(internal_uri)
|
112
|
+
end
|
113
|
+
rels = object_relations[args.first] || []
|
114
|
+
rels.map {|o| o.respond_to?(:internal_uri) ? o.internal_uri : o } #TODO, could just return the object
|
144
115
|
end
|
145
116
|
|
146
117
|
def load_relationships
|
@@ -185,12 +156,10 @@ module ActiveFedora
|
|
185
156
|
|
186
157
|
|
187
158
|
def ids_for_outbound(predicate)
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
id_array << o.gsub("info:fedora/", "")
|
159
|
+
(object_relations[predicate] || []).map do |o|
|
160
|
+
o = o.to_s if o.kind_of? RDF::Literal
|
161
|
+
o.kind_of?(String) ? o.gsub("info:fedora/", "") : o.pid
|
192
162
|
end
|
193
|
-
id_array
|
194
163
|
end
|
195
164
|
|
196
165
|
def load_bidirectional(name, inbound_method_name, outbound_method_name, opts)
|
@@ -219,7 +188,7 @@ module ActiveFedora
|
|
219
188
|
if opts[:response_format] == :id_array && !self.class.relationship_has_solr_filter_query?(:self,"#{name}")
|
220
189
|
return id_array
|
221
190
|
else
|
222
|
-
query = self.class.outbound_relationship_query(
|
191
|
+
query = self.class.outbound_relationship_query(name,id_array)
|
223
192
|
solr_result = SolrService.instance.conn.query(query)
|
224
193
|
if opts[:response_format] == :solr
|
225
194
|
return solr_result
|
@@ -238,13 +207,6 @@ module ActiveFedora
|
|
238
207
|
end
|
239
208
|
|
240
209
|
module ClassMethods
|
241
|
-
def vocabularies
|
242
|
-
return @vocabularies if @vocabularies
|
243
|
-
@vocabularies = {}
|
244
|
-
predicate_mappings.keys.each { |ns| @vocabularies[ns] = RDF::Vocabulary.new(ns)}
|
245
|
-
@vocabularies
|
246
|
-
end
|
247
|
-
|
248
210
|
# Allows for a relationship to be treated like any other attribute of a model class. You define
|
249
211
|
# relationships in your model class using this method. You then have access to several
|
250
212
|
# helper methods to list, append, and remove objects from the list of relationships.
|
@@ -320,91 +282,29 @@ module ActiveFedora
|
|
320
282
|
create_bidirectional_relationship_finders(name, outbound_predicate, inbound_predicate, opts)
|
321
283
|
end
|
322
284
|
|
323
|
-
|
324
|
-
#
|
325
|
-
#
|
326
|
-
#
|
327
|
-
|
328
|
-
|
329
|
-
# to predicate in RELS-EXT would be broken.
|
330
|
-
def named_predicate_exists_with_different_name?(subject,name,predicate)
|
331
|
-
if named_relationships_desc.has_key?(subject)
|
332
|
-
named_relationships_desc[subject].each_pair do |existing_name, args|
|
333
|
-
return true if !args[:predicate].nil? && args[:predicate] == predicate && existing_name != name
|
334
|
-
end
|
335
|
-
end
|
336
|
-
return false
|
337
|
-
end
|
338
|
-
|
339
|
-
# ** EXPERIMENTAL **
|
340
|
-
#
|
341
|
-
# Return hash that stores named relationship metadata defined by has_relationship calls
|
342
|
-
# ====Example
|
343
|
-
# For the following relationship
|
344
|
-
#
|
345
|
-
# has_relationship "audio_records", :has_part, :type=>AudioRecord
|
346
|
-
# Results in the following returned by named_relationships_desc
|
347
|
-
# {:self=>{"audio_records"=>{:type=>AudioRecord, :singular=>nil, :predicate=>:has_part, :inbound=>false}}}
|
348
|
-
def named_relationships_desc
|
349
|
-
@class_named_relationships_desc ||= Hash[:self => {}]
|
350
|
-
#class_named_relationships_desc
|
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 => {}]
|
351
291
|
end
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
def register_named_subject(subject)
|
358
|
-
unless named_relationships_desc.has_key?(subject)
|
359
|
-
named_relationships_desc[subject] = {}
|
292
|
+
|
293
|
+
|
294
|
+
def register_subject(subject)
|
295
|
+
if !relationships.has_key?(subject)
|
296
|
+
relationships[subject] = {}
|
360
297
|
end
|
361
298
|
end
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
register_named_subject(subject)
|
369
|
-
opts.merge!({:predicate=>predicate})
|
370
|
-
named_relationships_desc[subject][name] = opts
|
299
|
+
|
300
|
+
def register_predicate(subject, predicate)
|
301
|
+
register_subject(subject)
|
302
|
+
if !relationships[subject].has_key?(predicate)
|
303
|
+
relationships[subject][predicate] = []
|
304
|
+
end
|
371
305
|
end
|
372
|
-
|
373
|
-
# ** EXPERIMENTAL **
|
374
|
-
#
|
375
|
-
# Used in has_relationship call to create dynamic helper methods to
|
376
|
-
# append and remove objects to and from a named relationship
|
377
|
-
# ====Example
|
378
|
-
# For the following relationship
|
379
|
-
#
|
380
|
-
# has_relationship "audio_records", :has_part, :type=>AudioRecord
|
381
|
-
#
|
382
|
-
# Methods audio_records_append and audio_records_remove are created.
|
383
|
-
# Boths methods take an object that is kind_of? ActiveFedora::Base as a parameter
|
384
|
-
def create_named_relationship_methods(name)
|
385
|
-
append_method_name = "#{name.to_s.downcase}_append"
|
386
|
-
remove_method_name = "#{name.to_s.downcase}_remove"
|
387
|
-
self.send(:define_method,:"#{append_method_name}") {|object| add_named_relationship(name,object)}
|
388
|
-
self.send(:define_method,:"#{remove_method_name}") {|object| remove_named_relationship(name,object)}
|
389
|
-
end
|
390
306
|
|
391
|
-
# ** EXPERIMENTAL **
|
392
|
-
# Similar to +create_named_relationship_methods+ except we are merely creating an alias for outbound portion of bidirectional
|
393
|
-
#
|
394
|
-
# ====Example
|
395
|
-
# has_bidirectional_relationship "members", :has_collection_member, :is_member_of_collection
|
396
|
-
#
|
397
|
-
# Method members_outbound_append and members_outbound_remove added
|
398
|
-
# This method will create members_append which does same thing as members_outbound_append
|
399
|
-
# and will create members_remove which does same thing as members_outbound_remove
|
400
|
-
def create_bidirectional_named_relationship_methods(name,outbound_name)
|
401
|
-
append_method_name = "#{name.to_s.downcase}_append"
|
402
|
-
remove_method_name = "#{name.to_s.downcase}_remove"
|
403
|
-
self.send(:define_method,:"#{append_method_name}") {|object| add_named_relationship(outbound_name,object)}
|
404
|
-
self.send(:define_method,:"#{remove_method_name}") {|object| remove_named_relationship(outbound_name,object)}
|
405
|
-
end
|
406
307
|
|
407
|
-
|
408
308
|
def create_inbound_relationship_finders(name, predicate, opts = {})
|
409
309
|
class_eval <<-END, __FILE__, __LINE__
|
410
310
|
def #{name}(opts={})
|
@@ -472,62 +372,6 @@ module ActiveFedora
|
|
472
372
|
end
|
473
373
|
END
|
474
374
|
end
|
475
|
-
|
476
|
-
# relationships are tracked as a hash of structure
|
477
|
-
# @example
|
478
|
-
# ds.relationships # => {:self=>{:has_model=>["afmodel:SimpleThing"],:has_part=>["demo:20"]},:inbound=>{:is_part_of=>["demo:6"]}
|
479
|
-
def relationships
|
480
|
-
@class_relationships ||= Hash[:self => {}]
|
481
|
-
end
|
482
|
-
|
483
|
-
|
484
|
-
def register_subject(subject)
|
485
|
-
if !relationships.has_key?(subject)
|
486
|
-
relationships[subject] = {}
|
487
|
-
end
|
488
|
-
end
|
489
|
-
|
490
|
-
def register_predicate(subject, predicate)
|
491
|
-
register_subject(subject)
|
492
|
-
if !relationships[subject].has_key?(predicate)
|
493
|
-
relationships[subject][predicate] = []
|
494
|
-
end
|
495
|
-
end
|
496
|
-
|
497
|
-
# If predicate is a symbol, looks up the predicate in the predicate_mappings
|
498
|
-
# If predicate is not a Symbol, returns the predicate untouched
|
499
|
-
# @raise UnregisteredPredicateError if the predicate is a symbol but is not found in the predicate_mappings
|
500
|
-
def predicate_lookup(predicate,namespace="info:fedora/fedora-system:def/relations-external#")
|
501
|
-
if predicate.class == Symbol
|
502
|
-
if predicate_mappings[namespace].has_key?(predicate)
|
503
|
-
return predicate_mappings[namespace][predicate]
|
504
|
-
else
|
505
|
-
raise ActiveFedora::UnregisteredPredicateError
|
506
|
-
end
|
507
|
-
end
|
508
|
-
return predicate
|
509
|
-
end
|
510
|
-
|
511
|
-
def predicate_config
|
512
|
-
@@predicate_config ||= YAML::load(File.open(ActiveFedora.predicate_config)) if File.exist?(ActiveFedora.predicate_config)
|
513
|
-
end
|
514
|
-
|
515
|
-
def predicate_mappings
|
516
|
-
predicate_config[:predicate_mapping]
|
517
|
-
end
|
518
|
-
|
519
|
-
def default_predicate_namespace
|
520
|
-
predicate_config[:default_namespace]
|
521
|
-
end
|
522
|
-
|
523
|
-
def find_predicate(predicate)
|
524
|
-
predicate_mappings.each do |namespace,predicates|
|
525
|
-
if predicates.fetch(predicate,nil)
|
526
|
-
return predicates[predicate], namespace
|
527
|
-
end
|
528
|
-
end
|
529
|
-
raise ActiveFedora::UnregisteredPredicateError, "Unregistered predicate: #{predicate.inspect}"
|
530
|
-
end
|
531
375
|
|
532
376
|
|
533
377
|
end
|