solis 0.72.0 → 0.74.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa7c729b1acbe8c1881ebf3cc00ac228830bf04d269447f55b2f029c7eef703c
4
- data.tar.gz: 81ceb99f9f6284b8c4163bfe4d263f6703edbe1733eb42fcc6c31530be2c8d91
3
+ metadata.gz: 166805286e332f8a5a9f572fa6ab7841f2f234223384b298139fa25d8339cf91
4
+ data.tar.gz: e43b4f5b33c911c8759e96012165cd9203b6941113e511442d169b0acd61bfe3
5
5
  SHA512:
6
- metadata.gz: 6a5fe949952a2931c1189644690446ddc0b63ca719eb2f4b15f5cab83779d81b50872c3b57d4b677278cc4c6ca1e54ff8f14ff4b8c09ce842e8e5a3226835177
7
- data.tar.gz: 03af55e0505d6e987522e8d799450be43a83b9968c60f7741b7c5bb2d75f0874d7d127b955f31ad028a35b2993b2ecdefb91653edf5e9941c4e7dfc796658696
6
+ metadata.gz: 7a091ee239234b0a71cfde2cbebb19905af07af63bf2e58dedb6c0178a7f2c4ac9d3f875df509cecf689857c4dcfac2cc76fa0f4b8dc4ef2d7b1df566af4edc8
7
+ data.tar.gz: 96dc87a0b2b208f6f56adcae71b391a7cbd18b22ac2ba4ea6d936d87d39bd98d88a2c74bed54d12c6a73fa00896ec23dbd60bf4b52474cc5d7f11f4048188961
data/lib/solis/graph.rb CHANGED
@@ -351,7 +351,7 @@ module Solis
351
351
 
352
352
  @sparql_client = SPARQL::Client.new(@sparql_endpoint)
353
353
  result = @sparql_client.query("with <#{graph_name}> delete {?s ?p ?o} where{?s ?p ?o}")
354
- LOGGER.info(result.first.to_a.first.last.value)
354
+ LOGGER.info(result)
355
355
  true
356
356
  end
357
357
 
data/lib/solis/model.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'securerandom'
2
2
  require 'iso8601'
3
+ require 'hashdiff'
3
4
  require_relative 'query'
4
5
 
5
6
  module Solis
@@ -71,9 +72,9 @@ module Solis
71
72
  def query
72
73
  raise "I need a SPARQL endpoint" if self.class.sparql_endpoint.nil?
73
74
 
74
- #before_read_proc&.call(self)
75
+ # before_read_proc&.call(self)
75
76
  result = Solis::Query.new(self)
76
- #after_read_proc&.call(result)
77
+ # after_read_proc&.call(result)
77
78
  result
78
79
  end
79
80
 
@@ -111,7 +112,7 @@ module Solis
111
112
  sparql = SPARQL::Client.new(self.class.sparql_endpoint)
112
113
 
113
114
  raise Solis::Error::QueryError, "#{self.id} is still referenced, refusing to delete" if is_referenced?(sparql)
114
- #sparql.query('delete{}')
115
+ # sparql.query('delete{}')
115
116
  before_delete_proc&.call(self)
116
117
  # graph = as_graph(self, false)
117
118
  # Solis::LOGGER.info graph.dump(:ttl) if ConfigFile[:debug]
@@ -136,8 +137,8 @@ values ?s {<#{self.graph_id}>}
136
137
 
137
138
  before_create_proc&.call(self)
138
139
 
139
- if exists?(sparql)
140
- data = Model.properties_to_hash(self)
140
+ if self.exists?(sparql)
141
+ data = properties_to_hash(self)
141
142
 
142
143
  result = update(data)
143
144
  else
@@ -173,47 +174,169 @@ values ?s {<#{self.graph_id}>}
173
174
  raise Solis::Error::NotFoundError if original_klass.nil?
174
175
  updated_klass = original_klass.deep_dup
175
176
 
176
- attributes.each_pair do |key, value|
177
+ attributes.each_pair do |key, value| # check each key. if it is an entity process it
178
+ unless original_klass.class.metadata[:attributes][key][:node].nil? #it is an entity
179
+ value = [value] unless value.is_a?(Array)
180
+ value.each do |sub_value|
181
+ embedded = self.class.graph.shape_as_model(original_klass.class.metadata[:attributes][key][:datatype].to_s).new(sub_value)
182
+ if embedded.exists?(sparql)
183
+ embedded_data = properties_to_hash(embedded)
184
+ embedded.update(embedded_data)
185
+ else
186
+ embedded.save
187
+ end
188
+ end
189
+ end
190
+
177
191
  updated_klass.instance_variable_set("@#{key}", value)
178
192
  end
179
193
 
194
+
195
+ # attributes.each_pair do |key, value|
196
+ # if value.is_a?(Hash)
197
+ # embedded = self.class.graph.shape_as_model(original_klass.class.metadata[:attributes][key][:datatype].to_s).new(value)
198
+ # if embedded.exists?(sparql)
199
+ # embedded_data = properties_to_hash(embedded)
200
+ # embedded.update(embedded_data)
201
+ # else
202
+ # embedded.save
203
+ # end
204
+ # elsif value.is_a?(Array)
205
+ # value.each do |sub_value|
206
+ # if sub_value.is_a?(Hash)
207
+ # if embedded.exists?(sparql)
208
+ # embedded_data = properties_to_hash(embedded)
209
+ # embedded.update(embedded_data)
210
+ # else
211
+ # embedded.save
212
+ # end
213
+ # end
214
+ # end
215
+ # end
216
+ #
217
+ # updated_klass.instance_variable_set("@#{key}", value)
218
+ # end
219
+
220
+ # attributes.each_pair do |key, value|
221
+ # updated_klass.instance_variable_set("@#{key}", value)
222
+ # end
223
+ # properties_original_klass=Model.properties_to_hash(original_klass)
224
+ # properties_updated_klass = Model.properties_to_hash(updated_klass)
225
+ # changes = Hashdiff.diff(properties_original_klass, properties_updated_klass)
226
+ # pp changes
227
+ #
228
+ # #a=self.class.graph.shape_as_model('Identificatienummer').new
229
+ # changes.each do |change|
230
+ # change_type = change[0]
231
+ # original_change_entity = change[1]
232
+ # change_entity = original_change_entity.split('.').last
233
+ # change[1] = change_object
234
+ # data = change[2]
235
+ #
236
+ # case change_type
237
+ # when '+' # new
238
+ # new_entity_hash = {} #self.class.graph.shape_as_model(change_object.classify).new
239
+ # Hashdiff.patch!(new_entity_hash, [change])
240
+ #
241
+ # new_entity = self.class.graph.shape_as_model(change_entity.classify).new(new_entity_hash[change_entity])
242
+ # new_entity.save
243
+ # when '-' # delete
244
+ # when '~' # change
245
+ # else
246
+ # raise RuntimeError, "Unknown change type(#{change_type}) for #{change[1]}"
247
+ # end
248
+ #
249
+ # end
250
+
251
+ # attributes.each_pair do |key, value|
252
+ # updated_klass.instance_variable_set("@#{key}", value)
253
+ # unless original_klass.class.metadata[:attributes][key][:node_kind].nil?
254
+ # inner_model = self.class.graph.shape_as_model(original_klass.class.metadata[:attributes][key][:datatype].to_s)
255
+ # if value.is_a?(Hash)
256
+ # value.each_pair do |inner_key, inner_value|
257
+ # next unless inner_model.metadata[:attributes][inner_key][:node_kind].is_a?(RDF::URI)
258
+ # inner_inner_model = self.class.graph.shape_as_model(inner_model.metadata[:attributes][inner_key][:datatype].to_s)
259
+ # # if inner_inner_model.class.ancestors.include?(Codetabel) && inner_value.key?('id')
260
+ # # inner_data = inner_inner_model.query.filter({ language: nil, filters: { id: [inner_value['id']] } }).find_all.map { |m| m }&.first
261
+ # # else
262
+ # inner_value = inner_value.first if inner_value.is_a?(Array)
263
+ # inner_data = inner_inner_model.new(inner_value)
264
+ # inner_data.save
265
+ # # end
266
+ # end
267
+ # elsif value.is_a?(Array)
268
+ # data = value.map do |m|
269
+ # if m.is_a?(Hash)
270
+ # m.each do |inner_key, inner_value|
271
+ # #next if inner_model.metadata[:attributes][inner_key][:class].nil?
272
+ # next unless inner_model.metadata[:attributes][inner_key][:node_kind].is_a?(RDF::URI)
273
+ # inner_inner_model = self.class.graph.shape_as_model(inner_model.class.metadata[:attributes][inner_key][:datatype].to_s)
274
+ # # if inner_inner_model.class.ancestors.include?(Codetabel) && inner_value.key?('id')
275
+ # # inner_data = inner_inner_model.query.filter({ language: nil, filters: { id: [inner_value['id']] } }).find_all.map { |m| m }&.first
276
+ # # else
277
+ # inner_value = inner_value.first if inner_value.is_a?(Array)
278
+ # inner_data = inner_inner_model.new(inner_value)
279
+ # inner_data.save
280
+ # # end
281
+ #
282
+ # inner_data
283
+ # end
284
+ # else
285
+ # m
286
+ # end
287
+ # end
288
+ # elsif value.is_a?(Object)
289
+ # value.save
290
+ # end
291
+ # end
292
+ # end
293
+
180
294
  before_update_proc&.call(original_klass, updated_klass)
181
295
 
182
- delete_graph = as_graph(original_klass, false)
296
+ properties_orignal_klass = properties_to_hash(original_klass)
297
+ properties_updated_klass = properties_to_hash(updated_klass)
298
+
299
+ if Hashdiff.best_diff(properties_orignal_klass, properties_updated_klass).empty?
300
+ Solis::LOGGER.info("#{original_klass.class.name} unchanged, skipping")
301
+ data = self.query.filter({ filters: { id: [id] } }).find_all.map { |m| m }&.first
302
+ else
183
303
 
184
- where_graph = RDF::Graph.new(graph_name: RDF::URI("#{self.class.graph_name}#{self.name.tableize}/#{id}"), data: RDF::Repository.new)
304
+ delete_graph = as_graph(original_klass, false)
185
305
 
186
- if id.is_a?(Array)
187
- id.each do |i|
188
- where_graph << [RDF::URI("#{self.class.graph_name}#{self.name.tableize}/#{i}"), :p, :o]
306
+ where_graph = RDF::Graph.new(graph_name: RDF::URI("#{self.class.graph_name}#{self.name.tableize}/#{id}"), data: RDF::Repository.new)
307
+
308
+ if id.is_a?(Array)
309
+ id.each do |i|
310
+ where_graph << [RDF::URI("#{self.class.graph_name}#{self.name.tableize}/#{i}"), :p, :o]
311
+ end
312
+ else
313
+ where_graph << [RDF::URI("#{self.class.graph_name}#{self.name.tableize}/#{id}"), :p, :o]
189
314
  end
190
- else
191
- where_graph << [RDF::URI("#{self.class.graph_name}#{self.name.tableize}/#{id}"), :p, :o]
192
- end
193
315
 
194
- insert_graph = as_graph(updated_klass, true)
316
+ insert_graph = as_graph(updated_klass, true)
195
317
 
196
- puts delete_graph.dump(:ttl) #if ConfigFile[:debug]
197
- puts insert_graph.dump(:ttl) #if ConfigFile[:debug]
198
- puts where_graph.dump(:ttl) #if ConfigFile[:debug]
318
+ # puts delete_graph.dump(:ttl) #if ConfigFile[:debug]
319
+ # puts insert_graph.dump(:ttl) #if ConfigFile[:debug]
320
+ # puts where_graph.dump(:ttl) #if ConfigFile[:debug]
199
321
 
200
- #if ConfigFile[:debug]
201
- delete_insert_query = SPARQL::Client::Update::DeleteInsert.new(delete_graph, insert_graph, where_graph, graph: insert_graph.name).to_s
202
- delete_insert_query.gsub!('_:p', '?p')
203
- puts delete_insert_query
204
- data = sparql.query(delete_insert_query)
205
- #pp data
206
- #end
322
+ # if ConfigFile[:debug]
323
+ delete_insert_query = SPARQL::Client::Update::DeleteInsert.new(delete_graph, insert_graph, where_graph, graph: insert_graph.name).to_s
324
+ delete_insert_query.gsub!('_:p', '?p')
325
+ # puts delete_insert_query
326
+ data = sparql.query(delete_insert_query)
327
+ # pp data
328
+ # end
207
329
 
208
- # sparql.delete_insert(delete_graph, insert_graph, where_graph, graph: insert_graph.name)
330
+ # sparql.delete_insert(delete_graph, insert_graph, where_graph, graph: insert_graph.name)
209
331
 
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
332
  data = self.query.filter({ filters: { id: [id] } }).find_all.map { |m| m }&.first
333
+ if data.nil?
334
+ sparql.insert_data(insert_graph, graph: insert_graph.name)
335
+ data = self.query.filter({ filters: { id: [id] } }).find_all.map { |m| m }&.first
336
+ end
214
337
  end
215
-
216
338
  after_update_proc&.call(updated_klass, data)
339
+
217
340
  data
218
341
  rescue StandardError => e
219
342
  original_graph = as_graph(original_klass, false)
@@ -386,7 +509,7 @@ values ?s {<#{self.graph_id}>}
386
509
 
387
510
  graph << [id, RDF::RDFV.type, klass_metadata[:target_class]]
388
511
 
389
- #load existing object and overwrite
512
+ # load existing object and overwrite
390
513
  original_klass = klass.query.filter({ filters: { id: [uuid] } }).find_all { |f| f.id == uuid }.first || nil
391
514
 
392
515
  if original_klass.nil?
@@ -411,11 +534,9 @@ values ?s {<#{self.graph_id}>}
411
534
  def make_graph(graph, hierarchy, id, klass, klass_metadata, resolve_all)
412
535
  klass_metadata[:attributes].each do |attribute, metadata|
413
536
  data = klass.instance_variable_get("@#{attribute}")
414
-
415
- raise Solis::Error::InvalidAttributeError,
416
- "#{hierarchy.join('.')}.#{attribute} min=#{metadata[:mincount]} and max=#{metadata[:maxcount]}" if data.nil? &&
417
- metadata[:mincount] > 0 &&
418
- graph.query(RDF::Query.new({ attribute.to_sym => { RDF.type => metadata[:node] } })).size == 0
537
+ if data.nil? && metadata[:mincount] > 0 && graph.query(RDF::Query.new({ attribute.to_sym => { RDF.type => metadata[:node] } })).size == 0
538
+ raise Solis::Error::InvalidAttributeError, "#{hierarchy.join('.')}.#{attribute} min=#{metadata[:mincount]} and max=#{metadata[:maxcount]}"
539
+ end
419
540
 
420
541
  # skip if nil or an object that is empty
421
542
  next if data.nil? || ([Hash, Array, String].include?(data.class) && data&.empty?)
@@ -427,7 +548,7 @@ values ?s {<#{self.graph_id}>}
427
548
  data = data.to_json
428
549
  end
429
550
 
430
- #make it an object
551
+ # make it an object
431
552
  unless metadata[:node_kind].nil?
432
553
  model = self.class.graph.shape_as_model(metadata[:datatype].to_s)
433
554
  if data.is_a?(Hash)
@@ -449,7 +570,7 @@ values ?s {<#{self.graph_id}>}
449
570
  internal_resolve = false
450
571
  d = build_ttl_objekt2(graph, d, hierarchy, internal_resolve)
451
572
  else
452
- #d = "#{klass.class.graph_name}#{attribute.tableize}/#{d.id}"
573
+ # d = "#{klass.class.graph_name}#{attribute.tableize}/#{d.id}"
453
574
  d = "#{klass.class.graph_name}#{d.name.tableize}/#{d.id}"
454
575
  end
455
576
  elsif defined?(d.name) && self.class.graph.shape?(d.name)
@@ -554,7 +675,7 @@ values ?s {<#{self.graph_id}>}
554
675
  end
555
676
 
556
677
  if model && d.is_a?(Hash)
557
- #TODO: figure out in what use case we need the parent_model
678
+ # TODO: figure out in what use case we need the parent_model
558
679
  # model_instance = if parent_model
559
680
  # parent_model.new(d)
560
681
  # else
@@ -606,7 +727,7 @@ values ?s {<#{self.graph_id}>}
606
727
  id
607
728
  end
608
729
 
609
- def self.properties_to_hash(model)
730
+ def properties_to_hash(model)
610
731
  n = {}
611
732
  model.class.metadata[:attributes].each_key do |m|
612
733
  if model.instance_variable_get("@#{m}").is_a?(Array)
data/lib/solis/query.rb CHANGED
@@ -191,11 +191,11 @@ order by ?s
191
191
  from_cache = Graphiti.context[:object]&.from_cache || '0'
192
192
  if @query_cache.key?(query_key) && from_cache.eql?('1')
193
193
  result = @query_cache[query_key]
194
- Solis::LOGGER.info("CACHE: from #{query_key}")# if ConfigFile[:debug]
194
+ Solis::LOGGER.info("CACHE: from #{query_key}") if ConfigFile[:debug]
195
195
  else
196
196
  result = graph_to_object(sparql_client.query(query))
197
197
  @query_cache[query_key] = result unless result.nil? || result.empty?
198
- Solis::LOGGER.info("CACHE: to #{query_key}")# if ConfigFile[:debug]
198
+ Solis::LOGGER.info("CACHE: to #{query_key}") if ConfigFile[:debug]
199
199
  end
200
200
 
201
201
  result
data/lib/solis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Solis
2
- VERSION = "0.72.0"
2
+ VERSION = "0.74.0"
3
3
  end
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.72.0
4
+ version: 0.74.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-02-28 00:00:00.000000000 Z
11
+ date: 2024-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport