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
@@ -251,46 +251,46 @@ module Valkyrie::Persistence::Postgres
|
|
251
251
|
|
252
252
|
private
|
253
253
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
end
|
254
|
+
def find_ordered_references_by(resource:, property:, model: nil)
|
255
|
+
if model
|
256
|
+
run_query(find_ordered_references_with_type_query, property, resource.id.to_s, model)
|
257
|
+
else
|
258
|
+
run_query(find_ordered_references_query, property, resource.id.to_s)
|
260
259
|
end
|
260
|
+
end
|
261
261
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
end
|
262
|
+
def find_unordered_references_by(resource:, property:, model: nil)
|
263
|
+
if model
|
264
|
+
run_query(find_references_with_type_query, property, resource.id.to_s, model)
|
265
|
+
else
|
266
|
+
run_query(find_references_query, property, resource.id.to_s)
|
268
267
|
end
|
268
|
+
end
|
269
269
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
270
|
+
# Determines whether or not an Object is a Valkyrie ID
|
271
|
+
# @param [Object] id
|
272
|
+
# @raise [ArgumentError]
|
273
|
+
def validate_id(id)
|
274
|
+
raise ArgumentError, 'id must be a Valkyrie::ID' unless id.is_a? Valkyrie::ID
|
275
|
+
end
|
276
276
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
277
|
+
# Determines whether or not a resource has been persisted
|
278
|
+
# @param [Object] resource
|
279
|
+
# @raise [ArgumentError]
|
280
|
+
def ensure_persisted(resource)
|
281
|
+
raise ArgumentError, 'resource is not saved' unless resource.persisted?
|
282
|
+
end
|
283
283
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
284
|
+
# Accesses the data type in PostgreSQL used for the primary key
|
285
|
+
# (For example, a UUID)
|
286
|
+
# @see https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaCache.html#method-i-columns_hash
|
287
|
+
# @return [Symbol]
|
288
|
+
def id_type
|
289
|
+
@id_type ||= orm_class.columns_hash["id"].type
|
290
|
+
end
|
291
291
|
|
292
|
-
|
293
|
-
|
294
|
-
|
292
|
+
def ordered_property?(resource:, property:)
|
293
|
+
resource.ordered_attribute?(property)
|
294
|
+
end
|
295
295
|
end
|
296
296
|
end
|
@@ -65,412 +65,412 @@ module Valkyrie::Persistence::Solr
|
|
65
65
|
|
66
66
|
private
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end
|
68
|
+
# Maps Solr Document fields to attributes with single values
|
69
|
+
# Filters for fields which store the Valkyrie resource type
|
70
|
+
# @param [Hash] attribute_hash
|
71
|
+
# @return [Hash]
|
72
|
+
def add_single_values(attribute_hash)
|
73
|
+
attribute_hash.select do |k, v|
|
74
|
+
field = k.to_s.split("_").last
|
75
|
+
property = k.to_s.gsub("_#{field}", "")
|
76
|
+
next true if multivalued?(field)
|
77
|
+
next false if property == "internal_resource"
|
78
|
+
next false if v.length > 1
|
79
|
+
true
|
81
80
|
end
|
81
|
+
end
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
83
|
+
# Determines whether or not a field is multivalued
|
84
|
+
# @note this is tied to conventions in the Solr Schema
|
85
|
+
# @see https://github.com/samvera-labs/valkyrie/blob/master/solr/config/schema.xml
|
86
|
+
# @see https://lucene.apache.org/solr/guide/defining-fields.html#defining-fields
|
87
|
+
# @param [String] field
|
88
|
+
# @return [Boolean]
|
89
|
+
def multivalued?(field)
|
90
|
+
field.end_with?('m', 'mv')
|
91
|
+
end
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
93
|
+
# If optimistic locking is enabled for this Valkyrie Resource, generates a Hash containing the locking token
|
94
|
+
# @return [Hash]
|
95
|
+
def lock_hash
|
96
|
+
return {} unless resource.optimistic_locking_enabled? && lock_token.present?
|
97
|
+
{ _version_: lock_token }
|
98
|
+
end
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
100
|
+
# Retrieves the lock token from the resource attributes
|
101
|
+
# @return [String]
|
102
|
+
def lock_token
|
103
|
+
@lock_token ||= begin
|
104
|
+
found_token = resource[Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK]
|
105
|
+
.find { |token| token.adapter_id == resource_factory.adapter_id }
|
106
|
+
return if found_token.nil?
|
107
|
+
found_token.token
|
109
108
|
end
|
109
|
+
end
|
110
110
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
end
|
111
|
+
# Generates the Valkyrie Resource attribute Hash
|
112
|
+
# @return [Hash]
|
113
|
+
def attribute_hash
|
114
|
+
properties.each_with_object({}) do |property, hsh|
|
115
|
+
next if property == Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK
|
116
|
+
attr = resource_attributes[property]
|
117
|
+
mapper_val = SolrMapperValue.for(Property.new(property, attr)).result
|
118
|
+
unless mapper_val.respond_to?(:apply_to)
|
119
|
+
raise "Unable to cast #{resource_attributes[:internal_resource]}#" \
|
120
|
+
"#{property} which has been set to an instance of '#{attr.class}'"
|
121
|
+
end
|
122
|
+
mapper_val.apply_to(hsh)
|
124
123
|
end
|
124
|
+
end
|
125
125
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
end
|
126
|
+
# Accesses the keys for the attributes on the Valkyrie Resource
|
127
|
+
# @return [Array<Symbol>]
|
128
|
+
def properties
|
129
|
+
resource_attributes.keys - [:id, :created_at, :updated_at, :new_record]
|
130
|
+
end
|
131
|
+
|
132
|
+
# Access the attributes for the Valkyrie resources
|
133
|
+
# @return [Hash]
|
134
|
+
def resource_attributes
|
135
|
+
@resource_attributes ||= resource.attributes
|
136
|
+
end
|
137
|
+
|
138
|
+
##
|
139
|
+
# A container resource for holding a `key`, `value, and `scope` of a value
|
140
|
+
# in a resource together for casting.
|
141
|
+
class Property
|
142
|
+
attr_reader :key, :value, :scope
|
143
|
+
# @param key [Symbol] Property identifier.
|
144
|
+
# @param value [Object] Value or list of values which are underneath the
|
145
|
+
# key.
|
146
|
+
# @param scope [Object] The resource or point where the key and values
|
147
|
+
# came from.
|
148
|
+
def initialize(key, value, scope = [])
|
149
|
+
@key = key
|
150
|
+
@value = value
|
151
|
+
@scope = scope
|
153
152
|
end
|
153
|
+
end
|
154
154
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
155
|
+
##
|
156
|
+
# Represents a key/value combination in the solr document, used for isolating logic around
|
157
|
+
# how to apply a value to a hash.
|
158
|
+
class SolrRow
|
159
|
+
attr_reader :key, :fields, :values
|
160
|
+
# @param key [Symbol] Solr key.
|
161
|
+
# @param fields [Array<Symbol>] Field suffixes to index into.
|
162
|
+
# @param values [Array] Values to index into the given fields.
|
163
|
+
def initialize(key:, fields:, values:)
|
164
|
+
@key = key
|
165
|
+
@fields = Array.wrap(fields)
|
166
|
+
@values = Array.wrap(values)
|
167
|
+
end
|
168
168
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
end
|
177
|
-
hsh
|
169
|
+
# @param hsh [Hash] The solr hash to apply to.
|
170
|
+
# @return [Hash] The updated solr hash.
|
171
|
+
def apply_to(hsh)
|
172
|
+
return hsh if values.blank?
|
173
|
+
fields.each do |field|
|
174
|
+
hsh["#{key}_#{field}".to_sym] ||= []
|
175
|
+
hsh["#{key}_#{field}".to_sym] += values
|
178
176
|
end
|
177
|
+
hsh
|
179
178
|
end
|
179
|
+
end
|
180
180
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
181
|
+
##
|
182
|
+
# Wraps up multiple SolrRows to apply them all at once, while looking like
|
183
|
+
# just one.
|
184
|
+
class CompositeSolrRow
|
185
|
+
attr_reader :solr_rows
|
186
186
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
187
|
+
# @param [Array<Valkyrie::Persistence::Solr::Mapper::SolrRow>] solr_rows
|
188
|
+
def initialize(solr_rows)
|
189
|
+
@solr_rows = solr_rows
|
190
|
+
end
|
191
191
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
end
|
199
|
-
hsh
|
192
|
+
# Merge a Hash of attribute values into a logical row of Solr fields
|
193
|
+
# @param [Hash] hsh
|
194
|
+
# @see Valkyrie::Persistence::Solr::Mapper::SolrRow#apply_to
|
195
|
+
def apply_to(hsh)
|
196
|
+
solr_rows.each do |solr_row|
|
197
|
+
solr_row.apply_to(hsh)
|
200
198
|
end
|
199
|
+
hsh
|
201
200
|
end
|
201
|
+
end
|
202
202
|
|
203
|
-
|
204
|
-
|
205
|
-
|
203
|
+
# Container for casting mappers.
|
204
|
+
class SolrMapperValue < ::Valkyrie::ValueMapper
|
205
|
+
end
|
206
206
|
|
207
|
-
|
208
|
-
|
209
|
-
|
207
|
+
# Casts {Boolean} values into a recognizable string in Solr.
|
208
|
+
class BooleanPropertyValue < ::Valkyrie::ValueMapper
|
209
|
+
SolrMapperValue.register(self)
|
210
210
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
211
|
+
# Determines whether or not a Property value behaves like a boolean value
|
212
|
+
# @param [Object] value
|
213
|
+
# @return [Boolean]
|
214
|
+
def self.handles?(value)
|
215
|
+
value.is_a?(Property) && ([true, false].include? value.value)
|
216
|
+
end
|
217
217
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
end
|
218
|
+
# Constructs a SolrRow object for a Property with a Boolean value
|
219
|
+
# @note this prepends the string "boolean-" to the value indexed in Solr
|
220
|
+
# @return [SolrRow]
|
221
|
+
def result
|
222
|
+
calling_mapper.for(Property.new(value.key, "boolean-#{value.value}")).result
|
224
223
|
end
|
224
|
+
end
|
225
225
|
|
226
|
-
|
227
|
-
|
228
|
-
|
226
|
+
# Casts nested resources into a JSON string in solr.
|
227
|
+
class NestedObjectValue < ::Valkyrie::ValueMapper
|
228
|
+
SolrMapperValue.register(self)
|
229
229
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
230
|
+
# Determines whether or not a Property value is a Hash
|
231
|
+
# @param [Object] value
|
232
|
+
# @return [Boolean]
|
233
|
+
def self.handles?(value)
|
234
|
+
value.value.is_a?(Hash) || value.value.is_a?(Valkyrie::Resource)
|
235
|
+
end
|
236
236
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
end
|
237
|
+
# Constructs a SolrRow object for a Property with a Hash value
|
238
|
+
# @note this prepends the string "serialized-" to the value indexed in Solr
|
239
|
+
# This is indexed as a stored multivalued text
|
240
|
+
# @see https://lucene.apache.org/solr/guide/defining-fields.html#defining-fields
|
241
|
+
# @see https://github.com/samvera-labs/valkyrie/blob/master/solr/config/schema.xml
|
242
|
+
# @return [SolrRow]
|
243
|
+
def result
|
244
|
+
SolrRow.new(key: value.key, fields: ["tsim"], values: "serialized-#{value.value.to_json}")
|
246
245
|
end
|
246
|
+
end
|
247
247
|
|
248
|
-
|
249
|
-
|
250
|
-
|
248
|
+
# Casts enumerable values one by one.
|
249
|
+
class EnumerableValue < ::Valkyrie::ValueMapper
|
250
|
+
SolrMapperValue.register(self)
|
251
251
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
252
|
+
# Determines whether or not a Property value is an Array
|
253
|
+
# @param [Object] value
|
254
|
+
# @return [Boolean]
|
255
|
+
def self.handles?(value)
|
256
|
+
value.is_a?(Property) && value.value.is_a?(Array)
|
257
|
+
end
|
258
258
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
end
|
259
|
+
# Constructs a CompositeSolrRow object for a set of Property values
|
260
|
+
# @return [CompositeSolrRow]
|
261
|
+
def result
|
262
|
+
CompositeSolrRow.new(
|
263
|
+
value.value.map do |val|
|
264
|
+
calling_mapper.for(Property.new(value.key, val, value.value)).result
|
265
|
+
end
|
266
|
+
)
|
268
267
|
end
|
268
|
+
end
|
269
269
|
|
270
|
-
|
271
|
-
|
272
|
-
|
270
|
+
# Skips nil values.
|
271
|
+
class NilPropertyValue < ::Valkyrie::ValueMapper
|
272
|
+
SolrMapperValue.register(self)
|
273
273
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
274
|
+
# Determines whether or not a Property value responds as nil
|
275
|
+
# @param [Object] value
|
276
|
+
# @return [Boolean]
|
277
|
+
def self.handles?(value)
|
278
|
+
value.is_a?(Property) && value.value.nil?
|
279
|
+
end
|
280
280
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
end
|
281
|
+
# Constructs a SolrRow object for a Property with a nil value
|
282
|
+
# @return [SolrRow]
|
283
|
+
def result
|
284
|
+
SolrRow.new(key: value.key, fields: [], values: nil)
|
286
285
|
end
|
286
|
+
end
|
287
287
|
|
288
|
-
|
289
|
-
|
290
|
-
|
288
|
+
# Casts {Valkyrie::ID} values into a recognizable string in solr.
|
289
|
+
class IDPropertyValue < ::Valkyrie::ValueMapper
|
290
|
+
SolrMapperValue.register(self)
|
291
291
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
292
|
+
# Determines whether or not a Property value is a Valkyrie ID
|
293
|
+
# @param [Object] value
|
294
|
+
# @return [Boolean]
|
295
|
+
def self.handles?(value)
|
296
|
+
value.is_a?(Property) && value.value.is_a?(::Valkyrie::ID)
|
297
|
+
end
|
298
298
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
end
|
299
|
+
# Constructs a SolrRow object for the Property Valkyrie ID value
|
300
|
+
# @note this prepends the string "id-" to the value indexed in Solr
|
301
|
+
# @return [SolrRow]
|
302
|
+
def result
|
303
|
+
calling_mapper.for(Property.new(value.key, "id-#{value.value.id}")).result
|
305
304
|
end
|
305
|
+
end
|
306
306
|
|
307
|
-
|
308
|
-
|
309
|
-
|
307
|
+
# Casts {RDF::URI} values into a recognizable string in solr.
|
308
|
+
class URIPropertyValue < ::Valkyrie::ValueMapper
|
309
|
+
SolrMapperValue.register(self)
|
310
310
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
311
|
+
# Determines whether or not a Property value is a URI
|
312
|
+
# @param [Object] value
|
313
|
+
# @return [Boolean]
|
314
|
+
def self.handles?(value)
|
315
|
+
value.is_a?(Property) && value.value.is_a?(::RDF::URI)
|
316
|
+
end
|
317
317
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
end
|
318
|
+
# Constructs a SolrRow object for the Property URI value
|
319
|
+
# @note this prepends the string "uri-" to the value indexed in Solr
|
320
|
+
# @return [SolrRow]
|
321
|
+
def result
|
322
|
+
calling_mapper.for(Property.new(value.key, "uri-#{value.value}")).result
|
324
323
|
end
|
324
|
+
end
|
325
325
|
|
326
|
-
|
327
|
-
|
328
|
-
|
326
|
+
# Casts {Integer} values into a recognizable string in Solr.
|
327
|
+
class IntegerPropertyValue < ::Valkyrie::ValueMapper
|
328
|
+
SolrMapperValue.register(self)
|
329
329
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
330
|
+
# Determines whether or not a Property value is an Integer
|
331
|
+
# @param [Object] value
|
332
|
+
# @return [Boolean]
|
333
|
+
def self.handles?(value)
|
334
|
+
value.is_a?(Property) && value.value.is_a?(Integer)
|
335
|
+
end
|
336
336
|
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
end
|
337
|
+
# Constructs a SolrRow object for the Property Integer value
|
338
|
+
# @note this prepends the string "integer-" to the value indexed in Solr
|
339
|
+
# @return [SolrRow]
|
340
|
+
def result
|
341
|
+
calling_mapper.for(Property.new(value.key, "integer-#{value.value}")).result
|
343
342
|
end
|
343
|
+
end
|
344
344
|
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
345
|
+
# Casts {Float} values into a recognizable string in Solr.
|
346
|
+
class FloatPropertyValue < ::Valkyrie::ValueMapper
|
347
|
+
SolrMapperValue.register(self)
|
348
|
+
def self.handles?(value)
|
349
|
+
value.is_a?(Property) && value.value.is_a?(Float)
|
350
|
+
end
|
351
351
|
|
352
|
-
|
353
|
-
|
354
|
-
end
|
352
|
+
def result
|
353
|
+
calling_mapper.for(Property.new(value.key, "float-#{value.value}")).result
|
355
354
|
end
|
355
|
+
end
|
356
356
|
|
357
|
-
|
358
|
-
|
359
|
-
|
357
|
+
# Casts {DateTime} values into a recognizable string in Solr.
|
358
|
+
class DateTimePropertyValue < ::Valkyrie::ValueMapper
|
359
|
+
SolrMapperValue.register(self)
|
360
360
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
361
|
+
# Determines whether or not a Property value is a DateTime or Time
|
362
|
+
# @param [Object] value
|
363
|
+
# @return [Boolean]
|
364
|
+
def self.handles?(value)
|
365
|
+
value.is_a?(Property) && (value.value.is_a?(Time) || value.value.is_a?(DateTime))
|
366
|
+
end
|
367
367
|
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
368
|
+
# Constructs a SolrRow object for a datestamp derived from the value
|
369
|
+
# @note this prepends the string "datetime-" to the value indexed in Solr
|
370
|
+
# @return [SolrRow]
|
371
|
+
def result
|
372
|
+
calling_mapper.for(Property.new(value.key, "datetime-#{JSON.parse(to_datetime(value.value).to_json)}")).result
|
373
|
+
end
|
374
374
|
|
375
|
-
|
375
|
+
private
|
376
376
|
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
end
|
377
|
+
# Converts a value to a UTC timestamp if it is a DateTime or behaves like a Time value
|
378
|
+
# @param [Object] value
|
379
|
+
# @return [Time]
|
380
|
+
def to_datetime(value)
|
381
|
+
return value.new_offset(0) if value.is_a?(DateTime)
|
382
|
+
return value.to_datetime.new_offset(0) if value.respond_to?(:to_datetime)
|
384
383
|
end
|
384
|
+
end
|
385
385
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
386
|
+
# Handles casting language-tagged strings when there are both
|
387
|
+
# language-tagged and non-language-tagged strings in Solr. Assumes English
|
388
|
+
# for non-language-tagged strings.
|
389
|
+
class SharedStringPropertyValue < ::Valkyrie::ValueMapper
|
390
|
+
SolrMapperValue.register(self)
|
391
391
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
392
|
+
# Determines whether or not a Property value is a String whether or not the Property has an RDF literal specifying the language tag
|
393
|
+
# @param [Object] value
|
394
|
+
# @return [Boolean]
|
395
|
+
def self.handles?(value)
|
396
|
+
value.is_a?(Property) && value.value.is_a?(String) && value.scope.find { |x| x.is_a?(::RDF::Literal) }.present?
|
397
|
+
end
|
398
398
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
end
|
399
|
+
# Constructs a CompositeSolrRow object with the language-tagged literal value
|
400
|
+
# @return [CompositeSolrRow]
|
401
|
+
def result
|
402
|
+
CompositeSolrRow.new(
|
403
|
+
[
|
404
|
+
calling_mapper.for(Property.new(value.key, value.value)).result,
|
405
|
+
calling_mapper.for(Property.new("#{value.key}_lang", "eng")).result,
|
406
|
+
calling_mapper.for(Property.new("#{value.key}_type", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString")).result
|
407
|
+
]
|
408
|
+
)
|
410
409
|
end
|
410
|
+
end
|
411
411
|
|
412
|
-
|
413
|
-
|
414
|
-
|
412
|
+
# Handles casting strings.
|
413
|
+
class StringPropertyValue < ::Valkyrie::ValueMapper
|
414
|
+
SolrMapperValue.register(self)
|
415
415
|
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
416
|
+
# Determines whether or not a Property value is a String
|
417
|
+
# @param [Object] value
|
418
|
+
# @return [Boolean]
|
419
|
+
def self.handles?(value)
|
420
|
+
value.is_a?(Property) && value.value.is_a?(String)
|
421
|
+
end
|
422
422
|
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
423
|
+
# Constructs a SolrRow object with the String values and Solr field settings
|
424
|
+
# @return [SolrRow]
|
425
|
+
def result
|
426
|
+
SolrRow.new(key: value.key, fields: fields, values: value.value)
|
427
|
+
end
|
428
428
|
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
end
|
429
|
+
# Generates the Solr fields used during the indexing
|
430
|
+
# String are normally indexed using the following:
|
431
|
+
# - stored text
|
432
|
+
# - stored english text
|
433
|
+
# - stored single string
|
434
|
+
# - multivalued string
|
435
|
+
# - stored multivalued text
|
436
|
+
# - stored multivalued english text
|
437
|
+
# If the string is greater than 1000 characters in length, it is only indexed as a stored multivalued text
|
438
|
+
# @see https://lucene.apache.org/solr/guide/defining-fields.html#defining-fields
|
439
|
+
# @see https://github.com/samvera-labs/valkyrie/blob/master/solr/config/schema.xml
|
440
|
+
# @return [Array<Symbol>]
|
441
|
+
def fields
|
442
|
+
if value.value.length > 1000
|
443
|
+
[:tsim]
|
444
|
+
else
|
445
|
+
[:tsim, :ssim, :tesim, :tsi, :ssi, :tesi]
|
447
446
|
end
|
448
447
|
end
|
448
|
+
end
|
449
449
|
|
450
|
-
|
451
|
-
|
452
|
-
|
450
|
+
# Handles casting language-typed {RDF::Literal}s
|
451
|
+
class LiteralPropertyValue < ::Valkyrie::ValueMapper
|
452
|
+
SolrMapperValue.register(self)
|
453
453
|
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
454
|
+
# Determines whether or not a Property value is an RDF literal
|
455
|
+
# @param [Object] value
|
456
|
+
# @return [Boolean]
|
457
|
+
def self.handles?(value)
|
458
|
+
value.is_a?(Property) && value.value.is_a?(::RDF::Literal)
|
459
|
+
end
|
460
460
|
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
end
|
461
|
+
# Constructs a CompositeSolrRow object with the language-tagged literal value
|
462
|
+
# @return [CompositeSolrRow]
|
463
|
+
def result
|
464
|
+
key = value.key
|
465
|
+
val = value.value
|
466
|
+
CompositeSolrRow.new(
|
467
|
+
[
|
468
|
+
calling_mapper.for(Property.new(key, val.to_s)).result,
|
469
|
+
calling_mapper.for(Property.new("#{key}_lang", val.language.to_s)).result,
|
470
|
+
calling_mapper.for(Property.new("#{key}_type", val.datatype.to_s)).result
|
471
|
+
]
|
472
|
+
)
|
474
473
|
end
|
474
|
+
end
|
475
475
|
end
|
476
476
|
end
|