valkyrie 1.2.0.rc1 → 1.2.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +12 -4
- data/lib/valkyrie/persistence/composite_persister.rb +1 -1
- data/lib/valkyrie/persistence/fedora/list_node.rb +42 -3
- data/lib/valkyrie/persistence/fedora/metadata_adapter.rb +26 -0
- data/lib/valkyrie/persistence/fedora/ordered_list.rb +36 -5
- data/lib/valkyrie/persistence/fedora/ordered_reader.rb +6 -0
- data/lib/valkyrie/persistence/fedora/permissive_schema.rb +20 -1
- data/lib/valkyrie/persistence/fedora/persister.rb +33 -4
- data/lib/valkyrie/persistence/fedora/persister/alternate_identifier.rb +6 -0
- data/lib/valkyrie/persistence/fedora/persister/model_converter.rb +254 -4
- data/lib/valkyrie/persistence/fedora/persister/orm_converter.rb +250 -3
- data/lib/valkyrie/persistence/fedora/persister/resource_factory.rb +6 -0
- data/lib/valkyrie/persistence/fedora/query_service.rb +22 -4
- data/lib/valkyrie/persistence/memory/metadata_adapter.rb +2 -0
- data/lib/valkyrie/persistence/memory/persister.rb +11 -3
- data/lib/valkyrie/persistence/memory/query_service.rb +11 -0
- data/lib/valkyrie/persistence/postgres/metadata_adapter.rb +2 -0
- data/lib/valkyrie/persistence/postgres/orm.rb +4 -0
- data/lib/valkyrie/persistence/postgres/orm_converter.rb +62 -2
- data/lib/valkyrie/persistence/postgres/persister.rb +18 -7
- data/lib/valkyrie/persistence/postgres/query_service.rb +103 -11
- data/lib/valkyrie/persistence/postgres/resource_converter.rb +10 -0
- data/lib/valkyrie/persistence/postgres/resource_factory.rb +3 -0
- data/lib/valkyrie/persistence/solr/composite_indexer.rb +10 -0
- data/lib/valkyrie/persistence/solr/metadata_adapter.rb +7 -0
- data/lib/valkyrie/persistence/solr/model_converter.rb +137 -0
- data/lib/valkyrie/persistence/solr/orm_converter.rb +168 -0
- data/lib/valkyrie/persistence/solr/persister.rb +13 -5
- data/lib/valkyrie/persistence/solr/queries.rb +1 -0
- data/lib/valkyrie/persistence/solr/queries/default_paginator.rb +11 -1
- data/lib/valkyrie/persistence/solr/queries/find_all_query.rb +12 -0
- data/lib/valkyrie/persistence/solr/queries/find_by_alternate_identifier_query.rb +12 -0
- data/lib/valkyrie/persistence/solr/queries/find_by_id_query.rb +11 -0
- data/lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb +13 -0
- data/lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb +9 -0
- data/lib/valkyrie/persistence/solr/queries/find_members_query.rb +23 -0
- data/lib/valkyrie/persistence/solr/queries/find_ordered_references_query.rb +50 -0
- data/lib/valkyrie/persistence/solr/queries/find_references_query.rb +15 -0
- data/lib/valkyrie/persistence/solr/query_service.rb +47 -14
- data/lib/valkyrie/persistence/solr/repository.rb +21 -4
- data/lib/valkyrie/persistence/solr/resource_factory.rb +2 -0
- data/lib/valkyrie/resource.rb +1 -0
- data/lib/valkyrie/specs/shared_specs.rb +1 -0
- data/lib/valkyrie/specs/shared_specs/persister.rb +92 -2
- data/lib/valkyrie/specs/shared_specs/queries.rb +12 -0
- data/lib/valkyrie/specs/shared_specs/solr_indexer.rb +40 -0
- data/lib/valkyrie/storage/fedora.rb +0 -2
- data/lib/valkyrie/version.rb +1 -1
- metadata +4 -2
@@ -3,6 +3,12 @@ require 'valkyrie/resource'
|
|
3
3
|
require 'valkyrie/types'
|
4
4
|
|
5
5
|
module Valkyrie::Persistence::Fedora
|
6
|
+
# Class modeling alternate identifiers as first-order Valkyrie::Resources
|
7
|
+
# Alternate identifiers generalize identifiers from external systems
|
8
|
+
# Examples include NOIDs, ARKs, and EZIDs
|
9
|
+
# @see https://confluence.ucop.edu/display/Curation/NOID
|
10
|
+
# @see http://n2t.net/e/ark_ids.html
|
11
|
+
# @see https://ezid.cdlib.org/learn/#01
|
6
12
|
class AlternateIdentifier < ::Valkyrie::Resource
|
7
13
|
attribute :references, ::Valkyrie::Types::ID.optional
|
8
14
|
end
|
@@ -5,12 +5,18 @@ module Valkyrie::Persistence::Fedora
|
|
5
5
|
class ModelConverter
|
6
6
|
attr_reader :resource, :adapter, :subject_uri
|
7
7
|
delegate :connection, :connection_prefix, :base_path, to: :adapter
|
8
|
+
|
9
|
+
# @param [Valkyrie::Resource] resource
|
10
|
+
# @param [Valkyrie::Persistence::Fedora::MetadataAdapter] adapter
|
11
|
+
# @param [RDF::URI] subject_uri
|
8
12
|
def initialize(resource:, adapter:, subject_uri: RDF::URI(""))
|
9
13
|
@resource = resource
|
10
14
|
@adapter = adapter
|
11
15
|
@subject_uri = subject_uri
|
12
16
|
end
|
13
17
|
|
18
|
+
# Convert a Valkyrie Resource into a RDF LDP basic container
|
19
|
+
# @return [Ldp::Container::Basic]
|
14
20
|
def convert
|
15
21
|
graph_resource.graph.delete([nil, nil, nil])
|
16
22
|
properties.each do |property|
|
@@ -22,30 +28,47 @@ module Valkyrie::Persistence::Fedora
|
|
22
28
|
graph_resource
|
23
29
|
end
|
24
30
|
|
25
|
-
#
|
31
|
+
# Access the Valkyrie attribute names to be used for the Fedora resource properties
|
32
|
+
# Filters resource properties to remove properties that should not be persisted to Fedora.
|
26
33
|
# * new_record is a virtual property for marking unsaved objects
|
34
|
+
# @return [Array<Symbol>]
|
27
35
|
def properties
|
28
36
|
resource_attributes.keys - [:new_record]
|
29
37
|
end
|
30
38
|
|
31
39
|
delegate :attributes, to: :resource, prefix: true
|
32
40
|
|
41
|
+
# Construct the LDP Basic Container modeling the Valkyrie Resource in Fedora
|
42
|
+
# @see https://www.w3.org/TR/ldp/#ldpc
|
43
|
+
# @return [Ldp::Container::Basic]
|
33
44
|
def graph_resource
|
34
45
|
@graph_resource ||= ::Ldp::Container::Basic.new(connection, subject, nil, base_path)
|
35
46
|
end
|
36
47
|
|
48
|
+
# Generate a URI from the Valkyrie Resource ID to be used as the RDF subject for Fedora LDP resources
|
49
|
+
# @return [RDF::URI]
|
37
50
|
def subject
|
38
51
|
adapter.id_to_uri(resource.id) if resource.try(:id)
|
39
52
|
end
|
40
53
|
|
54
|
+
# Provide the Class used for values
|
55
|
+
# This should be derived from Valkyrie::ValueMapper as a base class
|
56
|
+
# @return [Class]
|
41
57
|
def property_converter
|
42
58
|
FedoraValue
|
43
59
|
end
|
44
60
|
|
61
|
+
# Class modeling properties for Fedora LDP resources
|
62
|
+
# These map directly to attributes on the Valkyrie resources and generate a new graph or populate an existing graph
|
45
63
|
class Property
|
46
64
|
attr_reader :key, :value, :subject, :adapter, :resource
|
47
65
|
delegate :schema, to: :adapter
|
48
66
|
|
67
|
+
# @param [RDF::URI] subject RDF URI referencing the LDP container in the graph store
|
68
|
+
# @param [Symbol] key attribute key used to map to the RDF predicate
|
69
|
+
# @param [Object] value
|
70
|
+
# @param [Valkyrie::Persistence::Fedora::MetadataAdapter] adapter
|
71
|
+
# @param [Valkyrie::Resource] resource
|
49
72
|
def initialize(subject, key, value, adapter, resource)
|
50
73
|
@subject = subject
|
51
74
|
@key = key
|
@@ -54,6 +77,9 @@ module Valkyrie::Persistence::Fedora
|
|
54
77
|
@resource = resource
|
55
78
|
end
|
56
79
|
|
80
|
+
# Populate the RDF graph containing statements about the LDP container
|
81
|
+
# @param [RDF::Graph] graph
|
82
|
+
# @return [RDF::Graph]
|
57
83
|
def to_graph(graph = RDF::Graph.new)
|
58
84
|
Array(value).each do |val|
|
59
85
|
graph << RDF::Statement.new(subject, predicate, val)
|
@@ -61,17 +87,27 @@ module Valkyrie::Persistence::Fedora
|
|
61
87
|
graph
|
62
88
|
end
|
63
89
|
|
90
|
+
# Retrieve the RDF predicate for this Valkyrie Resource attribute (being converted)
|
91
|
+
# This is used to generate RDF statements (triples) from Resource attributes
|
92
|
+
# @return [RDF::URI]
|
64
93
|
def predicate
|
65
94
|
schema.predicate_for(resource: resource, property: key)
|
66
95
|
end
|
67
96
|
end
|
68
97
|
|
98
|
+
# Class modeling RDF properties which are sets of graphs
|
99
|
+
# (i. e. this generates a parent graph from a set of child graphs)
|
69
100
|
class CompositeProperty
|
70
101
|
attr_reader :properties
|
102
|
+
|
103
|
+
# @param [Array<Property>] properties
|
71
104
|
def initialize(properties)
|
72
105
|
@properties = properties
|
73
106
|
end
|
74
107
|
|
108
|
+
# Generate the RDF graph
|
109
|
+
# @param [RDF::Graph] graph RDF graph being populated with "member" graphs
|
110
|
+
# @return [RDF::Graph] the populated "parent" graph
|
75
111
|
def to_graph(graph = RDF::Graph.new)
|
76
112
|
properties.each do |property|
|
77
113
|
property.to_graph(graph)
|
@@ -80,8 +116,16 @@ module Valkyrie::Persistence::Fedora
|
|
80
116
|
end
|
81
117
|
end
|
82
118
|
|
119
|
+
# Class modeling RDF properties which are single, existing graphs
|
120
|
+
# (i. e. this inserts a single existing "child" graph into a "parent" graph)
|
83
121
|
class GraphProperty
|
84
122
|
attr_reader :key, :graph, :subject, :adapter, :resource
|
123
|
+
|
124
|
+
# @param [RDF::URI] subject RDF URI referencing the LDP container in the graph store
|
125
|
+
# @param [Symbol] key attribute key used to map to the RDF predicate
|
126
|
+
# @param [RDF::Graph] graph RDF graph for the existing property
|
127
|
+
# @param [Valkyrie::Persistence::Fedora::MetadataAdapter] adapter
|
128
|
+
# @param [Valkyrie::Resource] resource
|
85
129
|
def initialize(subject, key, graph, adapter, resource)
|
86
130
|
@subject = subject
|
87
131
|
@key = key
|
@@ -90,70 +134,193 @@ module Valkyrie::Persistence::Fedora
|
|
90
134
|
@resource = resource
|
91
135
|
end
|
92
136
|
|
137
|
+
# Appends the existing graph to a new or existing "parent" graph
|
138
|
+
# @param [RDF::Graph] passed_graph
|
139
|
+
# @return [RDF::Graph] the updated "parent" graph
|
93
140
|
def to_graph(passed_graph = RDF::Graph.new)
|
94
141
|
passed_graph << graph
|
95
142
|
end
|
96
143
|
end
|
97
144
|
|
145
|
+
# (Abstract) base class for Fedora property values
|
98
146
|
class FedoraValue < ::Valkyrie::ValueMapper
|
99
147
|
end
|
100
148
|
|
149
|
+
# Class mapping Fedora property values which must be ordered
|
150
|
+
# This assumes that the value being mapped is actually an Array (or Enumerable)
|
101
151
|
class OrderedMembers < ::Valkyrie::ValueMapper
|
102
152
|
FedoraValue.register(self)
|
153
|
+
|
154
|
+
# Determines whether or not the Valkyrie attribute value can be ordered
|
155
|
+
# @param [Object] value
|
156
|
+
# @return [Boolean]
|
103
157
|
def self.handles?(value)
|
104
158
|
value.is_a?(Property) && value.key == :member_ids && Array(value.value).present?
|
105
159
|
end
|
106
160
|
|
161
|
+
# Construct a graph from the value array
|
162
|
+
# @return [GraphProperty]
|
107
163
|
def result
|
108
164
|
initialize_list
|
109
165
|
apply_first_and_last
|
110
166
|
GraphProperty.new(value.subject, value.key, graph, value.adapter, value.resource)
|
111
167
|
end
|
112
168
|
|
169
|
+
# Generate the RDF Graph from from the ordered value array
|
170
|
+
# @return [RDF::Graph]
|
113
171
|
def graph
|
114
172
|
@graph ||= ordered_list.to_graph
|
115
173
|
end
|
116
174
|
|
175
|
+
# Append the RDF statements asserting that two RDF resources are the "first" and "last" elements of the linked list
|
176
|
+
# @return [RDF::Graph]
|
117
177
|
def apply_first_and_last
|
118
178
|
return if ordered_list.to_a.empty?
|
119
179
|
graph << RDF::Statement.new(value.subject, ::RDF::Vocab::IANA.first, ordered_list.head.next.rdf_subject)
|
120
180
|
graph << RDF::Statement.new(value.subject, ::RDF::Vocab::IANA.last, ordered_list.tail.prev.rdf_subject)
|
121
181
|
end
|
122
182
|
|
183
|
+
# Populate an OrderedList object (wrapping an RDF graph implementation of a linked list) using the value array
|
123
184
|
def initialize_list
|
124
185
|
Array(value.value).each_with_index do |val, index|
|
125
186
|
ordered_list.insert_proxy_for_at(index, calling_mapper.for(Property.new(value.subject, :member_id, val, value.adapter, value.resource)).result.value)
|
126
187
|
end
|
127
188
|
end
|
128
189
|
|
190
|
+
# Construct an OrderedList object
|
191
|
+
# @return [OrderedList]
|
129
192
|
def ordered_list
|
130
193
|
@ordered_list ||= OrderedList.new(RDF::Graph.new, nil, nil, value.adapter)
|
131
194
|
end
|
132
195
|
end
|
133
196
|
|
197
|
+
class OrderedProperties < ::Valkyrie::ValueMapper
|
198
|
+
FedoraValue.register(self)
|
199
|
+
def self.handles?(value)
|
200
|
+
value.is_a?(Property) && ordered?(value) && !OrderedMembers.handles?(value) && Array(value.value).present? && value.value.is_a?(Array)
|
201
|
+
end
|
202
|
+
|
203
|
+
def self.ordered?(value)
|
204
|
+
return false unless value.resource.class.schema[value.key]
|
205
|
+
value.resource.class.schema[value.key].meta.try(:[], :ordered)
|
206
|
+
end
|
207
|
+
|
208
|
+
delegate :subject, to: :value
|
209
|
+
|
210
|
+
def result
|
211
|
+
initialize_list
|
212
|
+
apply_first_and_last
|
213
|
+
GraphProperty.new(value.subject, value.key, graph, value.adapter, value.resource)
|
214
|
+
end
|
215
|
+
|
216
|
+
def graph
|
217
|
+
@graph ||= ordered_list.to_graph
|
218
|
+
end
|
219
|
+
|
220
|
+
def apply_first_and_last
|
221
|
+
return if ordered_list.to_a.empty?
|
222
|
+
graph << RDF::Statement.new(subject, predicate, node_id)
|
223
|
+
graph << RDF::Statement.new(node_id, ::RDF::Vocab::IANA.first, ordered_list.head.next.rdf_subject)
|
224
|
+
graph << RDF::Statement.new(node_id, ::RDF::Vocab::IANA.last, ordered_list.tail.prev.rdf_subject)
|
225
|
+
end
|
226
|
+
|
227
|
+
def node_id
|
228
|
+
@node_id ||= ordered_list.send(:new_node_subject)
|
229
|
+
end
|
230
|
+
|
231
|
+
def predicate
|
232
|
+
value.schema.predicate_for(resource: value.resource, property: value.key)
|
233
|
+
end
|
234
|
+
|
235
|
+
def initialize_list
|
236
|
+
Array(value.value).each_with_index do |val, index|
|
237
|
+
property = NestedProperty.new(value: val, scope: value)
|
238
|
+
obj = calling_mapper.for(property.property).result
|
239
|
+
# Append value directly if possible.
|
240
|
+
if obj.respond_to?(:value)
|
241
|
+
ordered_list.insert_proxy_for_at(index, obj.value)
|
242
|
+
# If value is a nested object, take its graph and append it.
|
243
|
+
elsif obj.respond_to?(:graph)
|
244
|
+
append_to_graph(obj: obj, index: index, property: property.property)
|
245
|
+
end
|
246
|
+
graph << ordered_list.to_graph
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
class NestedProperty
|
251
|
+
attr_reader :value, :scope
|
252
|
+
def initialize(value:, scope:)
|
253
|
+
@value = value
|
254
|
+
@scope = scope
|
255
|
+
end
|
256
|
+
|
257
|
+
def property
|
258
|
+
@property ||= Property.new(node, key, value, scope.adapter, scope.resource)
|
259
|
+
end
|
260
|
+
|
261
|
+
def key
|
262
|
+
scope.key.to_s.singularize.to_sym
|
263
|
+
end
|
264
|
+
|
265
|
+
def node
|
266
|
+
@node ||= ::RDF::URI("##{::RDF::Node.new.id}")
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
def append_to_graph(obj:, index:, property:)
|
271
|
+
proxy_node = obj.graph.query([nil, property.predicate, nil]).objects[0]
|
272
|
+
obj.graph.delete([nil, property.predicate, nil])
|
273
|
+
ordered_list.insert_proxy_for_at(index, proxy_node)
|
274
|
+
obj.to_graph(graph)
|
275
|
+
end
|
276
|
+
|
277
|
+
def ordered_list
|
278
|
+
@ordered_list ||= OrderedList.new(RDF::Graph.new, nil, nil, value.adapter)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
# Class mapping Valkyrie attribute values which have already been
|
283
|
+
# mapped to Valkyrie::Persistence::Fedora::Persister::ModelConverter::Property objects
|
134
284
|
class NestedProperty < ::Valkyrie::ValueMapper
|
135
285
|
FedoraValue.register(self)
|
286
|
+
|
287
|
+
# Determines whether or not the Valkyrie attribute value can be ordered
|
288
|
+
# @param [Object] value
|
289
|
+
# @return [Boolean]
|
136
290
|
def self.handles?(value)
|
137
291
|
value.is_a?(Property) && value.value.is_a?(Hash) && value.value[:internal_resource]
|
138
292
|
end
|
139
293
|
|
294
|
+
# Generate a new parent graph containing the child graph generated from the ModelConverter::Property objects
|
295
|
+
# @return [GraphProperty]
|
140
296
|
def result
|
141
297
|
nested_graph << RDF::Statement.new(value.subject, value.predicate, subject_uri)
|
142
298
|
GraphProperty.new(value.subject, value.key, nested_graph, value.adapter, value.resource)
|
143
299
|
end
|
144
300
|
|
301
|
+
# Generate the "child" graph from the value in the ModelConverter::Property
|
302
|
+
# @return [RDF::Graph]
|
145
303
|
def nested_graph
|
146
304
|
@nested_graph ||= ModelConverter.new(resource: Valkyrie::Types::Anything[value.value], adapter: value.adapter, subject_uri: subject_uri).convert.graph
|
147
305
|
end
|
148
306
|
|
307
|
+
# Generate a new RDF hash URI for the "child" graph for the ModelConverter::Property
|
308
|
+
# @see https://github.com/fcrepo4/fcrepo4/blob/master/fcrepo-kernel-modeshape/src/main/java/org/fcrepo/kernel/modeshape/rdf/JcrRdfTools.java#L455
|
309
|
+
# @return [RDF::Graph]
|
149
310
|
def subject_uri
|
150
311
|
@subject_uri ||= ::RDF::URI(RDF::Node.new.to_s.gsub("_:", "#"))
|
151
312
|
end
|
152
313
|
end
|
153
314
|
|
315
|
+
# Class used to map values converted into default Ruby data types (e. g. Strings)
|
316
|
+
# into Valkyrie::Persistence::Fedora::Persister::ModelConverter::Property objects
|
154
317
|
class MappedFedoraValue < ::Valkyrie::ValueMapper
|
155
318
|
private
|
156
319
|
|
320
|
+
# Map a default Ruby data type
|
321
|
+
# (This maps the existing Property to a FedoraValue first)
|
322
|
+
# @param [Object] converted_value
|
323
|
+
# @return [Valkyrie::Persistence::Fedora::Persister::ModelConverter::Property]
|
157
324
|
def map_value(converted_value:)
|
158
325
|
calling_mapper.for(
|
159
326
|
Property.new(
|
@@ -167,12 +334,24 @@ module Valkyrie::Persistence::Fedora
|
|
167
334
|
end
|
168
335
|
end
|
169
336
|
|
337
|
+
# Class mapping Property objects for Valkyrie IDs using typed RDF literals
|
338
|
+
# This generates a custom datatype URI for Valkyrie IDs
|
339
|
+
# @see https://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal
|
340
|
+
# @see https://www.w3.org/TR/rdf11-concepts/#datatype-iris
|
170
341
|
class NestedInternalValkyrieID < MappedFedoraValue
|
171
342
|
FedoraValue.register(self)
|
343
|
+
|
344
|
+
# Determines whether or not the value is a Property for Valkyrie ID with a hash URI for the RDF graph
|
345
|
+
# @param [Object] value
|
346
|
+
# @return [Boolean]
|
172
347
|
def self.handles?(value)
|
173
348
|
value.is_a?(Property) && value.value.is_a?(Valkyrie::ID) && value.subject.to_s.include?("#")
|
174
349
|
end
|
175
350
|
|
351
|
+
# Converts the RDF literal into the Property
|
352
|
+
# For example, a Valkyrie::ID with the value "db67d786-d187-46b8-a44f-a494f0c65ec2"
|
353
|
+
# will first be mapped to RDF::Literal "db67d786-d187-46b8-a44f-a494f0c65ec2"^^<http://example.com/predicate/valkyrie_id>
|
354
|
+
# @return [Valkyrie::Persistence::Fedora::Persister::ModelConverter::Property]
|
176
355
|
def result
|
177
356
|
map_value(converted_value: RDF::Literal.new(
|
178
357
|
value.value,
|
@@ -181,23 +360,40 @@ module Valkyrie::Persistence::Fedora
|
|
181
360
|
end
|
182
361
|
end
|
183
362
|
|
363
|
+
# Class mapping Property objects for Valkyrie IDs which have not been mapped to Fedora LDP URIs
|
184
364
|
class InternalValkyrieID < MappedFedoraValue
|
185
365
|
FedoraValue.register(self)
|
366
|
+
|
367
|
+
# Determines whether or not the value is a Property for Valkyrie ID which is not contain an adapter resource path URI
|
368
|
+
# @param [Object] value
|
369
|
+
# @return [Boolean]
|
186
370
|
def self.handles?(value)
|
187
371
|
value.is_a?(Property) && value.value.is_a?(Valkyrie::ID) && !value.value.to_s.include?("://")
|
188
372
|
end
|
189
373
|
|
374
|
+
# Generates the Property for this URI
|
375
|
+
# For example, a Valkyrie::ID with the value "c0831f2e-f86b-4d4a-9331-020b7418b068"
|
376
|
+
# will first be mapped to <http://localhost:8988/rest/test_fed/c0/83/1f/2e/c0831f2e-f86b-4d4a-9331-020b7418b068>
|
377
|
+
# @return [Valkyrie::Persistence::Fedora::Persister::ModelConverter::Property]
|
190
378
|
def result
|
191
379
|
map_value(converted_value: value.adapter.id_to_uri(value.value))
|
192
380
|
end
|
193
381
|
end
|
194
382
|
|
383
|
+
# Class for mapping Property objects for Boolean values
|
195
384
|
class BooleanValue < MappedFedoraValue
|
196
385
|
FedoraValue.register(self)
|
386
|
+
|
387
|
+
# Determines whether or not the value is a Property for boolean values
|
388
|
+
# @param [Object] value
|
389
|
+
# @return [Boolean]
|
197
390
|
def self.handles?(value)
|
198
391
|
value.is_a?(Property) && ([true, false].include? value.value)
|
199
392
|
end
|
200
393
|
|
394
|
+
# Generates the Property for this boolean
|
395
|
+
# RDF::Literal::Boolean:0x3fc310fdf120("false"^^<http://example.com/predicate/valkyrie_bool>)
|
396
|
+
# @return [Valkyrie::Persistence::Fedora::Persister::ModelConverter::Property]
|
201
397
|
def result
|
202
398
|
map_value(converted_value: RDF::Literal.new(
|
203
399
|
value.value,
|
@@ -206,12 +402,20 @@ module Valkyrie::Persistence::Fedora
|
|
206
402
|
end
|
207
403
|
end
|
208
404
|
|
405
|
+
# Class for mapping Property objects for Integer values
|
209
406
|
class IntegerValue < MappedFedoraValue
|
210
407
|
FedoraValue.register(self)
|
408
|
+
|
409
|
+
# Determines whether or not the value is a Property for Integer values
|
410
|
+
# @param [Object] value
|
411
|
+
# @return [Boolean]
|
211
412
|
def self.handles?(value)
|
212
413
|
value.is_a?(Property) && value.value.is_a?(Integer)
|
213
414
|
end
|
214
415
|
|
416
|
+
# Generates the Property for this Integer
|
417
|
+
# #<RDF::Literal::Integer:0x3fc8a104f570("1"^^<http://example.com/predicate/valkyrie_int>)>
|
418
|
+
# @return [Valkyrie::Persistence::Fedora::Persister::ModelConverter::Property]
|
215
419
|
def result
|
216
420
|
map_value(converted_value: RDF::Literal.new(
|
217
421
|
value.value,
|
@@ -220,12 +424,34 @@ module Valkyrie::Persistence::Fedora
|
|
220
424
|
end
|
221
425
|
end
|
222
426
|
|
427
|
+
class FloatValue < MappedFedoraValue
|
428
|
+
FedoraValue.register(self)
|
429
|
+
def self.handles?(value)
|
430
|
+
value.is_a?(Property) && value.value.is_a?(Float)
|
431
|
+
end
|
432
|
+
|
433
|
+
def result
|
434
|
+
map_value(converted_value: RDF::Literal.new(
|
435
|
+
value.value,
|
436
|
+
datatype: PermissiveSchema.valkyrie_float
|
437
|
+
))
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
# Class for mapping Property objects for DateTime values
|
223
442
|
class DateTimeValue < MappedFedoraValue
|
224
443
|
FedoraValue.register(self)
|
444
|
+
|
445
|
+
# Determines whether or not the value is a Property for DateTime values
|
446
|
+
# @param [Object] value
|
447
|
+
# @return [Boolean]
|
225
448
|
def self.handles?(value)
|
226
449
|
value.is_a?(Property) && value.value.is_a?(DateTime)
|
227
450
|
end
|
228
451
|
|
452
|
+
# Generates the Property for this DateTime
|
453
|
+
# This will first be mapped to an RDF::Literal::DateTime object such as "2018-08-08T11:24:18.2087-04:00"^^<http://example.com/predicate/valkyrie_datetime>
|
454
|
+
# @return [Valkyrie::Persistence::Fedora::Persister::ModelConverter::Property]
|
229
455
|
def result
|
230
456
|
map_value(converted_value: RDF::Literal.new(
|
231
457
|
value.value,
|
@@ -234,18 +460,26 @@ module Valkyrie::Persistence::Fedora
|
|
234
460
|
end
|
235
461
|
end
|
236
462
|
|
237
|
-
#
|
238
|
-
#
|
463
|
+
# Class for mapping Property objects for Time values
|
464
|
+
# Technically Valkyrie does not support time, but when other persisters support time
|
465
|
+
# this code will make Fedora compliant with the established patterns.
|
239
466
|
#
|
240
467
|
# https://github.com/samvera-labs/valkyrie/wiki/Supported-Data-Types
|
241
468
|
class TimeValue < MappedFedoraValue
|
242
469
|
FedoraValue.register(self)
|
470
|
+
|
471
|
+
# Determines whether or not the value is a Property for Time values
|
472
|
+
# @param [Object] value
|
473
|
+
# @return [Boolean]
|
243
474
|
def self.handles?(value)
|
244
475
|
value.is_a?(Property) && value.value.is_a?(Time)
|
245
476
|
end
|
246
477
|
|
478
|
+
# Generates the Property for this Time
|
479
|
+
# This will first be mapped to an RDF::Literal::DateTime object such as "2018-08-08T11:24:18.2087-04:00"^^<http://example.com/predicate/valkyrie_datetime>
|
480
|
+
# @return [Valkyrie::Persistence::Fedora::Persister::ModelConverter::Property]
|
247
481
|
def result
|
248
|
-
# cast it to datetime for storage, to preserve
|
482
|
+
# cast it to datetime for storage, to preserve milliseconds and date
|
249
483
|
map_value(converted_value:
|
250
484
|
RDF::Literal.new(
|
251
485
|
value.value.to_datetime,
|
@@ -254,12 +488,21 @@ module Valkyrie::Persistence::Fedora
|
|
254
488
|
end
|
255
489
|
end
|
256
490
|
|
491
|
+
# Class for mapping Property objects for simple Valkyrie IDs
|
257
492
|
class IdentifiableValue < MappedFedoraValue
|
258
493
|
FedoraValue.register(self)
|
494
|
+
|
495
|
+
# Determines whether or not the value is a Property for Valkyrie::ID values
|
496
|
+
# @param [Object] value
|
497
|
+
# @return [Boolean]
|
259
498
|
def self.handles?(value)
|
260
499
|
value.is_a?(Property) && value.value.is_a?(Valkyrie::ID)
|
261
500
|
end
|
262
501
|
|
502
|
+
# Converts the RDF literal into the Property
|
503
|
+
# For example, a Valkyrie::ID with the value "adapter://1"
|
504
|
+
# will first be mapped to RDF::Literal "adapter://1"^^<http://example.com/predicate/valkyrie_id>
|
505
|
+
# @return [Valkyrie::Persistence::Fedora::Persister::ModelConverter::Property]
|
263
506
|
def result
|
264
507
|
map_value(converted_value: RDF::Literal.new(
|
265
508
|
value.value,
|
@@ -268,12 +511,19 @@ module Valkyrie::Persistence::Fedora
|
|
268
511
|
end
|
269
512
|
end
|
270
513
|
|
514
|
+
# Class mapping Property objects for value arrays
|
271
515
|
class EnumerableValue < MappedFedoraValue
|
272
516
|
FedoraValue.register(self)
|
517
|
+
|
518
|
+
# Determines whether or not the value is a Property for Array values
|
519
|
+
# @param [Object] value
|
520
|
+
# @return [Boolean]
|
273
521
|
def self.handles?(value)
|
274
522
|
value.is_a?(Property) && value.value.is_a?(Array)
|
275
523
|
end
|
276
524
|
|
525
|
+
# Construct a CompositeProperty composed of the mapped Array elements
|
526
|
+
# @return [CompositeProperty]
|
277
527
|
def result
|
278
528
|
new_values = value.value.map do |val|
|
279
529
|
map_value(converted_value: val)
|