solis 0.72.0 → 0.73.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/solis/model.rb +130 -39
- data/lib/solis/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a91e5038f9e0a152b51ad35d25c6bdd99ef383bfb0da8fb7baf1d08baddbf49a
|
4
|
+
data.tar.gz: b4b1a434aae6a337358815e8b0dc5ff37edea7e0ffb56d85a9d7d1590677ea92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35f713d36e731ac83203fec6f3d82bd6ad5f321c68ccf1424fd8f0c6b82183392e2c76d62cdd7eac6542318810c62940d9a4e1badb5dd817177509bf65753c9e
|
7
|
+
data.tar.gz: 5a9efc223d46e01936aed52e649e856344c7847307f6a39d7b094b48d2b553542a8059ce846bd483634cfb7046f9ab9646ed2130bab81de5c196b43af48b95c2
|
data/lib/solis/model.rb
CHANGED
@@ -71,9 +71,9 @@ module Solis
|
|
71
71
|
def query
|
72
72
|
raise "I need a SPARQL endpoint" if self.class.sparql_endpoint.nil?
|
73
73
|
|
74
|
-
#before_read_proc&.call(self)
|
74
|
+
# before_read_proc&.call(self)
|
75
75
|
result = Solis::Query.new(self)
|
76
|
-
#after_read_proc&.call(result)
|
76
|
+
# after_read_proc&.call(result)
|
77
77
|
result
|
78
78
|
end
|
79
79
|
|
@@ -111,7 +111,7 @@ module Solis
|
|
111
111
|
sparql = SPARQL::Client.new(self.class.sparql_endpoint)
|
112
112
|
|
113
113
|
raise Solis::Error::QueryError, "#{self.id} is still referenced, refusing to delete" if is_referenced?(sparql)
|
114
|
-
#sparql.query('delete{}')
|
114
|
+
# sparql.query('delete{}')
|
115
115
|
before_delete_proc&.call(self)
|
116
116
|
# graph = as_graph(self, false)
|
117
117
|
# Solis::LOGGER.info graph.dump(:ttl) if ConfigFile[:debug]
|
@@ -136,8 +136,8 @@ values ?s {<#{self.graph_id}>}
|
|
136
136
|
|
137
137
|
before_create_proc&.call(self)
|
138
138
|
|
139
|
-
if exists?(sparql)
|
140
|
-
data =
|
139
|
+
if self.exists?(sparql)
|
140
|
+
data = properties_to_hash(self)
|
141
141
|
|
142
142
|
result = update(data)
|
143
143
|
else
|
@@ -174,46 +174,139 @@ values ?s {<#{self.graph_id}>}
|
|
174
174
|
updated_klass = original_klass.deep_dup
|
175
175
|
|
176
176
|
attributes.each_pair do |key, value|
|
177
|
+
if value.is_a?(Hash)
|
178
|
+
embedded = self.class.graph.shape_as_model(original_klass.class.metadata[:attributes][key][:datatype].to_s).new(value)
|
179
|
+
if embedded.exists?(sparql)
|
180
|
+
embedded_data = properties_to_hash(embedded)
|
181
|
+
embedded.update(embedded_data)
|
182
|
+
else
|
183
|
+
embedded.save
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
177
187
|
updated_klass.instance_variable_set("@#{key}", value)
|
178
188
|
end
|
179
189
|
|
190
|
+
# attributes.each_pair do |key, value|
|
191
|
+
# updated_klass.instance_variable_set("@#{key}", value)
|
192
|
+
# end
|
193
|
+
# properties_original_klass=Model.properties_to_hash(original_klass)
|
194
|
+
# properties_updated_klass = Model.properties_to_hash(updated_klass)
|
195
|
+
# changes = Hashdiff.diff(properties_original_klass, properties_updated_klass)
|
196
|
+
# pp changes
|
197
|
+
#
|
198
|
+
# #a=self.class.graph.shape_as_model('Identificatienummer').new
|
199
|
+
# changes.each do |change|
|
200
|
+
# change_type = change[0]
|
201
|
+
# original_change_entity = change[1]
|
202
|
+
# change_entity = original_change_entity.split('.').last
|
203
|
+
# change[1] = change_object
|
204
|
+
# data = change[2]
|
205
|
+
#
|
206
|
+
# case change_type
|
207
|
+
# when '+' # new
|
208
|
+
# new_entity_hash = {} #self.class.graph.shape_as_model(change_object.classify).new
|
209
|
+
# Hashdiff.patch!(new_entity_hash, [change])
|
210
|
+
#
|
211
|
+
# new_entity = self.class.graph.shape_as_model(change_entity.classify).new(new_entity_hash[change_entity])
|
212
|
+
# new_entity.save
|
213
|
+
# when '-' # delete
|
214
|
+
# when '~' # change
|
215
|
+
# else
|
216
|
+
# raise RuntimeError, "Unknown change type(#{change_type}) for #{change[1]}"
|
217
|
+
# end
|
218
|
+
#
|
219
|
+
# end
|
220
|
+
|
221
|
+
# attributes.each_pair do |key, value|
|
222
|
+
# updated_klass.instance_variable_set("@#{key}", value)
|
223
|
+
# unless original_klass.class.metadata[:attributes][key][:node_kind].nil?
|
224
|
+
# inner_model = self.class.graph.shape_as_model(original_klass.class.metadata[:attributes][key][:datatype].to_s)
|
225
|
+
# if value.is_a?(Hash)
|
226
|
+
# value.each_pair do |inner_key, inner_value|
|
227
|
+
# next unless inner_model.metadata[:attributes][inner_key][:node_kind].is_a?(RDF::URI)
|
228
|
+
# inner_inner_model = self.class.graph.shape_as_model(inner_model.metadata[:attributes][inner_key][:datatype].to_s)
|
229
|
+
# # if inner_inner_model.class.ancestors.include?(Codetabel) && inner_value.key?('id')
|
230
|
+
# # inner_data = inner_inner_model.query.filter({ language: nil, filters: { id: [inner_value['id']] } }).find_all.map { |m| m }&.first
|
231
|
+
# # else
|
232
|
+
# inner_value = inner_value.first if inner_value.is_a?(Array)
|
233
|
+
# inner_data = inner_inner_model.new(inner_value)
|
234
|
+
# inner_data.save
|
235
|
+
# # end
|
236
|
+
# end
|
237
|
+
# elsif value.is_a?(Array)
|
238
|
+
# data = value.map do |m|
|
239
|
+
# if m.is_a?(Hash)
|
240
|
+
# m.each do |inner_key, inner_value|
|
241
|
+
# #next if inner_model.metadata[:attributes][inner_key][:class].nil?
|
242
|
+
# next unless inner_model.metadata[:attributes][inner_key][:node_kind].is_a?(RDF::URI)
|
243
|
+
# inner_inner_model = self.class.graph.shape_as_model(inner_model.class.metadata[:attributes][inner_key][:datatype].to_s)
|
244
|
+
# # if inner_inner_model.class.ancestors.include?(Codetabel) && inner_value.key?('id')
|
245
|
+
# # inner_data = inner_inner_model.query.filter({ language: nil, filters: { id: [inner_value['id']] } }).find_all.map { |m| m }&.first
|
246
|
+
# # else
|
247
|
+
# inner_value = inner_value.first if inner_value.is_a?(Array)
|
248
|
+
# inner_data = inner_inner_model.new(inner_value)
|
249
|
+
# inner_data.save
|
250
|
+
# # end
|
251
|
+
#
|
252
|
+
# inner_data
|
253
|
+
# end
|
254
|
+
# else
|
255
|
+
# m
|
256
|
+
# end
|
257
|
+
# end
|
258
|
+
# elsif value.is_a?(Object)
|
259
|
+
# value.save
|
260
|
+
# end
|
261
|
+
# end
|
262
|
+
# end
|
263
|
+
|
180
264
|
before_update_proc&.call(original_klass, updated_klass)
|
181
265
|
|
182
|
-
|
266
|
+
properties_orignal_klass = properties_to_hash(original_klass)
|
267
|
+
properties_updated_klsss = properties_to_hash(updated_klass)
|
268
|
+
|
269
|
+
if Hashdiff.best_diff(properties_orignal_klass, properties_updated_klsss).empty?
|
270
|
+
Solis::LOGGER.info("#{original_klass.class.name} unchanged, skipping")
|
271
|
+
data = self.query.filter({ filters: { id: [id] } }).find_all.map { |m| m }&.first
|
272
|
+
else
|
273
|
+
|
274
|
+
delete_graph = as_graph(original_klass, false)
|
183
275
|
|
184
|
-
|
276
|
+
where_graph = RDF::Graph.new(graph_name: RDF::URI("#{self.class.graph_name}#{self.name.tableize}/#{id}"), data: RDF::Repository.new)
|
185
277
|
|
186
|
-
|
187
|
-
|
188
|
-
|
278
|
+
if id.is_a?(Array)
|
279
|
+
id.each do |i|
|
280
|
+
where_graph << [RDF::URI("#{self.class.graph_name}#{self.name.tableize}/#{i}"), :p, :o]
|
281
|
+
end
|
282
|
+
else
|
283
|
+
where_graph << [RDF::URI("#{self.class.graph_name}#{self.name.tableize}/#{id}"), :p, :o]
|
189
284
|
end
|
190
|
-
else
|
191
|
-
where_graph << [RDF::URI("#{self.class.graph_name}#{self.name.tableize}/#{id}"), :p, :o]
|
192
|
-
end
|
193
285
|
|
194
|
-
|
286
|
+
insert_graph = as_graph(updated_klass, true)
|
195
287
|
|
196
|
-
|
197
|
-
|
198
|
-
|
288
|
+
# puts delete_graph.dump(:ttl) #if ConfigFile[:debug]
|
289
|
+
# puts insert_graph.dump(:ttl) #if ConfigFile[:debug]
|
290
|
+
# puts where_graph.dump(:ttl) #if ConfigFile[:debug]
|
199
291
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
292
|
+
# if ConfigFile[:debug]
|
293
|
+
delete_insert_query = SPARQL::Client::Update::DeleteInsert.new(delete_graph, insert_graph, where_graph, graph: insert_graph.name).to_s
|
294
|
+
delete_insert_query.gsub!('_:p', '?p')
|
295
|
+
# puts delete_insert_query
|
296
|
+
data = sparql.query(delete_insert_query)
|
297
|
+
# pp data
|
298
|
+
# end
|
207
299
|
|
208
|
-
|
300
|
+
# sparql.delete_insert(delete_graph, insert_graph, where_graph, graph: insert_graph.name)
|
209
301
|
|
210
|
-
data = self.query.filter({ filters: { id: [id] } }).find_all.map { |m| m }&.first
|
211
|
-
if data.nil?
|
212
|
-
sparql.insert_data(insert_graph, graph: insert_graph.name)
|
213
302
|
data = self.query.filter({ filters: { id: [id] } }).find_all.map { |m| m }&.first
|
303
|
+
if data.nil?
|
304
|
+
sparql.insert_data(insert_graph, graph: insert_graph.name)
|
305
|
+
data = self.query.filter({ filters: { id: [id] } }).find_all.map { |m| m }&.first
|
306
|
+
end
|
214
307
|
end
|
215
|
-
|
216
308
|
after_update_proc&.call(updated_klass, data)
|
309
|
+
|
217
310
|
data
|
218
311
|
rescue StandardError => e
|
219
312
|
original_graph = as_graph(original_klass, false)
|
@@ -386,7 +479,7 @@ values ?s {<#{self.graph_id}>}
|
|
386
479
|
|
387
480
|
graph << [id, RDF::RDFV.type, klass_metadata[:target_class]]
|
388
481
|
|
389
|
-
#load existing object and overwrite
|
482
|
+
# load existing object and overwrite
|
390
483
|
original_klass = klass.query.filter({ filters: { id: [uuid] } }).find_all { |f| f.id == uuid }.first || nil
|
391
484
|
|
392
485
|
if original_klass.nil?
|
@@ -411,11 +504,9 @@ values ?s {<#{self.graph_id}>}
|
|
411
504
|
def make_graph(graph, hierarchy, id, klass, klass_metadata, resolve_all)
|
412
505
|
klass_metadata[:attributes].each do |attribute, metadata|
|
413
506
|
data = klass.instance_variable_get("@#{attribute}")
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
metadata[:mincount] > 0 &&
|
418
|
-
graph.query(RDF::Query.new({ attribute.to_sym => { RDF.type => metadata[:node] } })).size == 0
|
507
|
+
if data.nil? && metadata[:mincount] > 0 && graph.query(RDF::Query.new({ attribute.to_sym => { RDF.type => metadata[:node] } })).size == 0
|
508
|
+
raise Solis::Error::InvalidAttributeError, "#{hierarchy.join('.')}.#{attribute} min=#{metadata[:mincount]} and max=#{metadata[:maxcount]}"
|
509
|
+
end
|
419
510
|
|
420
511
|
# skip if nil or an object that is empty
|
421
512
|
next if data.nil? || ([Hash, Array, String].include?(data.class) && data&.empty?)
|
@@ -427,7 +518,7 @@ values ?s {<#{self.graph_id}>}
|
|
427
518
|
data = data.to_json
|
428
519
|
end
|
429
520
|
|
430
|
-
#make it an object
|
521
|
+
# make it an object
|
431
522
|
unless metadata[:node_kind].nil?
|
432
523
|
model = self.class.graph.shape_as_model(metadata[:datatype].to_s)
|
433
524
|
if data.is_a?(Hash)
|
@@ -449,7 +540,7 @@ values ?s {<#{self.graph_id}>}
|
|
449
540
|
internal_resolve = false
|
450
541
|
d = build_ttl_objekt2(graph, d, hierarchy, internal_resolve)
|
451
542
|
else
|
452
|
-
#d = "#{klass.class.graph_name}#{attribute.tableize}/#{d.id}"
|
543
|
+
# d = "#{klass.class.graph_name}#{attribute.tableize}/#{d.id}"
|
453
544
|
d = "#{klass.class.graph_name}#{d.name.tableize}/#{d.id}"
|
454
545
|
end
|
455
546
|
elsif defined?(d.name) && self.class.graph.shape?(d.name)
|
@@ -554,7 +645,7 @@ values ?s {<#{self.graph_id}>}
|
|
554
645
|
end
|
555
646
|
|
556
647
|
if model && d.is_a?(Hash)
|
557
|
-
#TODO: figure out in what use case we need the parent_model
|
648
|
+
# TODO: figure out in what use case we need the parent_model
|
558
649
|
# model_instance = if parent_model
|
559
650
|
# parent_model.new(d)
|
560
651
|
# else
|
@@ -606,7 +697,7 @@ values ?s {<#{self.graph_id}>}
|
|
606
697
|
id
|
607
698
|
end
|
608
699
|
|
609
|
-
def
|
700
|
+
def properties_to_hash(model)
|
610
701
|
n = {}
|
611
702
|
model.class.metadata[:attributes].each_key do |m|
|
612
703
|
if model.instance_variable_get("@#{m}").is_a?(Array)
|
data/lib/solis/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.73.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mehmet Celik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|