active-fedora 9.10.0 → 9.11.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 +3 -0
- data/History.txt +3 -0
- data/active-fedora.gemspec +3 -2
- data/lib/active_fedora/aggregation/base_extension.rb +17 -0
- data/lib/active_fedora/aggregation/list_source.rb +103 -0
- data/lib/active_fedora/aggregation/ordered_reader.rb +27 -0
- data/lib/active_fedora/aggregation/proxy.rb +18 -0
- data/lib/active_fedora/aggregation.rb +11 -0
- data/lib/active_fedora/associations/builder/aggregation.rb +51 -0
- data/lib/active_fedora/associations/builder/filter.rb +18 -0
- data/lib/active_fedora/associations/builder/orders.rb +63 -0
- data/lib/active_fedora/associations/filter_association.rb +71 -0
- data/lib/active_fedora/associations/orders_association.rb +149 -0
- data/lib/active_fedora/associations.rb +40 -0
- data/lib/active_fedora/attached_files.rb +2 -1
- data/lib/active_fedora/attribute_methods.rb +4 -4
- data/lib/active_fedora/autosave_association.rb +14 -0
- data/lib/active_fedora/base.rb +1 -0
- data/lib/active_fedora/cleaner.rb +1 -1
- data/lib/active_fedora/errors.rb +3 -0
- data/lib/active_fedora/fedora.rb +17 -7
- data/lib/active_fedora/file/attributes.rb +6 -6
- data/lib/active_fedora/file/streaming.rb +13 -4
- data/lib/active_fedora/file.rb +1 -16
- data/lib/active_fedora/orders/collection_proxy.rb +8 -0
- data/lib/active_fedora/orders/list_node.rb +161 -0
- data/lib/active_fedora/orders/ordered_list.rb +264 -0
- data/lib/active_fedora/orders/target_proxy.rb +60 -0
- data/lib/active_fedora/orders.rb +12 -0
- data/lib/active_fedora/reflection.rb +216 -43
- data/lib/active_fedora/relation/finder_methods.rb +2 -2
- data/lib/active_fedora/validations.rb +1 -1
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/with_metadata/metadata_node.rb +1 -2
- data/lib/active_fedora.rb +7 -0
- data/lib/generators/active_fedora/config/solr/templates/solr/config/schema.xml +1 -1
- data/solr/config/schema.xml +1 -1
- data/spec/integration/attached_files_spec.rb +4 -4
- data/spec/integration/attributes_spec.rb +8 -0
- data/spec/integration/file_spec.rb +23 -1
- data/spec/integration/has_many_associations_spec.rb +23 -0
- data/spec/integration/om_datastream_spec.rb +6 -6
- data/spec/integration/versionable_spec.rb +6 -6
- data/spec/unit/active_fedora_spec.rb +1 -1
- data/spec/unit/aggregation/list_source_spec.rb +134 -0
- data/spec/unit/aggregation/ordered_reader_spec.rb +43 -0
- data/spec/unit/fedora_spec.rb +1 -1
- data/spec/unit/file_spec.rb +0 -19
- data/spec/unit/filter_spec.rb +133 -0
- data/spec/unit/ordered_spec.rb +369 -0
- data/spec/unit/orders/list_node_spec.rb +151 -0
- data/spec/unit/orders/ordered_list_spec.rb +335 -0
- data/spec/unit/orders/reflection_spec.rb +22 -0
- data/spec/unit/reflection_spec.rb +2 -4
- metadata +29 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bce277ca040d2e5d2b6f20ad12ded43a0d09a81e
|
|
4
|
+
data.tar.gz: 41626c552b9571d1993bc95f3719a0b12a24eb5b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b48ed0579be52f0683f6293adc4ff4908706d125f924119cabc2e01076bfcf2501e7732ef9b057948f6aeffd0f10679626d033aab52313523839020005d543ac
|
|
7
|
+
data.tar.gz: 2dfa7a8abb57bc8dc376da0767fd5d70ecf13bc9bbcb6f0542faaad5b8d70973367c1f81776aa8e4e704655029676b9ec124836f3736d1940c36a7e470b3092d
|
data/.rubocop.yml
CHANGED
|
@@ -87,6 +87,7 @@ Metrics/ClassLength:
|
|
|
87
87
|
- 'lib/active_fedora/associations/collection_proxy.rb'
|
|
88
88
|
- 'lib/active_fedora/associations/collection_association.rb'
|
|
89
89
|
- 'lib/active_fedora/reflection.rb'
|
|
90
|
+
- 'lib/active_fedora/orders/ordered_list.rb'
|
|
90
91
|
|
|
91
92
|
Metrics/MethodLength:
|
|
92
93
|
Enabled: false
|
|
@@ -123,6 +124,8 @@ Style/PredicateName:
|
|
|
123
124
|
- 'lib/active_fedora/attached_files.rb'
|
|
124
125
|
- 'lib/active_fedora/associations.rb'
|
|
125
126
|
- 'lib/active_fedora/association_hash.rb'
|
|
127
|
+
- 'lib/active_fedora/aggregation/list_source.rb'
|
|
128
|
+
- 'lib/active_fedora/associations/builder/aggregation.rb'
|
|
126
129
|
|
|
127
130
|
Style/GuardClause:
|
|
128
131
|
Exclude:
|
data/History.txt
CHANGED
data/active-fedora.gemspec
CHANGED
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
|
18
18
|
s.add_dependency 'solrizer', '~> 3.4'
|
|
19
19
|
s.add_dependency 'om', '~> 3.1'
|
|
20
20
|
s.add_dependency 'nom-xml', '>= 0.5.1'
|
|
21
|
-
s.add_dependency "activesupport", '>= 4.2', '< 6'
|
|
21
|
+
s.add_dependency "activesupport", '>= 4.2.4', '< 6'
|
|
22
22
|
s.add_dependency "activemodel", '>= 4.2', '< 6'
|
|
23
23
|
s.add_dependency "active-triples", '~> 0.7.1'
|
|
24
24
|
s.add_dependency "rdf-rdfxml", '~> 1.1'
|
|
@@ -36,7 +36,8 @@ Gem::Specification.new do |s|
|
|
|
36
36
|
s.add_development_dependency "rspec-its"
|
|
37
37
|
s.add_development_dependency "equivalent-xml"
|
|
38
38
|
s.add_development_dependency "simplecov", '~> 0.8'
|
|
39
|
-
|
|
39
|
+
# Pin to rubocop 0.38.0 due to https://github.com/nevir/rubocop-rspec/issues/78
|
|
40
|
+
s.add_development_dependency "rubocop", '~> 0.38.0'
|
|
40
41
|
s.add_development_dependency "rubocop-rspec", '~> 1.4'
|
|
41
42
|
|
|
42
43
|
s.files = `git ls-files`.split("\n")
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module ActiveFedora::Aggregation
|
|
2
|
+
module BaseExtension
|
|
3
|
+
def ordered_by
|
|
4
|
+
ordered_by_ids.lazy.map { |x| ActiveFedora::Base.find(x) }
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
def ordered_by_ids
|
|
10
|
+
if id.present?
|
|
11
|
+
ActiveFedora::SolrService.query("{!join from=proxy_in_ssi to=id}ordered_targets_ssim:#{id}").map { |x| x["id"] }
|
|
12
|
+
else
|
|
13
|
+
[]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
module ActiveFedora
|
|
2
|
+
module Aggregation
|
|
3
|
+
class ListSource < ActiveFedora::Base
|
|
4
|
+
delegate :order_will_change!, to: :ordered_self
|
|
5
|
+
property :head, predicate: ::RDF::Vocab::IANA['first'], multiple: false
|
|
6
|
+
property :tail, predicate: ::RDF::Vocab::IANA.last, multiple: false
|
|
7
|
+
property :nodes, predicate: ::RDF::Vocab::DC.hasPart
|
|
8
|
+
|
|
9
|
+
def save(*args)
|
|
10
|
+
return true if has_unpersisted_proxy_for? || !changed?
|
|
11
|
+
persist_ordered_self if ordered_self.changed?
|
|
12
|
+
super
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Overriding so that we don't track previously_changed, which was
|
|
16
|
+
# rather expensive.
|
|
17
|
+
def clear_changed_attributes
|
|
18
|
+
@changed_attributes.clear
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def changed?
|
|
22
|
+
super || ordered_self.changed?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Ordered list representation of proxies in graph.
|
|
26
|
+
# @return [Array<ListNode>]
|
|
27
|
+
def ordered_self
|
|
28
|
+
@ordered_self ||= ordered_list_factory.new(resource, head_subject, tail_subject)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Allow this to be set so that -=, += will work.
|
|
32
|
+
# @param [ActiveFedora::Orders::OrderedList] An ordered list object this
|
|
33
|
+
# graph should contain.
|
|
34
|
+
attr_writer :ordered_self
|
|
35
|
+
|
|
36
|
+
# Serializing head/tail/nodes slows things down CONSIDERABLY, and is not
|
|
37
|
+
# useful.
|
|
38
|
+
# @note This method is used by ActiveFedora::Base upstream for indexing,
|
|
39
|
+
# at https://github.com/projecthydra/active_fedora/blob/master/lib/active_fedora/profile_indexing_service.rb.
|
|
40
|
+
def serializable_hash(_options = nil)
|
|
41
|
+
{}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def to_solr(solr_doc = {})
|
|
45
|
+
super.merge(ordered_targets_ssim: ordered_self.target_ids,
|
|
46
|
+
proxy_in_ssi: ordered_self.proxy_in.to_s)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Not useful and slows down indexing.
|
|
50
|
+
def create_date
|
|
51
|
+
nil
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Not useful, slows down indexing.
|
|
55
|
+
def modified_date
|
|
56
|
+
nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Not useful, slows down indexing.
|
|
60
|
+
def has_model
|
|
61
|
+
["ActiveFedora::Aggregation::ListSource"]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def persist_ordered_self
|
|
67
|
+
nodes_will_change!
|
|
68
|
+
# Delete old statements
|
|
69
|
+
subj = resource.subjects.to_a.select { |x| x.to_s.split("/").last.to_s.include?("#g") }
|
|
70
|
+
subj.each do |s|
|
|
71
|
+
resource.delete [s, nil, nil]
|
|
72
|
+
end
|
|
73
|
+
# Assert head and tail
|
|
74
|
+
self.head = ordered_self.head.next.rdf_subject
|
|
75
|
+
self.tail = ordered_self.tail.prev.rdf_subject
|
|
76
|
+
graph = ordered_self.to_graph
|
|
77
|
+
resource << graph
|
|
78
|
+
# Set node subjects to a term in AF JUST so that AF will persist the
|
|
79
|
+
# sub-graphs.
|
|
80
|
+
# TODO: Find a way to fix this.
|
|
81
|
+
self.nodes = nil
|
|
82
|
+
self.nodes += graph.subjects.to_a
|
|
83
|
+
ordered_self.changes_committed!
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def has_unpersisted_proxy_for?
|
|
87
|
+
ordered_self.select(&:new_record?).map(&:target).find { |x| x.respond_to?(:uri) }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def head_subject
|
|
91
|
+
head_id.first
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def tail_subject
|
|
95
|
+
tail_id.first
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def ordered_list_factory
|
|
99
|
+
ActiveFedora::Orders::OrderedList
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module ActiveFedora::Aggregation
|
|
2
|
+
##
|
|
3
|
+
# Lazily iterates over a doubly linked list, fixing up nodes if necessary.
|
|
4
|
+
class OrderedReader
|
|
5
|
+
include Enumerable
|
|
6
|
+
attr_reader :root
|
|
7
|
+
def initialize(root)
|
|
8
|
+
@root = root
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def each
|
|
12
|
+
proxy = first_head
|
|
13
|
+
while proxy
|
|
14
|
+
yield proxy unless proxy.nil?
|
|
15
|
+
next_proxy = proxy.next
|
|
16
|
+
next_proxy.try(:prev=, proxy) if next_proxy && next_proxy.prev != proxy
|
|
17
|
+
proxy = next_proxy
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def first_head
|
|
24
|
+
root.head
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module ActiveFedora::Aggregation
|
|
2
|
+
class Proxy < ActiveFedora::Base
|
|
3
|
+
belongs_to :container, predicate: ::RDF::Vocab::ORE.proxyIn, class_name: 'ActiveFedora::Base'
|
|
4
|
+
belongs_to :target, predicate: ::RDF::Vocab::ORE.proxyFor, class_name: 'ActiveFedora::Base'
|
|
5
|
+
belongs_to :next, predicate: ::RDF::Vocab::IANA.next, class_name: 'ActiveFedora::Aggregation::Proxy'
|
|
6
|
+
belongs_to :prev, predicate: ::RDF::Vocab::IANA.prev, class_name: 'ActiveFedora::Aggregation::Proxy'
|
|
7
|
+
|
|
8
|
+
type ::RDF::Vocab::ORE.Proxy
|
|
9
|
+
|
|
10
|
+
def as_list
|
|
11
|
+
if self.next
|
|
12
|
+
[self] + self.next.as_list
|
|
13
|
+
else
|
|
14
|
+
[self]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module ActiveFedora::Associations::Builder
|
|
2
|
+
class Aggregation < ActiveFedora::Associations::Builder::Association
|
|
3
|
+
def self.valid_options(_options)
|
|
4
|
+
[:through, :class_name, :has_member_relation, :type_validator]
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.build(model, name, options)
|
|
8
|
+
model.indirectly_contains name, { has_member_relation: has_member_relation(options), through: proxy_class, foreign_key: proxy_foreign_key, inserted_content_relation: inserted_content_relation }.merge(indirect_options(options))
|
|
9
|
+
model.contains contains_key(options), class_name: list_source_class
|
|
10
|
+
model.orders name, through: contains_key(options)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.indirect_options(options)
|
|
14
|
+
{
|
|
15
|
+
class_name: options[:class_name],
|
|
16
|
+
type_validator: options[:type_validator]
|
|
17
|
+
}.select { |_k, v| v.present? }
|
|
18
|
+
end
|
|
19
|
+
private_class_method :indirect_options
|
|
20
|
+
|
|
21
|
+
def self.has_member_relation(options)
|
|
22
|
+
options[:has_member_relation] || ::RDF::DC.hasPart
|
|
23
|
+
end
|
|
24
|
+
private_class_method :has_member_relation
|
|
25
|
+
|
|
26
|
+
def self.inserted_content_relation
|
|
27
|
+
::RDF::Vocab::ORE.proxyFor
|
|
28
|
+
end
|
|
29
|
+
private_class_method :inserted_content_relation
|
|
30
|
+
|
|
31
|
+
def self.proxy_class
|
|
32
|
+
"ActiveFedora::Aggregation::Proxy"
|
|
33
|
+
end
|
|
34
|
+
private_class_method :proxy_class
|
|
35
|
+
|
|
36
|
+
def self.proxy_foreign_key
|
|
37
|
+
:target
|
|
38
|
+
end
|
|
39
|
+
private_class_method :proxy_foreign_key
|
|
40
|
+
|
|
41
|
+
def self.contains_key(options)
|
|
42
|
+
options[:through]
|
|
43
|
+
end
|
|
44
|
+
private_class_method :contains_key
|
|
45
|
+
|
|
46
|
+
def self.list_source_class
|
|
47
|
+
"ActiveFedora::Aggregation::ListSource"
|
|
48
|
+
end
|
|
49
|
+
private_class_method :list_source_class
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module ActiveFedora::Associations::Builder
|
|
2
|
+
class Filter < ActiveFedora::Associations::Builder::CollectionAssociation
|
|
3
|
+
def self.valid_options(options)
|
|
4
|
+
super + [:extending_from, :condition]
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.macro
|
|
8
|
+
:filter
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.define_readers(mixin, name)
|
|
12
|
+
super
|
|
13
|
+
mixin.redefine_method("#{name.to_s.singularize}_ids") do
|
|
14
|
+
association(name).ids_reader
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module ActiveFedora::Associations::Builder
|
|
2
|
+
class Orders < ActiveFedora::Associations::Builder::CollectionAssociation
|
|
3
|
+
include ActiveFedora::AutosaveAssociation::AssociationBuilderExtension
|
|
4
|
+
def self.macro
|
|
5
|
+
:orders
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def self.valid_options(options)
|
|
9
|
+
super + [:through, :unordered_reflection]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.define_readers(mixin, name)
|
|
13
|
+
super
|
|
14
|
+
mixin.redefine_method(target_accessor(name)) do
|
|
15
|
+
association(name).target_reader
|
|
16
|
+
end
|
|
17
|
+
mixin.redefine_method("#{target_accessor(name)}=") do |nodes|
|
|
18
|
+
association(name).target_writer(nodes)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.build(model, name, options)
|
|
23
|
+
options = { unordered_reflection: unordered_reflection(model, name) }.merge(options)
|
|
24
|
+
name = :"ordered_#{name.to_s.singularize}_proxies"
|
|
25
|
+
model.property :head, predicate: ::RDF::Vocab::IANA['first']
|
|
26
|
+
model.property :tail, predicate: ::RDF::Vocab::IANA.last
|
|
27
|
+
model.send(:define_method, :apply_first_and_last) do
|
|
28
|
+
source = send(options[:through])
|
|
29
|
+
source.save
|
|
30
|
+
return if head.map(&:rdf_subject) == source.head_id && tail.map(&:rdf_subject) == source.tail_id
|
|
31
|
+
self.head = source.head_id
|
|
32
|
+
self.tail = source.tail_id
|
|
33
|
+
save! if changed?
|
|
34
|
+
end
|
|
35
|
+
model.include ActiveFedora::Associations::Builder::Orders::FixFirstLast
|
|
36
|
+
super
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
module FixFirstLast
|
|
40
|
+
def save(*args)
|
|
41
|
+
super.tap do |result|
|
|
42
|
+
apply_first_and_last if result
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def save!(*args)
|
|
47
|
+
super.tap do |result|
|
|
48
|
+
apply_first_and_last if result
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.target_accessor(name)
|
|
54
|
+
name.to_s.gsub("_proxies", "").pluralize
|
|
55
|
+
end
|
|
56
|
+
private_class_method :target_accessor
|
|
57
|
+
|
|
58
|
+
def self.unordered_reflection(model, original_name)
|
|
59
|
+
model._reflect_on_association(original_name)
|
|
60
|
+
end
|
|
61
|
+
private_class_method :unordered_reflection
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module ActiveFedora::Associations
|
|
2
|
+
class FilterAssociation < ::ActiveFedora::Associations::CollectionAssociation
|
|
3
|
+
# @param [Array] records a list of records to replace the current association with
|
|
4
|
+
# @raise [ArgumentError] if one of the records doesn't match the prescribed condition
|
|
5
|
+
def writer(records)
|
|
6
|
+
records.each { |r| validate_assertion!(r) }
|
|
7
|
+
existing_matching_records.each do |r|
|
|
8
|
+
extending_from.delete(r)
|
|
9
|
+
end
|
|
10
|
+
extending_from.concat(records)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
delegate :delete, to: :extending_from
|
|
14
|
+
|
|
15
|
+
# @param [Array] records a list of records to append to the current association
|
|
16
|
+
# @raise [ArgumentError] if one of the records doesn't match the prescribed condition
|
|
17
|
+
def concat(records)
|
|
18
|
+
records.flatten.each { |r| validate_assertion!(r) }
|
|
19
|
+
extending_from.concat(records)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def ids_reader
|
|
23
|
+
load_target
|
|
24
|
+
super
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def count_records
|
|
28
|
+
ids_reader.length
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
# target should never be cached as part of this objects state, because
|
|
34
|
+
# extending_from.target could change and we want to reflect those changes
|
|
35
|
+
def target
|
|
36
|
+
find_target
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def find_target?
|
|
40
|
+
true
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def find_target
|
|
44
|
+
existing_matching_records
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# We can't create an association scope on here until we can figure a way to
|
|
48
|
+
# index/query the condition in Solr
|
|
49
|
+
def association_scope
|
|
50
|
+
nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def existing_matching_records
|
|
54
|
+
extending_from.reader.to_a.select do |r|
|
|
55
|
+
validate_assertion(r)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def extending_from
|
|
60
|
+
owner.association(options.fetch(:extending_from))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def validate_assertion(record)
|
|
64
|
+
record.send(options.fetch(:condition))
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def validate_assertion!(record)
|
|
68
|
+
raise ArgumentError, "#{record.class} with ID: #{record.id} was expected to #{options.fetch(:condition)}, but it was false" unless validate_assertion(record)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
module ActiveFedora::Associations
|
|
2
|
+
class OrdersAssociation < ::ActiveFedora::Associations::CollectionAssociation
|
|
3
|
+
def initialize(*args)
|
|
4
|
+
super
|
|
5
|
+
@target = find_target
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def inspect
|
|
9
|
+
"#<ActiveFedora::Associations::OrdersAssociation:#{object_id}>"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def reader(*args)
|
|
13
|
+
@proxy ||= ActiveFedora::Orders::CollectionProxy.new(self)
|
|
14
|
+
@null_proxy ||= ActiveFedora::Orders::CollectionProxy.new(self)
|
|
15
|
+
super
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Meant to override all nodes with the given nodes.
|
|
19
|
+
# @param [Array<ActiveFedora::Base>] nodes Nodes to set as ordered members
|
|
20
|
+
def target_writer(nodes)
|
|
21
|
+
target_reader.clear
|
|
22
|
+
target_reader.concat(nodes)
|
|
23
|
+
target_reader
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def target_reader
|
|
27
|
+
@target_proxy ||= ActiveFedora::Orders::TargetProxy.new(self)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def find_reflection
|
|
31
|
+
reflection
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def replace(new_ordered_list)
|
|
35
|
+
raise unless new_ordered_list.is_a? ActiveFedora::Orders::OrderedList
|
|
36
|
+
list_container.ordered_self = new_ordered_list
|
|
37
|
+
@target = find_target
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def find_target
|
|
41
|
+
ordered_proxies
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def load_target
|
|
45
|
+
@target = find_target
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Append a target node to the end of the order.
|
|
49
|
+
# @param [ActiveFedora::Base] record Record to append
|
|
50
|
+
def append_target(record, _skip_callbacks = false)
|
|
51
|
+
unless unordered_association.target.include?(record)
|
|
52
|
+
unordered_association.concat(record)
|
|
53
|
+
end
|
|
54
|
+
target.append_target(record, proxy_in: owner)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Insert a target node in a specific position
|
|
58
|
+
# @param [Integer] loc Position to insert record.
|
|
59
|
+
# @param [ActiveFedora::Base] record Record to insert
|
|
60
|
+
def insert_target_at(loc, record)
|
|
61
|
+
unless unordered_association.target.include?(record)
|
|
62
|
+
unordered_association.concat(record)
|
|
63
|
+
end
|
|
64
|
+
target.insert_at(loc, record, proxy_in: owner)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Insert a target ID in a specific position
|
|
68
|
+
# @param [Integer] loc Position to insert record ID
|
|
69
|
+
# @param [String] id ID of record to insert.
|
|
70
|
+
def insert_target_id_at(loc, id)
|
|
71
|
+
raise ArgumentError, "ID can not be nil" if id.nil?
|
|
72
|
+
unless unordered_association.ids_reader.include?(id)
|
|
73
|
+
raise ArgumentError, "#{id} is not a part of #{unordered_association.reflection.name}"
|
|
74
|
+
end
|
|
75
|
+
target.insert_proxy_for_at(loc, ActiveFedora::Base.id_to_uri(id), proxy_in: owner)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Delete whatever node is at a specific position
|
|
79
|
+
# @param [Integer] loc Position to delete
|
|
80
|
+
delegate :delete_at, to: :target
|
|
81
|
+
|
|
82
|
+
# Delete all occurences of the specified target
|
|
83
|
+
# @param obj object to delete
|
|
84
|
+
delegate :delete_target, to: :target
|
|
85
|
+
|
|
86
|
+
# Delete multiple list nodes.
|
|
87
|
+
# @param [Array<ActiveFedora::Orders::ListNode>] records
|
|
88
|
+
def delete_records(records, _method = nil)
|
|
89
|
+
records.each do |record|
|
|
90
|
+
delete_record(record)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Delete a list node
|
|
95
|
+
# @param [ActiveFedora::Orders::ListNode] record Node to delete.
|
|
96
|
+
def delete_record(record)
|
|
97
|
+
target.delete_node(record)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def insert_record(record, _force = true, _validate = true)
|
|
101
|
+
record.save_target
|
|
102
|
+
list_container.save
|
|
103
|
+
# NOTE: This turns out to be pretty cheap, but should we be doing it
|
|
104
|
+
# elsewhere?
|
|
105
|
+
unless list_container.changed?
|
|
106
|
+
owner.head = [list_container.head_id.first]
|
|
107
|
+
owner.tail = [list_container.tail_id.first]
|
|
108
|
+
owner.save
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def scope(*_args)
|
|
113
|
+
@scope ||= ActiveFedora::Relation.new(klass)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
private
|
|
117
|
+
|
|
118
|
+
def ordered_proxies
|
|
119
|
+
list_container.ordered_self
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def create_list_node(record)
|
|
123
|
+
node = ListNode.new(RDF::URI.new("#{list_container.uri}##{::RDF::Node.new.id}"), list_container.resource)
|
|
124
|
+
node.proxyIn = owner
|
|
125
|
+
node.proxyFor = record
|
|
126
|
+
node
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def association_scope
|
|
130
|
+
nil
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def list_container
|
|
134
|
+
list_container_association.reader
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def list_container_association
|
|
138
|
+
owner.association(options[:through])
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def unordered_association
|
|
142
|
+
owner.association(unordered_reflection_name)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def unordered_reflection_name
|
|
146
|
+
reflection.unordered_reflection.name
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
@@ -29,6 +29,8 @@ module ActiveFedora
|
|
|
29
29
|
autoload :DirectlyContainsOneAssociation
|
|
30
30
|
autoload :IndirectlyContainsAssociation
|
|
31
31
|
autoload :ContainsAssociation
|
|
32
|
+
autoload :FilterAssociation
|
|
33
|
+
autoload :OrdersAssociation
|
|
32
34
|
autoload :DeleteProxy
|
|
33
35
|
autoload :ContainedFinder
|
|
34
36
|
autoload :RecordComposite
|
|
@@ -50,6 +52,10 @@ module ActiveFedora
|
|
|
50
52
|
|
|
51
53
|
autoload :Property, 'active_fedora/associations/builder/property'
|
|
52
54
|
autoload :SingularProperty, 'active_fedora/associations/builder/singular_property'
|
|
55
|
+
|
|
56
|
+
autoload :Aggregation, 'active_fedora/associations/builder/aggregation'
|
|
57
|
+
autoload :Filter, 'active_fedora/associations/builder/filter'
|
|
58
|
+
autoload :Orders, 'active_fedora/associations/builder/orders'
|
|
53
59
|
end
|
|
54
60
|
|
|
55
61
|
eager_autoload do
|
|
@@ -280,6 +286,40 @@ module ActiveFedora
|
|
|
280
286
|
Builder::HasAndBelongsToMany.build(self, name, options)
|
|
281
287
|
Builder::Property.build(self, name, options.slice(:class_name, :predicate))
|
|
282
288
|
end
|
|
289
|
+
|
|
290
|
+
##
|
|
291
|
+
# Allows ordering of an association
|
|
292
|
+
# @example
|
|
293
|
+
# class Image < ActiveFedora::Base
|
|
294
|
+
# contains :list_resource, class_name:
|
|
295
|
+
# "ActiveFedora::Aggregation::ListSource"
|
|
296
|
+
# orders :generic_files, through: :list_resource
|
|
297
|
+
# end
|
|
298
|
+
def orders(name, options = {})
|
|
299
|
+
Builder::Orders.build(self, name, options)
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
##
|
|
303
|
+
# Convenience method for building an ordered aggregation.
|
|
304
|
+
# @example
|
|
305
|
+
# class Image < ActiveFedora::Base
|
|
306
|
+
# ordered_aggregation :members, through: :list_source
|
|
307
|
+
# end
|
|
308
|
+
def ordered_aggregation(name, options = {})
|
|
309
|
+
Builder::Aggregation.build(self, name, options)
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
##
|
|
313
|
+
# Create an association filter on the class
|
|
314
|
+
# @example
|
|
315
|
+
# class Image < ActiveFedora::Base
|
|
316
|
+
# aggregates :generic_files
|
|
317
|
+
# filters_association :generic_files, as: :large_files, condition: :big_file?
|
|
318
|
+
# end
|
|
319
|
+
def filters_association(extending_from, options = {})
|
|
320
|
+
name = options.delete(:as)
|
|
321
|
+
Builder::Filter.build(self, name, options.merge(extending_from: extending_from))
|
|
322
|
+
end
|
|
283
323
|
end
|
|
284
324
|
end
|
|
285
325
|
end
|
|
@@ -131,7 +131,8 @@ module ActiveFedora
|
|
|
131
131
|
|
|
132
132
|
def create_singleton_association(file_path)
|
|
133
133
|
undeclared_files << file_path.to_sym
|
|
134
|
-
|
|
134
|
+
|
|
135
|
+
association = Associations::BasicContainsAssociation.new(self, Reflection::ContainsReflection.new(file_path, nil, { class_name: 'ActiveFedora::File' }, self.class))
|
|
135
136
|
@association_cache[file_path.to_sym] = association
|
|
136
137
|
|
|
137
138
|
singleton_class.send :define_method, accessor_name(file_path) do
|