valkyrie 2.1.1 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +33 -29
- data/.lando.yml +40 -0
- data/.rubocop.yml +4 -1
- data/.tool-versions +1 -1
- data/CHANGELOG.md +26 -0
- data/README.md +19 -47
- data/Rakefile +21 -20
- data/db/config.yml +3 -10
- data/lib/generators/valkyrie/resource_generator.rb +3 -3
- data/lib/valkyrie.rb +13 -13
- data/lib/valkyrie/change_set.rb +3 -3
- data/lib/valkyrie/id.rb +14 -14
- data/lib/valkyrie/indexers/access_controls_indexer.rb +17 -17
- data/lib/valkyrie/persistence/fedora/list_node.rb +43 -43
- data/lib/valkyrie/persistence/fedora/ordered_list.rb +90 -90
- data/lib/valkyrie/persistence/fedora/ordered_reader.rb +5 -5
- data/lib/valkyrie/persistence/fedora/permissive_schema.rb +1 -1
- data/lib/valkyrie/persistence/fedora/persister.rb +80 -82
- data/lib/valkyrie/persistence/fedora/persister/model_converter.rb +15 -15
- data/lib/valkyrie/persistence/fedora/persister/orm_converter.rb +38 -18
- data/lib/valkyrie/persistence/fedora/query_service.rb +38 -40
- data/lib/valkyrie/persistence/memory/persister.rb +33 -33
- data/lib/valkyrie/persistence/memory/query_service.rb +26 -30
- data/lib/valkyrie/persistence/postgres/orm_converter.rb +52 -52
- data/lib/valkyrie/persistence/postgres/query_service.rb +34 -34
- data/lib/valkyrie/persistence/shared/json_value_mapper.rb +1 -1
- data/lib/valkyrie/persistence/solr/model_converter.rb +337 -337
- data/lib/valkyrie/persistence/solr/orm_converter.rb +3 -3
- data/lib/valkyrie/persistence/solr/queries/find_members_query.rb +1 -1
- data/lib/valkyrie/persistence/solr/query_service.rb +12 -12
- data/lib/valkyrie/specs/shared_specs/persister.rb +2 -2
- data/lib/valkyrie/storage/fedora.rb +16 -16
- data/lib/valkyrie/storage_adapter.rb +11 -11
- data/lib/valkyrie/version.rb +1 -1
- data/tasks/dev.rake +14 -51
- data/valkyrie.gemspec +3 -4
- metadata +22 -33
- data/.docker-stack/valkyrie-development/docker-compose.yml +0 -53
- data/.docker-stack/valkyrie-test/docker-compose.yml +0 -53
- data/tasks/docker.rake +0 -31
@@ -40,24 +40,24 @@ module Valkyrie::Indexers
|
|
40
40
|
|
41
41
|
private
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
43
|
+
# rubocop:disable Metrics/MethodLength
|
44
|
+
def default_config
|
45
|
+
if defined?(Hydra) && Hydra.respond_to?(:config)
|
46
|
+
{
|
47
|
+
read_groups: Hydra.config[:permissions][:read].group,
|
48
|
+
read_users: Hydra.config[:permissions][:read].individual,
|
49
|
+
edit_groups: Hydra.config[:permissions][:edit].group,
|
50
|
+
edit_users: Hydra.config[:permissions][:edit].individual
|
51
|
+
}
|
52
|
+
else
|
53
|
+
{
|
54
|
+
read_groups: 'read_access_group_ssim',
|
55
|
+
read_users: 'read_access_person_ssim',
|
56
|
+
edit_groups: 'edit_access_group_ssim',
|
57
|
+
edit_users: 'edit_access_person_ssim'
|
58
|
+
}
|
60
59
|
end
|
60
|
+
end
|
61
61
|
# rubocop:enable Metrics/MethodLength
|
62
62
|
end
|
63
63
|
end
|
@@ -85,60 +85,60 @@ module Valkyrie::Persistence::Fedora
|
|
85
85
|
|
86
86
|
private
|
87
87
|
|
88
|
-
|
88
|
+
attr_reader :next_uri, :prev_uri, :node_cache
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
# Class used to populate the RDF graph structure for the linked lists
|
91
|
+
class Builder
|
92
|
+
attr_reader :uri, :graph
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
94
|
+
# @param uri [RDF::URI] the URI for the linked list in the graph store
|
95
|
+
# @param graph [RDF::Repository] the RDF graph to be populated
|
96
|
+
def initialize(uri, graph)
|
97
|
+
@uri = uri
|
98
|
+
@graph = graph
|
99
|
+
end
|
100
100
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
101
|
+
# Populates attributes for the LinkedNode
|
102
|
+
# @param instance [ListNode]
|
103
|
+
def populate(instance)
|
104
|
+
instance.proxy_for = resource.proxy_for
|
105
|
+
instance.proxy_in = resource.proxy_in
|
106
|
+
instance.next_uri = resource.next
|
107
|
+
instance.prev_uri = resource.prev
|
108
|
+
end
|
109
109
|
|
110
|
-
|
110
|
+
private
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
112
|
+
# Constructs a set of triples using ActiveTriples as objects
|
113
|
+
# @return [Valkyrie::Persistence::Fedora::ListNode::Resource]
|
114
|
+
def resource
|
115
|
+
@resource ||= Resource.new(uri, graph: graph)
|
117
116
|
end
|
117
|
+
end
|
118
118
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
119
|
+
# Class for providing a set of triples modeling linked list nodes
|
120
|
+
class Resource
|
121
|
+
def self.property(property, predicate:)
|
122
|
+
define_method property do
|
123
|
+
graph.query([uri, predicate, nil]).objects.first
|
124
|
+
end
|
125
125
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
end
|
126
|
+
define_method "#{property}=" do |val|
|
127
|
+
return if val.nil?
|
128
|
+
graph << [uri, predicate, val]
|
130
129
|
end
|
130
|
+
end
|
131
131
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
132
|
+
property :proxy_for, predicate: ::RDF::Vocab::ORE.proxyFor
|
133
|
+
property :proxy_in, predicate: ::RDF::Vocab::ORE.proxyIn
|
134
|
+
property :next, predicate: ::RDF::Vocab::IANA.next
|
135
|
+
property :prev, predicate: ::RDF::Vocab::IANA.prev
|
136
136
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
end
|
137
|
+
attr_reader :graph, :uri
|
138
|
+
def initialize(uri, graph: RDF::Graph.new)
|
139
|
+
@uri = uri
|
140
|
+
@graph = graph
|
142
141
|
end
|
142
|
+
end
|
143
143
|
end
|
144
144
|
end
|
@@ -67,111 +67,111 @@ module Valkyrie::Persistence::Fedora
|
|
67
67
|
|
68
68
|
private
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
70
|
+
attr_reader :node_cache
|
71
|
+
|
72
|
+
# Append a node to a linked list
|
73
|
+
# @param source [ListNode] the node being appended
|
74
|
+
# @param append_node [ListNode] the node already in the existing list
|
75
|
+
def append_to(source, append_node)
|
76
|
+
source.prev = append_node
|
77
|
+
append_node.next.prev = source
|
78
|
+
source.next = append_node.next
|
79
|
+
append_node.next = source
|
80
|
+
@changed = true
|
81
|
+
end
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
# Constructs a new OrderedReader for this OrderedList
|
84
|
+
# @return [OrderedReader]
|
85
|
+
def ordered_reader
|
86
|
+
OrderedReader.new(self)
|
87
|
+
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
89
|
+
# Populates the list with constructed ListNode Objects
|
90
|
+
# @param subject [RDF::URI]
|
91
|
+
def build_node(subject = nil)
|
92
|
+
return nil unless subject
|
93
|
+
node_cache.fetch(subject) do
|
94
|
+
ListNode.new(node_cache, subject, adapter, graph)
|
96
95
|
end
|
96
|
+
end
|
97
97
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
98
|
+
# Generates hash URIs for the subject of the LinkedList
|
99
|
+
# Should one of these URIs already be in use, a new URI will be generated
|
100
|
+
# @return [RDF::URI]
|
101
|
+
def new_node_subject
|
102
|
+
node = ::RDF::URI("##{::RDF::Node.new.id}")
|
103
|
+
node = ::RDF::URI("##{::RDF::Node.new.id}") while node_cache.key?(node)
|
104
|
+
node
|
105
|
+
end
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
107
|
+
# Class used for caching LinkedNode objects mapped to URIs
|
108
|
+
class NodeCache
|
109
|
+
def initialize
|
110
|
+
@cache ||= {}
|
111
|
+
end
|
112
112
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
113
|
+
# Retrieve the ListNode for a given URI
|
114
|
+
# If a block is passed, set its output to the cache
|
115
|
+
# @param uri [RDF::URI]
|
116
|
+
# @return [ListNode]
|
117
|
+
def fetch(uri)
|
118
|
+
@cache[uri] ||= yield if block_given?
|
119
|
+
end
|
120
120
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
121
|
+
# Determines whether or not the cache contains a key
|
122
|
+
# @param key [Object]
|
123
|
+
# @return [Boolean]
|
124
|
+
def key?(key)
|
125
|
+
@cache.key?(key)
|
127
126
|
end
|
127
|
+
end
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
129
|
+
# Class modeling sentinels within the linked list
|
130
|
+
# @see https://en.wikipedia.org/wiki/Sentinel_value
|
131
|
+
class Sentinel
|
132
|
+
attr_reader :parent, :next, :prev
|
133
|
+
attr_writer :next, :prev
|
134
|
+
|
135
|
+
# @param parent [Valkyrie::Persistence::Fedora::OrderedList]
|
136
|
+
# @param next_node [ListNode]
|
137
|
+
# @param prev_node [ListNode]
|
138
|
+
def initialize(parent, next_node: nil, prev_node: nil)
|
139
|
+
@parent = parent
|
140
|
+
@next = next_node
|
141
|
+
@prev = prev_node
|
142
|
+
end
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
144
|
+
# Ensure that this always behaves like a NilClass
|
145
|
+
# @return [TrueClass]
|
146
|
+
def nil?
|
147
|
+
true
|
148
|
+
end
|
149
149
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
end
|
150
|
+
# Ensure that this does not have a URI
|
151
|
+
# @return [NilClass]
|
152
|
+
def rdf_subject
|
153
|
+
nil
|
155
154
|
end
|
155
|
+
end
|
156
156
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
end
|
157
|
+
class HeadSentinel < Sentinel
|
158
|
+
# @param parent [Valkyrie::Persistence::Fedora::OrderedList]
|
159
|
+
# @param next_node [ListNode]
|
160
|
+
# @param prev_node [ListNode]
|
161
|
+
def initialize(*args)
|
162
|
+
super
|
163
|
+
@next ||= TailSentinel.new(parent, prev_node: self)
|
165
164
|
end
|
165
|
+
end
|
166
166
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
end
|
167
|
+
class TailSentinel < Sentinel
|
168
|
+
# @param parent [Valkyrie::Persistence::Fedora::OrderedList]
|
169
|
+
# @param next_node [ListNode]
|
170
|
+
# @param prev_node [ListNode]
|
171
|
+
def initialize(*args)
|
172
|
+
super
|
173
|
+
prev.next = self if prev&.next != self
|
175
174
|
end
|
175
|
+
end
|
176
176
|
end
|
177
177
|
end
|
@@ -26,10 +26,10 @@ module Valkyrie::Persistence::Fedora
|
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
# Access the "first" (head) node for the linked list
|
30
|
+
# @return [Valkyrie::Persistence::Fedora::OrderedList::HeadSentinel]
|
31
|
+
def first_head
|
32
|
+
root.head
|
33
|
+
end
|
34
34
|
end
|
35
35
|
end
|
@@ -92,7 +92,7 @@ module Valkyrie::Persistence::Fedora
|
|
92
92
|
existing_predicates = schema.find { |_k, v| v == RDF::URI(predicate.to_s) }
|
93
93
|
predicate_name = predicate.to_s.gsub(URI_PREFIX, '')
|
94
94
|
|
95
|
-
return predicate_name if existing_predicates.
|
95
|
+
return predicate_name if existing_predicates.blank?
|
96
96
|
existing_predicates.first
|
97
97
|
end
|
98
98
|
end
|
@@ -86,97 +86,95 @@ module Valkyrie::Persistence::Fedora
|
|
86
86
|
|
87
87
|
private
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
adapter.persister.save(resource: alternate_resource)
|
101
|
-
end
|
102
|
-
end
|
89
|
+
# Ensure that all alternate IDs for a given resource are persisted
|
90
|
+
# @param [Valkyrie::Resource] resource
|
91
|
+
# @return [Array<Valkyrie::Persistence::Fedora::AlternateIdentifier>]
|
92
|
+
def find_or_create_alternate_ids(resource)
|
93
|
+
return nil unless resource.try(:alternate_ids)
|
94
|
+
|
95
|
+
resource.alternate_ids.map do |alternate_identifier|
|
96
|
+
adapter.query_service.find_by(id: alternate_identifier)
|
97
|
+
rescue ::Valkyrie::Persistence::ObjectNotFoundError
|
98
|
+
alternate_resource = ::Valkyrie::Persistence::Fedora::AlternateIdentifier.new(id: alternate_identifier)
|
99
|
+
adapter.persister.save(resource: alternate_resource)
|
103
100
|
end
|
101
|
+
end
|
104
102
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
103
|
+
# Ensure that any Resources referenced by alternate IDs are deleted when a Resource has these IDs deleted
|
104
|
+
# @param [Valkyrie::Resource] updated_resource
|
105
|
+
def cleanup_alternate_resources(updated_resource)
|
106
|
+
persisted_resource = adapter.query_service.find_by(id: updated_resource.id)
|
107
|
+
removed_identifiers = persisted_resource.alternate_ids - updated_resource.alternate_ids
|
110
108
|
|
111
|
-
|
112
|
-
|
113
|
-
end
|
109
|
+
removed_identifiers.each do |removed_id|
|
110
|
+
adapter.persister.delete(resource: adapter.query_service.find_by(id: removed_id))
|
114
111
|
end
|
112
|
+
end
|
115
113
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
resource
|
114
|
+
# Ensure that any Resources referenced by alternate IDs are persisted when a Resource has these IDs added
|
115
|
+
# @param [Valkyrie::Resource] resource
|
116
|
+
# @param [Array<Valkyrie::Persistence::Fedora::AlternateIdentifier>] alternate_resources
|
117
|
+
# @return [Valkyrie::Resource]
|
118
|
+
def save_reference_to_resource(resource, alternate_resources)
|
119
|
+
alternate_resources.each do |alternate_resource|
|
120
|
+
alternate_resource.references = resource.id
|
121
|
+
adapter.persister.save(resource: alternate_resource)
|
127
122
|
end
|
128
123
|
|
129
|
-
|
130
|
-
|
131
|
-
# @return [Valkyrie::Persistence::OptimisticLockToken]
|
132
|
-
# @see https://github.com/samvera-labs/valkyrie/wiki/Optimistic-Locking
|
133
|
-
# @note Fedora's last modified response is not granular enough to produce an effective lock token
|
134
|
-
# therefore, we use the same implementation as the memory adapter. This could fail to lock a
|
135
|
-
# resource if Fedora updated this resource between the time it was saved and Valkyrie created
|
136
|
-
# the token.
|
137
|
-
def generate_lock_token(resource)
|
138
|
-
return unless resource.optimistic_locking_enabled?
|
139
|
-
token = Valkyrie::Persistence::OptimisticLockToken.new(adapter_id: adapter.id, token: Time.now.to_r)
|
140
|
-
resource.send("#{Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK}=", token)
|
141
|
-
end
|
124
|
+
resource
|
125
|
+
end
|
142
126
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
retrieved_lock_tokens = adapter.query_service.find_by(id: resource.id)[Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK]
|
158
|
-
retrieved_lock_token = retrieved_lock_tokens.find { |lock_token| lock_token.adapter_id == adapter.id }
|
159
|
-
return if retrieved_lock_token.blank?
|
160
|
-
|
161
|
-
raise Valkyrie::Persistence::StaleObjectError, "The object #{resource.id} has been updated by another process." unless current_lock_token == retrieved_lock_token
|
162
|
-
end
|
127
|
+
# Generate the lock token for a Resource, and set it for attribute
|
128
|
+
# @param [Valkyrie::Resource] resource
|
129
|
+
# @return [Valkyrie::Persistence::OptimisticLockToken]
|
130
|
+
# @see https://github.com/samvera-labs/valkyrie/wiki/Optimistic-Locking
|
131
|
+
# @note Fedora's last modified response is not granular enough to produce an effective lock token
|
132
|
+
# therefore, we use the same implementation as the memory adapter. This could fail to lock a
|
133
|
+
# resource if Fedora updated this resource between the time it was saved and Valkyrie created
|
134
|
+
# the token.
|
135
|
+
def generate_lock_token(resource)
|
136
|
+
return unless resource.optimistic_locking_enabled?
|
137
|
+
token = Valkyrie::Persistence::OptimisticLockToken.new(adapter_id: adapter.id, token: Time.now.to_r)
|
138
|
+
resource.send("#{Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK}=", token)
|
139
|
+
end
|
163
140
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
141
|
+
# Determine whether or not a lock token is still valid for a persisted Resource
|
142
|
+
# If the persisted Resource has been updated since it was last read into memory,
|
143
|
+
# then the resouce in memory has been invalidated and Valkyrie::Persistence::StaleObjectError
|
144
|
+
# is raised.
|
145
|
+
# @param [Valkyrie::Resource] resource
|
146
|
+
# @see https://github.com/samvera-labs/valkyrie/wiki/Optimistic-Locking
|
147
|
+
# @raise [Valkyrie::Persistence::StaleObjectError]
|
148
|
+
def validate_lock_token(resource)
|
149
|
+
return unless resource.optimistic_locking_enabled?
|
150
|
+
return if resource.id.blank?
|
151
|
+
|
152
|
+
current_lock_token = resource[Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK].find { |lock_token| lock_token.adapter_id == adapter.id }
|
153
|
+
return if current_lock_token.blank?
|
154
|
+
|
155
|
+
retrieved_lock_tokens = adapter.query_service.find_by(id: resource.id)[Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK]
|
156
|
+
retrieved_lock_token = retrieved_lock_tokens.find { |lock_token| lock_token.adapter_id == adapter.id }
|
157
|
+
return if retrieved_lock_token.blank?
|
158
|
+
|
159
|
+
raise Valkyrie::Persistence::StaleObjectError, "The object #{resource.id} has been updated by another process." unless current_lock_token == retrieved_lock_token
|
160
|
+
end
|
171
161
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
162
|
+
# Retrieve the lock token that holds Fedora's system-managed last-modified date
|
163
|
+
# @param [Valkyrie::Resource] resource
|
164
|
+
# @return [Valkyrie::Persistence::OptimisticLockToken]
|
165
|
+
def native_lock_token(resource)
|
166
|
+
return unless resource.optimistic_locking_enabled?
|
167
|
+
resource[Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK].find { |lock_token| lock_token.adapter_id.to_s == "native-#{adapter.id}" }
|
168
|
+
end
|
169
|
+
|
170
|
+
# Set Fedora request headers:
|
171
|
+
# * `Prefer: handling=lenient; received="minimal"` allows us to avoid sending all server-managed triples
|
172
|
+
# * `If-Unmodified-Since` triggers Fedora's server-side optimistic locking
|
173
|
+
# @param request [Faraday::Request]
|
174
|
+
# @param lock_token [Valkyrie::Persistence::OptimisticLockToken]
|
175
|
+
def update_request_headers(request, lock_token)
|
176
|
+
request.headers["Prefer"] = "handling=lenient; received=\"minimal\""
|
177
|
+
request.headers["If-Unmodified-Since"] = lock_token.token if lock_token
|
178
|
+
end
|
181
179
|
end
|
182
180
|
end
|