activefedora-aggregation 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +35 -3
- data/lib/active_fedora/aggregation/association.rb +13 -9
- data/lib/active_fedora/aggregation/builder.rb +4 -0
- data/lib/active_fedora/aggregation/proxy.rb +4 -1
- data/lib/active_fedora/aggregation/{aggregator.rb → proxy_container.rb} +30 -15
- data/lib/active_fedora/aggregation/version.rb +1 -1
- data/lib/active_fedora/aggregation.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a55076e62ea008d34356dd58d2a502eb71114ab
|
4
|
+
data.tar.gz: 6b17d9e6891e6a8c280c7cc1edba9ab2408b8687
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79a25936d708e62ee1747ee4ab26bf58b24716eab159f209a8eb5cc58231f7f96a86cdfb2e64cc55bdaf51dba9af6107e524bd4c6627f4de155ac11201688d08
|
7
|
+
data.tar.gz: c0f461eacfbe9437bc3950c9c0f560eea944974dc4d5bf116e3d23a4ed7e19c97d920b7df36ddff5def8ca84b47c7ba35a5ed299301c10a5831b68f65b5c6e5f
|
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
[](http://badge.fury.io/rb/activefedora-aggregation) [](https://travis-ci.org/curationexperts/activefedora-aggregation)
|
1
2
|
# ActiveFedora::Aggregation
|
2
3
|
|
3
4
|
Aggregations for ActiveFedora.
|
@@ -7,17 +8,48 @@ Aggregations for ActiveFedora.
|
|
7
8
|
class GenericFile < ActiveFedora::Base
|
8
9
|
end
|
9
10
|
|
10
|
-
generic_file1 = GenericFile.create
|
11
|
-
generic_file2 = GenericFile.create
|
11
|
+
generic_file1 = GenericFile.create(id: 'file1')
|
12
|
+
generic_file2 = GenericFile.create(id: 'file2')
|
12
13
|
|
13
14
|
class Image < ActiveFedora::Base
|
14
15
|
aggregates :generic_files
|
15
16
|
end
|
16
17
|
|
17
|
-
image = Image.create
|
18
|
+
image = Image.create(id: 'my_image')
|
18
19
|
image.generic_files = [generic_file2, generic_file1]
|
19
20
|
image.save
|
20
21
|
|
21
22
|
```
|
22
23
|
|
23
24
|
Now the "generic\_files" method returns an ordered list of GenericFile objects.
|
25
|
+
|
26
|
+
Here's what the graph looks like:
|
27
|
+
|
28
|
+
```ttl
|
29
|
+
<http://127.0.0.1:8983/fedora/rest/dev/my_image> a <http://www.w3.org/ns/ldp#RDFSource>,
|
30
|
+
<http://www.w3.org/ns/ldp#Container>;
|
31
|
+
<http://www.w3.org/ns/ldp#contains> <http://127.0.0.1:8983/fedora/rest/dev/my_image/files>;
|
32
|
+
<info:fedora/fedora-system:def/model#hasModel> "Image" .
|
33
|
+
|
34
|
+
<http://127.0.0.1:8983/fedora/rest/dev/my_image/files> a <http://www.w3.org/ns/ldp#RDFSource>,
|
35
|
+
<http://www.w3.org/ns/ldp#Container>;
|
36
|
+
<http://www.iana.org/assignments/relation/first> <http://127.0.0.1:8983/fedora/rest/dev/my_image/files/5a5af870-594b-4966-93f6-0348402583f0>;
|
37
|
+
<http://www.iana.org/assignments/relation/last> <http://127.0.0.1:8983/fedora/rest/dev/my_image/files/9cc70b3d-c9d7-4cfc-b504-adbcb0bdfb3d>;
|
38
|
+
<http://www.w3.org/ns/ldp#contains> <http://127.0.0.1:8983/fedora/rest/dev/my_image/files/5a5af870-594b-4966-93f6-0348402583f0>,
|
39
|
+
<http://127.0.0.1:8983/fedora/rest/dev/my_image/files/9cc70b3d-c9d7-4cfc-b504-adbcb0bdfb3d>;
|
40
|
+
<info:fedora/fedora-system:def/model#hasModel> "ActiveFedora::Aggregation::ProxyContainer" .
|
41
|
+
|
42
|
+
<http://127.0.0.1:8983/fedora/rest/dev/my_image/files/5a5af870-594b-4966-93f6-0348402583f0> a <http://www.w3.org/ns/ldp#RDFSource>,
|
43
|
+
<http://www.w3.org/ns/ldp#Container>;
|
44
|
+
<http://www.iana.org/assignments/relation/next> <http://127.0.0.1:8983/fedora/rest/dev/my_image/files/9cc70b3d-c9d7-4cfc-b504-adbcb0bdfb3d>;
|
45
|
+
<http://www.openarchives.org/ore/terms/proxyFor> <http://127.0.0.1:8983/fedora/rest/dev/file2>;
|
46
|
+
<http://www.openarchives.org/ore/terms/proxyIn> <http://127.0.0.1:8983/fedora/rest/dev/my_image/files>;
|
47
|
+
<info:fedora/fedora-system:def/model#hasModel> "ActiveFedora::Aggregation::Proxy" .
|
48
|
+
|
49
|
+
<http://127.0.0.1:8983/fedora/rest/dev/my_image/files/9cc70b3d-c9d7-4cfc-b504-adbcb0bdfb3d> a <http://www.w3.org/ns/ldp#RDFSource>,
|
50
|
+
<http://www.w3.org/ns/ldp#Container>;
|
51
|
+
<http://www.iana.org/assignments/relation/prev> <http://127.0.0.1:8983/fedora/rest/dev/my_image/files/5a5af870-594b-4966-93f6-0348402583f0>;
|
52
|
+
<http://www.openarchives.org/ore/terms/proxyFor> <http://127.0.0.1:8983/fedora/rest/dev/file1>;
|
53
|
+
<http://www.openarchives.org/ore/terms/proxyIn> <http://127.0.0.1:8983/fedora/rest/dev/my_image/files>;
|
54
|
+
<info:fedora/fedora-system:def/model#hasModel> "ActiveFedora::Aggregation::Proxy" .
|
55
|
+
```
|
@@ -14,38 +14,42 @@ module ActiveFedora::Aggregation
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def == other
|
17
|
-
|
17
|
+
container.to_a == other
|
18
18
|
end
|
19
19
|
|
20
20
|
def create(&block)
|
21
21
|
klass.create(&block).tap do |created|
|
22
|
-
|
22
|
+
container << created
|
23
23
|
end
|
24
24
|
save #causes the (head/tail) pointers on the aggregation to be persisted
|
25
25
|
end
|
26
26
|
|
27
27
|
def save
|
28
|
-
|
28
|
+
container.save
|
29
29
|
end
|
30
30
|
|
31
31
|
def target=(vals)
|
32
|
-
|
32
|
+
container.target=(vals)
|
33
33
|
end
|
34
34
|
|
35
35
|
def target_ids=(vals)
|
36
|
-
|
36
|
+
container.target_ids=(vals)
|
37
37
|
end
|
38
38
|
|
39
39
|
def target_ids
|
40
|
-
|
40
|
+
container.target_ids
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
@
|
43
|
+
def container
|
44
|
+
@container ||= begin
|
45
|
+
ProxyContainer.find_or_initialize(klass.uri_to_id(uri)).tap do |container|
|
46
|
+
container.parent = @parent
|
47
|
+
end
|
48
|
+
end
|
45
49
|
end
|
46
50
|
|
47
51
|
def first
|
48
|
-
|
52
|
+
container.first
|
49
53
|
end
|
50
54
|
|
51
55
|
def uri
|
@@ -5,6 +5,10 @@ module ActiveFedora::Aggregation
|
|
5
5
|
def build
|
6
6
|
reflection = super
|
7
7
|
configure_dependency
|
8
|
+
model.has_and_belongs_to_many :proxies, predicate: ::RDF::Vocab::ORE.aggregates, class_name: 'ActiveFedora::Aggregation::Proxy', inverse_of: :containers
|
9
|
+
model.belongs_to :head, predicate: ::RDF::Vocab::IANA['first'], class_name: 'ActiveFedora::Aggregation::Proxy'
|
10
|
+
model.belongs_to :tail, predicate: ::RDF::Vocab::IANA.last, class_name: 'ActiveFedora::Aggregation::Proxy'
|
11
|
+
|
8
12
|
reflection
|
9
13
|
end
|
10
14
|
|
@@ -1,10 +1,13 @@
|
|
1
1
|
module ActiveFedora::Aggregation
|
2
2
|
class Proxy < ActiveFedora::Base
|
3
|
-
|
3
|
+
# HABTM is actually only belongs to one
|
4
|
+
has_and_belongs_to_many :containers, predicate: ::RDF::Vocab::ORE.proxyIn, class_name: 'ActiveFedora::Base'
|
4
5
|
belongs_to :target, predicate: ::RDF::Vocab::ORE.proxyFor, class_name: 'ActiveFedora::Base'
|
5
6
|
belongs_to :next, predicate: ::RDF::Vocab::IANA.next, class_name: 'ActiveFedora::Aggregation::Proxy'
|
6
7
|
belongs_to :prev, predicate: ::RDF::Vocab::IANA.prev, class_name: 'ActiveFedora::Aggregation::Proxy'
|
7
8
|
|
9
|
+
type ::RDF::Vocab::ORE.Proxy
|
10
|
+
|
8
11
|
def as_list
|
9
12
|
if self.next
|
10
13
|
[self] + self.next.as_list
|
@@ -1,11 +1,26 @@
|
|
1
1
|
module ActiveFedora::Aggregation
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
class ProxyContainer < ActiveFedora::Base
|
3
|
+
type ::RDF::Vocab::LDP.IndirectContainer
|
4
|
+
|
5
|
+
attr_writer :parent
|
6
|
+
|
7
|
+
property :membership_resource, predicate: ::RDF::Vocab::LDP.membershipResource
|
8
|
+
property :member_relation, predicate: ::RDF::Vocab::LDP.hasMemberRelation
|
9
|
+
property :inserted_content_relation, predicate: ::RDF::Vocab::LDP.insertedContentRelation
|
10
|
+
|
11
|
+
after_initialize :default_relations
|
12
|
+
|
13
|
+
def parent
|
14
|
+
@parent || raise("Parent hasn't been set on #{self.class}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_relations
|
18
|
+
self.member_relation = [::RDF::URI.new("http://pcdm.org/hasMember")] # TODO wrong predicate!
|
19
|
+
self.inserted_content_relation = [::RDF::Vocab::ORE.proxyFor]
|
20
|
+
end
|
6
21
|
|
7
22
|
def first
|
8
|
-
head.target
|
23
|
+
parent.head.target
|
9
24
|
end
|
10
25
|
|
11
26
|
# This can be a very expensive operation. avoid if possible
|
@@ -28,9 +43,9 @@ module ActiveFedora::Aggregation
|
|
28
43
|
proxy.prev_id = new_proxies[idx-1].id unless idx == 0
|
29
44
|
end
|
30
45
|
|
31
|
-
|
32
|
-
|
33
|
-
|
46
|
+
parent.head = new_proxies.first
|
47
|
+
parent.tail = new_proxies.last
|
48
|
+
parent.proxies = new_proxies
|
34
49
|
end
|
35
50
|
|
36
51
|
# TODO clear out the old proxies (or reuse them)
|
@@ -56,16 +71,16 @@ module ActiveFedora::Aggregation
|
|
56
71
|
# @param obj [ActiveFedora::Base]
|
57
72
|
def << (obj)
|
58
73
|
node = if persisted?
|
59
|
-
proxies.create(id: mint_proxy_id, target: obj, prev: tail)
|
74
|
+
parent.proxies.create(id: mint_proxy_id, target: obj, prev: parent.tail)
|
60
75
|
else
|
61
|
-
proxies.build(id: mint_proxy_id, target: obj, prev: tail)
|
76
|
+
parent.proxies.build(id: mint_proxy_id, target: obj, prev: parent.tail)
|
62
77
|
end
|
63
78
|
# set the old tail, if present, to have this new proxy as its next
|
64
|
-
|
79
|
+
parent.tail.update(next: node) if parent.tail
|
65
80
|
# update the tail to point at the new node
|
66
|
-
|
81
|
+
parent.tail = node
|
67
82
|
# if this is the first node, set it to be the head
|
68
|
-
|
83
|
+
parent.head = node unless parent.head
|
69
84
|
reset_target!
|
70
85
|
end
|
71
86
|
|
@@ -86,8 +101,8 @@ module ActiveFedora::Aggregation
|
|
86
101
|
|
87
102
|
# return the proxies in order
|
88
103
|
def list_of_proxies
|
89
|
-
@proxy_list ||= if head
|
90
|
-
head.as_list
|
104
|
+
@proxy_list ||= if parent.head
|
105
|
+
parent.head.as_list
|
91
106
|
else
|
92
107
|
[]
|
93
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activefedora-aggregation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -127,11 +127,11 @@ files:
|
|
127
127
|
- bin/console
|
128
128
|
- bin/setup
|
129
129
|
- lib/active_fedora/aggregation.rb
|
130
|
-
- lib/active_fedora/aggregation/aggregator.rb
|
131
130
|
- lib/active_fedora/aggregation/association.rb
|
132
131
|
- lib/active_fedora/aggregation/base_extension.rb
|
133
132
|
- lib/active_fedora/aggregation/builder.rb
|
134
133
|
- lib/active_fedora/aggregation/proxy.rb
|
134
|
+
- lib/active_fedora/aggregation/proxy_container.rb
|
135
135
|
- lib/active_fedora/aggregation/reflection.rb
|
136
136
|
- lib/active_fedora/aggregation/through_association.rb
|
137
137
|
- lib/active_fedora/aggregation/version.rb
|